From 35715a88980963ab917bf10085b1526b19ce7138 Mon Sep 17 00:00:00 2001 From: "Raoul v. R" Date: Tue, 18 Aug 2020 22:53:31 +0200 Subject: [PATCH] Version 6.1.0 --- build/sparse-octree.esm.js | 54 +- build/sparse-octree.js | 3413 +- build/sparse-octree.min.js | 4 +- package.json | 2 +- pnpm-lock.yaml | 3459 +- public/demo/index.js | 68894 +++++++++++++++++++++++++++++++---- public/demo/index.min.js | 21 +- public/docs/index.html | 6 +- public/docs/index.json | 4 +- 9 files changed, 64339 insertions(+), 11518 deletions(-) diff --git a/build/sparse-octree.esm.js b/build/sparse-octree.esm.js index a94688c..f89af49 100644 --- a/build/sparse-octree.esm.js +++ b/build/sparse-octree.esm.js @@ -1,11 +1,10 @@ /** - * sparse-octree v6.0.2 build Sat Jan 18 2020 + * sparse-octree v6.1.0 build Tue Aug 18 2020 * https://github.com/vanruesc/sparse-octree * Copyright 2020 Raoul van Rüschen * @license Zlib */ import { Vector3, Box3, Ray } from 'math-ds'; -import IteratorResult from 'iterator-result'; /** * Describes all possible octant corner connections. @@ -831,6 +830,57 @@ class OctreeRaycaster { } +/** + * iterator-result v1.0.0 build Fri Dec 27 2019 + * https://github.com/vanruesc/iterator-result + * Copyright 2019 Raoul van Rüschen, Zlib + */ +/** + * A basic iterator result. + */ + +class IteratorResult { + + /** + * Constructs a new iterator result. + * + * @param {Object} [value=null] - A value. + * @param {Boolean} [done=false] - Whether this result is past the end of the iterated sequence. + */ + + constructor(value = null, done = false) { + + /** + * The value returned by the iterator. + * + * @type {Object} + */ + + this.value = value; + + /** + * Whether this result is past the end of the iterated sequence. + * + * @type {Boolean} + */ + + this.done = done; + + } + + /** + * Resets this iterator result. + */ + + reset() { + + this.value = null; + this.done = false; + + } + +} + /** * A 3D box. * diff --git a/build/sparse-octree.js b/build/sparse-octree.js index 1376287..cb0e7f2 100644 --- a/build/sparse-octree.js +++ b/build/sparse-octree.js @@ -1,1162 +1,2267 @@ /** - * sparse-octree v6.0.2 build Sat Jan 18 2020 + * sparse-octree v6.1.0 build Tue Aug 18 2020 * https://github.com/vanruesc/sparse-octree * Copyright 2020 Raoul van Rüschen * @license Zlib */ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('math-ds'), require('iterator-result')) : - typeof define === 'function' && define.amd ? define(['exports', 'math-ds', 'iterator-result'], factory) : - (global = global || self, factory(global.SPARSEOCTREE = {}, global.MATHDS, global.ITERATORRESULT)); -}(this, (function (exports, mathDs, IteratorResult) { 'use strict'; - - IteratorResult = IteratorResult && IteratorResult.hasOwnProperty('default') ? IteratorResult['default'] : IteratorResult; - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function"); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - writable: true, - configurable: true - } - }); - if (superClass) _setPrototypeOf(subClass, superClass); - } - - function _getPrototypeOf(o) { - _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { - return o.__proto__ || Object.getPrototypeOf(o); - }; - return _getPrototypeOf(o); - } - - function _setPrototypeOf(o, p) { - _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { - o.__proto__ = p; - return o; - }; - - return _setPrototypeOf(o, p); - } - - function _assertThisInitialized(self) { - if (self === void 0) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return self; - } - - function _possibleConstructorReturn(self, call) { - if (call && (typeof call === "object" || typeof call === "function")) { - return call; - } - - return _assertThisInitialized(self); - } - - function _superPropBase(object, property) { - while (!Object.prototype.hasOwnProperty.call(object, property)) { - object = _getPrototypeOf(object); - if (object === null) break; - } - - return object; - } - - function _get(target, property, receiver) { - if (typeof Reflect !== "undefined" && Reflect.get) { - _get = Reflect.get; - } else { - _get = function _get(target, property, receiver) { - var base = _superPropBase(target, property); - - if (!base) return; - var desc = Object.getOwnPropertyDescriptor(base, property); - - if (desc.get) { - return desc.get.call(receiver); - } - - return desc.value; - }; - } - - return _get(target, property, receiver || target); - } - - function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); - } - - function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) { - for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; - - return arr2; - } - } - - function _iterableToArray(iter) { - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); - } - - function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance"); - } - - var edges = [new Uint8Array([0, 4]), new Uint8Array([1, 5]), new Uint8Array([2, 6]), new Uint8Array([3, 7]), new Uint8Array([0, 2]), new Uint8Array([1, 3]), new Uint8Array([4, 6]), new Uint8Array([5, 7]), new Uint8Array([0, 1]), new Uint8Array([2, 3]), new Uint8Array([4, 5]), new Uint8Array([6, 7])]; - var layout = [new Uint8Array([0, 0, 0]), new Uint8Array([0, 0, 1]), new Uint8Array([0, 1, 0]), new Uint8Array([0, 1, 1]), new Uint8Array([1, 0, 0]), new Uint8Array([1, 0, 1]), new Uint8Array([1, 1, 0]), new Uint8Array([1, 1, 1])]; - var c = new mathDs.Vector3(); - - var CubicOctant = function () { - function CubicOctant() { - var min = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new mathDs.Vector3(); - var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - - _classCallCheck(this, CubicOctant); - - this.min = min; - this.size = size; - this.children = null; - } - - _createClass(CubicOctant, [{ - key: "getCenter", - value: function getCenter(target) { - return target.copy(this.min).addScalar(this.size * 0.5); - } - }, { - key: "getDimensions", - value: function getDimensions(target) { - return target.set(this.size, this.size, this.size); - } - }, { - key: "split", - value: function split() { - var min = this.min; - var mid = this.getCenter(c); - var halfSize = this.size * 0.5; - var children = this.children = [null, null, null, null, null, null, null, null]; - var i, combination; - - for (i = 0; i < 8; ++i) { - combination = layout[i]; - children[i] = new this.constructor(new mathDs.Vector3(combination[0] === 0 ? min.x : mid.x, combination[1] === 0 ? min.y : mid.y, combination[2] === 0 ? min.z : mid.z), halfSize); - } - } - }, { - key: "max", - get: function get() { - return this.min.clone().addScalar(this.size); - } - }]); - - return CubicOctant; - }(); - - var c$1 = new mathDs.Vector3(); - - var Octant = function () { - function Octant() { - var min = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new mathDs.Vector3(); - var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new mathDs.Vector3(); - - _classCallCheck(this, Octant); - - this.min = min; - this.max = max; - this.children = null; - } - - _createClass(Octant, [{ - key: "getCenter", - value: function getCenter(target) { - return target.addVectors(this.min, this.max).multiplyScalar(0.5); - } - }, { - key: "getDimensions", - value: function getDimensions(target) { - return target.subVectors(this.max, this.min); - } - }, { - key: "split", - value: function split() { - var min = this.min; - var max = this.max; - var mid = this.getCenter(c$1); - var children = this.children = [null, null, null, null, null, null, null, null]; - var i, combination; - - for (i = 0; i < 8; ++i) { - combination = layout[i]; - children[i] = new this.constructor(new mathDs.Vector3(combination[0] === 0 ? min.x : mid.x, combination[1] === 0 ? min.y : mid.y, combination[2] === 0 ? min.z : mid.z), new mathDs.Vector3(combination[0] === 0 ? mid.x : max.x, combination[1] === 0 ? mid.y : max.y, combination[2] === 0 ? mid.z : max.z)); - } - } - }]); - - return Octant; - }(); - - var RayPointIntersection = function RayPointIntersection(distance, distanceToRay, point) { - var object = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; - - _classCallCheck(this, RayPointIntersection); - - this.distance = distance; - this.distanceToRay = distanceToRay; - this.point = point; - this.object = object; - }; - - function testPoints(octants, raycaster, intersects) { - var threshold = raycaster.params.Points.threshold; - var thresholdSq = threshold * threshold; - var intersectPoint; - var distance, distanceToRay; - var rayPointDistanceSq; - var i, j, il, jl; - var octant, points, point; - - for (i = 0, il = octants.length; i < il; ++i) { - octant = octants[i]; - points = octant.points; - - if (points !== null) { - for (j = 0, jl = points.length; j < jl; ++j) { - point = points[j]; - rayPointDistanceSq = raycaster.ray.distanceSqToPoint(point); - - if (rayPointDistanceSq < thresholdSq) { - intersectPoint = raycaster.ray.closestPointToPoint(point, new mathDs.Vector3()); - distance = raycaster.ray.origin.distanceTo(intersectPoint); - - if (distance >= raycaster.near && distance <= raycaster.far) { - distanceToRay = Math.sqrt(rayPointDistanceSq); - intersects.push(new RayPointIntersection(distance, distanceToRay, intersectPoint, octant.data[j])); - } - } - } - } - } - } - - var Flags = function Flags() { - _classCallCheck(this, Flags); - - this.value = 0; - }; - - function findEntryOctant(tx0, ty0, tz0, txm, tym, tzm) { - var entry = 0; - - if (tx0 > ty0 && tx0 > tz0) { - if (tym < tx0) { - entry |= 2; - } - - if (tzm < tx0) { - entry |= 1; - } - } else if (ty0 > tz0) { - if (txm < ty0) { - entry |= 4; - } - - if (tzm < ty0) { - entry |= 1; - } - } else { - if (txm < tz0) { - entry |= 4; - } - - if (tym < tz0) { - entry |= 2; - } - } - - return entry; - } - - var octantTable = [new Uint8Array([4, 2, 1]), new Uint8Array([5, 3, 8]), new Uint8Array([6, 8, 3]), new Uint8Array([7, 8, 8]), new Uint8Array([8, 6, 5]), new Uint8Array([8, 7, 8]), new Uint8Array([8, 8, 7]), new Uint8Array([8, 8, 8])]; - - function findNextOctant(currentOctant, tx1, ty1, tz1) { - var min; - var exit = 0; - - if (tx1 < ty1) { - min = tx1; - exit = 0; - } else { - min = ty1; - exit = 1; - } - - if (tz1 < min) { - exit = 2; - } - - return octantTable[currentOctant][exit]; - } - - var v = new mathDs.Vector3(); - var b = new mathDs.Box3(); - var d = new mathDs.Box3(); - var r = new mathDs.Ray(); - - function _intersectOctree(octree, ray, flags) { - var min = b.min.set(0, 0, 0); - var max = b.max.subVectors(octree.max, octree.min); - var dimensions = octree.getDimensions(d.min); - var halfDimensions = d.max.copy(dimensions).multiplyScalar(0.5); - var origin = r.origin.copy(ray.origin); - var direction = r.direction.copy(ray.direction); - var invDirX, invDirY, invDirZ; - var tx0, tx1, ty0, ty1, tz0, tz1; - origin.sub(octree.getCenter(v)).add(halfDimensions); - flags.value = 0; - - if (direction.x < 0.0) { - origin.x = dimensions.x - origin.x; - direction.x = -direction.x; - flags.value |= 4; - } - - if (direction.y < 0.0) { - origin.y = dimensions.y - origin.y; - direction.y = -direction.y; - flags.value |= 2; - } - - if (direction.z < 0.0) { - origin.z = dimensions.z - origin.z; - direction.z = -direction.z; - flags.value |= 1; - } - - invDirX = 1.0 / direction.x; - invDirY = 1.0 / direction.y; - invDirZ = 1.0 / direction.z; - tx0 = (min.x - origin.x) * invDirX; - tx1 = (max.x - origin.x) * invDirX; - ty0 = (min.y - origin.y) * invDirY; - ty1 = (max.y - origin.y) * invDirY; - tz0 = (min.z - origin.z) * invDirZ; - tz1 = (max.z - origin.z) * invDirZ; - return Math.max(Math.max(tx0, ty0), tz0) < Math.min(Math.min(tx1, ty1), tz1) ? [tx0, ty0, tz0, tx1, ty1, tz1] : null; - } - - var flags = new Flags(); - - function raycastOctant(octant, tx0, ty0, tz0, tx1, ty1, tz1, intersects) { - if (tx1 >= 0.0 && ty1 >= 0.0 && tz1 >= 0.0) { - var children = octant.children; - - if (children === null) { - intersects.push(octant); - } else { - var txm = 0.5 * (tx0 + tx1); - var tym = 0.5 * (ty0 + ty1); - var tzm = 0.5 * (tz0 + tz1); - var f = flags.value; - var currentOctant = findEntryOctant(tx0, ty0, tz0, txm, tym, tzm); - - do { - switch (currentOctant) { - case 0: - raycastOctant(children[f], tx0, ty0, tz0, txm, tym, tzm, intersects); - currentOctant = findNextOctant(currentOctant, txm, tym, tzm); - break; - - case 1: - raycastOctant(children[f ^ 1], tx0, ty0, tzm, txm, tym, tz1, intersects); - currentOctant = findNextOctant(currentOctant, txm, tym, tz1); - break; - - case 2: - raycastOctant(children[f ^ 2], tx0, tym, tz0, txm, ty1, tzm, intersects); - currentOctant = findNextOctant(currentOctant, txm, ty1, tzm); - break; - - case 3: - raycastOctant(children[f ^ 3], tx0, tym, tzm, txm, ty1, tz1, intersects); - currentOctant = findNextOctant(currentOctant, txm, ty1, tz1); - break; - - case 4: - raycastOctant(children[f ^ 4], txm, ty0, tz0, tx1, tym, tzm, intersects); - currentOctant = findNextOctant(currentOctant, tx1, tym, tzm); - break; - - case 5: - raycastOctant(children[f ^ 5], txm, ty0, tzm, tx1, tym, tz1, intersects); - currentOctant = findNextOctant(currentOctant, tx1, tym, tz1); - break; - - case 6: - raycastOctant(children[f ^ 6], txm, tym, tz0, tx1, ty1, tzm, intersects); - currentOctant = findNextOctant(currentOctant, tx1, ty1, tzm); - break; - - case 7: - raycastOctant(children[f ^ 7], txm, tym, tzm, tx1, ty1, tz1, intersects); - currentOctant = 8; - break; - } - } while (currentOctant < 8); - } - } - } - - var OctreeRaycaster = function () { - function OctreeRaycaster() { - _classCallCheck(this, OctreeRaycaster); - } - - _createClass(OctreeRaycaster, null, [{ - key: "intersectOctree", - value: function intersectOctree(octree, ray) { - var intersects = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; - - var parameters = _intersectOctree(octree, ray, flags); - - if (parameters !== null) { - raycastOctant.apply(void 0, [octree.root].concat(_toConsumableArray(parameters), [intersects])); - } - } - }]); - - return OctreeRaycaster; - }(); - - var b$1 = new mathDs.Box3(); - - var OctreeIterator = function () { - function OctreeIterator(octree) { - var region = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - - _classCallCheck(this, OctreeIterator); - - this.octree = octree; - this.region = region; - this.cull = region !== null; - this.result = new IteratorResult(); - this.trace = null; - this.indices = null; - this.reset(); - } - - _createClass(OctreeIterator, [{ - key: "reset", - value: function reset() { - var root = this.octree.root; - this.trace = []; - this.indices = []; - - if (root !== null) { - b$1.min = root.min; - b$1.max = root.max; - - if (!this.cull || this.region.intersectsBox(b$1)) { - this.trace.push(root); - this.indices.push(0); - } - } - - this.result.reset(); - return this; - } - }, { - key: "next", - value: function next() { - var cull = this.cull; - var region = this.region; - var indices = this.indices; - var trace = this.trace; - var octant = null; - var depth = trace.length - 1; - var index, children, child; - - while (octant === null && depth >= 0) { - index = indices[depth]++; - children = trace[depth].children; - - if (index < 8) { - if (children !== null) { - child = children[index]; - - if (cull) { - b$1.min = child.min; - b$1.max = child.max; - - if (!region.intersectsBox(b$1)) { - continue; - } - } - - trace.push(child); - indices.push(0); - ++depth; - } else { - octant = trace.pop(); - indices.pop(); - } - } else { - trace.pop(); - indices.pop(); - --depth; - } - } - - this.result.value = octant; - this.result.done = octant === null; - return this.result; - } - }, { - key: "return", - value: function _return(value) { - this.result.value = value; - this.result.done = true; - return this.result; - } - }, { - key: Symbol.iterator, - value: function value() { - return this; - } - }]); - - return OctreeIterator; - }(); - - var b$2 = new mathDs.Box3(); - - function _getDepth(octant) { - var children = octant.children; - var result = 0; - var i, l, d; - - if (children !== null) { - for (i = 0, l = children.length; i < l; ++i) { - d = 1 + _getDepth(children[i]); - - if (d > result) { - result = d; - } - } - } - - return result; - } - - function _cull(octant, region, result) { - var children = octant.children; - var i, l; - b$2.min = octant.min; - b$2.max = octant.max; - - if (region.intersectsBox(b$2)) { - if (children !== null) { - for (i = 0, l = children.length; i < l; ++i) { - _cull(children[i], region, result); - } - } else { - result.push(octant); - } - } - } - - function _findNodesByLevel(octant, level, depth, result) { - var children = octant.children; - var i, l; - - if (depth === level) { - result.push(octant); - } else if (children !== null) { - ++depth; - - for (i = 0, l = children.length; i < l; ++i) { - _findNodesByLevel(children[i], level, depth, result); - } - } - } - - var Octree = function () { - function Octree(root) { - _classCallCheck(this, Octree); - - this.root = root; - } - - _createClass(Octree, [{ - key: "getCenter", - value: function getCenter(target) { - return this.root.getCenter(target); - } - }, { - key: "getDimensions", - value: function getDimensions(target) { - return this.root.getDimensions(target); - } - }, { - key: "cull", - value: function cull(region) { - var result = []; - - _cull(this.root, region, result); - - return result; - } - }, { - key: "getDepth", - value: function getDepth() { - return _getDepth(this.root); - } - }, { - key: "findNodesByLevel", - value: function findNodesByLevel(level) { - var result = []; - - _findNodesByLevel(this.root, level, 0, result); - - return result; - } - }, { - key: "raycast", - value: function raycast(raycaster) { - var intersects = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; - OctreeRaycaster.intersectOctree(this, raycaster.ray, intersects); - return intersects; - } - }, { - key: "leaves", - value: function leaves(region) { - return new OctreeIterator(this, region); - } - }, { - key: Symbol.iterator, - value: function value() { - return new OctreeIterator(this); - } - }, { - key: "min", - get: function get() { - return this.root.min; - } - }, { - key: "max", - get: function get() { - return this.root.max; - } - }, { - key: "children", - get: function get() { - return this.root.children; - } - }]); - - return Octree; - }(); - - var p = new mathDs.Vector3(); - - var PointOctant = function (_Octant) { - _inherits(PointOctant, _Octant); - - function PointOctant(min, max) { - var _this; - - _classCallCheck(this, PointOctant); - - _this = _possibleConstructorReturn(this, _getPrototypeOf(PointOctant).call(this, min, max)); - _this.points = null; - _this.data = null; - return _this; - } - - _createClass(PointOctant, [{ - key: "distanceToSquared", - value: function distanceToSquared(point) { - var clampedPoint = p.copy(point).clamp(this.min, this.max); - return clampedPoint.sub(point).lengthSquared(); - } - }, { - key: "distanceToCenterSquared", - value: function distanceToCenterSquared(point) { - var center = this.getCenter(p); - var dx = point.x - center.x; - var dy = point.y - center.x; - var dz = point.z - center.z; - return dx * dx + dy * dy + dz * dz; - } - }, { - key: "contains", - value: function contains(point, bias) { - var min = this.min; - var max = this.max; - return point.x >= min.x - bias && point.y >= min.y - bias && point.z >= min.z - bias && point.x <= max.x + bias && point.y <= max.y + bias && point.z <= max.z + bias; - } - }, { - key: "redistribute", - value: function redistribute(bias) { - var children = this.children; - var points = this.points; - var data = this.data; - var i, j, il, jl; - var child, point, entry; - - if (children !== null && points !== null) { - for (i = 0, il = points.length; i < il; ++i) { - point = points[i]; - entry = data[i]; - - for (j = 0, jl = children.length; j < jl; ++j) { - child = children[j]; - - if (child.contains(point, bias)) { - if (child.points === null) { - child.points = []; - child.data = []; - } - - child.points.push(point); - child.data.push(entry); - break; - } - } - } - - this.points = null; - this.data = null; - } - } - }, { - key: "merge", - value: function merge() { - var children = this.children; - - if (children !== null) { - var points = []; - var data = []; - var i, l, child; - - for (i = 0, l = children.length; i < l; ++i) { - child = children[i]; - - if (child.points !== null) { - points = points.concat(child.points); - data = data.concat(child.data); - } - } - - this.children = null; - this.points = points; - this.data = data; - } - } - }]); - - return PointOctant; - }(Octant); - - function _countPoints(octant) { - var children = octant.children; - var result = 0; - var i, l; - - if (children !== null) { - for (i = 0, l = children.length; i < l; ++i) { - result += _countPoints(children[i]); - } - } else if (octant.points !== null) { - result = octant.points.length; - } - - return result; - } - - function _insert(point, data, octree, octant, depth) { - var children = octant.children; - var exists = false; - var done = false; - var i, l; - - if (octant.contains(point, octree.bias)) { - if (children === null) { - if (octant.points === null) { - octant.points = []; - octant.data = []; - } else { - for (i = 0, l = octant.points.length; !exists && i < l; ++i) { - exists = octant.points[i].equals(point); - } - } - - if (exists) { - octant.data[i - 1] = data; - done = true; - } else if (octant.points.length < octree.maxPoints || depth === octree.maxDepth) { - octant.points.push(point.clone()); - octant.data.push(data); - ++octree.pointCount; - done = true; - } else { - octant.split(); - octant.redistribute(octree.bias); - children = octant.children; - } - } - - if (children !== null) { - ++depth; - - for (i = 0, l = children.length; !done && i < l; ++i) { - done = _insert(point, data, octree, children[i], depth); - } - } - } - - return done; - } - - function _remove(point, octree, octant, parent) { - var children = octant.children; - var result = null; - var i, l; - var points, data, last; - - if (octant.contains(point, octree.bias)) { - if (children !== null) { - for (i = 0, l = children.length; result === null && i < l; ++i) { - result = _remove(point, octree, children[i], octant); - } - } else if (octant.points !== null) { - points = octant.points; - data = octant.data; - - for (i = 0, l = points.length; i < l; ++i) { - if (points[i].equals(point)) { - last = l - 1; - result = data[i]; - - if (i < last) { - points[i] = points[last]; - data[i] = data[last]; - } - - points.pop(); - data.pop(); - --octree.pointCount; - - if (parent !== null && _countPoints(parent) <= octree.maxPoints) { - parent.merge(); - } - - break; - } - } - } - } - - return result; - } - - function _get$1(point, octree, octant) { - var children = octant.children; - var result = null; - var i, l; - var points; - - if (octant.contains(point, octree.bias)) { - if (children !== null) { - for (i = 0, l = children.length; result === null && i < l; ++i) { - result = _get$1(point, octree, children[i]); - } - } else if (octant.points !== null) { - points = octant.points; - - for (i = 0, l = points.length; result === null && i < l; ++i) { - if (point.equals(points[i])) { - result = octant.data[i]; - } - } - } - } - - return result; - } - - function _move(point, position, octree, octant, parent, depth) { - var children = octant.children; - var result = null; - var i, l; - var points; - - if (octant.contains(point, octree.bias)) { - if (octant.contains(position, octree.bias)) { - if (children !== null) { - ++depth; - - for (i = 0, l = children.length; result === null && i < l; ++i) { - result = _move(point, position, octree, children[i], octant, depth); - } - } else if (octant.points !== null) { - points = octant.points; - - for (i = 0, l = points.length; i < l; ++i) { - if (point.equals(points[i])) { - points[i].copy(position); - result = octant.data[i]; - break; - } - } - } - } else { - result = _remove(point, octree, octant, parent); - - _insert(position, result, octree, parent, depth - 1); - } - } - - return result; - } - - function _findNearestPoint(point, maxDistance, skipSelf, octant) { - var result = null; - var bestDistance = maxDistance; - var i, l; - - if (octant.children !== null) { - var sortedChildren = octant.children.map(function (child) { - return { - octant: child, - distance: child.distanceToCenterSquared(point) - }; - }).sort(function (a, b) { - return a.distance - b.distance; - }); - var child, intermediateResult; - - for (i = 0, l = sortedChildren.length; i < l; ++i) { - child = sortedChildren[i].octant; - - if (child.contains(point, bestDistance)) { - intermediateResult = _findNearestPoint(point, bestDistance, skipSelf, child); - - if (intermediateResult !== null) { - bestDistance = intermediateResult.distance; - result = intermediateResult; - - if (bestDistance === 0.0) { - break; - } - } - } - } - } else if (octant.points !== null) { - var points = octant.points; - var index = -1; - var distance; - - for (i = 0, l = points.length; i < l; ++i) { - if (points[i].equals(point)) { - if (!skipSelf) { - bestDistance = 0.0; - index = i; - break; - } - } else { - distance = point.distanceTo(points[i]); - - if (distance < bestDistance) { - bestDistance = distance; - index = i; - } - } - } - - if (index >= 0) { - result = { - point: points[index], - data: octant.data[index], - distance: bestDistance - }; - } - } - - return result; - } - - function _findPoints(point, radius, skipSelf, octant, result) { - var children = octant.children; - var i, l; - - if (children !== null) { - var child; - - for (i = 0, l = children.length; i < l; ++i) { - child = children[i]; - - if (child.contains(point, radius)) { - _findPoints(point, radius, skipSelf, child, result); - } - } - } else if (octant.points !== null) { - var points = octant.points; - var rSq = radius * radius; - - var _p; - - for (i = 0, l = points.length; i < l; ++i) { - _p = points[i]; - - if (_p.equals(point)) { - if (!skipSelf) { - result.push({ - point: _p.clone(), - data: octant.data[i] - }); - } - } else if (_p.distanceToSquared(point) <= rSq) { - result.push({ - point: _p.clone(), - data: octant.data[i] - }); - } - } - } - } - - var PointOctree = function (_Octree) { - _inherits(PointOctree, _Octree); - - function PointOctree(min, max) { - var _this2; - - var bias = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.0; - var maxPoints = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 8; - var maxDepth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 8; - - _classCallCheck(this, PointOctree); - - _this2 = _possibleConstructorReturn(this, _getPrototypeOf(PointOctree).call(this, new PointOctant(min, max))); - _this2.bias = Math.max(0.0, bias); - _this2.maxPoints = Math.max(1, Math.round(maxPoints)); - _this2.maxDepth = Math.max(0, Math.round(maxDepth)); - _this2.pointCount = 0; - return _this2; - } - - _createClass(PointOctree, [{ - key: "countPoints", - value: function countPoints(octant) { - return _countPoints(octant); - } - }, { - key: "insert", - value: function insert(point, data) { - return _insert(point, data, this, this.root, 0); - } - }, { - key: "remove", - value: function remove(point) { - return _remove(point, this, this.root, null); - } - }, { - key: "get", - value: function get(point) { - return _get$1(point, this, this.root); - } - }, { - key: "move", - value: function move(point, position) { - return _move(point, position, this, this.root, null, 0); - } - }, { - key: "findNearestPoint", - value: function findNearestPoint(point) { - var maxDistance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity; - var skipSelf = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - - var result = _findNearestPoint(point, maxDistance, skipSelf, this.root); - - if (result !== null) { - result.point = result.point.clone(); - } - - return result; - } - }, { - key: "findPoints", - value: function findPoints(point, radius) { - var skipSelf = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - var result = []; - - _findPoints(point, radius, skipSelf, this.root, result); - - return result; - } - }, { - key: "raycast", - value: function raycast(raycaster) { - var intersects = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; - - var octants = _get(_getPrototypeOf(PointOctree.prototype), "raycast", this).call(this, raycaster); - - if (octants.length > 0) { - testPoints(octants, raycaster, intersects); - } - - return intersects; - } - }]); - - return PointOctree; - }(Octree); - - exports.CubicOctant = CubicOctant; - exports.Flags = Flags; - exports.Octant = Octant; - exports.Octree = Octree; - exports.OctreeIterator = OctreeIterator; - exports.OctreeRaycaster = OctreeRaycaster; - exports.PointOctant = PointOctant; - exports.PointOctree = PointOctree; - exports.RayPointIntersection = RayPointIntersection; - exports.edges = edges; - exports.findEntryOctant = findEntryOctant; - exports.findNextOctant = findNextOctant; - exports.intersectOctree = _intersectOctree; - exports.layout = layout; - exports.testPoints = testPoints; - - Object.defineProperty(exports, '__esModule', { value: true }); + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('math-ds')) : + typeof define === 'function' && define.amd ? define(['exports', 'math-ds'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SPARSEOCTREE = {}, global.MATHDS)); +}(this, (function (exports, mathDs) { 'use strict'; + + /** + * Describes all possible octant corner connections. + * + * @type {Uint8Array[]} + */ + + var edges = [ + + // X-Axis. + new Uint8Array([0, 4]), + new Uint8Array([1, 5]), + new Uint8Array([2, 6]), + new Uint8Array([3, 7]), + + // Y-Axis. + new Uint8Array([0, 2]), + new Uint8Array([1, 3]), + new Uint8Array([4, 6]), + new Uint8Array([5, 7]), + + // Z-Axis. + new Uint8Array([0, 1]), + new Uint8Array([2, 3]), + new Uint8Array([4, 5]), + new Uint8Array([6, 7]) + + ]; + + /** + * A binary pattern that describes the standard octant layout: + * + * ```text + * 3____7 + * 2/___6/| + * | 1__|_5 + * 0/___4/ + * ``` + * + * This common layout is crucial for positional assumptions. + * + * @type {Uint8Array[]} + */ + + var layout = [ + + new Uint8Array([0, 0, 0]), + new Uint8Array([0, 0, 1]), + new Uint8Array([0, 1, 0]), + new Uint8Array([0, 1, 1]), + + new Uint8Array([1, 0, 0]), + new Uint8Array([1, 0, 1]), + new Uint8Array([1, 1, 0]), + new Uint8Array([1, 1, 1]) + + ]; + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var c = new mathDs.Vector3(); + + /** + * A cubic octant. + * + * @implements {Node} + */ + + var CubicOctant = function CubicOctant(min, size) { + if ( min === void 0 ) min = new mathDs.Vector3(); + if ( size === void 0 ) size = 0; + + + /** + * The lower bounds of this octant. + * + * @type {Vector3} + */ + + this.min = min; + + /** + * The size of this octant. + * + * @type {Number} + */ + + this.size = size; + + /** + * The children of this octant. + * + * @type {CubicOctant[]} + */ + + this.children = null; + + }; + + var prototypeAccessors = { max: { configurable: true } }; + + /** + * The upper bounds of this octant. + * + * Attention: Accessing this property creates a new vector! + * + * @type {Vector3} + */ + + prototypeAccessors.max.get = function () { + + return this.min.clone().addScalar(this.size); + + }; + + /** + * Computes the center of this octant. + * + * @param {Vector3} target - A target vector. + * @return {Vector3} The center. + */ + + CubicOctant.prototype.getCenter = function getCenter (target) { + + return target.copy(this.min).addScalar(this.size * 0.5); + + }; + + /** + * Returns the size of this octant as a vector. + * + * @param {Vector3} target - A target vector. + * @return {Vector3} The size. + */ + + CubicOctant.prototype.getDimensions = function getDimensions (target) { + + return target.set(this.size, this.size, this.size); + + }; + + /** + * Splits this octant into eight smaller ones. + */ + + CubicOctant.prototype.split = function split () { + + var min = this.min; + var mid = this.getCenter(c); + var halfSize = this.size * 0.5; + + var children = this.children = [ + null, null, null, null, + null, null, null, null + ]; + + var i, combination; + + for(i = 0; i < 8; ++i) { + + combination = layout[i]; + + children[i] = new this.constructor( + + new mathDs.Vector3( + (combination[0] === 0) ? min.x : mid.x, + (combination[1] === 0) ? min.y : mid.y, + (combination[2] === 0) ? min.z : mid.z + ), + + halfSize + + ); + + } + + }; + + Object.defineProperties( CubicOctant.prototype, prototypeAccessors ); + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var c$1 = new mathDs.Vector3(); + + /** + * An octant. + * + * @implements {Node} + */ + + var Octant = function Octant(min, max) { + if ( min === void 0 ) min = new mathDs.Vector3(); + if ( max === void 0 ) max = new mathDs.Vector3(); + + + /** + * The lower bounds of this octant. + * + * @type {Vector3} + */ + + this.min = min; + + /** + * The upper bounds of the octant. + * + * @type {Vector3} + */ + + this.max = max; + + /** + * The children of this octant. + * + * @type {Octant[]} + */ + + this.children = null; + + }; + + /** + * Computes the center of this octant. + * + * @param {Vector3} target - A target vector. + * @return {Vector3} The center. + */ + + Octant.prototype.getCenter = function getCenter (target) { + + return target.addVectors(this.min, this.max).multiplyScalar(0.5); + + }; + + /** + * Computes the size of this octant. + * + * @param {Vector3} target - A target vector. + * @return {Vector3} The size. + */ + + Octant.prototype.getDimensions = function getDimensions (target) { + + return target.subVectors(this.max, this.min); + + }; + + /** + * Splits this octant into eight smaller ones. + */ + + Octant.prototype.split = function split () { + + var min = this.min; + var max = this.max; + var mid = this.getCenter(c$1); + + var children = this.children = [ + null, null, null, null, + null, null, null, null + ]; + + var i, combination; + + for(i = 0; i < 8; ++i) { + + combination = layout[i]; + + children[i] = new this.constructor( + + new mathDs.Vector3( + (combination[0] === 0) ? min.x : mid.x, + (combination[1] === 0) ? min.y : mid.y, + (combination[2] === 0) ? min.z : mid.z + ), + + new mathDs.Vector3( + (combination[0] === 0) ? mid.x : max.x, + (combination[1] === 0) ? mid.y : max.y, + (combination[2] === 0) ? mid.z : max.z + ) + + ); + + } + + }; + + /** + * A collection of ray-point intersection data. + */ + + var RayPointIntersection = function RayPointIntersection(distance, distanceToRay, point, object) { + if ( object === void 0 ) object = null; + + + /** + * The distance from the origin of the ray to the point. + * + * @type {Number} + */ + + this.distance = distance; + + /** + * The shortest distance from the point to the ray. + * + * @type {Number} + */ + + this.distanceToRay = distanceToRay; + + /** + * The point. + * + * @type {Vector3} + */ + + this.point = point; + + /** + * The point's data. + * + * @type {Object} + */ + + this.object = object; + + }; + + /** + * Collects points that intersect with the given ray. + * + * @param {PointOctant[]} octants - An array containing octants that intersect with the ray. + * @param {Raycaster} raycaster - The raycaster. + * @param {RayPointIntersection[]} intersects - An array to be filled with intersecting points. + */ + + function testPoints(octants, raycaster, intersects) { + + var threshold = raycaster.params.Points.threshold; + var thresholdSq = threshold * threshold; + + var intersectPoint; + var distance, distanceToRay; + var rayPointDistanceSq; + + var i, j, il, jl; + var octant, points, point; + + for(i = 0, il = octants.length; i < il; ++i) { + + octant = octants[i]; + points = octant.points; + + if(points !== null) { + + for(j = 0, jl = points.length; j < jl; ++j) { + + point = points[j]; + rayPointDistanceSq = raycaster.ray.distanceSqToPoint(point); + + if(rayPointDistanceSq < thresholdSq) { + + intersectPoint = raycaster.ray.closestPointToPoint(point, new mathDs.Vector3()); + distance = raycaster.ray.origin.distanceTo(intersectPoint); + + if(distance >= raycaster.near && distance <= raycaster.far) { + + distanceToRay = Math.sqrt(rayPointDistanceSq); + + intersects.push(new RayPointIntersection( + distance, + distanceToRay, + intersectPoint, + octant.data[j] + )); + + } + + } + + } + + } + + } + + } + + /** + * A container for raycasting flags. + */ + + var Flags = function Flags() { + + /** + * The current flags. + * + * @type {Number} + */ + + this.value = 0; + + }; + + /** + * Finds the entry plane of the first octant that a ray travels through. + * + * Determining the first octant requires knowing which of the t0s is the + * largest. The tms of the other axes must also be compared against that + * largest t0. + * + * @param {Number} tx0 - Ray projection parameter. + * @param {Number} ty0 - Ray projection parameter. + * @param {Number} tz0 - Ray projection parameter. + * @param {Number} txm - Ray projection parameter mean. + * @param {Number} tym - Ray projection parameter mean. + * @param {Number} tzm - Ray projection parameter mean. + * @return {Number} The index of the first octant that the ray travels through. + */ + + function findEntryOctant(tx0, ty0, tz0, txm, tym, tzm) { + + var entry = 0; + + // Find the entry plane. + if(tx0 > ty0 && tx0 > tz0) { + + // YZ-plane. + if(tym < tx0) { + + entry |= 2; + + } + + if(tzm < tx0) { + + entry |= 1; + + } + + } else if(ty0 > tz0) { + + // XZ-plane. + if(txm < ty0) { + + entry |= 4; + + } + + if(tzm < ty0) { + + entry |= 1; + + } + + } else { + + // XY-plane. + if(txm < tz0) { + + entry |= 4; + + } + + if(tym < tz0) { + + entry |= 2; + + } + + } + + return entry; + + } + + /** + * A lookup-table containing octant ids. Used to determine the exit plane from + * an octant. + * + * @type {Uint8Array[]} + * @private + */ + + var octantTable = [ + + new Uint8Array([4, 2, 1]), + new Uint8Array([5, 3, 8]), + new Uint8Array([6, 8, 3]), + new Uint8Array([7, 8, 8]), + new Uint8Array([8, 6, 5]), + new Uint8Array([8, 7, 8]), + new Uint8Array([8, 8, 7]), + new Uint8Array([8, 8, 8]) + + ]; + + /** + * Finds the next octant that intersects with the ray based on the exit plane of + * the current one. + * + * @param {Number} currentOctant - The index of the current octant. + * @param {Number} tx1 - Ray projection parameter. + * @param {Number} ty1 - Ray projection parameter. + * @param {Number} tz1 - Ray projection parameter. + * @return {Number} The index of the next octant that the ray travels through. + */ + + function findNextOctant(currentOctant, tx1, ty1, tz1) { + + var min; + var exit = 0; + + // Find the exit plane. + if(tx1 < ty1) { + + min = tx1; + exit = 0; // YZ-plane. + + } else { + + min = ty1; + exit = 1; // XZ-plane. + + } + + if(tz1 < min) { + + exit = 2; // XY-plane. + + } + + return octantTable[currentOctant][exit]; + + } + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var v = new mathDs.Vector3(); + + /** + * A box. + * + * @type {Box3} + * @private + */ + + var b = new mathDs.Box3(); + + /** + * A box. + * + * @type {Box3} + * @private + */ + + var d = new mathDs.Box3(); + + /** + * A ray. + * + * @type {Ray} + * @private + */ + + var r = new mathDs.Ray(); + + /** + * Calculates ray projection parameters for the given octree and ray setup. + * + * @param {Octree} octree - The octree. + * @param {Ray} ray - A ray. + * @param {Flags} flags - Raycasting flags. + * @return {Number[]} The ray parameters tx0, ty0, tz0, tx1, ty1 and tz1, in that order, or null if the ray doesn't hit the octree. + */ + + function intersectOctree(octree, ray, flags) { + + // Translate the octant extents to the scene origin. + var min = b.min.set(0, 0, 0); + var max = b.max.subVectors(octree.max, octree.min); + + var dimensions = octree.getDimensions(d.min); + var halfDimensions = d.max.copy(dimensions).multiplyScalar(0.5); + + var origin = r.origin.copy(ray.origin); + var direction = r.direction.copy(ray.direction); + + var invDirX, invDirY, invDirZ; + var tx0, tx1, ty0, ty1, tz0, tz1; + + // Translate the ray to the center of the octant. + origin.sub(octree.getCenter(v)).add(halfDimensions); + + // Reset all flags. + flags.value = 0; + + // Handle rays with negative directions. + if(direction.x < 0.0) { + + origin.x = dimensions.x - origin.x; + direction.x = -direction.x; + flags.value |= 4; + + } + + if(direction.y < 0.0) { + + origin.y = dimensions.y - origin.y; + direction.y = -direction.y; + flags.value |= 2; + + } + + if(direction.z < 0.0) { + + origin.z = dimensions.z - origin.z; + direction.z = -direction.z; + flags.value |= 1; + + } + + // Improve IEEE double stability. + invDirX = 1.0 / direction.x; + invDirY = 1.0 / direction.y; + invDirZ = 1.0 / direction.z; + + // Project the ray to the octant's boundaries. + tx0 = (min.x - origin.x) * invDirX; + tx1 = (max.x - origin.x) * invDirX; + ty0 = (min.y - origin.y) * invDirY; + ty1 = (max.y - origin.y) * invDirY; + tz0 = (min.z - origin.z) * invDirZ; + tz1 = (max.z - origin.z) * invDirZ; + + // Check if the ray hits the octree. + return (Math.max(Math.max(tx0, ty0), tz0) < Math.min(Math.min(tx1, ty1), tz1)) ? + [tx0, ty0, tz0, tx1, ty1, tz1] : null; + + } + + /** + * Raycasting flags. + * + * @type {Flags} + */ + + var flags = new Flags(); + + /** + * Finds all octants that intersect with the given ray. + * + * @private + * @param {Octant} octant - The current octant. + * @param {Number} tx0 - A ray projection parameter. + * @param {Number} ty0 - A ray projection parameter. + * @param {Number} tz0 - A ray projection parameter. + * @param {Number} tx1 - A ray projection parameter. + * @param {Number} ty1 - A ray projection parameter. + * @param {Number} tz1 - A ray projection parameter. + * @param {Array} intersects - An array to be filled with the intersecting octants. + */ + + function raycastOctant(octant, tx0, ty0, tz0, tx1, ty1, tz1, intersects) { + + if(tx1 >= 0.0 && ty1 >= 0.0 && tz1 >= 0.0) { + + var children = octant.children; + + if(children === null) { + + // Leaf. + intersects.push(octant); + + } else { + + // Compute means. + var txm = 0.5 * (tx0 + tx1); + var tym = 0.5 * (ty0 + ty1); + var tzm = 0.5 * (tz0 + tz1); + + var f = flags.value; + var currentOctant = findEntryOctant(tx0, ty0, tz0, txm, tym, tzm); + + /* The possibilities for the next node are passed in the same respective + order as the t-values. Hence, if the first value is found to be the + greatest, the fourth one will be returned. If the second value is the + greatest, the fifth one will be returned, etc. */ + + do { + + switch(currentOctant) { + + case 0: + raycastOctant(children[f], tx0, ty0, tz0, txm, tym, tzm, intersects); + currentOctant = findNextOctant(currentOctant, txm, tym, tzm); + break; + + case 1: + raycastOctant(children[f ^ 1], tx0, ty0, tzm, txm, tym, tz1, intersects); + currentOctant = findNextOctant(currentOctant, txm, tym, tz1); + break; + + case 2: + raycastOctant(children[f ^ 2], tx0, tym, tz0, txm, ty1, tzm, intersects); + currentOctant = findNextOctant(currentOctant, txm, ty1, tzm); + break; + + case 3: + raycastOctant(children[f ^ 3], tx0, tym, tzm, txm, ty1, tz1, intersects); + currentOctant = findNextOctant(currentOctant, txm, ty1, tz1); + break; + + case 4: + raycastOctant(children[f ^ 4], txm, ty0, tz0, tx1, tym, tzm, intersects); + currentOctant = findNextOctant(currentOctant, tx1, tym, tzm); + break; + + case 5: + raycastOctant(children[f ^ 5], txm, ty0, tzm, tx1, tym, tz1, intersects); + currentOctant = findNextOctant(currentOctant, tx1, tym, tz1); + break; + + case 6: + raycastOctant(children[f ^ 6], txm, tym, tz0, tx1, ty1, tzm, intersects); + currentOctant = findNextOctant(currentOctant, tx1, ty1, tzm); + break; + + case 7: + raycastOctant(children[f ^ 7], txm, tym, tzm, tx1, ty1, tz1, intersects); + // Far top right octant. No other octants can be reached from here. + currentOctant = 8; + break; + + } + + } while(currentOctant < 8); + + } + + } + + } + + /** + * A raycaster for pointer-based octrees. + * + * Reference: + * "An Efficient Parametric Algorithm for Octree Traversal" + * by J. Revelles et al. (2000) + */ + + var OctreeRaycaster = function OctreeRaycaster () {}; + + OctreeRaycaster.intersectOctree = function intersectOctree$1 (octree, ray, intersects) { + if ( intersects === void 0 ) intersects = []; + + + var parameters = intersectOctree(octree, ray, flags); + + if(parameters !== null) { + + raycastOctant.apply(void 0, [ octree.root ].concat( parameters, [intersects] )); + + } + + }; + + /** + * iterator-result v1.0.0 build Fri Dec 27 2019 + * https://github.com/vanruesc/iterator-result + * Copyright 2019 Raoul van Rüschen, Zlib + */ + /** + * A basic iterator result. + */ + + var IteratorResult = function IteratorResult(value, done) { + if ( value === void 0 ) value = null; + if ( done === void 0 ) done = false; + + + /** + * The value returned by the iterator. + * + * @type {Object} + */ + + this.value = value; + + /** + * Whether this result is past the end of the iterated sequence. + * + * @type {Boolean} + */ + + this.done = done; + + }; + + /** + * Resets this iterator result. + */ + + IteratorResult.prototype.reset = function reset () { + + this.value = null; + this.done = false; + + }; + + /** + * A 3D box. + * + * @type {Box3} + * @private + */ + + var b$1 = new mathDs.Box3(); + + /** + * An octree iterator. + * + * @implements {Iterator} + * @implements {Iterable} + */ + + var OctreeIterator = function OctreeIterator(octree, region) { + if ( region === void 0 ) region = null; + + + /** + * The octree. + * + * @type {Octree} + * @private + */ + + this.octree = octree; + + /** + * A region used for octree culling. + * + * @type {Frustum|Box3} + */ + + this.region = region; + + /** + * Whether this iterator should respect the cull region. + * + * @type {Boolean} + */ + + this.cull = (region !== null); + + /** + * An iterator result. + * + * @type {IteratorResult} + * @private + */ + + this.result = new IteratorResult(); + + /** + * An octant trace. + * + * @type {Octant[]} + * @private + */ + + this.trace = null; + + /** + * Iteration indices. + * + * @type {Number[]} + * @private + */ + + this.indices = null; + + this.reset(); + + }; + + /** + * Resets this iterator. + * + * @return {OctreeIterator} This iterator. + */ + + OctreeIterator.prototype.reset = function reset () { + + var root = this.octree.root; + + this.trace = []; + this.indices = []; + + if(root !== null) { + + b$1.min = root.min; + b$1.max = root.max; + + if(!this.cull || this.region.intersectsBox(b$1)) { + + this.trace.push(root); + this.indices.push(0); + + } + + } + + this.result.reset(); + + return this; + + }; + + /** + * Iterates over the leaf octants. + * + * @return {IteratorResult} The next leaf octant. + */ + + OctreeIterator.prototype.next = function next () { + + var cull = this.cull; + var region = this.region; + var indices = this.indices; + var trace = this.trace; + + var octant = null; + var depth = trace.length - 1; + + var index, children, child; + + while(octant === null && depth >= 0) { + + index = indices[depth]++; + children = trace[depth].children; + + if(index < 8) { + + if(children !== null) { + + child = children[index]; + + if(cull) { + + b$1.min = child.min; + b$1.max = child.max; + + if(!region.intersectsBox(b$1)) { + + // Cull this octant. + continue; + + } + + } + + trace.push(child); + indices.push(0); + + ++depth; + + } else { + + octant = trace.pop(); + indices.pop(); + + } + + } else { + + trace.pop(); + indices.pop(); + + --depth; + + } + + } + + this.result.value = octant; + this.result.done = (octant === null); + + return this.result; + + }; + + /** + * Called when this iterator will no longer be run to completion. + * + * @param {Object} value - An interator result value. + * @return {IteratorResult} - A premature completion result. + */ + + OctreeIterator.prototype.return = function return$1 (value) { + + this.result.value = value; + this.result.done = true; + + return this.result; + + }; + + /** + * Returns this iterator. + * + * @return {Iterator} An iterator. + */ + + OctreeIterator.prototype[Symbol.iterator] = function () { + + return this; + + }; + + /** + * A 3D box. + * + * @type {Box3} + * @private + */ + + var b$2 = new mathDs.Box3(); + + /** + * Recursively calculates the depth of the given octree. + * + * @private + * @param {Node} octant - An octant. + * @return {Number} The depth. + */ + + function getDepth(octant) { + + var children = octant.children; + + var result = 0; + var i, l, d; + + if(children !== null) { + + for(i = 0, l = children.length; i < l; ++i) { + + d = 1 + getDepth(children[i]); + + if(d > result) { + + result = d; + + } + + } + + } + + return result; + + } + + /** + * Recursively collects octants that lie inside the specified region. + * + * @private + * @param {Node} octant - An octant. + * @param {Frustum|Box3} region - A region. + * @param {Node[]} result - A list to be filled with octants that intersect with the region. + */ + + function cull(octant, region, result) { + + var children = octant.children; + + var i, l; + + b$2.min = octant.min; + b$2.max = octant.max; + + if(region.intersectsBox(b$2)) { + + if(children !== null) { + + for(i = 0, l = children.length; i < l; ++i) { + + cull(children[i], region, result); + + } + + } else { + + result.push(octant); + + } + + } + + } + + /** + * Recursively fetches all octants with the specified depth level. + * + * @private + * @param {Node} octant - An octant. + * @param {Number} level - The target depth level. + * @param {Number} depth - The current depth level. + * @param {Node[]} result - A list to be filled with the identified octants. + */ + + function findNodesByLevel(octant, level, depth, result) { + + var children = octant.children; + + var i, l; + + if(depth === level) { + + result.push(octant); + + } else if(children !== null) { + + ++depth; + + for(i = 0, l = children.length; i < l; ++i) { + + findNodesByLevel(children[i], level, depth, result); + + } + + } + + } + + /** + * A pointer-based octree that subdivides space for fast spatial searches. + * + * @implements {Iterable} + * @implements {Node} + * @implements {Tree} + */ + + var Octree = function Octree(root) { + + /** + * The root octant. + * + * @type {Node} + * @protected + */ + + this.root = root; + + }; + + var prototypeAccessors$1 = { min: { configurable: true },max: { configurable: true },children: { configurable: true } }; + + /** + * The lower bounds of the root octant. + * + * @type {Vector3} + */ + + prototypeAccessors$1.min.get = function () { + + return this.root.min; + + }; + + /** + * The upper bounds of the root octant. + * + * @type {Vector3} + */ + + prototypeAccessors$1.max.get = function () { + + return this.root.max; + + }; + + /** + * The children of the root node. + * + * @type {Node[]} + */ + + prototypeAccessors$1.children.get = function () { + + return this.root.children; + + }; + + /** + * Calculates the center of this octree. + * + * @param {Vector3} target - A target vector. + * @return {Vector3} A vector that describes the center of this octree. + */ + + Octree.prototype.getCenter = function getCenter (target) { + + return this.root.getCenter(target); + + }; + + /** + * Calculates the size of this octree. + * + * @param {Vector3} target - A target vector. + * @return {Vector3} A vector that describes the size of this octree. + */ + + Octree.prototype.getDimensions = function getDimensions (target) { + + return this.root.getDimensions(target); + + }; + + /** + * Recursively collects nodes that intersect with the specified region. + * + * @param {Frustum|Box3} region - A region. + * @return {Node[]} The nodes. + */ + + Octree.prototype.cull = function cull$1 (region) { + + var result = []; + + cull(this.root, region, result); + + return result; + + }; + + /** + * Calculates the current depth of this octree. + * + * @return {Number} The depth. + */ + + Octree.prototype.getDepth = function getDepth$1 () { + + return getDepth(this.root); + + }; + + /** + * Fetches all nodes of a specific depth level. + * + * @param {Number} level - The depth level. + * @return {Node[]} The nodes. + */ + + Octree.prototype.findNodesByLevel = function findNodesByLevel$1 (level) { + + var result = []; + + findNodesByLevel(this.root, level, 0, result); + + return result; + + }; + + /** + * Finds the nodes that intersect with the given ray. The intersecting + * nodes are sorted by distance, closest first. + * + * @param {Raycaster} raycaster - A raycaster. + * @param {Node[]} [intersects] - An optional target list to be filled with the intersecting nodes. + * @return {Node[]} The intersecting nodes. + */ + + Octree.prototype.raycast = function raycast (raycaster, intersects) { + if ( intersects === void 0 ) intersects = []; + + + OctreeRaycaster.intersectOctree(this, raycaster.ray, intersects); + + return intersects; + + }; + + /** + * Returns an iterator that traverses the octree and returns leaf nodes. + * + * When a cull region is provided, the iterator will only return leaves that + * intersect with that region. + * + * @param {Frustum|Box3} [region] - A cull region. + * @return {Iterator} An iterator. + */ + + Octree.prototype.leaves = function leaves (region) { + + return new OctreeIterator(this, region); + + }; + + /** + * Returns an iterator that traverses the octree and returns all leaf nodes. + * + * @return {Iterator} An iterator. + */ + + Octree.prototype[Symbol.iterator] = function () { + + return new OctreeIterator(this); + + }; + + Object.defineProperties( Octree.prototype, prototypeAccessors$1 ); + + /** + * A point. + * + * @type {Vector3} + * @private + */ + + var p = new mathDs.Vector3(); + + /** + * An octant that maintains points. + */ + + var PointOctant = /*@__PURE__*/(function (Octant) { + function PointOctant(min, max) { + + Octant.call(this, min, max); + + /** + * The points. + * + * @type {Vector3[]} + */ + + this.points = null; + + /** + * Point data. + * + * @type {Array} + */ + + this.data = null; + + } + + if ( Octant ) PointOctant.__proto__ = Octant; + PointOctant.prototype = Object.create( Octant && Octant.prototype ); + PointOctant.prototype.constructor = PointOctant; + + /** + * Calculates the distance squared from this octant to the given point. + * + * @param {Vector3} point - A point. + * @return {Number} The distance squared. + */ + + PointOctant.prototype.distanceToSquared = function distanceToSquared (point) { + + var clampedPoint = p.copy(point).clamp(this.min, this.max); + + return clampedPoint.sub(point).lengthSquared(); + + }; + + /** + * Calculates the distance squared from the center of this octant to the given + * point. + * + * @param {Vector3} point - A point. + * @return {Number} The distance squared. + */ + + PointOctant.prototype.distanceToCenterSquared = function distanceToCenterSquared (point) { + + var center = this.getCenter(p); + + var dx = point.x - center.x; + var dy = point.y - center.x; + var dz = point.z - center.z; + + return dx * dx + dy * dy + dz * dz; + + }; + + /** + * Checks if the given point lies inside this octant's boundaries. + * + * This method can also be used to check if this octant intersects a sphere by + * providing a radius as bias. + * + * @param {Vector3} point - A point. + * @param {Number} bias - A padding that extends the boundaries temporarily. + * @return {Boolean} Whether the given point lies inside this octant. + */ + + PointOctant.prototype.contains = function contains (point, bias) { + + var min = this.min; + var max = this.max; + + return ( + point.x >= min.x - bias && + point.y >= min.y - bias && + point.z >= min.z - bias && + point.x <= max.x + bias && + point.y <= max.y + bias && + point.z <= max.z + bias + ); + + }; + + /** + * Redistributes the points of this octant to its children. + * + * Has no effect if there are no points or if this octant has no children. + * + * @param {Number} bias - A proximity threshold. + */ + + PointOctant.prototype.redistribute = function redistribute (bias) { + + var children = this.children; + var points = this.points; + var data = this.data; + + var i, j, il, jl; + var child, point, entry; + + if(children !== null && points !== null) { + + for(i = 0, il = points.length; i < il; ++i) { + + point = points[i]; + entry = data[i]; + + for(j = 0, jl = children.length; j < jl; ++j) { + + child = children[j]; + + if(child.contains(point, bias)) { + + if(child.points === null) { + + child.points = []; + child.data = []; + + } + + child.points.push(point); + child.data.push(entry); + + break; + + } + + } + + } + + this.points = null; + this.data = null; + + } + + }; + + /** + * Deletes all child nodes and collects their points. + */ + + PointOctant.prototype.merge = function merge () { + + var children = this.children; + + if(children !== null) { + + var points = []; + var data = []; + + var i, l, child; + + for(i = 0, l = children.length; i < l; ++i) { + + child = children[i]; + + if(child.points !== null) { + + points = points.concat(child.points); + data = data.concat(child.data); + + } + + } + + /** @ignore */ + this.children = null; + this.points = points; + this.data = data; + + } + + }; + + return PointOctant; + }(Octant)); + + /** + * Recursively counts how many points are in the given octant. + * + * @private + * @param {Octant} octant - An octant. + * @return {Number} The amount of points. + */ + + function countPoints(octant) { + + var children = octant.children; + + var result = 0; + var i, l; + + if(children !== null) { + + for(i = 0, l = children.length; i < l; ++i) { + + result += countPoints(children[i]); + + } + + } else if(octant.points !== null) { + + result = octant.points.length; + + } + + return result; + + } + + /** + * Recursively inserts a point into the octree. + * + * @private + * @param {Vector3} point - A point. + * @param {Object} data - An object that the point represents. + * @param {Octree} octree - The octree. + * @param {Octant} octant - The current octant. + * @param {Number} depth - The current depth. + * @return {Boolean} Whether the operation was successful. + */ + + function insert(point, data, octree, octant, depth) { + + var children = octant.children; + var exists = false; + var done = false; + var i, l; + + if(octant.contains(point, octree.bias)) { + + if(children === null) { + + if(octant.points === null) { + + octant.points = []; + octant.data = []; + + } else { + + for(i = 0, l = octant.points.length; !exists && i < l; ++i) { + + exists = octant.points[i].equals(point); + + } + + } + + if(exists) { + + octant.data[i - 1] = data; + done = true; + + } else if(octant.points.length < octree.maxPoints || depth === octree.maxDepth) { + + octant.points.push(point.clone()); + octant.data.push(data); + ++octree.pointCount; + done = true; + + } else { + + octant.split(); + octant.redistribute(octree.bias); + children = octant.children; + + } + + } + + if(children !== null) { + + ++depth; + + for(i = 0, l = children.length; !done && i < l; ++i) { + + done = insert(point, data, octree, children[i], depth); + + } + + } + + } + + return done; + + } + + /** + * Recursively finds a point in the octree and removes it. + * + * @private + * @param {Vector3} point - A point. + * @param {Octree} octree - The octree. + * @param {Octant} octant - The current octant. + * @param {Octant} parent - The parent of the current octant. + * @return {Object} The data entry of the removed point or null if it didn't exist. + */ + + function remove(point, octree, octant, parent) { + + var children = octant.children; + + var result = null; + + var i, l; + var points, data, last; + + if(octant.contains(point, octree.bias)) { + + if(children !== null) { + + for(i = 0, l = children.length; result === null && i < l; ++i) { + + result = remove(point, octree, children[i], octant); + + } + + } else if(octant.points !== null) { + + points = octant.points; + data = octant.data; + + for(i = 0, l = points.length; i < l; ++i) { + + if(points[i].equals(point)) { + + last = l - 1; + result = data[i]; + + // If the point is NOT the last one in the array: + if(i < last) { + + // Overwrite with the last point and data entry. + points[i] = points[last]; + data[i] = data[last]; + + } + + // Drop the last entry. + points.pop(); + data.pop(); + + --octree.pointCount; + + if(parent !== null && countPoints(parent) <= octree.maxPoints) { + + parent.merge(); + + } + + break; + + } + + } + + } + + } + + return result; + + } + + /** + * Recursively finds a point in the octree and fetches the associated data. + * + * @private + * @param {Vector3} point - A point. + * @param {Octree} octree - The octree. + * @param {Octant} octant - The current octant octant. + * @return {Object} The data entry that is associated with the given point or null if it doesn't exist. + */ + + function get(point, octree, octant) { + + var children = octant.children; + + var result = null; + + var i, l; + var points; + + if(octant.contains(point, octree.bias)) { + + if(children !== null) { + + for(i = 0, l = children.length; result === null && i < l; ++i) { + + result = get(point, octree, children[i]); + + } + + } else if(octant.points !== null) { + + points = octant.points; + + for(i = 0, l = points.length; result === null && i < l; ++i) { + + if(point.equals(points[i])) { + + result = octant.data[i]; + + } + + } + + } + + } + + return result; + + } + + /** + * Recursively moves an existing point to a new position. + * + * @private + * @param {Vector3} point - The point. + * @param {Vector3} position - The new position. + * @param {Octree} octree - The octree. + * @param {Octant} octant - The current octant. + * @param {Octant} parent - The parent of the current octant. + * @param {Number} depth - The current depth. + * @return {Object} The data entry of the updated point or null if it didn't exist. + */ + + function move(point, position, octree, octant, parent, depth) { + + var children = octant.children; + + var result = null; + + var i, l; + var points; + + if(octant.contains(point, octree.bias)) { + + if(octant.contains(position, octree.bias)) { + + // The point and the new position both fall into the current octant. + if(children !== null) { + + ++depth; + + for(i = 0, l = children.length; result === null && i < l; ++i) { + + result = move(point, position, octree, children[i], octant, depth); + + } + + } else if(octant.points !== null) { + + // No divergence - the point can be updated in place. + points = octant.points; + + for(i = 0, l = points.length; i < l; ++i) { + + if(point.equals(points[i])) { + + // The point exists! Update its position. + points[i].copy(position); + result = octant.data[i]; + + break; + + } + + } + + } + + } else { + + // Retrieve the point and remove it. + result = remove(point, octree, octant, parent); + + // Go back to the parent octant and add the updated point. + insert(position, result, octree, parent, depth - 1); + + } + + } + + return result; + + } + + /** + * Recursively finds the closest point to the given one. + * + * @private + * @param {Vector3} point - The point. + * @param {Number} maxDistance - The maximum distance. + * @param {Boolean} skipSelf - Whether a point that is exactly at the given position should be skipped. + * @param {Octant} octant - The current octant. + * @return {Object} An object representing the nearest point or null if there is none. + * @property {Vector3} point - The nearest point. + * @property {Object} data - The data that belongs to the point. + * @property {Number} distance - The distance to the given point. + */ + + function findNearestPoint(point, maxDistance, skipSelf, octant) { + + var result = null; + var bestDistance = maxDistance; + var i, l; + + if(octant.children !== null) { + + // Sort the children: smallest distance to the point first, ASC. + var sortedChildren = octant.children.map(function (child) { + + // Precompute distances. + return { + octant: child, + distance: child.distanceToCenterSquared(point) + }; + + }).sort(function (a, b) { return a.distance - b.distance; }); + + var child, intermediateResult; + + // Traverse from closest to furthest. + for(i = 0, l = sortedChildren.length; i < l; ++i) { + + child = sortedChildren[i].octant; + + if(child.contains(point, bestDistance)) { + + intermediateResult = findNearestPoint(point, bestDistance, skipSelf, child); + + if(intermediateResult !== null) { + + bestDistance = intermediateResult.distance; + result = intermediateResult; + + if(bestDistance === 0.0) { + + break; + + } + + } + + } + + } + + } else if(octant.points !== null) { + + var points = octant.points; + + var index = -1; + var distance; + + for(i = 0, l = points.length; i < l; ++i) { + + if(points[i].equals(point)) { + + if(!skipSelf) { + + bestDistance = 0.0; + index = i; + break; + + } + + } else { + + distance = point.distanceTo(points[i]); + + if(distance < bestDistance) { + + bestDistance = distance; + index = i; + + } + + } + + } + + if(index >= 0) { + + result = { + point: points[index], + data: octant.data[index], + distance: bestDistance + }; + + } + + } + + return result; + + } + + /** + * Recursively finds points that are inside the specified radius around a given + * position. + * + * @private + * @param {Vector3} point - A position. + * @param {Number} radius - A radius. + * @param {Boolean} skipSelf - Whether a point that is exactly at the given position should be skipped. + * @param {Octant} octant - The current octant. + * @param {Array} result - An array to be filled with objects. + * @property {Vector3} point - A point. + * @property {Object} data - The data that belongs to the point. + */ + + function findPoints(point, radius, skipSelf, octant, result) { + + var children = octant.children; + + var i, l; + + if(children !== null) { + + var child; + + for(i = 0, l = children.length; i < l; ++i) { + + child = children[i]; + + if(child.contains(point, radius)) { + + findPoints(point, radius, skipSelf, child, result); + + } + + } + + } else if(octant.points !== null) { + + var points = octant.points; + var rSq = radius * radius; + + var p; + + for(i = 0, l = points.length; i < l; ++i) { + + p = points[i]; + + if(p.equals(point)) { + + if(!skipSelf) { + + result.push({ + point: p.clone(), + data: octant.data[i] + }); + + } + + } else if(p.distanceToSquared(point) <= rSq) { + + result.push({ + point: p.clone(), + data: octant.data[i] + }); + + } + + } + + } + + } + + /** + * An octree that manages points. + */ + + var PointOctree = /*@__PURE__*/(function (Octree) { + function PointOctree(min, max, bias, maxPoints, maxDepth) { + if ( bias === void 0 ) bias = 0.0; + if ( maxPoints === void 0 ) maxPoints = 8; + if ( maxDepth === void 0 ) maxDepth = 8; + + + Octree.call(this, new PointOctant(min, max)); + + /** + * An octant boundary bias. + * + * @type {Number} + * @private + */ + + this.bias = Math.max(0.0, bias); + + /** + * The number of points per octant before a split occurs. + * + * This value works together with the maximum depth as a secondary limiting + * factor. Smaller values cause splits to occur earlier which results in a + * faster and deeper tree growth. + * + * @type {Number} + * @private + */ + + this.maxPoints = Math.max(1, Math.round(maxPoints)); + + /** + * The maximum tree depth level. + * + * It's possible to use Infinity, but keep in mind that allowing infinitely + * small octants can have a severely negative impact on performance. + * Finding a value that works best for a specific scene is advisable. + * + * @type {Number} + * @private + */ + + this.maxDepth = Math.max(0, Math.round(maxDepth)); + + /** + * The amount of points that are currently in this octree. + * + * @type {Number} + */ + + this.pointCount = 0; + + } + + if ( Octree ) PointOctree.__proto__ = Octree; + PointOctree.prototype = Object.create( Octree && Octree.prototype ); + PointOctree.prototype.constructor = PointOctree; + + /** + * Counts how many points are in the given octant. + * + * @param {Octant} octant - An octant. + * @return {Number} The amount of points. + */ + + PointOctree.prototype.countPoints = function countPoints$1 (octant) { + + return countPoints(octant); + + }; + + /** + * Puts a point into the octree. + * + * @param {Vector3} point - A point. If it's already in the octree, the data entry will be updated. + * @param {Object} data - A data object that belongs to the point. + * @return {Boolean} Whether the operation was successful. + */ + + PointOctree.prototype.insert = function insert$1 (point, data) { + + return insert(point, data, this, this.root, 0); + + }; + + /** + * Removes a point from the tree. + * + * @param {Vector3} point - A point. + * @return {Object} The data entry of the removed point or null if it didn't exist. + */ + + PointOctree.prototype.remove = function remove$1 (point) { + + return remove(point, this, this.root, null); + + }; + + /** + * Retrieves the data of the specified point. + * + * @param {Vector3} point - A position. + * @return {Object} The data entry that is associated with the given point or null if it doesn't exist. + */ + + PointOctree.prototype.get = function get$1 (point) { + + return get(point, this, this.root); + + }; + + /** + * Moves an existing point to a new position. Has no effect if the point + * doesn't exist. + * + * @param {Vector3} point - The point. + * @param {Vector3} position - The new position. + * @return {Object} The data entry of the updated point or null if it didn't exist. + */ + + PointOctree.prototype.move = function move$1 (point, position) { + + return move(point, position, this, this.root, null, 0); + + }; + + /** + * Finds the closest point to the given one. + * + * @param {Vector3} point - A point. + * @param {Number} [maxDistance=Infinity] - An upper limit for the distance between the points. + * @param {Boolean} [skipSelf=false] - Whether a point that is exactly at the given position should be skipped. + * @return {Object} An object representing the nearest point or null if there is none. + * @property {Vector3} point - The nearest point. + * @property {Object} data - The data that belongs to the point. + * @property {Number} distance - The distance to the given point. + */ + + PointOctree.prototype.findNearestPoint = function findNearestPoint$1 (point, maxDistance, skipSelf) { + if ( maxDistance === void 0 ) maxDistance = Infinity; + if ( skipSelf === void 0 ) skipSelf = false; + + + var result = findNearestPoint(point, maxDistance, skipSelf, this.root); + + if(result !== null) { + + result.point = result.point.clone(); + + } + + return result; + + }; + + /** + * Finds points that are in the specified radius around the given position. + * + * @param {Vector3} point - A position. + * @param {Number} radius - A radius. + * @param {Boolean} [skipSelf=false] - Whether a point that is exactly at the given position should be skipped. + * @return {Array} An array of objects. + * @property {Vector3} point - A point. + * @property {Object} data - The data that belongs to the point. + */ + + PointOctree.prototype.findPoints = function findPoints$1 (point, radius, skipSelf) { + if ( skipSelf === void 0 ) skipSelf = false; + + + var result = []; + + findPoints(point, radius, skipSelf, this.root, result); + + return result; + + }; + + /** + * Finds the points that intersect with the given ray. + * + * @param {Raycaster} raycaster - The raycaster. + * @param {Array} [intersects] - An array to be filled with the intersecting points. + * @return {RayPointIntersection[]} The intersecting points. + */ + + PointOctree.prototype.raycast = function raycast (raycaster, intersects) { + if ( intersects === void 0 ) intersects = []; + + + var octants = Octree.prototype.raycast.call(this, raycaster); + + if(octants.length > 0) { + + testPoints(octants, raycaster, intersects); + + } + + return intersects; + + }; + + return PointOctree; + }(Octree)); + + exports.CubicOctant = CubicOctant; + exports.Flags = Flags; + exports.Octant = Octant; + exports.Octree = Octree; + exports.OctreeIterator = OctreeIterator; + exports.OctreeRaycaster = OctreeRaycaster; + exports.PointOctant = PointOctant; + exports.PointOctree = PointOctree; + exports.RayPointIntersection = RayPointIntersection; + exports.edges = edges; + exports.findEntryOctant = findEntryOctant; + exports.findNextOctant = findNextOctant; + exports.intersectOctree = intersectOctree; + exports.layout = layout; + exports.testPoints = testPoints; + + Object.defineProperty(exports, '__esModule', { value: true }); }))); diff --git a/build/sparse-octree.min.js b/build/sparse-octree.min.js index 5b4d990..2331e18 100644 --- a/build/sparse-octree.min.js +++ b/build/sparse-octree.min.js @@ -1,7 +1,7 @@ /** - * sparse-octree v6.0.2 build Sat Jan 18 2020 + * sparse-octree v6.1.0 build Tue Aug 18 2020 * https://github.com/vanruesc/sparse-octree * Copyright 2020 Raoul van Rüschen * @license Zlib */ -!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("math-ds"),require("iterator-result")):"function"==typeof define&&define.amd?define(["exports","math-ds","iterator-result"],n):n((t=t||self).SPARSEOCTREE={},t.MATHDS,t.ITERATORRESULT)}(this,(function(t,n,e){"use strict";function i(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}function r(t,n){for(var e=0;e0&&void 0!==arguments[0]?arguments[0]:new n.Vector3,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;i(this,t),this.min=e,this.size=r,this.children=null}return o(t,[{key:"getCenter",value:function(t){return t.copy(this.min).addScalar(.5*this.size)}},{key:"getDimensions",value:function(t){return t.set(this.size,this.size,this.size)}},{key:"split",value:function(){var t,e,i=this.min,r=this.getCenter(d),o=.5*this.size,l=this.children=[null,null,null,null,null,null,null,null];for(t=0;t<8;++t)e=y[t],l[t]=new this.constructor(new n.Vector3(0===e[0]?i.x:r.x,0===e[1]?i.y:r.y,0===e[2]?i.z:r.z),o)}},{key:"max",get:function(){return this.min.clone().addScalar(this.size)}}]),t}(),v=new n.Vector3,g=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new n.Vector3,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new n.Vector3;i(this,t),this.min=e,this.max=r,this.children=null}return o(t,[{key:"getCenter",value:function(t){return t.addVectors(this.min,this.max).multiplyScalar(.5)}},{key:"getDimensions",value:function(t){return t.subVectors(this.max,this.min)}},{key:"split",value:function(){var t,e,i=this.min,r=this.max,o=this.getCenter(v),l=this.children=[null,null,null,null,null,null,null,null];for(t=0;t<8;++t)e=y[t],l[t]=new this.constructor(new n.Vector3(0===e[0]?i.x:o.x,0===e[1]?i.y:o.y,0===e[2]?i.z:o.z),new n.Vector3(0===e[0]?o.x:r.x,0===e[1]?o.y:r.y,0===e[2]?o.z:r.z))}}]),t}(),m=function t(n,e,r){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;i(this,t),this.distance=n,this.distanceToRay=e,this.point=r,this.object=o};function w(t,e,i){var r,o,l,a,u,s,c,h,f,y,d,p=e.params.Points.threshold,v=p*p;for(u=0,c=t.length;u=e.near&&o<=e.far&&(l=Math.sqrt(a),i.push(new m(o,l,r,f.data[s]))))}var x=function t(){i(this,t),this.value=0};function b(t,n,e,i,r,o){var l=0;return t>n&&t>e?(re?(i=0&&o>=0&&l>=0){var u=t.children;if(null===u)a.push(t);else{var s=.5*(n+r),c=.5*(e+o),h=.5*(i+l),f=T.value,y=b(n,e,i,s,c,h);do{switch(y){case 0:C(u[f],n,e,i,s,c,h,a),y=A(y,s,c,h);break;case 1:C(u[1^f],n,e,h,s,c,l,a),y=A(y,s,c,l);break;case 2:C(u[2^f],n,c,i,s,o,h,a),y=A(y,s,o,h);break;case 3:C(u[3^f],n,c,h,s,o,l,a),y=A(y,s,o,l);break;case 4:C(u[4^f],s,e,i,r,c,h,a),y=A(y,r,c,h);break;case 5:C(u[5^f],s,e,h,r,c,l,a),y=A(y,r,c,l);break;case 6:C(u[6^f],s,c,i,r,o,h,a),y=A(y,r,o,h);break;case 7:C(u[7^f],s,c,h,r,o,l,a),y=8}}while(y<8)}}}var j=function(){function t(){i(this,t)}return o(t,null,[{key:"intersectOctree",value:function(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],i=S(t,n,T);null!==i&&C.apply(void 0,[t.root].concat(h(i),[e]))}}]),t}(),q=new n.Box3,V=function(){function t(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;i(this,t),this.octree=n,this.region=r,this.cull=null!==r,this.result=new e,this.trace=null,this.indices=null,this.reset()}return o(t,[{key:"reset",value:function(){var t=this.octree.root;return this.trace=[],this.indices=[],null!==t&&(q.min=t.min,q.max=t.max,this.cull&&!this.region.intersectsBox(q)||(this.trace.push(t),this.indices.push(0))),this.result.reset(),this}},{key:"next",value:function(){for(var t,n,e,i=this.cull,r=this.region,o=this.indices,l=this.trace,a=null,u=l.length-1;null===a&&u>=0;)if(t=o[u]++,n=l[u].children,t<8)if(null!==n){if(e=n[t],i&&(q.min=e.min,q.max=e.max,!r.intersectsBox(q)))continue;l.push(e),o.push(0),++u}else a=l.pop(),o.pop();else l.pop(),o.pop(),--u;return this.result.value=a,this.result.done=null===a,this.result}},{key:"return",value:function(t){return this.result.value=t,this.result.done=!0,this.result}},{key:Symbol.iterator,value:function(){return this}}]),t}(),R=new n.Box3;var M=function(){function t(n){i(this,t),this.root=n}return o(t,[{key:"getCenter",value:function(t){return this.root.getCenter(t)}},{key:"getDimensions",value:function(t){return this.root.getDimensions(t)}},{key:"cull",value:function(t){var n=[];return function t(n,e,i){var r,o,l=n.children;if(R.min=n.min,R.max=n.max,e.intersectsBox(R))if(null!==l)for(r=0,o=l.length;rl&&(l=r);return l}(this.root)}},{key:"findNodesByLevel",value:function(t){var n=[];return function t(n,e,i,r){var o,l,a=n.children;if(i===e)r.push(n);else if(null!==a)for(++i,o=0,l=a.length;o1&&void 0!==arguments[1]?arguments[1]:[];return j.intersectOctree(this,t.ray,n),n}},{key:"leaves",value:function(t){return new V(this,t)}},{key:Symbol.iterator,value:function(){return new V(this)}},{key:"min",get:function(){return this.root.min}},{key:"max",get:function(){return this.root.max}},{key:"children",get:function(){return this.root.children}}]),t}(),D=new n.Vector3,E=function(t){function n(t,e){var r;return i(this,n),(r=s(this,a(n).call(this,t,e))).points=null,r.data=null,r}return l(n,t),o(n,[{key:"distanceToSquared",value:function(t){return D.copy(t).clamp(this.min,this.max).sub(t).lengthSquared()}},{key:"distanceToCenterSquared",value:function(t){var n=this.getCenter(D),e=t.x-n.x,i=t.y-n.x,r=t.z-n.z;return e*e+i*i+r*r}},{key:"contains",value:function(t,n){var e=this.min,i=this.max;return t.x>=e.x-n&&t.y>=e.y-n&&t.z>=e.z-n&&t.x<=i.x+n&&t.y<=i.y+n&&t.z<=i.z+n}},{key:"redistribute",value:function(t){var n,e,i,r,o,l,a,u=this.children,s=this.points,c=this.data;if(null!==u&&null!==s){for(n=0,i=s.length;n=0&&(l={point:f[y],data:i.data[y],distance:a})}return l}function L(t,n,e,i,r){var o,l,a,u=i.children;if(null!==u)for(o=0,l=u.length;o2&&void 0!==arguments[2]?arguments[2]:0,l=arguments.length>3&&void 0!==arguments[3]?arguments[3]:8,u=arguments.length>4&&void 0!==arguments[4]?arguments[4]:8;return i(this,n),(r=s(this,a(n).call(this,new E(t,e)))).bias=Math.max(0,o),r.maxPoints=Math.max(1,Math.round(l)),r.maxDepth=Math.max(0,Math.round(u)),r.pointCount=0,r}return l(n,t),o(n,[{key:"countPoints",value:function(t){return _(t)}},{key:"insert",value:function(t,n){return B(t,n,this,this.root,0)}},{key:"remove",value:function(t){return I(t,this,this.root,null)}},{key:"get",value:function(t){return function t(n,e,i){var r,o,l,a=i.children,u=null;if(i.contains(n,e.bias))if(null!==a)for(r=0,o=a.length;null===u&&r1&&void 0!==arguments[1]?arguments[1]:1/0,e=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=N(t,n,e,this.root);return null!==i&&(i.point=i.point.clone()),i}},{key:"findPoints",value:function(t,n){var e=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=[];return L(t,n,e,this.root,i),i}},{key:"raycast",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],i=c(a(n.prototype),"raycast",this).call(this,t);return i.length>0&&w(i,t,e),e}}]),n}(M);t.CubicOctant=p,t.Flags=x,t.Octant=g,t.Octree=M,t.OctreeIterator=V,t.OctreeRaycaster=j,t.PointOctant=E,t.PointOctree=F,t.RayPointIntersection=m,t.edges=f,t.findEntryOctant=b,t.findNextOctant=A,t.intersectOctree=S,t.layout=y,t.testPoints=w,Object.defineProperty(t,"__esModule",{value:!0})})); +!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("math-ds")):"function"==typeof define&&define.amd?define(["exports","math-ds"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).SPARSEOCTREE={},t.MATHDS)}(this,(function(t,n){"use strict";var e=[new Uint8Array([0,4]),new Uint8Array([1,5]),new Uint8Array([2,6]),new Uint8Array([3,7]),new Uint8Array([0,2]),new Uint8Array([1,3]),new Uint8Array([4,6]),new Uint8Array([5,7]),new Uint8Array([0,1]),new Uint8Array([2,3]),new Uint8Array([4,5]),new Uint8Array([6,7])],i=[new Uint8Array([0,0,0]),new Uint8Array([0,0,1]),new Uint8Array([0,1,0]),new Uint8Array([0,1,1]),new Uint8Array([1,0,0]),new Uint8Array([1,0,1]),new Uint8Array([1,1,0]),new Uint8Array([1,1,1])],r=new n.Vector3,o=function(t,e){void 0===t&&(t=new n.Vector3),void 0===e&&(e=0),this.min=t,this.size=e,this.children=null},s={max:{configurable:!0}};s.max.get=function(){return this.min.clone().addScalar(this.size)},o.prototype.getCenter=function(t){return t.copy(this.min).addScalar(.5*this.size)},o.prototype.getDimensions=function(t){return t.set(this.size,this.size,this.size)},o.prototype.split=function(){var t,e,o=this.min,s=this.getCenter(r),a=.5*this.size,l=this.children=[null,null,null,null,null,null,null,null];for(t=0;t<8;++t)e=i[t],l[t]=new this.constructor(new n.Vector3(0===e[0]?o.x:s.x,0===e[1]?o.y:s.y,0===e[2]?o.z:s.z),a)},Object.defineProperties(o.prototype,s);var a=new n.Vector3,l=function(t,e){void 0===t&&(t=new n.Vector3),void 0===e&&(e=new n.Vector3),this.min=t,this.max=e,this.children=null};l.prototype.getCenter=function(t){return t.addVectors(this.min,this.max).multiplyScalar(.5)},l.prototype.getDimensions=function(t){return t.subVectors(this.max,this.min)},l.prototype.split=function(){var t,e,r=this.min,o=this.max,s=this.getCenter(a),l=this.children=[null,null,null,null,null,null,null,null];for(t=0;t<8;++t)e=i[t],l[t]=new this.constructor(new n.Vector3(0===e[0]?r.x:s.x,0===e[1]?r.y:s.y,0===e[2]?r.z:s.z),new n.Vector3(0===e[0]?s.x:o.x,0===e[1]?s.y:o.y,0===e[2]?s.z:o.z))};var u=function(t,n,e,i){void 0===i&&(i=null),this.distance=t,this.distanceToRay=n,this.point=e,this.object=i};function c(t,e,i){var r,o,s,a,l,c,h,p,f,d,y,v=e.params.Points.threshold,m=v*v;for(l=0,h=t.length;l=e.near&&o<=e.far&&(s=Math.sqrt(a),i.push(new u(o,s,r,f.data[c]))))}var h=function(){this.value=0};function p(t,n,e,i,r,o){var s=0;return t>n&&t>e?(re?(i=0&&o>=0&&s>=0){var l=t.children;if(null===l)a.push(t);else{var u=.5*(n+r),c=.5*(e+o),h=.5*(i+s),f=w.value,y=p(n,e,i,u,c,h);do{switch(y){case 0:b(l[f],n,e,i,u,c,h,a),y=d(y,u,c,h);break;case 1:b(l[1^f],n,e,h,u,c,s,a),y=d(y,u,c,s);break;case 2:b(l[2^f],n,c,i,u,o,h,a),y=d(y,u,o,h);break;case 3:b(l[3^f],n,c,h,u,o,s,a),y=d(y,u,o,s);break;case 4:b(l[4^f],u,e,i,r,c,h,a),y=d(y,r,c,h);break;case 5:b(l[5^f],u,e,h,r,c,s,a),y=d(y,r,c,s);break;case 6:b(l[6^f],u,c,i,r,o,h,a),y=d(y,r,o,h);break;case 7:b(l[7^f],u,c,h,r,o,s,a),y=8}}while(y<8)}}}var z=function(){};z.intersectOctree=function(t,n,e){void 0===e&&(e=[]);var i=g(t,n,w);null!==i&&b.apply(void 0,[t.root].concat(i,[e]))};var A=function(t,n){void 0===t&&(t=null),void 0===n&&(n=!1),this.value=t,this.done=n};A.prototype.reset=function(){this.value=null,this.done=!1};var U=new n.Box3,O=function(t,n){void 0===n&&(n=null),this.octree=t,this.region=n,this.cull=null!==n,this.result=new A,this.trace=null,this.indices=null,this.reset()};O.prototype.reset=function(){var t=this.octree.root;return this.trace=[],this.indices=[],null!==t&&(U.min=t.min,U.max=t.max,this.cull&&!this.region.intersectsBox(U)||(this.trace.push(t),this.indices.push(0))),this.result.reset(),this},O.prototype.next=function(){for(var t,n,e,i=this.cull,r=this.region,o=this.indices,s=this.trace,a=null,l=s.length-1;null===a&&l>=0;)if(t=o[l]++,n=s[l].children,t<8)if(null!==n){if(e=n[t],i&&(U.min=e.min,U.max=e.max,!r.intersectsBox(U)))continue;s.push(e),o.push(0),++l}else a=s.pop(),o.pop();else s.pop(),o.pop(),--l;return this.result.value=a,this.result.done=null===a,this.result},O.prototype.return=function(t){return this.result.value=t,this.result.done=!0,this.result},O.prototype[Symbol.iterator]=function(){return this};var P=new n.Box3;var C=function(t){this.root=t},S={min:{configurable:!0},max:{configurable:!0},children:{configurable:!0}};S.min.get=function(){return this.root.min},S.max.get=function(){return this.root.max},S.children.get=function(){return this.root.children},C.prototype.getCenter=function(t){return this.root.getCenter(t)},C.prototype.getDimensions=function(t){return this.root.getDimensions(t)},C.prototype.cull=function(t){var n=[];return function t(n,e,i){var r,o,s=n.children;if(P.min=n.min,P.max=n.max,e.intersectsBox(P))if(null!==s)for(r=0,o=s.length;rs&&(s=r);return s}(this.root)},C.prototype.findNodesByLevel=function(t){var n=[];return function t(n,e,i,r){var o,s,a=n.children;if(i===e)r.push(n);else if(null!==a)for(++i,o=0,s=a.length;o=e.x-n&&t.y>=e.y-n&&t.z>=e.z-n&&t.x<=i.x+n&&t.y<=i.y+n&&t.z<=i.z+n},n.prototype.redistribute=function(t){var n,e,i,r,o,s,a,l=this.children,u=this.points,c=this.data;if(null!==l&&null!==u){for(n=0,i=u.length;n=0&&(a={point:f[d],data:r.data[d],distance:l})}return a}(t,n,e,this.root);return null!==i&&(i.point=i.point.clone()),i},n.prototype.findPoints=function(t,n,e){void 0===e&&(e=!1);var i=[];return function t(n,e,i,r,o){var s,a,l,u=r.children;if(null!==u)for(s=0,a=u.length;s0&&c(i,n,e),e},n}(C);t.CubicOctant=o,t.Flags=h,t.Octant=l,t.Octree=C,t.OctreeIterator=O,t.OctreeRaycaster=z,t.PointOctant=V,t.PointOctree=_,t.RayPointIntersection=u,t.edges=e,t.findEntryOctant=p,t.findNextOctant=d,t.intersectOctree=g,t.layout=i,t.testPoints=c,Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/package.json b/package.json index a2e33bb..267b8df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sparse-octree", - "version": "6.0.2", + "version": "6.1.0", "description": "A sparse octree data structure.", "homepage": "https://github.com/vanruesc/sparse-octree", "main": "build/sparse-octree.js", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d9f6fd5..d4ea738 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,841 +1,48 @@ +dependencies: + iterator-result: 1.0.0 devDependencies: - '@babel/core': 7.8.3 - '@babel/preset-env': 7.8.3_@babel+core@7.8.3 - '@rollup/plugin-node-resolve': 7.0.0_rollup@1.29.0 - ava: 2.4.0 - cross-env: 6.0.3 - dat.gui: 0.7.6 - delta-controls: 2.0.4_math-ds@1.1.3 + '@rollup/plugin-buble': 0.21.3_rollup@2.26.3 + '@rollup/plugin-node-resolve': 9.0.0_rollup@2.26.3 + ava: 3.11.1 + concurrently: 5.3.0 + cross-env: 7.0.2 + dat.gui: 0.7.7 esdoc: 1.1.0 esdoc-importpath-plugin: 1.0.2 esdoc-standard-plugin: 1.0.0 - eslint: 6.8.0 - eslint-config-delta: 1.0.1 - iterator-result: 1.0.0 - math-ds: 1.1.3 - octree-helper: 1.1.0_bc902020feb1935eeb21de33d862e386 - rimraf: 3.0.0 - rollup: 1.29.0 - rollup-plugin-babel: 4.3.3_@babel+core@7.8.3+rollup@1.29.0 - rollup-plugin-terser: 5.2.0_rollup@1.29.0 - synthetic-event: 1.0.0 - three: 0.112.1 - three-demo: 3.15.0_6274b0b1a501bff7e0ffa21e46b83b56 + eslint: 7.7.0 + eslint-config-aether: 1.1.1 + eslint-watch: 7.0.0_eslint@7.7.0 + esm: 3.2.25 + http-server: 0.12.3 + math-ds: 1.2.1 + octree-helper: 1.1.6_8ca993b03224d609f7e1cb2dd634b0e9 + rimraf: 3.0.2 + rollup: 2.26.3 + rollup-plugin-terser: 7.0.0_rollup@2.26.3 + spatial-controls: 3.0.0_three@0.119.1 + three: 0.119.1 + three-demo: 4.0.1_dat.gui@0.7.7+three@0.119.1 lockfileVersion: 5.1 packages: - /@ava/babel-plugin-throws-helper/4.0.0: - dev: true - engines: - node: '>=8.9.4 <9 || >=10.0.0 <11 || >=12.0.0' - resolution: - integrity: sha512-3diBLIVBPPh3j4+hb5lo0I1D+S/O/VDJPI4Y502apBxmwEqjyXG4gTSPFUlm41sSZeZzMarT/Gzovw9kV7An0w== - /@ava/babel-preset-stage-4/4.0.0_@babel+core@7.8.3: - dependencies: - '@babel/plugin-proposal-async-generator-functions': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-proposal-dynamic-import': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-proposal-optional-catch-binding': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-dotall-regex': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-modules-commonjs': 7.8.3_@babel+core@7.8.3 - dev: true - engines: - node: '>=8.9.4 <9 || >=10.0.0 <11 || >=12.0.0' - peerDependencies: - '@babel/core': '*' - resolution: - integrity: sha512-lZEV1ZANzfzSYBU6WHSErsy7jLPbD1iIgAboASPMcKo7woVni5/5IKWeT0RxC8rY802MFktur3OKEw2JY1Tv2w== - /@ava/babel-preset-transform-test-files/6.0.0: - dependencies: - '@ava/babel-plugin-throws-helper': 4.0.0 - babel-plugin-espower: 3.0.1 - dev: true - engines: - node: '>=8.9.4 <9 || >=10.0.0 <11 || >=12.0.0' - resolution: - integrity: sha512-8eKhFzZp7Qcq1VLfoC75ggGT8nQs9q8fIxltU47yCB7Wi7Y8Qf6oqY1Bm0z04fIec24vEgr0ENhDHEOUGVDqnA== - /@babel/code-frame/7.8.3: - dependencies: - '@babel/highlight': 7.8.3 - dev: true - resolution: - integrity: sha512-a9gxpmdXtZEInkCSHUJDLHZVBgb1QS0jhss4cPP93EW7s+uC5bikET2twEF3KV+7rDblJcmNvTR7VJejqd2C2g== - /@babel/compat-data/7.8.1: - dependencies: - browserslist: 4.8.3 - invariant: 2.2.4 - semver: 5.7.1 - dev: true - resolution: - integrity: sha512-Z+6ZOXvyOWYxJ50BwxzdhRnRsGST8Y3jaZgxYig575lTjVSs3KtJnmESwZegg6e2Dn0td1eDhoWlp1wI4BTCPw== - /@babel/core/7.8.3: - dependencies: - '@babel/code-frame': 7.8.3 - '@babel/generator': 7.8.3 - '@babel/helpers': 7.8.3 - '@babel/parser': 7.8.3 - '@babel/template': 7.8.3 - '@babel/traverse': 7.8.3 - '@babel/types': 7.8.3 - convert-source-map: 1.7.0 - debug: 4.1.1 - gensync: 1.0.0-beta.1 - json5: 2.1.1 - lodash: 4.17.15 - resolve: 1.14.2 - semver: 5.7.1 - source-map: 0.5.7 - dev: true - engines: - node: '>=6.9.0' - resolution: - integrity: sha512-4XFkf8AwyrEG7Ziu3L2L0Cv+WyY47Tcsp70JFmpftbAA1K7YL/sgE9jh9HyNj08Y/U50ItUchpN0w6HxAoX1rA== - /@babel/generator/7.8.3: - dependencies: - '@babel/types': 7.8.3 - jsesc: 2.5.2 - lodash: 4.17.15 - source-map: 0.5.7 - dev: true - resolution: - integrity: sha512-WjoPk8hRpDRqqzRpvaR8/gDUPkrnOOeuT2m8cNICJtZH6mwaCo3v0OKMI7Y6SM1pBtyijnLtAL0HDi41pf41ug== - /@babel/helper-annotate-as-pure/7.8.3: + /@babel/code-frame/7.10.4: dependencies: - '@babel/types': 7.8.3 + '@babel/highlight': 7.10.4 dev: true resolution: - integrity: sha512-6o+mJrZBxOoEX77Ezv9zwW7WV8DdluouRKNY/IR5u/YTMuKHgugHOzYWlYvYLpLA9nPsQCAAASpCIbjI9Mv+Uw== - /@babel/helper-builder-binary-assignment-operator-visitor/7.8.3: - dependencies: - '@babel/helper-explode-assignable-expression': 7.8.3 - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-5eFOm2SyFPK4Rh3XMMRDjN7lBH0orh3ss0g3rTYZnBQ+r6YPj7lgDyCvPphynHvUrobJmeMignBr6Acw9mAPlw== - /@babel/helper-call-delegate/7.8.3: - dependencies: - '@babel/helper-hoist-variables': 7.8.3 - '@babel/traverse': 7.8.3 - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-6Q05px0Eb+N4/GTyKPPvnkig7Lylw+QzihMpws9iiZQv7ZImf84ZsZpQH7QoWN4n4tm81SnSzPgHw2qtO0Zf3A== - /@babel/helper-compilation-targets/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/compat-data': 7.8.1 - '@babel/core': 7.8.3 - browserslist: 4.8.3 - invariant: 2.2.4 - levenary: 1.1.0 - semver: 5.7.1 - dev: true - peerDependencies: - '@babel/core': ^7.0.0 - resolution: - integrity: sha512-JLylPCsFjhLN+6uBSSh3iYdxKdeO9MNmoY96PE/99d8kyBFaXLORtAVhqN6iHa+wtPeqxKLghDOZry0+Aiw9Tw== - /@babel/helper-create-regexp-features-plugin/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-regex': 7.8.3 - regexpu-core: 4.6.0 - dev: true - peerDependencies: - '@babel/core': ^7.0.0 - resolution: - integrity: sha512-Gcsm1OHCUr9o9TcJln57xhWHtdXbA2pgQ58S0Lxlks0WMGNXuki4+GLfX0p+L2ZkINUGZvfkz8rzoqJQSthI+Q== - /@babel/helper-define-map/7.8.3: - dependencies: - '@babel/helper-function-name': 7.8.3 - '@babel/types': 7.8.3 - lodash: 4.17.15 - dev: true - resolution: - integrity: sha512-PoeBYtxoZGtct3md6xZOCWPcKuMuk3IHhgxsRRNtnNShebf4C8YonTSblsK4tvDbm+eJAw2HAPOfCr+Q/YRG/g== - /@babel/helper-explode-assignable-expression/7.8.3: - dependencies: - '@babel/traverse': 7.8.3 - '@babel/types': 7.8.3 + integrity: sha512-vG6SvB6oYEhvgisZNFRmRCUkLz11c7rp+tbNTynGqc6mS1d5ATd/sGyV6W0KZZnXRKMTzZDRgQT3Ou9jhpAfUg== + /@babel/helper-validator-identifier/7.10.4: dev: true resolution: - integrity: sha512-N+8eW86/Kj147bO9G2uclsg5pwfs/fqqY5rwgIL7eTBklgXjcOJ3btzS5iM6AitJcftnY7pm2lGsrJVYLGjzIw== - /@babel/helper-function-name/7.8.3: - dependencies: - '@babel/helper-get-function-arity': 7.8.3 - '@babel/template': 7.8.3 - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-BCxgX1BC2hD/oBlIFUgOCQDOPV8nSINxCwM3o93xP4P9Fq6aV5sgv2cOOITDMtCfQ+3PvHp3l689XZvAM9QyOA== - /@babel/helper-get-function-arity/7.8.3: - dependencies: - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-FVDR+Gd9iLjUMY1fzE2SR0IuaJToR4RkCDARVfsBBPSP53GEqSFjD8gNyxg246VUyc/ALRxFaAK8rVG7UT7xRA== - /@babel/helper-hoist-variables/7.8.3: - dependencies: - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-ky1JLOjcDUtSc+xkt0xhYff7Z6ILTAHKmZLHPxAhOP0Nd77O+3nCsd6uSVYur6nJnCI029CrNbYlc0LoPfAPQg== - /@babel/helper-member-expression-to-functions/7.8.3: - dependencies: - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-fO4Egq88utkQFjbPrSHGmGLFqmrshs11d46WI+WZDESt7Wu7wN2G2Iu+NMMZJFDOVRHAMIkB5SNh30NtwCA7RA== - /@babel/helper-module-imports/7.8.3: - dependencies: - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-R0Bx3jippsbAEtzkpZ/6FIiuzOURPcMjHp+Z6xPe6DtApDJx+w7UYyOLanZqO8+wKR9G10s/FmHXvxaMd9s6Kg== - /@babel/helper-module-transforms/7.8.3: - dependencies: - '@babel/helper-module-imports': 7.8.3 - '@babel/helper-simple-access': 7.8.3 - '@babel/helper-split-export-declaration': 7.8.3 - '@babel/template': 7.8.3 - '@babel/types': 7.8.3 - lodash: 4.17.15 - dev: true - resolution: - integrity: sha512-C7NG6B7vfBa/pwCOshpMbOYUmrYQDfCpVL/JCRu0ek8B5p8kue1+BCXpg2vOYs7w5ACB9GTOBYQ5U6NwrMg+3Q== - /@babel/helper-optimise-call-expression/7.8.3: - dependencies: - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-Kag20n86cbO2AvHca6EJsvqAd82gc6VMGule4HwebwMlwkpXuVqrNRj6CkCV2sKxgi9MyAUnZVnZ6lJ1/vKhHQ== - /@babel/helper-plugin-utils/7.8.3: - dev: true - resolution: - integrity: sha512-j+fq49Xds2smCUNYmEHF9kGNkhbet6yVIBp4e6oeQpH1RUs/Ir06xUKzDjDkGcaaokPiTNs2JBWHjaE4csUkZQ== - /@babel/helper-regex/7.8.3: - dependencies: - lodash: 4.17.15 - dev: true - resolution: - integrity: sha512-BWt0QtYv/cg/NecOAZMdcn/waj/5P26DR4mVLXfFtDokSR6fyuG0Pj+e2FqtSME+MqED1khnSMulkmGl8qWiUQ== - /@babel/helper-remap-async-to-generator/7.8.3: - dependencies: - '@babel/helper-annotate-as-pure': 7.8.3 - '@babel/helper-wrap-function': 7.8.3 - '@babel/template': 7.8.3 - '@babel/traverse': 7.8.3 - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-kgwDmw4fCg7AVgS4DukQR/roGp+jP+XluJE5hsRZwxCYGg+Rv9wSGErDWhlI90FODdYfd4xG4AQRiMDjjN0GzA== - /@babel/helper-replace-supers/7.8.3: - dependencies: - '@babel/helper-member-expression-to-functions': 7.8.3 - '@babel/helper-optimise-call-expression': 7.8.3 - '@babel/traverse': 7.8.3 - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-xOUssL6ho41U81etpLoT2RTdvdus4VfHamCuAm4AHxGr+0it5fnwoVdwUJ7GFEqCsQYzJUhcbsN9wB9apcYKFA== - /@babel/helper-simple-access/7.8.3: - dependencies: - '@babel/template': 7.8.3 - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-VNGUDjx5cCWg4vvCTR8qQ7YJYZ+HBjxOgXEl7ounz+4Sn7+LMD3CFrCTEU6/qXKbA2nKg21CwhhBzO0RpRbdCw== - /@babel/helper-split-export-declaration/7.8.3: - dependencies: - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-3x3yOeyBhW851hroze7ElzdkeRXQYQbFIb7gLK1WQYsw2GWDay5gAJNw1sWJ0VFP6z5J1whqeXH/WCdCjZv6dA== - /@babel/helper-wrap-function/7.8.3: - dependencies: - '@babel/helper-function-name': 7.8.3 - '@babel/template': 7.8.3 - '@babel/traverse': 7.8.3 - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-LACJrbUET9cQDzb6kG7EeD7+7doC3JNvUgTEQOx2qaO1fKlzE/Bf05qs9w1oXQMmXlPO65lC3Tq9S6gZpTErEQ== - /@babel/helpers/7.8.3: - dependencies: - '@babel/template': 7.8.3 - '@babel/traverse': 7.8.3 - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-LmU3q9Pah/XyZU89QvBgGt+BCsTPoQa+73RxAQh8fb8qkDyIfeQnmgs+hvzhTCKTzqOyk7JTkS3MS1S8Mq5yrQ== - /@babel/highlight/7.8.3: + integrity: sha512-3U9y+43hz7ZM+rzG24Qe2mufW5KhvFg/NhnNph+i9mgCtdTCtMJuI1TMkrIUiK7Ix4PYlRF9I5dhqaLYA/ADXw== + /@babel/highlight/7.10.4: dependencies: + '@babel/helper-validator-identifier': 7.10.4 chalk: 2.4.2 - esutils: 2.0.3 js-tokens: 4.0.0 dev: true resolution: - integrity: sha512-PX4y5xQUvy0fnEVHrYOarRPXVWafSjTW9T0Hab8gVIawpl2Sj0ORyrygANq+KjcNlSSTw0YCLSNA8OyZ1I4yEg== - /@babel/parser/7.8.3: - dev: true - engines: - node: '>=6.0.0' - hasBin: true - resolution: - integrity: sha512-/V72F4Yp/qmHaTALizEm9Gf2eQHV3QyTL3K0cNfijwnMnb1L+LDlAubb/ZnSdGAVzVSWakujHYs1I26x66sMeQ== - /@babel/plugin-proposal-async-generator-functions/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/helper-remap-async-to-generator': 7.8.3 - '@babel/plugin-syntax-async-generators': 7.8.4_@babel+core@7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-NZ9zLv848JsV3hs8ryEh7Uaz/0KsmPLqv0+PdkDJL1cJy0K4kOCFa8zc1E3mp+RHPQcpdfb/6GovEsW4VDrOMw== - /@babel/plugin-proposal-dynamic-import/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/plugin-syntax-dynamic-import': 7.8.3_@babel+core@7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-NyaBbyLFXFLT9FP+zk0kYlUlA8XtCUbehs67F0nnEg7KICgMc2mNkIeu9TYhKzyXMkrapZFwAhXLdnt4IYHy1w== - /@babel/plugin-proposal-json-strings/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/plugin-syntax-json-strings': 7.8.3_@babel+core@7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-KGhQNZ3TVCQG/MjRbAUwuH+14y9q0tpxs1nWWs3pbSleRdDro9SAMMDyye8HhY1gqZ7/NqIc8SKhya0wRDgP1Q== - /@babel/plugin-proposal-nullish-coalescing-operator/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/plugin-syntax-nullish-coalescing-operator': 7.8.3_@babel+core@7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-TS9MlfzXpXKt6YYomudb/KU7nQI6/xnapG6in1uZxoxDghuSMZsPb6D2fyUwNYSAp4l1iR7QtFOjkqcRYcUsfw== - /@babel/plugin-proposal-object-rest-spread/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/plugin-syntax-object-rest-spread': 7.8.3_@babel+core@7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-8qvuPwU/xxUCt78HocNlv0mXXo0wdh9VT1R04WU8HGOfaOob26pF+9P5/lYjN/q7DHOX1bvX60hnhOvuQUJdbA== - /@babel/plugin-proposal-optional-catch-binding/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/plugin-syntax-optional-catch-binding': 7.8.3_@babel+core@7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-0gkX7J7E+AtAw9fcwlVQj8peP61qhdg/89D5swOkjYbkboA2CVckn3kiyum1DE0wskGb7KJJxBdyEBApDLLVdw== - /@babel/plugin-proposal-optional-chaining/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/plugin-syntax-optional-chaining': 7.8.3_@babel+core@7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-QIoIR9abkVn+seDE3OjA08jWcs3eZ9+wJCKSRgo3WdEU2csFYgdScb+8qHB3+WXsGJD55u+5hWCISI7ejXS+kg== - /@babel/plugin-proposal-unicode-property-regex/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-create-regexp-features-plugin': 7.8.3_@babel+core@7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - engines: - node: '>=4' - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-1/1/rEZv2XGweRwwSkLpY+s60za9OZ1hJs4YDqFHCw0kYWYwL5IFljVY1MYBL+weT1l9pokDO2uhSTLVxzoHkQ== - /@babel/plugin-syntax-async-generators/7.8.4_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-tycmZxkGfZaxhMRbXlPXuVFpdWlXpir2W4AMhSJgRKzk/eDlIXOhb2LHWoLpDF7TEHylV5zNhykX6KAgHJmTNw== - /@babel/plugin-syntax-dynamic-import/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-5gdGbFon+PszYzqs83S3E5mpi7/y/8M9eC90MRTZfduQOYW76ig6SOSPNe41IG5LoP3FGBn2N0RjVDSQiS94kQ== - /@babel/plugin-syntax-json-strings/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA== - /@babel/plugin-syntax-nullish-coalescing-operator/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-aSff4zPII1u2QD7y+F8oDsz19ew4IGEJg9SVW+bqwpwtfFleiQDMdzA/R+UlWDzfnHFCxxleFT0PMIrR36XLNQ== - /@babel/plugin-syntax-object-rest-spread/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA== - /@babel/plugin-syntax-optional-catch-binding/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q== - /@babel/plugin-syntax-optional-chaining/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg== - /@babel/plugin-syntax-top-level-await/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-kwj1j9lL/6Wd0hROD3b/OZZ7MSrZLqqn9RAZ5+cYYsflQ9HZBIKCUkr3+uL1MEJ1NePiUbf98jjiMQSv0NMR9g== - /@babel/plugin-transform-arrow-functions/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-0MRF+KC8EqH4dbuITCWwPSzsyO3HIWWlm30v8BbbpOrS1B++isGxPnnuq/IZvOX5J2D/p7DQalQm+/2PnlKGxg== - /@babel/plugin-transform-async-to-generator/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-module-imports': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/helper-remap-async-to-generator': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-imt9tFLD9ogt56Dd5CI/6XgpukMwd/fLGSrix2httihVe7LOGVPhyhMh1BU5kDM7iHD08i8uUtmV2sWaBFlHVQ== - /@babel/plugin-transform-block-scoped-functions/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-vo4F2OewqjbB1+yaJ7k2EJFHlTP3jR634Z9Cj9itpqNjuLXvhlVxgnjsHsdRgASR8xYDrx6onw4vW5H6We0Jmg== - /@babel/plugin-transform-block-scoping/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - lodash: 4.17.15 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-pGnYfm7RNRgYRi7bids5bHluENHqJhrV4bCZRwc5GamaWIIs07N4rZECcmJL6ZClwjDz1GbdMZFtPs27hTB06w== - /@babel/plugin-transform-classes/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-annotate-as-pure': 7.8.3 - '@babel/helper-define-map': 7.8.3 - '@babel/helper-function-name': 7.8.3 - '@babel/helper-optimise-call-expression': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/helper-replace-supers': 7.8.3 - '@babel/helper-split-export-declaration': 7.8.3 - globals: 11.12.0 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-SjT0cwFJ+7Rbr1vQsvphAHwUHvSUPmMjMU/0P59G8U2HLFqSa082JO7zkbDNWs9kH/IUqpHI6xWNesGf8haF1w== - /@babel/plugin-transform-computed-properties/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-O5hiIpSyOGdrQZRQ2ccwtTVkgUDBBiCuK//4RJ6UfePllUTCENOzKxfh6ulckXKc0DixTFLCfb2HVkNA7aDpzA== - /@babel/plugin-transform-destructuring/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-H4X646nCkiEcHZUZaRkhE2XVsoz0J/1x3VVujnn96pSoGCtKPA99ZZA+va+gK+92Zycd6OBKCD8tDb/731bhgQ== - /@babel/plugin-transform-dotall-regex/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-create-regexp-features-plugin': 7.8.3_@babel+core@7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-kLs1j9Nn4MQoBYdRXH6AeaXMbEJFaFu/v1nQkvib6QzTj8MZI5OQzqmD83/2jEM1z0DLilra5aWO5YpyC0ALIw== - /@babel/plugin-transform-duplicate-keys/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-s8dHiBUbcbSgipS4SMFuWGqCvyge5V2ZeAWzR6INTVC3Ltjig/Vw1G2Gztv0vU/hRG9X8IvKvYdoksnUfgXOEQ== - /@babel/plugin-transform-exponentiation-operator/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-builder-binary-assignment-operator-visitor': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-zwIpuIymb3ACcInbksHaNcR12S++0MDLKkiqXHl3AzpgdKlFNhog+z/K0+TGW+b0w5pgTq4H6IwV/WhxbGYSjQ== - /@babel/plugin-transform-for-of/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-ZjXznLNTxhpf4Q5q3x1NsngzGA38t9naWH8Gt+0qYZEJAcvPI9waSStSh56u19Ofjr7QmD0wUsQ8hw8s/p1VnA== - /@babel/plugin-transform-function-name/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-function-name': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-rO/OnDS78Eifbjn5Py9v8y0aR+aSYhDhqAwVfsTl0ERuMZyr05L1aFSCJnbv2mmsLkit/4ReeQ9N2BgLnOcPCQ== - /@babel/plugin-transform-literals/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-3Tqf8JJ/qB7TeldGl+TT55+uQei9JfYaregDcEAyBZ7akutriFrt6C/wLYIer6OYhleVQvH/ntEhjE/xMmy10A== - /@babel/plugin-transform-member-expression-literals/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-3Wk2EXhnw+rP+IDkK6BdtPKsUE5IeZ6QOGrPYvw52NwBStw9V1ZVzxgK6fSKSxqUvH9eQPR3tm3cOq79HlsKYA== - /@babel/plugin-transform-modules-amd/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-module-transforms': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - babel-plugin-dynamic-import-node: 2.3.0 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-MadJiU3rLKclzT5kBH4yxdry96odTUwuqrZM+GllFI/VhxfPz+k9MshJM+MwhfkCdxxclSbSBbUGciBngR+kEQ== - /@babel/plugin-transform-modules-commonjs/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-module-transforms': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/helper-simple-access': 7.8.3 - babel-plugin-dynamic-import-node: 2.3.0 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-JpdMEfA15HZ/1gNuB9XEDlZM1h/gF/YOH7zaZzQu2xCFRfwc01NXBMHHSTT6hRjlXJJs5x/bfODM3LiCk94Sxg== - /@babel/plugin-transform-modules-systemjs/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-hoist-variables': 7.8.3 - '@babel/helper-module-transforms': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - babel-plugin-dynamic-import-node: 2.3.0 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-8cESMCJjmArMYqa9AO5YuMEkE4ds28tMpZcGZB/jl3n0ZzlsxOAi3mC+SKypTfT8gjMupCnd3YiXCkMjj2jfOg== - /@babel/plugin-transform-modules-umd/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-module-transforms': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-evhTyWhbwbI3/U6dZAnx/ePoV7H6OUG+OjiJFHmhr9FPn0VShjwC2kdxqIuQ/+1P50TMrneGzMeyMTFOjKSnAw== - /@babel/plugin-transform-named-capturing-groups-regex/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-create-regexp-features-plugin': 7.8.3_@babel+core@7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0 - resolution: - integrity: sha512-f+tF/8UVPU86TrCb06JoPWIdDpTNSGGcAtaD9mLP0aYGA0OS0j7j7DHJR0GTFrUZPUU6loZhbsVZgTh0N+Qdnw== - /@babel/plugin-transform-new-target/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-QuSGysibQpyxexRyui2vca+Cmbljo8bcRckgzYV4kRIsHpVeyeC3JDO63pY+xFZ6bWOBn7pfKZTqV4o/ix9sFw== - /@babel/plugin-transform-object-super/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/helper-replace-supers': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-57FXk+gItG/GejofIyLIgBKTas4+pEU47IXKDBWFTxdPd7F80H8zybyAY7UoblVfBhBGs2EKM+bJUu2+iUYPDQ== - /@babel/plugin-transform-parameters/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-call-delegate': 7.8.3 - '@babel/helper-get-function-arity': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-/pqngtGb54JwMBZ6S/D3XYylQDFtGjWrnoCF4gXZOUpFV/ujbxnoNGNvDGu6doFWRPBveE72qTx/RRU44j5I/Q== - /@babel/plugin-transform-property-literals/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-uGiiXAZMqEoQhRWMK17VospMZh5sXWg+dlh2soffpkAl96KAm+WZuJfa6lcELotSRmooLqg0MWdH6UUq85nmmg== - /@babel/plugin-transform-regenerator/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - regenerator-transform: 0.14.1 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-qt/kcur/FxrQrzFR432FGZznkVAjiyFtCOANjkAKwCbt465L6ZCiUQh2oMYGU3Wo8LRFJxNDFwWn106S5wVUNA== - /@babel/plugin-transform-reserved-words/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-mwMxcycN3omKFDjDQUl+8zyMsBfjRFr0Zn/64I41pmjv4NJuqcYlEtezwYtw9TFd9WR1vN5kiM+O0gMZzO6L0A== - /@babel/plugin-transform-shorthand-properties/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-I9DI6Odg0JJwxCHzbzW08ggMdCezoWcuQRz3ptdudgwaHxTjxw5HgdFJmZIkIMlRymL6YiZcped4TTCB0JcC8w== - /@babel/plugin-transform-spread/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-CkuTU9mbmAoFOI1tklFWYYbzX5qCIZVXPVy0jpXgGwkplCndQAa58s2jr66fTeQnA64bDox0HL4U56CFYoyC7g== - /@babel/plugin-transform-sticky-regex/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/helper-regex': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-9Spq0vGCD5Bb4Z/ZXXSK5wbbLFMG085qd2vhL1JYu1WcQ5bXqZBAYRzU1d+p79GcHs2szYv5pVQCX13QgldaWw== - /@babel/plugin-transform-template-literals/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-annotate-as-pure': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-820QBtykIQOLFT8NZOcTRJ1UNuztIELe4p9DCgvj4NK+PwluSJ49we7s9FB1HIGNIYT7wFUJ0ar2QpCDj0escQ== - /@babel/plugin-transform-typeof-symbol/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-3TrkKd4LPqm4jHs6nPtSDI/SV9Cm5PRJkHLUgTcqRQQTMAZ44ZaAdDZJtvWFSaRcvT0a1rTmJ5ZA5tDKjleF3g== - /@babel/plugin-transform-unicode-regex/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-create-regexp-features-plugin': 7.8.3_@babel+core@7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-+ufgJjYdmWfSQ+6NS9VGUR2ns8cjJjYbrbi11mZBTaWm+Fui/ncTLFF28Ei1okavY+xkojGr1eJxNsWYeA5aZw== - /@babel/preset-env/7.8.3_@babel+core@7.8.3: - dependencies: - '@babel/compat-data': 7.8.1 - '@babel/core': 7.8.3 - '@babel/helper-compilation-targets': 7.8.3_@babel+core@7.8.3 - '@babel/helper-module-imports': 7.8.3 - '@babel/helper-plugin-utils': 7.8.3 - '@babel/plugin-proposal-async-generator-functions': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-proposal-dynamic-import': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-proposal-json-strings': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-proposal-nullish-coalescing-operator': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-proposal-object-rest-spread': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-proposal-optional-catch-binding': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-proposal-optional-chaining': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-proposal-unicode-property-regex': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-syntax-async-generators': 7.8.4_@babel+core@7.8.3 - '@babel/plugin-syntax-dynamic-import': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-syntax-json-strings': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-syntax-nullish-coalescing-operator': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-syntax-object-rest-spread': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-syntax-optional-catch-binding': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-syntax-optional-chaining': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-syntax-top-level-await': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-arrow-functions': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-async-to-generator': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-block-scoped-functions': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-block-scoping': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-classes': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-computed-properties': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-destructuring': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-dotall-regex': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-duplicate-keys': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-exponentiation-operator': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-for-of': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-function-name': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-literals': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-member-expression-literals': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-modules-amd': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-modules-commonjs': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-modules-systemjs': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-modules-umd': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-named-capturing-groups-regex': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-new-target': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-object-super': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-parameters': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-property-literals': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-regenerator': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-reserved-words': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-shorthand-properties': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-spread': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-sticky-regex': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-template-literals': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-typeof-symbol': 7.8.3_@babel+core@7.8.3 - '@babel/plugin-transform-unicode-regex': 7.8.3_@babel+core@7.8.3 - '@babel/types': 7.8.3 - browserslist: 4.8.3 - core-js-compat: 3.6.4 - invariant: 2.2.4 - levenary: 1.1.0 - semver: 5.7.1 - dev: true - peerDependencies: - '@babel/core': ^7.0.0-0 - resolution: - integrity: sha512-Rs4RPL2KjSLSE2mWAx5/iCH+GC1ikKdxPrhnRS6PfFVaiZeom22VFKN4X8ZthyN61kAaR05tfXTbCvatl9WIQg== - /@babel/template/7.8.3: - dependencies: - '@babel/code-frame': 7.8.3 - '@babel/parser': 7.8.3 - '@babel/types': 7.8.3 - dev: true - resolution: - integrity: sha512-04m87AcQgAFdvuoyiQ2kgELr2tV8B4fP/xJAVUL3Yb3bkNdMedD3d0rlSQr3PegP0cms3eHjl1F7PWlvWbU8FQ== - /@babel/traverse/7.8.3: - dependencies: - '@babel/code-frame': 7.8.3 - '@babel/generator': 7.8.3 - '@babel/helper-function-name': 7.8.3 - '@babel/helper-split-export-declaration': 7.8.3 - '@babel/parser': 7.8.3 - '@babel/types': 7.8.3 - debug: 4.1.1 - globals: 11.12.0 - lodash: 4.17.15 - dev: true - resolution: - integrity: sha512-we+a2lti+eEImHmEXp7bM9cTxGzxPmBiVJlLVD+FuuQMeeO7RaDbutbgeheDkw+Xe3mCfJHnGOWLswT74m2IPg== - /@babel/types/7.8.3: - dependencies: - esutils: 2.0.3 - lodash: 4.17.15 - to-fast-properties: 2.0.0 - dev: true - resolution: - integrity: sha512-jBD+G8+LWpMBBWvVcdr4QysjUE4mU/syrhN17o1u3gx0/WzJB1kwiVZAXRtWbsIPOwW8pF/YJV5+nmetPzepXg== + integrity: sha512-i6rgnR/YgPEQzZZnbTHHuZdlE8qyoBNalD6F+q4vAFlcMEcqmkoG+mPqJYJCo63qPf74+Y1UZsl3l6f7/RIkmA== /@concordance/react/2.0.0: dependencies: arrify: 1.0.1 @@ -862,38 +69,54 @@ packages: /@nodelib/fs.walk/1.2.4: dependencies: '@nodelib/fs.scandir': 2.1.3 - fastq: 1.6.0 + fastq: 1.8.0 dev: true engines: node: '>= 8' resolution: integrity: sha512-1V9XOY4rDW0rehzbrcqAmHnz8e7SKvX27gh8Gt2WgB0+pdzdiLV83p72kZPU+jvMbS1qU5mauP2iOvO8rhmurQ== - /@rollup/plugin-node-resolve/7.0.0_rollup@1.29.0: + /@rollup/plugin-buble/0.21.3_rollup@2.26.3: + dependencies: + '@rollup/pluginutils': 3.1.0_rollup@2.26.3 + '@types/buble': 0.19.2 + buble: 0.20.0 + rollup: 2.26.3 + dev: true + engines: + node: '>= 8.0.0' + peerDependencies: + rollup: ^1.20.0||^2.0.0 + resolution: + integrity: sha512-Iv8cCuFPnMdqV4pcyU+OrfjOfagPArRQ1PyQjx5KgHk3dARedI+8PNTLSMpJts0lQJr8yF2pAU4GxpxCBJ9HYw== + /@rollup/plugin-node-resolve/9.0.0_rollup@2.26.3: dependencies: - '@rollup/pluginutils': 3.0.4_rollup@1.29.0 - '@types/resolve': 0.0.8 + '@rollup/pluginutils': 3.1.0_rollup@2.26.3 + '@types/resolve': 1.17.1 builtin-modules: 3.1.0 + deepmerge: 4.2.2 is-module: 1.0.0 - resolve: 1.14.2 - rollup: 1.29.0 + resolve: 1.17.0 + rollup: 2.26.3 dev: true engines: - node: '>= 8.0.0' + node: '>= 10.0.0' peerDependencies: - rollup: ^1.20.0 + rollup: ^1.20.0||^2.0.0 resolution: - integrity: sha512-+vOx2+WMBMFotYKM3yYeDGZxIvcQ7yO4g+SuKDFsjKaq8Lw3EPgfB6qNlp8Z/3ceDCEhHvC9/b+PgBGwDQGbzQ== - /@rollup/pluginutils/3.0.4_rollup@1.29.0: + integrity: sha512-gPz+utFHLRrd41WMP13Jq5mqqzHL3OXrfj3/MkSyB6UBIcuNt9j60GCbarzMzdf1VHFpOxfQh/ez7wyadLMqkg== + /@rollup/pluginutils/3.1.0_rollup@2.26.3: dependencies: - estree-walker: 0.6.1 - rollup: 1.29.0 + '@types/estree': 0.0.39 + estree-walker: 1.0.1 + picomatch: 2.2.2 + rollup: 2.26.3 dev: true engines: node: '>= 8.0.0' peerDependencies: - rollup: ^1.20.0 + rollup: ^1.20.0||^2.0.0 resolution: - integrity: sha512-buc0oeq2zqQu2mpMyvZgAaQvitikYjT/4JYhA4EXwxX8/g0ZGHoGiX+0AwmfhrNqH4oJv67gn80sTZFQ/jL1bw== + integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg== /@sindresorhus/is/0.14.0: dev: true engines: @@ -902,51 +125,64 @@ packages: integrity: sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ== /@szmarczak/http-timer/1.1.2: dependencies: - defer-to-connect: 1.1.1 + defer-to-connect: 1.1.3 dev: true engines: node: '>=6' resolution: integrity: sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA== - /@types/color-name/1.1.1: + /@types/buble/0.19.2: + dependencies: + magic-string: 0.25.7 dev: true resolution: - integrity: sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== - /@types/estree/0.0.42: + integrity: sha512-uUD8zIfXMKThmFkahTXDGI3CthFH1kMg2dOm3KLi4GlC5cbARA64bEcUMbbWdWdE73eoc/iBB9PiTMqH0dNS2Q== + /@types/color-name/1.1.1: dev: true resolution: - integrity: sha512-K1DPVvnBCPxzD+G51/cxVIoc2X8uUVl1zpJeE6iKcgHMj4+tbat5Xu4TjV7v2QSDbIeAfLi2hIk+u2+s0MlpUQ== - /@types/events/3.0.0: + integrity: sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== + /@types/estree/0.0.39: dev: true resolution: - integrity: sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g== - /@types/glob/7.1.1: + integrity: sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== + /@types/glob/7.1.3: dependencies: - '@types/events': 3.0.0 '@types/minimatch': 3.0.3 - '@types/node': 13.1.8 + '@types/node': 14.6.0 dev: true resolution: - integrity: sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w== + integrity: sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w== /@types/minimatch/3.0.3: dev: true resolution: integrity: sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== - /@types/node/13.1.8: + /@types/node/14.6.0: dev: true resolution: - integrity: sha512-6XzyyNM9EKQW4HKuzbo/CkOIjn/evtCmsU+MUM1xDfJ+3/rNjBttM1NgN7AOQvN6tP1Sl1D1PIKMreTArnxM9A== - /@types/resolve/0.0.8: + integrity: sha512-mikldZQitV94akrc4sCcSjtJfsTKt4p+e/s0AGscVA6XArQ9kFclP+ZiYUMnq987rc6QlYxXv/EivqlfSLxpKA== + /@types/normalize-package-data/2.4.0: + dev: true + resolution: + integrity: sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA== + /@types/resolve/1.17.1: dependencies: - '@types/node': 13.1.8 + '@types/node': 14.6.0 dev: true resolution: - integrity: sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ== + integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw== /abab/1.0.4: dev: true optional: true resolution: integrity: sha1-X6rZwsB/YN12dw9xzwJbYqY8/U4= + /acorn-dynamic-import/4.0.0_acorn@6.4.1: + dependencies: + acorn: 6.4.1 + dev: true + peerDependencies: + acorn: ^6.0.0 + resolution: + integrity: sha512-d3OEjQV4ROpoflsnUA8HozoIR504TFxNivYEUi6uwz0IYhBkTDXGuWlNdMtybRt3nqVx/L6XqMt0FxkXuWKZhw== /acorn-globals/1.0.9: dependencies: acorn: 2.7.0 @@ -954,14 +190,28 @@ packages: optional: true resolution: integrity: sha1-VbtemGkVB7dFedBRNBMhfDgMVM8= - /acorn-jsx/5.1.0_acorn@7.1.0: + /acorn-jsx/5.2.0_acorn@6.4.1: + dependencies: + acorn: 6.4.1 + dev: true + peerDependencies: + acorn: ^6.0.0 || ^7.0.0 + resolution: + integrity: sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ== + /acorn-jsx/5.2.0_acorn@7.4.0: dependencies: - acorn: 7.1.0 + acorn: 7.4.0 dev: true peerDependencies: acorn: ^6.0.0 || ^7.0.0 resolution: - integrity: sha512-tMUqwBWfLFbJbizRmEcWSLw6HnFzfdJs2sOJEOwwtVPMoH/0Ay+E703oZz78VSXZiiDcZrQ5XKjPIUQixhmgVw== + integrity: sha512-HiUX/+K2YpkpJ+SzBffkM/AQ2YE03S0U1kjTLVpoJdhZMOWy8qvXVN9JdLqv2QsaQ6MPYQIuNmwD8zOiYUofLQ== + /acorn-walk/7.2.0: + dev: true + engines: + node: '>=0.4.0' + resolution: + integrity: sha512-OPdCF6GsMIP+Az+aWfAAOEt2/+iVDKE7oy6lJ098aoe59oAmK76qV6Gw60SbZ8jHuG2wH058GF4pLFbYamYrVA== /acorn/2.7.0: dev: true engines: @@ -970,36 +220,50 @@ packages: optional: true resolution: integrity: sha1-q259nYhqrKiwhbwzEreaGYQz8Oc= - /acorn/7.1.0: + /acorn/6.4.1: dev: true engines: node: '>=0.4.0' hasBin: true resolution: - integrity: sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ== - /ajv/6.11.0: + integrity: sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA== + /acorn/7.4.0: + dev: true + engines: + node: '>=0.4.0' + hasBin: true + resolution: + integrity: sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w== + /aggregate-error/3.0.1: + dependencies: + clean-stack: 2.2.0 + indent-string: 4.0.0 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-quoaXsZ9/BLNae5yiNoUz+Nhkwz83GhWwtYFglcjEQB2NDHCIpApbqXxIFnm4Pq/Nvhrsq5sYJFyohrrxnTGAA== + /ajv/6.12.4: dependencies: - fast-deep-equal: 3.1.1 + fast-deep-equal: 3.1.3 fast-json-stable-stringify: 2.1.0 json-schema-traverse: 0.4.1 uri-js: 4.2.2 dev: true resolution: - integrity: sha512-nCprB/0syFYy9fVYU1ox1l2KN8S9I+tziH8D4zdZuLT3N6RMlGSGt5FSTpAiHB/Whv8Qs1cWHma1aMKZyaHRKA== + integrity: sha512-eienB2c9qVQs2KWexhkrdMLVDoIQCz5KSeLxwg9Lzk4DOfBtIK9PQwwufcsn1jjGuf9WZmqPMbGxOzfcuphJCQ== /ansi-align/3.0.0: dependencies: string-width: 3.1.0 dev: true resolution: integrity: sha512-ZpClVKqXN3RGBmKibdfWzqCY4lnjEuoNzU5T0oEFpfd/z5qJHVarukridD4juLO2FXMiwUQxr9WqQtaYa8XRYw== - /ansi-escapes/4.3.0: - dependencies: - type-fest: 0.8.1 + /ansi-colors/4.1.1: dev: true engines: - node: '>=8' + node: '>=6' resolution: - integrity: sha512-EiYhwo0v255HUL6eDyuLrXEkTi7WwVCLAw+SeOQ7M7qdun1z1pum4DEm/nuqIVbPvi9RPPc9k9LbyBv6H0DwVg== + integrity: sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== /ansi-regex/2.1.1: dev: true engines: @@ -1050,7 +314,7 @@ packages: /anymatch/3.1.1: dependencies: normalize-path: 3.0.0 - picomatch: 2.2.1 + picomatch: 2.2.2 dev: true engines: node: '>= 8' @@ -1062,44 +326,24 @@ packages: dev: true resolution: integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg== - /arr-flatten/1.1.0: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg== /array-find-index/1.0.2: dev: true engines: node: '>=0.10.0' resolution: integrity: sha1-3wEKoSh+Fku9pvlyOwqWoexBh6E= - /array-union/1.0.2: - dependencies: - array-uniq: 1.0.3 - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk= /array-union/2.1.0: dev: true engines: node: '>=8' resolution: integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== - /array-uniq/1.0.3: + /arrgv/1.0.2: dev: true engines: - node: '>=0.10.0' - resolution: - integrity: sha1-r2rId6Jcx/dOBYiUdThY39sk/bY= - /array-uniq/2.1.0: - dev: true - engines: - node: '>=6' + node: '>=8.0.0' resolution: - integrity: sha512-bdHxtev7FN6+MXI1YFW0Q8mQ8dTJc2S8AMfju+ZR77pbg2yAdVyDlwkaUI7Har0LyOMRFPHrJ9lYdyjZZswdlQ== + integrity: sha512-a4eg4yhp7mmruZDQFqVMlxNRFGi/i1r87pt8SDHy0/I8PqSXoUTlWZRdAZo0VXgvEARcujbtTk8kiZRi1uDGRw== /arrify/1.0.1: dev: true engines: @@ -1138,102 +382,90 @@ packages: node: '>=8' resolution: integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ== + /async/2.6.3: + dependencies: + lodash: 4.17.20 + dev: true + resolution: + integrity: sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg== /asynckit/0.4.0: dev: true optional: true resolution: integrity: sha1-x57Zf380y48robyXkLzDZkdLS3k= - /ava/2.4.0: + /ava/3.11.1: dependencies: - '@ava/babel-preset-stage-4': 4.0.0_@babel+core@7.8.3 - '@ava/babel-preset-transform-test-files': 6.0.0 - '@babel/core': 7.8.3 - '@babel/generator': 7.8.3 '@concordance/react': 2.0.0 - ansi-escapes: 4.3.0 + acorn: 7.4.0 + acorn-walk: 7.2.0 ansi-styles: 4.2.1 - arr-flatten: 1.1.0 - array-union: 2.1.0 - array-uniq: 2.1.0 + arrgv: 1.0.2 arrify: 2.0.1 - bluebird: 3.7.2 - chalk: 2.4.2 - chokidar: 3.3.1 - chunkd: 1.0.0 - ci-parallel-vars: 1.0.0 - clean-stack: 2.2.0 + callsites: 3.1.0 + chalk: 4.1.0 + chokidar: 3.4.2 + chunkd: 2.0.1 + ci-info: 2.0.0 + ci-parallel-vars: 1.0.1 clean-yaml-object: 0.1.0 cli-cursor: 3.1.0 cli-truncate: 2.1.0 - code-excerpt: 2.1.1 - common-path-prefix: 1.0.0 - concordance: 4.0.0 + code-excerpt: 3.0.0 + common-path-prefix: 3.0.0 + concordance: 5.0.0 convert-source-map: 1.7.0 currently-unhandled: 0.4.1 debug: 4.1.1 - del: 4.1.1 - dot-prop: 5.2.0 - emittery: 0.4.1 - empower-core: 1.2.0 + del: 5.1.0 + emittery: 0.7.1 equal-length: 1.0.1 - escape-string-regexp: 2.0.0 - esm: 3.2.25 - figures: 3.1.0 - find-up: 4.1.0 - get-port: 5.1.1 - globby: 10.0.2 - ignore-by-default: 1.0.1 + figures: 3.2.0 + globby: 11.0.1 + ignore-by-default: 2.0.0 import-local: 3.0.2 indent-string: 4.0.0 - is-ci: 2.0.0 is-error: 2.2.2 - is-observable: 2.0.0 - is-plain-object: 3.0.0 - is-promise: 2.1.0 - lodash: 4.17.15 - loud-rejection: 2.2.0 - make-dir: 3.0.0 - matcher: 2.1.0 + is-plain-object: 4.1.1 + is-promise: 4.0.0 + lodash: 4.17.20 + matcher: 3.0.0 md5-hex: 3.0.1 - meow: 5.0.0 - micromatch: 4.0.2 + mem: 6.1.0 ms: 2.1.2 - observable-to-promise: 1.0.0 - ora: 3.4.0 - package-hash: 4.0.0 + ora: 4.1.1 + p-map: 4.0.0 + picomatch: 2.2.2 pkg-conf: 3.1.0 - plur: 3.1.1 - pretty-ms: 5.1.0 - require-precompiled: 0.1.0 + plur: 4.0.0 + pretty-ms: 7.0.0 + read-pkg: 5.2.0 resolve-cwd: 3.0.0 slash: 3.0.0 - source-map-support: 0.5.16 - stack-utils: 1.0.2 - strip-ansi: 5.2.0 - strip-bom-buf: 2.0.0 + source-map-support: 0.5.19 + stack-utils: 2.0.2 + strip-ansi: 6.0.0 supertap: 1.0.0 - supports-color: 7.1.0 + temp-dir: 2.0.0 trim-off-newlines: 1.0.1 - trim-right: 1.0.1 - unique-temp-dir: 1.0.0 - update-notifier: 3.0.1 - write-file-atomic: 3.0.1 + update-notifier: 4.1.1 + write-file-atomic: 3.0.3 + yargs: 15.4.1 dev: true engines: - node: '>=8.9.4 <9 || >=10.0.0 <11 || >=12.0.0' + node: '>=10.18.0 <11 || >=12.14.0 <12.17.0 || >=12.17.0 <13 || >=14.0.0' hasBin: true resolution: - integrity: sha512-CQWtzZZZeU2g4StojRv6MO9RIRi4sLxGSB9+3C3hv0ttUEG1tkJLTLyrBQeFS4WEeK12Z4ovE3f2iPVhSy8elA== + integrity: sha512-yGPD0msa5Qronw7GHDNlLaB7oU5zryYtXeuvny40YV6TMskSghqK7Ky3NisM/sr+aqI3DY7sfmORx8dIWQgMoQ== /aws-sign2/0.7.0: dev: true optional: true resolution: integrity: sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg= - /aws4/1.9.1: + /aws4/1.10.1: dev: true optional: true resolution: - integrity: sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug== + integrity: sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA== /babel-code-frame/6.26.0: dependencies: chalk: 1.1.3 @@ -1248,7 +480,7 @@ packages: babel-runtime: 6.26.0 babel-types: 6.26.0 detect-indent: 3.0.1 - lodash: 4.17.15 + lodash: 4.17.20 source-map: 0.5.7 dev: true resolution: @@ -1260,7 +492,7 @@ packages: babel-types: 6.26.0 detect-indent: 4.0.0 jsesc: 1.3.0 - lodash: 4.17.15 + lodash: 4.17.20 source-map: 0.5.7 trim-right: 1.0.1 dev: true @@ -1272,24 +504,6 @@ packages: dev: true resolution: integrity: sha1-8830cDhYA1sqKVHG7F7fbGLyYw4= - /babel-plugin-dynamic-import-node/2.3.0: - dependencies: - object.assign: 4.1.0 - dev: true - resolution: - integrity: sha512-o6qFkpeQEBxcqt0XYlWzAVxNCSCZdUgcR8IRlhD/8DylxjjO4foPcvTW0GGKa/cVt3rvxZ7o5ippJ+/0nvLhlQ== - /babel-plugin-espower/3.0.1: - dependencies: - '@babel/generator': 7.8.3 - '@babel/parser': 7.8.3 - call-matcher: 1.1.0 - core-js: 2.6.11 - espower-location-detector: 1.0.0 - espurify: 1.8.1 - estraverse: 4.3.0 - dev: true - resolution: - integrity: sha512-Ms49U7VIAtQ/TtcqRbD6UBmJBUCSxiC3+zPc+eGqxKUIFO1lTshyEDRUjhoAbd2rWfwYf3cZ62oXozrd8W6J0A== /babel-runtime/6.26.0: dependencies: core-js: 2.6.11 @@ -1307,7 +521,7 @@ packages: debug: 2.6.9 globals: 9.18.0 invariant: 2.2.4 - lodash: 4.17.15 + lodash: 4.17.20 dev: true resolution: integrity: sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4= @@ -1315,7 +529,7 @@ packages: dependencies: babel-runtime: 6.26.0 esutils: 2.0.3 - lodash: 4.17.15 + lodash: 4.17.20 to-fast-properties: 1.0.3 dev: true resolution: @@ -1329,6 +543,12 @@ packages: dev: true resolution: integrity: sha1-ibTRmasr7kneFk6gK4nORi1xt2c= + /basic-auth/1.1.0: + dev: true + engines: + node: '>= 0.6' + resolution: + integrity: sha1-RSIe5Cn37h5QNb4/UVM/HN/SmIQ= /bcrypt-pbkdf/1.0.2: dependencies: tweetnacl: 0.14.5 @@ -1336,39 +556,35 @@ packages: optional: true resolution: integrity: sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4= - /binary-extensions/2.0.0: + /binary-extensions/2.1.0: dev: true engines: node: '>=8' resolution: - integrity: sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow== - /bluebird/3.7.2: - dev: true - resolution: - integrity: sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== - /blueimp-md5/2.12.0: + integrity: sha512-1Yj8h9Q+QDF5FzhMs/c9+6UntbD5MkRfRwac8DoEm9ZfUBZ7tZ55YcGVAzEe4bXsdQHEk+s9S5wsOKVdZrw0tQ== + /blueimp-md5/2.17.0: dev: true resolution: - integrity: sha512-zo+HIdIhzojv6F1siQPqPFROyVy7C50KzHv/k/Iz+BtvtVzSHXiMXOpq2wCfNkeBqdCv+V8XOV96tsEt2W/3rQ== + integrity: sha512-x5PKJHY5rHQYaADj6NwPUR2QRCUVSggPzrUKkeENpj871o9l9IefJbO2jkT5UvYykeOK9dx0VmkIo6dZ+vThYw== /boolbase/1.0.0: dev: true resolution: integrity: sha1-aN/1++YMUes3cl6p4+0xDcwed24= - /boxen/3.2.0: + /boxen/4.2.0: dependencies: ansi-align: 3.0.0 camelcase: 5.3.1 - chalk: 2.4.2 + chalk: 3.0.0 cli-boxes: 2.2.0 - string-width: 3.1.0 - term-size: 1.2.0 - type-fest: 0.3.1 - widest-line: 2.0.1 + string-width: 4.2.0 + term-size: 2.2.0 + type-fest: 0.8.1 + widest-line: 3.1.0 dev: true engines: - node: '>=6' + node: '>=8' resolution: - integrity: sha512-cU4J/+NodM3IHdSL2yN8bqYqnmlBTidDR4RC7nJs61ZmtGz8VZzM3HLQX0zY5mrSmPtR3xWwsq2jOUQqFZN8+A== + integrity: sha512-eB4uT9RGzg2odpER62bBwSLvUeGC+WbRjjyyFhGsKnc8wp/m0+hQsMUvUe3H2V0D5vw0nBdO1hCJoZo5mKeuIQ== /brace-expansion/1.1.11: dependencies: balanced-match: 1.0.0 @@ -1384,15 +600,19 @@ packages: node: '>=8' resolution: integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A== - /browserslist/4.8.3: + /buble/0.20.0: dependencies: - caniuse-lite: 1.0.30001021 - electron-to-chromium: 1.3.337 - node-releases: 1.1.45 + acorn: 6.4.1 + acorn-dynamic-import: 4.0.0_acorn@6.4.1 + acorn-jsx: 5.2.0_acorn@6.4.1 + chalk: 2.4.2 + magic-string: 0.25.7 + minimist: 1.2.5 + regexpu-core: 4.5.4 dev: true hasBin: true resolution: - integrity: sha512-iU43cMMknxG1ClEZ2MDKeonKE1CCrFVkQK2AqO2YWFmvIrx4JWrvQ4w4hQez6EpVI8rHTtqh/ruHHDHSOKxvUg== + integrity: sha512-/1gnaMQE8xvd5qsNBl+iTuyjJ9XxeaVxAMF86dQ4EyxFJOZtsgOS8Ra+7WHgZTam5IFDtt4BguN0sH0tVTKrOw== /buffer-from/1.1.1: dev: true resolution: @@ -1406,8 +626,8 @@ packages: /cacheable-request/6.1.0: dependencies: clone-response: 1.0.2 - get-stream: 5.1.0 - http-cache-semantics: 4.0.3 + get-stream: 5.2.0 + http-cache-semantics: 4.1.0 keyv: 3.1.0 lowercase-keys: 2.0.0 normalize-url: 4.5.0 @@ -1417,53 +637,18 @@ packages: node: '>=8' resolution: integrity: sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg== - /call-matcher/1.1.0: - dependencies: - core-js: 2.6.11 - deep-equal: 1.1.1 - espurify: 1.8.1 - estraverse: 4.3.0 - dev: true - resolution: - integrity: sha512-IoQLeNwwf9KTNbtSA7aEBb1yfDbdnzwjCetjkC8io5oGeOmK2CBNdg0xr+tadRYKO0p7uQyZzvon0kXlZbvGrw== - /call-signature/0.0.2: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-qEq8glpV70yysCi9dOIFpluaSZY= /callsites/3.1.0: dev: true engines: node: '>=6' resolution: integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ== - /camelcase-keys/4.2.0: - dependencies: - camelcase: 4.1.0 - map-obj: 2.0.0 - quick-lru: 1.1.0 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-oqpfsa9oh1glnDLBQUJteJI7m3c= - /camelcase/4.1.0: - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0= /camelcase/5.3.1: dev: true engines: node: '>=6' resolution: integrity: sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== - /caniuse-lite/1.0.30001021: - dev: true - resolution: - integrity: sha512-wuMhT7/hwkgd8gldgp2jcrUjOU9RXJ4XxGumQeOsUr91l3WwmM68Cpa/ymCnWEDqakwFXhuDQbaKNHXBPgeE9g== /caseless/0.12.0: dev: true optional: true @@ -1491,17 +676,31 @@ packages: node: '>=4' resolution: integrity: sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== - /chardet/0.7.0: + /chalk/3.0.0: + dependencies: + ansi-styles: 4.2.1 + supports-color: 7.1.0 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg== + /chalk/4.1.0: + dependencies: + ansi-styles: 4.2.1 + supports-color: 7.1.0 dev: true + engines: + node: '>=10' resolution: - integrity: sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== + integrity: sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A== /cheerio/0.20.0: dependencies: css-select: 1.2.0 dom-serializer: 0.1.1 entities: 1.1.2 htmlparser2: 3.8.3 - lodash: 4.17.15 + lodash: 4.17.20 dev: true engines: node: '>= 0.6' @@ -1538,41 +737,41 @@ packages: dom-serializer: 0.1.1 entities: 1.1.2 htmlparser2: 3.10.1 - lodash: 4.17.15 + lodash: 4.17.20 parse5: 3.0.3 dev: true engines: node: '>= 0.6' resolution: integrity: sha1-S59TqBsn5NXawxwP/Qz6A8xoMNs= - /chokidar/3.3.1: + /chokidar/3.4.2: dependencies: anymatch: 3.1.1 braces: 3.0.2 - glob-parent: 5.1.0 + glob-parent: 5.1.1 is-binary-path: 2.1.0 is-glob: 4.0.1 normalize-path: 3.0.0 - readdirp: 3.3.0 + readdirp: 3.4.0 dev: true engines: node: '>= 8.10.0' optionalDependencies: - fsevents: 2.1.2 + fsevents: 2.1.3 resolution: - integrity: sha512-4QYCEWOcK3OJrxwvyyAOxFuhpvOVCYkr33LPfFNBjAD/w3sEzWsp2BUOkI4l9bHvWioAd0rc6NlHUOEaWkTeqg== - /chunkd/1.0.0: + integrity: sha512-IZHaDeBeI+sZJRX7lGcXsdzgvZqKv6sECqsbErJA4mHWfpRrD8B97kSFN4cQz6nGBGiuFia1MKR4d6c1o8Cv7A== + /chunkd/2.0.1: dev: true resolution: - integrity: sha512-xx3Pb5VF9QaqCotolyZ1ywFBgyuJmu6+9dLiqBxgelEse9Xsr3yUlpoX3O4Oh11M00GT2kYMsRByTKIMJW2Lkg== + integrity: sha512-7d58XsFmOq0j6el67Ug9mHf9ELUXsQXYJBkyxhH/k+6Ke0qXRnv0kbemx+Twc6fRJ07C49lcbdgm9FL1Ei/6SQ== /ci-info/2.0.0: dev: true resolution: integrity: sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ== - /ci-parallel-vars/1.0.0: + /ci-parallel-vars/1.0.1: dev: true resolution: - integrity: sha512-u6dx20FBXm+apMi+5x7UVm6EH7BL1gc4XrcnQewjcB7HWRcor/V5qWc3RG2HwpgDJ26gIi2DSEu3B7sXynAw/g== + integrity: sha512-uvzpYrpmidaoxvIQHM+rKSrigjOe9feHYbw4uOI2gdfe1C3xIlxO+kVXq83WQWNniTf8bAxVpy+cQeFQsMERKg== /clean-stack/2.2.0: dev: true engines: @@ -1591,14 +790,6 @@ packages: node: '>=6' resolution: integrity: sha512-gpaBrMAizVEANOpfZp/EEUixTXDyGt7DFzdK5hU+UbWt/J0lB0w20ncZj59Z9a93xHb9u12zF5BS6i9RKbtg4w== - /cli-cursor/2.1.0: - dependencies: - restore-cursor: 2.0.0 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU= /cli-cursor/3.1.0: dependencies: restore-cursor: 3.1.0 @@ -1607,12 +798,12 @@ packages: node: '>=8' resolution: integrity: sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw== - /cli-spinners/2.2.0: + /cli-spinners/2.4.0: dev: true engines: node: '>=6' resolution: - integrity: sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ== + integrity: sha512-sJAofoarcm76ZGpuooaO0eDy8saEy+YoZBLjC4h8srt4jeBnkYeOgqxgsJQTpyt2LjI5PTfLJHSL+41Yu4fEJA== /cli-truncate/2.1.0: dependencies: slice-ansi: 3.0.0 @@ -1622,10 +813,22 @@ packages: node: '>=8' resolution: integrity: sha512-n8fOixwDD6b/ObinzTrp1ZKFzbgvKZvuz/TvejnLn1aQfC6r52XEx85FmuC+3HI+JM7coBRXUvNqEU2PHVrHpg== - /cli-width/2.2.0: + /cliui/5.0.0: + dependencies: + string-width: 3.1.0 + strip-ansi: 5.2.0 + wrap-ansi: 5.1.0 + dev: true + resolution: + integrity: sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA== + /cliui/6.0.0: + dependencies: + string-width: 4.2.0 + strip-ansi: 6.0.0 + wrap-ansi: 6.2.0 dev: true resolution: - integrity: sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk= + integrity: sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ== /clone-response/1.0.2: dependencies: mimic-response: 1.0.1 @@ -1638,14 +841,14 @@ packages: node: '>=0.8' resolution: integrity: sha1-2jCcwmPfFZlMaIypAheco8fNfH4= - /code-excerpt/2.1.1: + /code-excerpt/3.0.0: dependencies: convert-to-spaces: 1.0.2 dev: true engines: - node: '>=4' + node: '>=10' resolution: - integrity: sha512-tJLhH3EpFm/1x7heIW0hemXJTUU5EWl2V0EIX558jp05Mt1U6DVryCgkp3l37cxqs+DNbNgxG43SkwJXpQ14Jw== + integrity: sha512-VHNTVhd7KsLGOqfX3SyeO8RyYPMp1GJOg194VITk04WMYCv4plV68YWe6TJZxd9MhobjtpMRnVky01gqZsalaw== /color-convert/1.9.3: dependencies: color-name: 1.1.3 @@ -1676,6 +879,12 @@ packages: dev: true resolution: integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + /colors/1.4.0: + dev: true + engines: + node: '>=0.1.90' + resolution: + integrity: sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== /combined-stream/1.0.8: dependencies: delayed-stream: 1.0.0 @@ -1689,45 +898,59 @@ packages: dev: true resolution: integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== - /common-path-prefix/1.0.0: + /common-path-prefix/3.0.0: dev: true resolution: - integrity: sha1-zVL28HEuC6q5fW+XModPIvR3UsA= + integrity: sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w== /concat-map/0.0.1: dev: true resolution: integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= - /concordance/4.0.0: + /concordance/5.0.0: dependencies: - date-time: 2.1.0 + date-time: 3.1.0 esutils: 2.0.3 fast-diff: 1.2.0 js-string-escape: 1.0.1 - lodash.clonedeep: 4.5.0 - lodash.flattendeep: 4.4.0 - lodash.islength: 4.0.1 - lodash.merge: 4.6.2 - md5-hex: 2.0.0 - semver: 5.7.1 + lodash: 4.17.20 + md5-hex: 3.0.1 + semver: 7.3.2 well-known-symbols: 2.0.0 dev: true engines: - node: '>=6.12.3 <7 || >=8.9.4 <9 || >=10.0.0' + node: '>=10.18.0 <11 || >=12.14.0 <13 || >=13.5.0' resolution: - integrity: sha512-l0RFuB8RLfCS0Pt2Id39/oCPykE01pyxgAFypWTlaGRgvLkZrtczZ8atEHpTeEIW+zYWXTBuA9cCSeEOScxReQ== - /configstore/4.0.0: + integrity: sha512-stOCz9ffg0+rytwTaL2njUOIyMfANwfwmqc9Dr4vTUS/x/KkVFlWx9Zlzu6tHYtjKxxaCF/cEAZgPDac+n35sg== + /concurrently/5.3.0: dependencies: - dot-prop: 4.2.0 - graceful-fs: 4.2.3 - make-dir: 1.3.0 - unique-string: 1.0.0 - write-file-atomic: 2.4.3 - xdg-basedir: 3.0.0 + chalk: 2.4.2 + date-fns: 2.15.0 + lodash: 4.17.20 + read-pkg: 4.0.1 + rxjs: 6.6.2 + spawn-command: 0.0.2-1 + supports-color: 6.1.0 + tree-kill: 1.2.2 + yargs: 13.3.2 dev: true engines: - node: '>=6' + node: '>=6.0.0' + hasBin: true + resolution: + integrity: sha512-8MhqOB6PWlBfA2vJ8a0bSFKATOdWlHiQlk11IfmQBPaHVP8oP2gsh2MObE6UR3hqDHqvaIvLTyceNW6obVuFHQ== + /configstore/5.0.1: + dependencies: + dot-prop: 5.2.0 + graceful-fs: 4.2.4 + make-dir: 3.1.0 + unique-string: 2.0.0 + write-file-atomic: 3.0.3 + xdg-basedir: 4.0.0 + dev: true + engines: + node: '>=8' resolution: - integrity: sha512-CmquAXFBocrzaSM8mtGPMM/HiWmyIpr4CcJl/rgY2uCObZ/S7cKU0silxslqJejl+t/T9HS8E0PUNQD81JGUEQ== + integrity: sha512-aMKprgk5YhBNyH25hj8wGt2+D52Sw1DRRIzqBwLp2Ya9mFmY8KPvvtvmna8SxVR9JMZ4kzMD68N22vlaRpkeFA== /convert-source-map/1.7.0: dependencies: safe-buffer: 5.1.2 @@ -1740,53 +963,39 @@ packages: node: '>= 4' resolution: integrity: sha1-fj5Iu+bZl7FBfdyihoIEtNPYVxU= - /core-js-compat/3.6.4: - dependencies: - browserslist: 4.8.3 - semver: 7.0.0 - dev: true - resolution: - integrity: sha512-zAa3IZPvsJ0slViBQ2z+vgyyTuhd3MFn1rBQjZSKVEgB0UMYhUkCj9jJUVPgGTGqWvsBVmfnruXgTcNyTlEiSA== /core-js/2.6.11: deprecated: 'core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.' dev: true requiresBuild: true resolution: integrity: sha512-5wjnpaT/3dV+XB4borEsnAYQchn00XSgTAWKDkEqv+K8KevjbzmofK6hfJ9TZIlpj2N0xQpazy7PiRQiWHqzWg== + /core-js/3.6.5: + dev: true + requiresBuild: true + resolution: + integrity: sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA== /core-util-is/1.0.2: dev: true resolution: integrity: sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= - /cross-env/6.0.3: - dependencies: - cross-spawn: 7.0.1 + /corser/2.0.1: dev: true engines: - node: '>=8.0' - hasBin: true - resolution: - integrity: sha512-+KqxF6LCvfhWvADcDPqo64yVIB31gv/jQulX2NGzKS/g3GEVz6/pt4wjHFtFWsHMddebWD/sDthJemzM4MaAag== - /cross-spawn/5.1.0: - dependencies: - lru-cache: 4.1.5 - shebang-command: 1.2.0 - which: 1.3.1 - dev: true + node: '>= 0.4.0' resolution: - integrity: sha1-6L0O/uWPz/b4+UUQoKVUu/ojVEk= - /cross-spawn/6.0.5: + integrity: sha1-jtolLsqrWEDc2XXOuQ2TcMgZ/4c= + /cross-env/7.0.2: dependencies: - nice-try: 1.0.5 - path-key: 2.0.1 - semver: 5.7.1 - shebang-command: 1.2.0 - which: 1.3.1 + cross-spawn: 7.0.3 dev: true engines: - node: '>=4.8' + node: '>=10.14' + npm: '>=6' + yarn: '>=1' + hasBin: true resolution: - integrity: sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== - /cross-spawn/7.0.1: + integrity: sha512-KZP/bMEOJEDCkDQAyRhu3RL2ZO/SUVrxQVI0G3YEQ+OLbRA3c6zgixe8Mq8a/z7+HKlNEjo8oiLUs8iRijY2Rw== + /cross-spawn/7.0.3: dependencies: path-key: 3.1.1 shebang-command: 2.0.0 @@ -1795,13 +1004,13 @@ packages: engines: node: '>= 8' resolution: - integrity: sha512-u7v4o84SwFpD32Z8IIcPZ6z1/ie24O6RU3RbtL5Y316l3KuHVPx9ItBgWQ6VlfAFnRnTtMUrsQ9MUUTuEZjogg== - /crypto-random-string/1.0.0: + integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== + /crypto-random-string/2.0.0: dev: true engines: - node: '>=4' + node: '>=8' resolution: - integrity: sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4= + integrity: sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA== /css-select/1.2.0: dependencies: boolbase: 1.0.0 @@ -1844,39 +1053,42 @@ packages: optional: true resolution: integrity: sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA= - /dat.gui/0.7.6: + /dat.gui/0.7.7: dev: true resolution: - integrity: sha512-9Uqr4aQUvp9q5P2b4y6gK604HXafubOq578OmOS8mjrIkYrBP4EbQ9gz9YRXgyPh7aQi+b9H/jAG7EucmhYpSA== - /date-time/2.1.0: + integrity: sha512-sRl/28gF/XRC5ywC9I4zriATTsQcpSsRG7seXCPnTkK8/EQMIbCu5NPMpICLGxX9ZEUvcXR3ArLYCtgreFoMDw== + /date-fns/2.15.0: + dev: true + engines: + node: '>=0.11' + resolution: + integrity: sha512-ZCPzAMJZn3rNUvvQIMlXhDr4A+Ar07eLeGsGREoWU19a3Pqf5oYa+ccd+B3F6XVtQY6HANMFdOQ8A+ipFnvJdQ== + /date-time/3.1.0: dependencies: time-zone: 1.0.0 dev: true engines: - node: '>=4' + node: '>=6' resolution: - integrity: sha512-/9+C44X7lot0IeiyfgJmETtRMhBidBYM2QFFIkGa0U1k+hSyY87Nw7PY3eDqpvCBm7I3WCSfPeZskW/YYq6m4g== + integrity: sha512-uqCUKXE5q1PNBXjPqvwhwJf9SwMoAHBgWJ6DcrnS5o+W2JOiIILl0JEdVD8SGujrNS02GGxgwAg2PN2zONgtjg== /debug/2.6.9: dependencies: ms: 2.0.0 dev: true resolution: integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== - /debug/4.1.1: + /debug/3.2.6: dependencies: ms: 2.1.2 dev: true resolution: - integrity: sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== - /decamelize-keys/1.1.0: + integrity: sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ== + /debug/4.1.1: dependencies: - decamelize: 1.2.0 - map-obj: 1.0.1 + ms: 2.1.2 dev: true - engines: - node: '>=0.10.0' resolution: - integrity: sha1-0XGoeTMlKAfrPLYdwcFEXQeN8tk= + integrity: sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw== /decamelize/1.2.0: dev: true engines: @@ -1891,17 +1103,6 @@ packages: node: '>=4' resolution: integrity: sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M= - /deep-equal/1.1.1: - dependencies: - is-arguments: 1.0.4 - is-date-object: 1.0.2 - is-regex: 1.0.5 - object-is: 1.0.2 - object-keys: 1.1.1 - regexp.prototype.flags: 1.3.0 - dev: true - resolution: - integrity: sha512-yd9c5AdiqVcR+JjcwUQb9DkhJc8ngNr0MahEBGvDiJw8puWab2yZlh+nkasOnZP+EGTAP6rRp2JzJhJZzvNF8g== /deep-extend/0.6.0: dev: true engines: @@ -1912,38 +1113,37 @@ packages: dev: true resolution: integrity: sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= + /deepmerge/4.2.2: + dev: true + engines: + node: '>=0.10.0' + resolution: + integrity: sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== /defaults/1.0.3: dependencies: clone: 1.0.4 dev: true resolution: integrity: sha1-xlYFHpgX2f8I7YgUd/P+QBnz730= - /defer-to-connect/1.1.1: + /defer-to-connect/1.1.3: dev: true resolution: - integrity: sha512-J7thop4u3mRTkYRQ+Vpfwy2G5Ehoy82I14+14W4YMDLKdWloI9gSzRbV30s/NckQGVJtPkWNcW4oMAUigTdqiQ== - /define-properties/1.1.3: + integrity: sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ== + /del/5.1.0: dependencies: - object-keys: 1.1.1 - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ== - /del/4.1.1: - dependencies: - '@types/glob': 7.1.1 - globby: 6.1.0 + globby: 10.0.2 + graceful-fs: 4.2.4 + is-glob: 4.0.1 is-path-cwd: 2.2.0 - is-path-in-cwd: 2.1.0 - p-map: 2.1.0 - pify: 4.0.1 - rimraf: 2.7.1 + is-path-inside: 3.0.2 + p-map: 3.0.0 + rimraf: 3.0.2 + slash: 3.0.0 dev: true engines: - node: '>=6' + node: '>=8' resolution: - integrity: sha512-QwGuEUouP2kVwQenAsOof5Fv8K9t3D8Ca8NxcXKrIpEHjTXK5J2nXLdP+ALI1cgv8wj7KuwBhTwBkOZSJKM5XQ== + integrity: sha512-wH9xOVHnczo9jN2IW68BabcecVPxacIA3g/7z6vhSU/4stOKQzeCRK0yD0A24WiAAUJmmVpWqrERcTxnLo3AnA== /delayed-stream/1.0.0: dev: true engines: @@ -1951,18 +1151,10 @@ packages: optional: true resolution: integrity: sha1-3zrhmayt+31ECqrgsp4icrJOxhk= - /delta-controls/2.0.4_math-ds@1.1.3: - dependencies: - math-ds: 1.1.3 - dev: true - peerDependencies: - math-ds: 1.x.x - resolution: - integrity: sha512-F1X+mCnSkVkYVP9l2tQ1OKfIfxqyNsceDsHQd3/3udCJ8/0c0BS+9F+r8NKL2SphgLK5dFWwZfqzqJ++u/Nnaw== /detect-indent/3.0.1: dependencies: get-stdin: 4.0.1 - minimist: 1.2.0 + minimist: 1.2.5 repeating: 1.1.3 dev: true engines: @@ -2001,21 +1193,10 @@ packages: dev: true resolution: integrity: sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA== - /dom-serializer/0.2.2: - dependencies: - domelementtype: 2.0.1 - entities: 2.0.0 - dev: true - resolution: - integrity: sha512-2/xPb3ORsQ42nHYiSunXkDjPLBaEj/xTwUO4B7XCZQTRk7EBtTOPaygh10YAAh2OI1Qrp6NWfpAhzswj0ydt9g== /domelementtype/1.3.1: dev: true resolution: integrity: sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w== - /domelementtype/2.0.1: - dev: true - resolution: - integrity: sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ== /domhandler/2.3.0: dependencies: domelementtype: 1.3.1 @@ -2030,26 +1211,18 @@ packages: integrity: sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA== /domutils/1.5.1: dependencies: - dom-serializer: 0.2.2 + dom-serializer: 0.1.1 domelementtype: 1.3.1 dev: true resolution: integrity: sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8= /domutils/1.7.0: dependencies: - dom-serializer: 0.2.2 + dom-serializer: 0.1.1 domelementtype: 1.3.1 dev: true resolution: integrity: sha512-Lgd2XcJ/NjEw+7tFvfKxOzCYKZsdct5lczQ2ZaQY8Djz7pfAD3Gbp8ySJWtreII/vDlMVmxwa6pHmdxIYgttDg== - /dot-prop/4.2.0: - dependencies: - is-obj: 1.0.1 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ== /dot-prop/5.2.0: dependencies: is-obj: 2.0.0 @@ -2070,16 +1243,22 @@ packages: optional: true resolution: integrity: sha1-OoOpBOVDUyh4dMVkt1SThoSamMk= - /electron-to-chromium/1.3.337: + /ecstatic/3.3.2: + dependencies: + he: 1.2.0 + mime: 1.6.0 + minimist: 1.2.5 + url-join: 2.0.5 dev: true + hasBin: true resolution: - integrity: sha512-uJ+wLjslYQ/2rAusDg+6FlK8DLhHWTLCe7gkofBehTifW7KCkPVTn5rhKSCncWYNq34Iy/o4OfswuEkAO2RBaw== - /emittery/0.4.1: + integrity: sha512-fLf9l1hnwrHI2xn9mEDT7KIi22UDqA2jaCwyCbSUJh9a1V+LEUSL/JO/6TIz/QyuBURWUHrFL5Kg2TtO1bkkog== + /emittery/0.7.1: dev: true engines: - node: '>=6' + node: '>=10' resolution: - integrity: sha512-r4eRSeStEGf6M5SKdrQhhLK5bOwOBxQhIE3YSTnZE3GpKiLfnnhE+tPtrJE79+eDJgm39BM6LSoI8SCx4HbwlQ== + integrity: sha512-d34LN4L6h18Bzz9xpoku2nPwKxCPlPMr3EEKTkoEBi+1/+b0lcRkRJ1UVyyZaKNeqGR3swcGl6s390DNO4YVgQ== /emoji-regex/7.0.3: dev: true resolution: @@ -2088,19 +1267,20 @@ packages: dev: true resolution: integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== - /empower-core/1.2.0: - dependencies: - call-signature: 0.0.2 - core-js: 2.6.11 - dev: true - resolution: - integrity: sha512-g6+K6Geyc1o6FdXs9HwrXleCFan7d66G5xSCfSF7x1mJDCes6t0om9lFQG3zOrzh3Bkb/45N0cZ5Gqsf7YrzGQ== /end-of-stream/1.4.4: dependencies: once: 1.4.0 dev: true resolution: integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q== + /enquirer/2.3.6: + dependencies: + ansi-colors: 4.1.1 + dev: true + engines: + node: '>=8.6' + resolution: + integrity: sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg== /entities/1.0.0: dev: true resolution: @@ -2109,10 +1289,6 @@ packages: dev: true resolution: integrity: sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w== - /entities/2.0.0: - dev: true - resolution: - integrity: sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw== /equal-length/1.0.1: dev: true engines: @@ -2125,38 +1301,12 @@ packages: dev: true resolution: integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g== - /es-abstract/1.17.2: - dependencies: - es-to-primitive: 1.2.1 - function-bind: 1.1.1 - has: 1.0.3 - has-symbols: 1.0.1 - is-callable: 1.1.5 - is-regex: 1.0.5 - object-inspect: 1.7.0 - object-keys: 1.1.1 - object.assign: 4.1.0 - string.prototype.trimleft: 2.1.1 - string.prototype.trimright: 2.1.1 - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-YoKuru3Lyoy7yVTBSH2j7UxTqe/je3dWAruC0sHvZX1GNd5zX8SSLvQqEgO9b3Ex8IW+goFI9arEEsFIbulhOw== - /es-to-primitive/1.2.1: - dependencies: - is-callable: 1.1.5 - is-date-object: 1.0.2 - is-symbol: 1.0.3 + /escape-goat/2.1.1: dev: true engines: - node: '>= 0.4' - resolution: - integrity: sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA== - /es6-error/4.1.1: - dev: true + node: '>=8' resolution: - integrity: sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg== + integrity: sha512-8/uIhbG12Csjy2JEW7D9pHbreaVaS/OpN3ycnyvElTdwM5n6GY6W6e2IPemfvGZeUMqZ9A/3GqIZMgKnBhAw/Q== /escape-html/1.0.3: dev: true resolution: @@ -2173,7 +1323,13 @@ packages: node: '>=8' resolution: integrity: sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w== - /escodegen/1.13.0: + /escape-string-regexp/4.0.0: + dev: true + engines: + node: '>=10' + resolution: + integrity: sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA== + /escodegen/1.14.3: dependencies: esprima: 4.0.1 estraverse: 4.3.0 @@ -2187,7 +1343,7 @@ packages: optionalDependencies: source-map: 0.6.1 resolution: - integrity: sha512-eYk2dCkxR07DsHA/X2hRBj0CFAZeri/LyDMc0C8JT1Hqi6JnVpMhJ7XFITbb0+yZS3lVkaPL2oCkZ3AVmeVbMw== + integrity: sha512-qFcX0XJkdg+PB3xjZZG/wKSuT1PnQWx57+TVSjIMmILd2yC/6ByYElPwJnslDsuWuSAp4AwJGumarAAmJch5Kw== /esdoc-accessor-plugin/1.0.0: dev: true engines: @@ -2309,11 +1465,11 @@ packages: hasBin: true resolution: integrity: sha512-vsUcp52XJkOWg9m1vDYplGZN2iDzvmjDL5M/Mp8qkoDG3p2s0yIQCIjKR5wfPBaM3eV14a6zhQNYiNTCVzPnxA== - /eslint-config-delta/1.0.1: + /eslint-config-aether/1.1.1: dev: true resolution: - integrity: sha512-Tbyfn3mjp8UF/0DsiUglsHB20KxZ6zUbCYZfh97o/DAeN/TgV05qrtfu/bH4m5zzLiKggVP1/fZorYkquXCmgA== - /eslint-scope/5.0.0: + integrity: sha512-dchqc/ENmk6UikxPKkzHrhttZihDsTAJ7OxRPZIg08BSQgEZVMHmqce17xahvn4Z1/Qagw1R7ZtZp+oNCJpMWA== + /eslint-scope/5.1.0: dependencies: esrecurse: 4.2.1 estraverse: 4.3.0 @@ -2321,91 +1477,104 @@ packages: engines: node: '>=8.0.0' resolution: - integrity: sha512-oYrhJW7S0bxAFDvWqzvMPRm6pcgcnWc4QnofCAqRTRfQC0JcwenzGglTtsLyIuuWFfkqDG9vz67cnttSd53djw== - /eslint-utils/1.4.3: + integrity: sha512-iiGRvtxWqgtx5m8EyQUJihBloE4EnYeGE/bz1wSPwJE6tZuJUtHlhqDM4Xj2ukE8Dyy1+HCZ4hE0fzIVMzb58w== + /eslint-utils/2.1.0: dependencies: - eslint-visitor-keys: 1.1.0 + eslint-visitor-keys: 1.3.0 dev: true engines: node: '>=6' resolution: - integrity: sha512-fbBN5W2xdY45KulGXmLHZ3c3FHfVYmKg0IrAKGOkT/464PQsx2UeIzfz1RmEci+KLm1bBaAzZAh8+/E+XAeZ8Q== - /eslint-visitor-keys/1.1.0: + integrity: sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg== + /eslint-visitor-keys/1.3.0: dev: true engines: node: '>=4' resolution: - integrity: sha512-8y9YjtM1JBJU/A9Kc+SbaOV4y29sSWckBwMHa+FGtVj5gN/sbnKDf6xJUl+8g7FAij9LVaP8C24DUiH/f/2Z9A== - /eslint/6.8.0: + integrity: sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ== + /eslint-watch/7.0.0_eslint@7.7.0: dependencies: - '@babel/code-frame': 7.8.3 - ajv: 6.11.0 - chalk: 2.4.2 - cross-spawn: 6.0.5 + chokidar: 3.4.2 + core-js: 3.6.5 + debug: 4.1.1 + eslint: 7.7.0 + execa: 4.0.3 + keypress: 0.2.1 + lodash.debounce: 4.0.8 + lodash.isempty: 4.4.0 + lodash.isequal: 4.5.0 + lodash.kebabcase: 4.1.1 + lodash.unionwith: 4.6.0 + optionator: 0.9.1 + source-map-support: 0.5.19 + dev: true + engines: + node: '>=10' + hasBin: true + peerDependencies: + eslint: '>=7 <8.0.0' + resolution: + integrity: sha512-xwEm3blWQbBoYI1eZTfpPAXfqkCteQPgMa28u8k/J97tFwtffSgDc7hCOoR1vxsSzmRLtEthxB0a6pwimPTgLQ== + /eslint/7.7.0: + dependencies: + '@babel/code-frame': 7.10.4 + ajv: 6.12.4 + chalk: 4.1.0 + cross-spawn: 7.0.3 debug: 4.1.1 doctrine: 3.0.0 - eslint-scope: 5.0.0 - eslint-utils: 1.4.3 - eslint-visitor-keys: 1.1.0 - espree: 6.1.2 - esquery: 1.0.1 + enquirer: 2.3.6 + eslint-scope: 5.1.0 + eslint-utils: 2.1.0 + eslint-visitor-keys: 1.3.0 + espree: 7.2.0 + esquery: 1.3.1 esutils: 2.0.3 file-entry-cache: 5.0.1 functional-red-black-tree: 1.0.1 - glob-parent: 5.1.0 - globals: 12.3.0 + glob-parent: 5.1.1 + globals: 12.4.0 ignore: 4.0.6 import-fresh: 3.2.1 imurmurhash: 0.1.4 - inquirer: 7.0.3 is-glob: 4.0.1 - js-yaml: 3.13.1 + js-yaml: 3.14.0 json-stable-stringify-without-jsonify: 1.0.1 - levn: 0.3.0 - lodash: 4.17.15 + levn: 0.4.1 + lodash: 4.17.20 minimatch: 3.0.4 - mkdirp: 0.5.1 natural-compare: 1.4.0 - optionator: 0.8.3 + optionator: 0.9.1 progress: 2.0.3 - regexpp: 2.0.1 - semver: 6.3.0 - strip-ansi: 5.2.0 - strip-json-comments: 3.0.1 + regexpp: 3.1.0 + semver: 7.3.2 + strip-ansi: 6.0.0 + strip-json-comments: 3.1.1 table: 5.4.6 text-table: 0.2.0 - v8-compile-cache: 2.1.0 + v8-compile-cache: 2.1.1 dev: true engines: - node: ^8.10.0 || ^10.13.0 || >=11.10.1 + node: ^10.12.0 || >=12.0.0 hasBin: true resolution: - integrity: sha512-K+Iayyo2LtyYhDSYwz5D5QdWw0hCacNzyq1Y821Xna2xSJj7cijoLLYmLxTQgcgZ9mC61nryMy9S7GRbYpI5Ig== + integrity: sha512-1KUxLzos0ZVsyL81PnRN335nDtQ8/vZUD6uMtWbF+5zDtjKcsklIi78XoE0MVL93QvWTu+E5y44VyyCsOMBrIg== /esm/3.2.25: dev: true engines: node: '>=6' resolution: integrity: sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA== - /espower-location-detector/1.0.0: - dependencies: - is-url: 1.2.4 - path-is-absolute: 1.0.1 - source-map: 0.5.7 - xtend: 4.0.2 - dev: true - resolution: - integrity: sha1-oXt+zFnTDheeK+9z+0E3cEyzMbU= - /espree/6.1.2: + /espree/7.2.0: dependencies: - acorn: 7.1.0 - acorn-jsx: 5.1.0_acorn@7.1.0 - eslint-visitor-keys: 1.1.0 + acorn: 7.4.0 + acorn-jsx: 5.2.0_acorn@7.4.0 + eslint-visitor-keys: 1.3.0 dev: true engines: - node: '>=6.0.0' + node: ^10.12.0 || >=12.0.0 resolution: - integrity: sha512-2iUPuuPP+yW1PZaMSDM9eyVf8D5P0Hi8h83YtZ5bPc/zHYjII5khoixIUTMO794NOY8F/ThF1Bo8ncZILarUTA== + integrity: sha512-H+cQ3+3JYRMEIOl87e7QdHX70ocly5iW4+dttuR8iYSPr/hXKFb+7dBsZ7+u1adC4VrnPlTkv0+OwuPnDop19g== /esprima/4.0.1: dev: true engines: @@ -2413,20 +1582,14 @@ packages: hasBin: true resolution: integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== - /espurify/1.8.1: - dependencies: - core-js: 2.6.11 - dev: true - resolution: - integrity: sha512-ZDko6eY/o+D/gHCWyHTU85mKDgYcS4FJj7S+YD6WIInm7GQ6AnOjmcL4+buFV/JOztVLELi/7MmuGU5NHta0Mg== - /esquery/1.0.1: + /esquery/1.3.1: dependencies: - estraverse: 4.3.0 + estraverse: 5.2.0 dev: true engines: - node: '>=0.6' + node: '>=0.10' resolution: - integrity: sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA== + integrity: sha512-olpvt9QG0vniUBZspVRN6lwB7hOZoTRtT+jzR+tS4ffYx2mzbw+z0XCOk44aaLYKApNX5nMm+E+P6o25ip/DHQ== /esrecurse/4.2.1: dependencies: estraverse: 4.3.0 @@ -2441,45 +1604,47 @@ packages: node: '>=4.0' resolution: integrity: sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw== - /estree-walker/0.6.1: + /estraverse/5.2.0: + dev: true + engines: + node: '>=4.0' + resolution: + integrity: sha512-BxbNGGNm0RyRYvUdHpIwv9IWzeM9XClbOxwoATuFdOE7ZE6wHL+HQ5T8hoPM+zHvmKzzsEqhgy0GrQ5X13afiQ== + /estree-walker/1.0.1: dev: true resolution: - integrity: sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w== + integrity: sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg== /esutils/2.0.3: dev: true engines: node: '>=0.10.0' resolution: integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g== - /execa/0.7.0: + /eventemitter3/4.0.4: + dev: true + resolution: + integrity: sha512-rlaVLnVxtxvoyLsQQFBx53YmXHDxRIzzTLbdfxqi4yocpSjAxXwkU0cScM5JgSKMqEhrZpnvQ2D9gjylR0AimQ== + /execa/4.0.3: dependencies: - cross-spawn: 5.1.0 - get-stream: 3.0.0 - is-stream: 1.1.0 - npm-run-path: 2.0.2 - p-finally: 1.0.0 - signal-exit: 3.0.2 - strip-eof: 1.0.0 + cross-spawn: 7.0.3 + get-stream: 5.2.0 + human-signals: 1.1.1 + is-stream: 2.0.0 + merge-stream: 2.0.0 + npm-run-path: 4.0.1 + onetime: 5.1.2 + signal-exit: 3.0.3 + strip-final-newline: 2.0.0 dev: true engines: - node: '>=4' + node: '>=10' resolution: - integrity: sha1-lEvs00zEHuMqY6n68nrVpl/Fl3c= + integrity: sha512-WFDXGHckXPWZX19t1kCsXzOpqX9LWYNqn4C+HqZlk/V0imTkzJZqf87ZBhvpHaftERYknpk0fjSylnXVlVgI0A== /extend/3.0.2: dev: true optional: true resolution: integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g== - /external-editor/3.1.0: - dependencies: - chardet: 0.7.0 - iconv-lite: 0.4.24 - tmp: 0.0.33 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew== /extsprintf/1.3.0: dev: true engines: @@ -2487,26 +1652,27 @@ packages: optional: true resolution: integrity: sha1-lpGEQOMEGnpBT4xS48V06zw+HgU= - /fast-deep-equal/3.1.1: + /fast-deep-equal/3.1.3: dev: true resolution: - integrity: sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA== + integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q== /fast-diff/1.2.0: dev: true resolution: integrity: sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w== - /fast-glob/3.1.1: + /fast-glob/3.2.4: dependencies: '@nodelib/fs.stat': 2.0.3 '@nodelib/fs.walk': 1.2.4 - glob-parent: 5.1.0 - merge2: 1.3.0 + glob-parent: 5.1.1 + merge2: 1.4.1 micromatch: 4.0.2 + picomatch: 2.2.2 dev: true engines: node: '>=8' resolution: - integrity: sha512-nTCREpBY8w8r+boyFYAx21iL6faSsQynliPHM4Uf56SbkyohCNxpVPEH9xrF5TXKy+IsjkPUHDKiUkzBVRXn9g== + integrity: sha512-kr/Oo6PX51265qeuCYsyGypiO5uJFgBS0jksyG7FUeCyQzNwYnzrNIMR1NXfkZXsMYXYLRAHgISHBz8gQcxKHQ== /fast-json-stable-stringify/2.1.0: dev: true resolution: @@ -2515,20 +1681,20 @@ packages: dev: true resolution: integrity: sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= - /fastq/1.6.0: + /fastq/1.8.0: dependencies: reusify: 1.0.4 dev: true resolution: - integrity: sha512-jmxqQ3Z/nXoeyDmWAzF9kH1aGZSis6e/SbfPmJpUnyZ0ogr6iscHQaml4wsEepEWSdtmpy+eVXmCRIMpxaXqOA== - /figures/3.1.0: + integrity: sha512-SMIZoZdLh/fgofivvIkmknUXyPnvxRE3DhtZ5Me3Mrsk5gyPL42F0xr51TdRXskBxHfMp+07bcYzfsYEsSQA9Q== + /figures/3.2.0: dependencies: escape-string-regexp: 1.0.5 dev: true engines: node: '>=8' resolution: - integrity: sha512-ravh8VRXqHuMvZt/d8GblBeqDMkdJMBdv/2KntFH+ra5MXkO7nxNKpzQ3n6QD/2da1kH0aWmNISdvhM7gl2gVg== + integrity: sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg== /file-entry-cache/5.0.1: dependencies: flat-cache: 2.0.1 @@ -2545,14 +1711,6 @@ packages: node: '>=8' resolution: integrity: sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ== - /find-up/2.1.0: - dependencies: - locate-path: 2.0.0 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-RdG35QbHF93UgndaK3eSCjwMV6c= /find-up/3.0.0: dependencies: locate-path: 3.0.0 @@ -2572,7 +1730,7 @@ packages: integrity: sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw== /flat-cache/2.0.1: dependencies: - flatted: 2.0.1 + flatted: 2.0.2 rimraf: 2.6.3 write: 1.0.3 dev: true @@ -2580,10 +1738,16 @@ packages: node: '>=4' resolution: integrity: sha512-LoQe6yDuUMDzQAEH8sgmh4Md6oZnc/7PjtwjNFSzveXqSHt6ka9fPBuso7IGf9Rz4uqnSnWiFH2B/zj24a5ReA== - /flatted/2.0.1: + /flatted/2.0.2: + dev: true + resolution: + integrity: sha512-r5wGx7YeOwNWNlCA0wQ86zKyDLMQr+/RB8xy74M4hTphfmjlijTSSXGuH8rnvKZnfT9i+75zmd8jcKdMR4O6jA== + /follow-redirects/1.13.0: dev: true + engines: + node: '>=4.0' resolution: - integrity: sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg== + integrity: sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA== /forever-agent/0.6.1: dev: true optional: true @@ -2593,7 +1757,7 @@ packages: dependencies: asynckit: 0.4.0 combined-stream: 1.0.8 - mime-types: 2.1.26 + mime-types: 2.1.27 dev: true engines: node: '>= 0.12' @@ -2602,7 +1766,7 @@ packages: integrity: sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ== /fs-extra/1.0.0: dependencies: - graceful-fs: 4.2.3 + graceful-fs: 4.2.4 jsonfile: 2.4.0 klaw: 1.3.1 dev: true @@ -2610,7 +1774,7 @@ packages: integrity: sha1-zTzl9+fLYUWIP8rjGR6Yd/hYeVA= /fs-extra/5.0.0: dependencies: - graceful-fs: 4.2.3 + graceful-fs: 4.2.4 jsonfile: 4.0.0 universalify: 0.1.2 dev: true @@ -2620,45 +1784,31 @@ packages: dev: true resolution: integrity: sha1-FQStJSMVjKpA20onh8sBQRmU6k8= - /fsevents/2.1.2: + /fsevents/2.1.3: dev: true engines: node: ^8.16.0 || ^10.6.0 || >=11.0.0 optional: true + os: + - darwin resolution: - integrity: sha512-R4wDiBwZ0KzpgOWetKDug1FZcYhqYnUYKtfZYt4mD5SBz76q0KR4Q9o7GIPamsVPGmW3EYPPJ0dOOjvx32ldZA== - /function-bind/1.1.1: - dev: true - resolution: - integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A== + integrity: sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ== /functional-red-black-tree/1.0.1: dev: true resolution: integrity: sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= - /gensync/1.0.0-beta.1: - dev: true - engines: - node: '>=6.9.0' - resolution: - integrity: sha512-r8EC6NO1sngH/zdD9fiRDLdcgnbayXah+mLgManTaIZJqEC1MZstmnox8KpnI2/fxQwrp5OpCOYWLp4rBl4Jcg== - /get-port/5.1.1: + /get-caller-file/2.0.5: dev: true engines: - node: '>=8' + node: 6.* || 8.* || >= 10.* resolution: - integrity: sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ== + integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== /get-stdin/4.0.1: dev: true engines: node: '>=0.10.0' resolution: integrity: sha1-uWjGsKBDhDJJAui/Gl3zJXmkUP4= - /get-stream/3.0.0: - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ= /get-stream/4.1.0: dependencies: pump: 3.0.0 @@ -2667,14 +1817,14 @@ packages: node: '>=6' resolution: integrity: sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w== - /get-stream/5.1.0: + /get-stream/5.2.0: dependencies: pump: 3.0.0 dev: true engines: node: '>=8' resolution: - integrity: sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw== + integrity: sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA== /getpass/0.1.7: dependencies: assert-plus: 1.0.0 @@ -2682,14 +1832,14 @@ packages: optional: true resolution: integrity: sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo= - /glob-parent/5.1.0: + /glob-parent/5.1.1: dependencies: is-glob: 4.0.1 dev: true engines: node: '>= 6' resolution: - integrity: sha512-qjtRgnIVmOfnKUE3NJAQEdk+lKrxfw8t5ke7SXtfMTHcjsBfOfWXCQfdb30zfDoZQ2IRSIiidmjtbHZPZ++Ihw== + integrity: sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ== /glob/7.1.6: dependencies: fs.realpath: 1.0.0 @@ -2701,28 +1851,22 @@ packages: dev: true resolution: integrity: sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== - /global-dirs/0.1.1: + /global-dirs/2.0.1: dependencies: ini: 1.3.5 dev: true engines: - node: '>=4' - resolution: - integrity: sha1-sxnA3UYH81PzvpzKTHL8FIxJ9EU= - /globals/11.12.0: - dev: true - engines: - node: '>=4' + node: '>=8' resolution: - integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== - /globals/12.3.0: + integrity: sha512-5HqUqdhkEovj2Of/ms3IeS/EekcO54ytHRLV4PEY2rhRwrHXLQjeVEES0Lhka0xwNDtGYn58wyC4s5+MHsOO6A== + /globals/12.4.0: dependencies: type-fest: 0.8.1 dev: true engines: node: '>=8' resolution: - integrity: sha512-wAfjdLgFsPZsklLJvOBUBmzYE8/CwhEqSBEMRXA3qxIiNtyqvjYurAtIfDh6chlEPUfmTY3MnZh5Hfh4q0UlIw== + integrity: sha512-BWICuzzDvDoH54NHKCseDanAhE3CeDorgDL5MT6LMXXj2WCnd9UC2szdk4AWLfjdgNBCXLUanXYcpBBKOSWGwg== /globals/9.18.0: dev: true engines: @@ -2731,31 +1875,32 @@ packages: integrity: sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ== /globby/10.0.2: dependencies: - '@types/glob': 7.1.1 + '@types/glob': 7.1.3 array-union: 2.1.0 dir-glob: 3.0.1 - fast-glob: 3.1.1 + fast-glob: 3.2.4 glob: 7.1.6 - ignore: 5.1.4 - merge2: 1.3.0 + ignore: 5.1.8 + merge2: 1.4.1 slash: 3.0.0 dev: true engines: node: '>=8' resolution: integrity: sha512-7dUi7RvCoT/xast/o/dLN53oqND4yk0nsHkhRgn9w65C4PofCLOoJ39iSOg+qVDdWQPIEj+eszMHQ+aLVwwQSg== - /globby/6.1.0: + /globby/11.0.1: dependencies: - array-union: 1.0.2 - glob: 7.1.6 - object-assign: 4.1.1 - pify: 2.3.0 - pinkie-promise: 2.0.1 + array-union: 2.1.0 + dir-glob: 3.0.1 + fast-glob: 3.2.4 + ignore: 5.1.8 + merge2: 1.4.1 + slash: 3.0.0 dev: true engines: - node: '>=0.10.0' + node: '>=10' resolution: - integrity: sha1-9abXDoOV4hyFj7BInWTfAkJNUGw= + integrity: sha512-iH9RmgwCmUJHi2z5o2l3eTtGBtXek1OYlHrbcxOYugyHLmAsZrPj43OtHThd62Buh/Vv6VyCBD2bdyWcGNQqoQ== /got/9.6.0: dependencies: '@sindresorhus/is': 0.14.0 @@ -2774,10 +1919,10 @@ packages: node: '>=8.6' resolution: integrity: sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q== - /graceful-fs/4.2.3: + /graceful-fs/4.2.4: dev: true resolution: - integrity: sha512-a30VEBm4PEdx1dRB7MFK7BejejvCvBronbLjht+sHuGYj8PHs7M/5Z+rt5lw551vZ7yfTCj4Vuyy3mSJytDWRQ== + integrity: sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw== /har-schema/2.0.0: dev: true engines: @@ -2785,16 +1930,17 @@ packages: optional: true resolution: integrity: sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI= - /har-validator/5.1.3: + /har-validator/5.1.5: dependencies: - ajv: 6.11.0 + ajv: 6.12.4 har-schema: 2.0.0 + deprecated: this library is no longer supported dev: true engines: node: '>=6' optional: true resolution: - integrity: sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g== + integrity: sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w== /has-ansi/2.0.0: dependencies: ansi-regex: 2.1.1 @@ -2815,39 +1961,21 @@ packages: node: '>=8' resolution: integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== - /has-symbols/1.0.1: - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg== /has-yarn/2.1.0: dev: true engines: node: '>=8' resolution: integrity: sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw== - /has/1.0.3: - dependencies: - function-bind: 1.1.1 - dev: true - engines: - node: '>= 0.4.0' - resolution: - integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw== - /hasha/5.1.0: - dependencies: - is-stream: 2.0.0 - type-fest: 0.8.1 + /he/1.2.0: dev: true - engines: - node: '>=8' + hasBin: true resolution: - integrity: sha512-OFPDWmzPN1l7atOV1TgBVmNtBxaIysToK6Ve9DK+vT6pYuklw/nPNT+HJbZi0KDcI6vWB+9tgvZ5YD7fA3CXcA== - /hosted-git-info/2.8.5: + integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw== + /hosted-git-info/2.8.8: dev: true resolution: - integrity: sha512-kssjab8CvdXfcXMXVcvsXum4Hwdq9XGtRD3TteMEvEbq0LXyiNQr6AprqKqfeaDXze7SxWvRxdpwE6ku7ikLkg== + integrity: sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg== /htmlparser2/3.10.1: dependencies: domelementtype: 1.3.1 @@ -2855,7 +1983,7 @@ packages: domutils: 1.7.0 entities: 1.1.2 inherits: 2.0.4 - readable-stream: 3.5.0 + readable-stream: 3.6.0 dev: true resolution: integrity: sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ== @@ -2869,10 +1997,38 @@ packages: dev: true resolution: integrity: sha1-mWwosZFRaovoZQGn15dX5ccMEGg= - /http-cache-semantics/4.0.3: + /http-cache-semantics/4.1.0: + dev: true + resolution: + integrity: sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ== + /http-proxy/1.18.1: + dependencies: + eventemitter3: 4.0.4 + follow-redirects: 1.13.0 + requires-port: 1.0.0 + dev: true + engines: + node: '>=8.0.0' + resolution: + integrity: sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ== + /http-server/0.12.3: + dependencies: + basic-auth: 1.1.0 + colors: 1.4.0 + corser: 2.0.1 + ecstatic: 3.3.2 + http-proxy: 1.18.1 + minimist: 1.2.5 + opener: 1.5.1 + portfinder: 1.0.28 + secure-compare: 3.0.1 + union: 0.5.0 dev: true + engines: + node: '>=6' + hasBin: true resolution: - integrity: sha512-TcIMG3qeVLgDr1TEd2XvHaTnMPwYQUQMIBLy+5pLSDKYFc7UIqj39w8EGzZkaxoLv/l2K8HaI0t5AVA+YYgUew== + integrity: sha512-be0dKG6pni92bRjq0kvExtj/NrrAd28/8fCXkaI/4piTwQMSDSLMhWyW0NI1V+DBI3aa1HMlQu46/HjVLfmugA== /http-signature/1.2.0: dependencies: assert-plus: 1.0.0 @@ -2885,6 +2041,12 @@ packages: optional: true resolution: integrity: sha1-muzZJRFHcvPZW2WmCruPfBj7rOE= + /human-signals/1.1.1: + dev: true + engines: + node: '>=8.12.0' + resolution: + integrity: sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw== /ice-cap/0.0.4: dependencies: cheerio: 0.20.0 @@ -2892,30 +2054,24 @@ packages: dev: true resolution: integrity: sha1-im0xq0ysjUtW3k+pRt8zUlYbbhg= - /iconv-lite/0.4.24: - dependencies: - safer-buffer: 2.1.2 + /ignore-by-default/2.0.0: dev: true engines: - node: '>=0.10.0' - resolution: - integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== - /ignore-by-default/1.0.1: - dev: true + node: '>=10 <11 || >=12 <13 || >=14' resolution: - integrity: sha1-SMptcvbGo68Aqa1K5odr44ieKwk= + integrity: sha512-+mQSgMRiFD3L3AOxLYOCxjIq4OnAmo5CIuC+lj5ehCJcPtV++QacEV7FdpzvYxH6DaOySWzQU6RR0lPLy37ckA== /ignore/4.0.6: dev: true engines: node: '>= 4' resolution: integrity: sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== - /ignore/5.1.4: + /ignore/5.1.8: dev: true engines: node: '>= 4' resolution: - integrity: sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A== + integrity: sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw== /import-fresh/3.2.1: dependencies: parent-module: 1.0.1 @@ -2974,75 +2130,37 @@ packages: dev: true resolution: integrity: sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw== - /inquirer/7.0.3: - dependencies: - ansi-escapes: 4.3.0 - chalk: 2.4.2 - cli-cursor: 3.1.0 - cli-width: 2.2.0 - external-editor: 3.1.0 - figures: 3.1.0 - lodash: 4.17.15 - mute-stream: 0.0.8 - run-async: 2.3.0 - rxjs: 6.5.4 - string-width: 4.2.0 - strip-ansi: 5.2.0 - through: 2.3.8 - dev: true - engines: - node: '>=6.0.0' - resolution: - integrity: sha512-+OiOVeVydu4hnCGLCSX+wedovR/Yzskv9BFqUNNKq9uU2qg7LCcCo3R86S2E7WLo0y/x2pnEZfZe1CoYnORUAw== /invariant/2.2.4: dependencies: loose-envify: 1.4.0 dev: true resolution: integrity: sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA== - /irregular-plurals/2.0.0: - dev: true - engines: - node: '>=6' - resolution: - integrity: sha512-Y75zBYLkh0lJ9qxeHlMjQ7bSbyiSqNW/UOPWDmzC7cXskL1hekSITh1Oc6JV0XCWWZ9DE8VYSB71xocLk3gmGw== - /is-arguments/1.0.4: + /irregular-plurals/3.2.0: dev: true engines: - node: '>= 0.4' + node: '>=8' resolution: - integrity: sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA== + integrity: sha512-YqTdPLfwP7YFN0SsD3QUVCkm9ZG2VzOXv3DOrw5G5mkMbVwptTwVcFv7/C0vOpBmgTxAeTG19XpUs1E522LW9Q== /is-arrayish/0.2.1: dev: true resolution: integrity: sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0= /is-binary-path/2.1.0: dependencies: - binary-extensions: 2.0.0 + binary-extensions: 2.1.0 dev: true engines: node: '>=8' resolution: integrity: sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw== - /is-callable/1.1.5: - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-ESKv5sMCJB2jnHTWZ3O5itG+O128Hsus4K4Qh1h2/cgn2vbgnLSVqfV46AeJA9D5EeeLa9w81KUXMtn34zhX+Q== /is-ci/2.0.0: dependencies: ci-info: 2.0.0 dev: true - hasBin: true - resolution: - integrity: sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w== - /is-date-object/1.0.2: - dev: true - engines: - node: '>= 0.4' + hasBin: true resolution: - integrity: sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g== + integrity: sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w== /is-error/2.2.2: dev: true resolution: @@ -3053,14 +2171,12 @@ packages: node: '>=0.10.0' resolution: integrity: sha1-qIwCU1eR8C7TfHahueqXc8gz+MI= - /is-finite/1.0.2: - dependencies: - number-is-nan: 1.0.1 + /is-finite/1.1.0: dev: true engines: node: '>=0.10.0' resolution: - integrity: sha1-zGZ3aVYCvlUO8R6LSqYwU0K20Ko= + integrity: sha512-cdyMtqX/BOqqNBBiKlIVkytNHm49MtMlYyn1zxzvJKWmFMlGzm+ry5BBfYyeY9YmNKbRSo/o7OX9w9ale0wg3w== /is-fullwidth-code-point/2.0.0: dev: true engines: @@ -3081,137 +2197,75 @@ packages: node: '>=0.10.0' resolution: integrity: sha512-5G0tKtBTFImOqDnLB2hG6Bp2qcKEFduo4tZu9MT/H6NQv/ghhy30o55ufafxJ/LdH79LLs2Kfrn85TLKyA7BUg== - /is-installed-globally/0.1.0: + /is-installed-globally/0.3.2: dependencies: - global-dirs: 0.1.1 - is-path-inside: 1.0.1 + global-dirs: 2.0.1 + is-path-inside: 3.0.2 dev: true engines: - node: '>=4' + node: '>=8' + resolution: + integrity: sha512-wZ8x1js7Ia0kecP/CHM/3ABkAmujX7WPvQk6uu3Fly/Mk44pySulQpnHG46OMjHGXApINnV4QhY3SWnECO2z5g== + /is-interactive/1.0.0: + dev: true + engines: + node: '>=8' resolution: - integrity: sha1-Df2Y9akRFxbdU13aZJL2e/PSWoA= + integrity: sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w== /is-module/1.0.0: dev: true resolution: integrity: sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE= - /is-npm/3.0.0: + /is-npm/4.0.0: dev: true engines: node: '>=8' resolution: - integrity: sha512-wsigDr1Kkschp2opC4G3yA6r9EgVA6NjRpWzIi9axXqeIaAATPRJc4uLujXe3Nd9uO8KoDyA4MD6aZSeXTADhA== + integrity: sha512-96ECIfh9xtDDlPylNPXhzjsykHsMJZ18ASpaWzQyBr4YRTcVjUvzaHayDAES2oU/3KpljhHUjtSRNiDwi0F0ig== /is-number/7.0.0: dev: true engines: node: '>=0.12.0' resolution: integrity: sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng== - /is-obj/1.0.1: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-PkcprB9f3gJc19g6iW2rn09n2w8= /is-obj/2.0.0: dev: true engines: node: '>=8' resolution: integrity: sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w== - /is-observable/2.0.0: - dev: true - engines: - node: '>=8' - resolution: - integrity: sha512-fhBZv3eFKUbyHXZ1oHujdo2tZ+CNbdpdzzlENgCGZUC8keoGxUew2jYFLYcUB4qo7LDD03o4KK11m/QYD7kEjg== /is-path-cwd/2.2.0: dev: true engines: node: '>=6' resolution: integrity: sha512-w942bTcih8fdJPJmQHFzkS76NEP8Kzzvmw92cXsazb8intwLqPibPPdXf4ANdKV3rYMuuQYGIWtvz9JilB3NFQ== - /is-path-in-cwd/2.1.0: - dependencies: - is-path-inside: 2.1.0 - dev: true - engines: - node: '>=6' - resolution: - integrity: sha512-rNocXHgipO+rvnP6dk3zI20RpOtrAM/kzbB258Uw5BWr3TpXi861yzjo16Dn4hUox07iw5AyeMLHWsujkjzvRQ== - /is-path-inside/1.0.1: - dependencies: - path-is-inside: 1.0.2 - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-jvW33lBDej/cprToZe96pVy0gDY= - /is-path-inside/2.1.0: - dependencies: - path-is-inside: 1.0.2 - dev: true - engines: - node: '>=6' - resolution: - integrity: sha512-wiyhTzfDWsvwAW53OBWF5zuvaOGlZ6PwYxAbPVDhpm+gM09xKQGjBq/8uYN12aDvMxnAnq3dxTyoSoRNmg5YFg== - /is-plain-obj/1.1.0: + /is-path-inside/3.0.2: dev: true engines: - node: '>=0.10.0' + node: '>=8' resolution: - integrity: sha1-caUMhCnfync8kqOQpKA7OfzVHT4= - /is-plain-object/3.0.0: - dependencies: - isobject: 4.0.0 + integrity: sha512-/2UGPSgmtqwo1ktx8NDHjuPwZWmHhO+gj0f93EkhLB5RgW9RZevWYYlIkS6zePc6U2WpOdQYIwHe9YC4DWEBVg== + /is-plain-object/4.1.1: dev: true engines: node: '>=0.10.0' resolution: - integrity: sha512-tZIpofR+P05k8Aocp7UI/2UTa9lTJSebCXpFFoR9aibpokDj/uXBsJ8luUu0tTVYKkMU6URDUuOfJZ7koewXvg== - /is-promise/2.1.0: - dev: true - resolution: - integrity: sha1-eaKp7OfwlugPNtKy87wWwf9L8/o= - /is-regex/1.0.5: - dependencies: - has: 1.0.3 - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-vlKW17SNq44owv5AQR3Cq0bQPEb8+kF3UKZ2fiZNOWtztYE5i0CzCZxFDwO58qAOWtxdBRVO/V5Qin1wjCqFYQ== - /is-stream/1.1.0: + integrity: sha512-5Aw8LLVsDlZsETVMhoMXzqsXwQqr/0vlnBYzIXJbYo2F4yYlhLHs+Ez7Bod7IIQKWkJbJfxrWD7pA1Dw1TKrwA== + /is-promise/4.0.0: dev: true - engines: - node: '>=0.10.0' resolution: - integrity: sha1-EtSj3U5o4Lec6428hBc66A2RykQ= + integrity: sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ== /is-stream/2.0.0: dev: true engines: node: '>=8' resolution: integrity: sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw== - /is-symbol/1.0.3: - dependencies: - has-symbols: 1.0.1 - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ== /is-typedarray/1.0.0: dev: true resolution: integrity: sha1-5HnICFjfDBsR3dppQPlgEfzaSpo= - /is-url/1.2.4: - dev: true - resolution: - integrity: sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww== - /is-utf8/0.2.1: - dev: true - resolution: - integrity: sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI= /is-yarn-global/0.3.0: dev: true resolution: @@ -3224,30 +2278,25 @@ packages: dev: true resolution: integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= - /isobject/4.0.0: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA== /isstream/0.1.2: dev: true optional: true resolution: integrity: sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo= /iterator-result/1.0.0: - dev: true + dev: false resolution: integrity: sha512-Zqg84fiN3tF7APhyqkHs9t0bYXpIL1zRs4hslexxfmgvDTTDFIUa501H+2KgTWjH0R4ifrWc5dRkfqSrXQm37Q== - /jest-worker/24.9.0: + /jest-worker/26.3.0: dependencies: + '@types/node': 14.6.0 merge-stream: 2.0.0 - supports-color: 6.1.0 + supports-color: 7.1.0 dev: true engines: - node: '>= 6' + node: '>= 10.13.0' resolution: - integrity: sha512-51PE4haMSXcHohnSMdM42anbvZANYTqMrr52tVKPqqsPJMzoP6FYYDVqahX/HrAoKEKz3uUPzSvKs9A3qR4iVw== + integrity: sha512-Vmpn2F6IASefL+DVBhPzI2J9/GJUsqzomdeN+P+dK8/jKxbh8R3BtFnx3FIta7wYlPU62cpJMJQo4kuOowcMnw== /js-string-escape/1.0.1: dev: true engines: @@ -3262,14 +2311,14 @@ packages: dev: true resolution: integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== - /js-yaml/3.13.1: + /js-yaml/3.14.0: dependencies: argparse: 1.0.10 esprima: 4.0.1 dev: true hasBin: true resolution: - integrity: sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw== + integrity: sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A== /jsbn/0.1.1: dev: true optional: true @@ -3282,10 +2331,10 @@ packages: acorn-globals: 1.0.9 cssom: 0.3.8 cssstyle: 0.2.37 - escodegen: 1.13.0 + escodegen: 1.14.3 nwmatcher: 1.4.4 parse5: 1.5.1 - request: 2.88.0 + request: 2.88.2 sax: 1.2.4 symbol-tree: 3.2.4 tough-cookie: 2.5.0 @@ -3306,13 +2355,6 @@ packages: hasBin: true resolution: integrity: sha1-RsP+yMGJKxKwgz25vHYiF226s0s= - /jsesc/2.5.2: - dev: true - engines: - node: '>=4' - hasBin: true - resolution: - integrity: sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA== /json-buffer/3.0.0: dev: true resolution: @@ -3339,25 +2381,16 @@ packages: optional: true resolution: integrity: sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus= - /json5/2.1.1: - dependencies: - minimist: 1.2.0 - dev: true - engines: - node: '>=6' - hasBin: true - resolution: - integrity: sha512-l+3HXD0GEI3huGq1njuqtzYK8OYJyXMkOLtQ53pjWh89tvWS2h6l+1zMkYWqlb57+SiQodKZyvMEFb2X+KrFhQ== /jsonfile/2.4.0: dev: true optionalDependencies: - graceful-fs: 4.2.3 + graceful-fs: 4.2.4 resolution: integrity: sha1-NzaitCi4e72gzIO1P6PWM6NcKug= /jsonfile/4.0.0: dev: true optionalDependencies: - graceful-fs: 4.2.3 + graceful-fs: 4.2.4 resolution: integrity: sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss= /jsprim/1.4.1: @@ -3372,6 +2405,10 @@ packages: optional: true resolution: integrity: sha1-MT5mvB5cwG5Di8G3SZwuXFastqI= + /keypress/0.2.1: + dev: true + resolution: + integrity: sha1-HoBFQlABjbrUw/6USX1uZ7YmnHc= /keyv/3.1.0: dependencies: json-buffer: 3.0.0 @@ -3381,7 +2418,7 @@ packages: /klaw/1.3.1: dev: true optionalDependencies: - graceful-fs: 4.2.3 + graceful-fs: 4.2.4 resolution: integrity: sha1-QIhDO0azsbolnXh4XY6W9zugJDk= /latest-version/5.1.0: @@ -3392,20 +2429,6 @@ packages: node: '>=8' resolution: integrity: sha512-weT+r0kTkRQdCdYCNtkMwWXQTMEswKrFBkm4ckQOMVhhqhIMI1UT2hMj+1iigIhgSZm5gTmrRXBNoGUgaTY1xA== - /leven/3.1.0: - dev: true - engines: - node: '>=6' - resolution: - integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A== - /levenary/1.1.0: - dependencies: - leven: 3.1.0 - dev: true - engines: - node: '>= 8' - resolution: - integrity: sha512-VHcwhO0UTpUW7rLPN2/OiWJdgA1e9BqEDALhrgCe/F+uUJnep6CoUsTzMeP8Rh0NGr9uKquXxqe7lwLZo509nQ== /levn/0.3.0: dependencies: prelude-ls: 1.1.2 @@ -3413,22 +2436,25 @@ packages: dev: true engines: node: '>= 0.8.0' + optional: true resolution: integrity: sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4= - /load-json-file/4.0.0: + /levn/0.4.1: dependencies: - graceful-fs: 4.2.3 - parse-json: 4.0.0 - pify: 3.0.0 - strip-bom: 3.0.0 + prelude-ls: 1.2.1 + type-check: 0.4.0 dev: true engines: - node: '>=4' + node: '>= 0.8.0' resolution: - integrity: sha1-L19Fq5HjMhYjT9U62rZo607AmTs= + integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ== + /lines-and-columns/1.1.6: + dev: true + resolution: + integrity: sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA= /load-json-file/5.3.0: dependencies: - graceful-fs: 4.2.3 + graceful-fs: 4.2.4 parse-json: 4.0.0 pify: 4.0.1 strip-bom: 3.0.0 @@ -3438,15 +2464,6 @@ packages: node: '>=6' resolution: integrity: sha512-cJGP40Jc/VXUsp8/OrnyKyTZ1y6v/dphm3bioS+RrKXjK2BB6wHUd6JptZEFDGgGahMT+InnZO5i1Ei9mpC8Bw== - /locate-path/2.0.0: - dependencies: - p-locate: 2.0.0 - path-exists: 3.0.0 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-K1aLJl7slExtnA3pw9u7ygNUzY4= /locate-path/3.0.0: dependencies: p-locate: 3.0.0 @@ -3472,10 +2489,10 @@ packages: dev: true resolution: integrity: sha1-euMBfpOWIqwxt9fX3LGzTbFpDTU= - /lodash.clonedeep/4.5.0: + /lodash.debounce/4.0.8: dev: true resolution: - integrity: sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8= + integrity: sha1-gteb/zCmfEAF/9XiUVMArZyk168= /lodash.defaults/4.2.0: dev: true resolution: @@ -3488,18 +2505,22 @@ packages: dev: true resolution: integrity: sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8= - /lodash.flattendeep/4.4.0: - dev: true - resolution: - integrity: sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI= /lodash.foreach/4.5.0: dev: true resolution: integrity: sha1-Gmo16s5AEoDH8G3d7DUWWrJ+PlM= - /lodash.islength/4.0.1: + /lodash.isempty/4.4.0: + dev: true + resolution: + integrity: sha1-b4bL7di+TsmHvpqvM8loTbGzHn4= + /lodash.isequal/4.5.0: dev: true resolution: - integrity: sha1-Tpho1FJXXXUK/9NYyXlUPcIO1Xc= + integrity: sha1-QVxEePK8wwEgwizhDtMib30+GOA= + /lodash.kebabcase/4.1.1: + dev: true + resolution: + integrity: sha1-hImxyw0p/4gZXM7KRI/21swpXDY= /lodash.map/4.6.0: dev: true resolution: @@ -3524,18 +2545,22 @@ packages: dev: true resolution: integrity: sha1-G7nzFO9ri63tE7VJFpsqlF62jk0= - /lodash/4.17.15: + /lodash.unionwith/4.6.0: + dev: true + resolution: + integrity: sha1-dNFAtcqBRubGQ8NyT1FSU42awfA= + /lodash/4.17.20: dev: true resolution: - integrity: sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== - /log-symbols/2.2.0: + integrity: sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== + /log-symbols/3.0.0: dependencies: chalk: 2.4.2 dev: true engines: - node: '>=4' + node: '>=8' resolution: - integrity: sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg== + integrity: sha512-dSkNGuI7iG3mfvDzUuYZyvk5dD9ocYCYzNU6CYDE6+Xqd+gwme6Z00NS3dUh8mq/73HaEtT7m6W+yUPtU6BZnQ== /loose-envify/1.4.0: dependencies: js-tokens: 4.0.0 @@ -3543,24 +2568,6 @@ packages: hasBin: true resolution: integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q== - /loud-rejection/1.6.0: - dependencies: - currently-unhandled: 0.4.1 - signal-exit: 3.0.2 - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-W0b4AUft7leIcPCG0Eghz5mOVR8= - /loud-rejection/2.2.0: - dependencies: - currently-unhandled: 0.4.1 - signal-exit: 3.0.2 - dev: true - engines: - node: '>=8' - resolution: - integrity: sha512-S0FayMXku80toa5sZ6Ro4C+s+EtFDCsyJNG/AzFMfX3AxD5Si4dZsgzm/kKnbOxHl5Cv8jBlno8+3XYIh2pNjQ== /lowercase-keys/1.0.1: dev: true engines: @@ -3573,41 +2580,28 @@ packages: node: '>=8' resolution: integrity: sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA== - /lru-cache/4.1.5: - dependencies: - pseudomap: 1.0.2 - yallist: 2.1.2 - dev: true - resolution: - integrity: sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g== - /make-dir/1.3.0: + /magic-string/0.25.7: dependencies: - pify: 3.0.0 + sourcemap-codec: 1.4.8 dev: true - engines: - node: '>=4' resolution: - integrity: sha512-2w31R7SJtieJJnQtGc7RVL2StM2vGYVfqUOvUDxH6bC6aJTxPxTF0GnIgCyu7tjockiUWAYQRbxa7vKn34s5sQ== - /make-dir/3.0.0: + integrity: sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA== + /make-dir/3.1.0: dependencies: semver: 6.3.0 dev: true engines: node: '>=8' resolution: - integrity: sha512-grNJDhb8b1Jm1qeqW5R/O63wUo4UXo2v2HMic6YT9i/HBlF93S8jkMgH7yugvY9ABDShH4VZMn8I+U8+fCNegw== - /map-obj/1.0.1: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0= - /map-obj/2.0.0: + integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw== + /map-age-cleaner/0.1.3: + dependencies: + p-defer: 1.0.0 dev: true engines: - node: '>=4' + node: '>=6' resolution: - integrity: sha1-plzSkIepJZi4eRJXpSPgISIqwfk= + integrity: sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w== /marked/0.3.19: dev: true engines: @@ -3615,101 +2609,89 @@ packages: hasBin: true resolution: integrity: sha512-ea2eGWOqNxPcXv8dyERdSr/6FmzvWwzjMxpfGB/sbMccXoct+xY+YukPD+QTUZwyvK7BZwcr4m21WBOW41pAkg== - /matcher/2.1.0: + /matcher/3.0.0: dependencies: - escape-string-regexp: 2.0.0 + escape-string-regexp: 4.0.0 dev: true engines: - node: '>=8' - resolution: - integrity: sha512-o+nZr+vtJtgPNklyeUKkkH42OsK8WAfdgaJE2FNxcjLPg+5QbeEoT6vRj8Xq/iv18JlQ9cmKsEu0b94ixWf1YQ== - /math-ds/1.1.3: - dev: true + node: '>=10' resolution: - integrity: sha512-Bn4cqPhOuh5K/OvDQK74UXFXuT692DWqly0g8e6dJVBaFilW5FbB0Bp4lReUST7tw9n8+FhCQERXongiQak2GQ== - /md5-hex/2.0.0: - dependencies: - md5-o-matic: 0.1.1 + integrity: sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng== + /math-ds/1.2.1: dev: true - engines: - node: '>=4' resolution: - integrity: sha1-0FiOnxx0lUSS7NJKwKxs6ZfZLjM= + integrity: sha512-Fzf0G2+h7d1DqWtQDw3QLmx4R5Uat4Lj3x0iRV4fLyuUH94pODq6Y2UOqSFN0aAU+mQHESBPGbcCyaAXDaYV+A== /md5-hex/3.0.1: dependencies: - blueimp-md5: 2.12.0 + blueimp-md5: 2.17.0 dev: true engines: node: '>=8' resolution: integrity: sha512-BUiRtTtV39LIJwinWBjqVsU9xhdnz7/i889V859IBFpuqGAj6LuOvHv5XLbgZ2R7ptJoJaEcxkv88/h25T7Ciw== - /md5-o-matic/0.1.1: - dev: true - resolution: - integrity: sha1-givM1l4RfFFPqxdrJZRdVBAKA8M= - /meow/5.0.0: + /mem/6.1.0: dependencies: - camelcase-keys: 4.2.0 - decamelize-keys: 1.1.0 - loud-rejection: 1.6.0 - minimist-options: 3.0.2 - normalize-package-data: 2.5.0 - read-pkg-up: 3.0.0 - redent: 2.0.0 - trim-newlines: 2.0.0 - yargs-parser: 10.1.0 + map-age-cleaner: 0.1.3 + mimic-fn: 3.1.0 dev: true engines: - node: '>=6' + node: '>=8' resolution: - integrity: sha512-CbTqYU17ABaLefO8vCU153ZZlprKYWDljcndKKDCFcYQITzWCXZAVk4QMFZPgvzrnUQ3uItnIE/LoUOwrT15Ig== + integrity: sha512-RlbnLQgRHk5lwqTtpEkBTQ2ll/CG/iB+J4Hy2Wh97PjgZgXgWJWrFF+XXujh3UUVLvR4OOTgZzcWMMwnehlEUg== /merge-stream/2.0.0: dev: true resolution: integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== - /merge2/1.3.0: + /merge2/1.4.1: dev: true engines: - node: '>= 6' + node: '>= 8' resolution: - integrity: sha512-2j4DAdlBOkiSZIsaXk4mTE3sRS02yBHAtfy127xRV3bQUFqXkjHCHLW6Scv7DwNRbIWNHH8zpnz9zMaKXIdvYw== + integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== /micromatch/4.0.2: dependencies: braces: 3.0.2 - picomatch: 2.2.1 + picomatch: 2.2.2 dev: true engines: node: '>=8' resolution: integrity: sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q== - /mime-db/1.43.0: + /mime-db/1.44.0: dev: true engines: node: '>= 0.6' optional: true resolution: - integrity: sha512-+5dsGEEovYbT8UY9yD7eE4XTc4UwJ1jBYlgaQQF38ENsKR3wj/8q8RFZrF9WIZpB2V1ArTVFUva8sAul1NzRzQ== - /mime-types/2.1.26: + integrity: sha512-/NOTfLrsPBVeH7YtFPgsVWveuL+4SjjYxaQ1xtM1KMFj7HdxlBlxeyNLzhyJVx7r4rZGJAZ/6lkKCitSc/Nmpg== + /mime-types/2.1.27: dependencies: - mime-db: 1.43.0 + mime-db: 1.44.0 dev: true engines: node: '>= 0.6' optional: true resolution: - integrity: sha512-01paPWYgLrkqAyrlDorC1uDwl2p3qZT7yl806vW7DvDoxwXi46jsjFbg+WdwotBIk6/MbEhO/dh5aZ5sNj/dWQ== - /mimic-fn/1.2.0: + integrity: sha512-JIhqnCasI9yD+SsmkquHBxTSEuZdQX5BuQnS2Vc7puQQQ+8yiP5AY5uWhpdv4YL4VM5c6iliiYWPgJ/nJQLp7w== + /mime/1.6.0: dev: true engines: node: '>=4' + hasBin: true resolution: - integrity: sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ== + integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg== /mimic-fn/2.1.0: dev: true engines: node: '>=6' resolution: integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== + /mimic-fn/3.1.0: + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-Ysbi9uYW9hFyfrThdDEQuykN4Ey6BuwPD2kpI5ES/nFTDn/98yxYNLZJcgUAKPT/mcrLLKaGzJR9YVxJrIdASQ== /mimic-response/1.0.1: dev: true engines: @@ -3722,30 +2704,21 @@ packages: dev: true resolution: integrity: sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== - /minimist-options/3.0.2: - dependencies: - arrify: 1.0.1 - is-plain-obj: 1.1.0 - dev: true - engines: - node: '>= 4' - resolution: - integrity: sha512-FyBrT/d0d4+uiZRbqznPXqw3IpZZG3gl3wKWiX784FycUKVwBt0uLBFkQrtE4tZOrgo78nZp2jnKz3L65T5LdQ== - /minimist/0.0.8: - dev: true - resolution: - integrity: sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0= /minimist/1.2.0: dev: true resolution: integrity: sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ= - /mkdirp/0.5.1: + /minimist/1.2.5: + dev: true + resolution: + integrity: sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== + /mkdirp/0.5.5: dependencies: - minimist: 0.0.8 + minimist: 1.2.5 dev: true hasBin: true resolution: - integrity: sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM= + integrity: sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ== /ms/2.0.0: dev: true resolution: @@ -3762,20 +2735,10 @@ packages: dev: true resolution: integrity: sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc= - /nice-try/1.0.5: - dev: true - resolution: - integrity: sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== - /node-releases/1.1.45: - dependencies: - semver: 6.3.0 - dev: true - resolution: - integrity: sha512-cXvGSfhITKI8qsV116u2FTzH5EWZJfgG7d4cpqwF8I8+1tWpD6AsvvGRKq2onR0DNj1jfqsjkXZsm14JMS7Cyg== /normalize-package-data/2.5.0: dependencies: - hosted-git-info: 2.8.5 - resolve: 1.14.2 + hosted-git-info: 2.8.8 + resolve: 1.17.0 semver: 5.7.1 validate-npm-package-license: 3.0.4 dev: true @@ -3793,26 +2756,20 @@ packages: node: '>=8' resolution: integrity: sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ== - /npm-run-path/2.0.2: + /npm-run-path/4.0.1: dependencies: - path-key: 2.0.1 + path-key: 3.1.1 dev: true engines: - node: '>=4' + node: '>=8' resolution: - integrity: sha1-NakjLfo11wZ7TLLd8jV7GHFTbF8= + integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw== /nth-check/1.0.2: dependencies: boolbase: 1.0.0 dev: true resolution: integrity: sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg== - /number-is-nan/1.0.1: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0= /nwmatcher/1.4.4: dev: true optional: true @@ -3823,81 +2780,36 @@ packages: optional: true resolution: integrity: sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ== - /object-assign/4.1.1: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= - /object-inspect/1.7.0: - dev: true - resolution: - integrity: sha512-a7pEHdh1xKIAgTySUGgLMx/xwDZskN1Ud6egYYN3EdRW4ZMPNEDUTF+hwy2LUC+Bl+SyLXANnwz/jyh/qutKUw== - /object-is/1.0.2: - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-Epah+btZd5wrrfjkJZq1AOB9O6OxUQto45hzFd7lXGrpHPGE0W1k+426yrZV+k6NJOzLNNW/nVsmZdIWsAqoOQ== - /object-keys/1.1.1: - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA== - /object.assign/4.1.0: - dependencies: - define-properties: 1.1.3 - function-bind: 1.1.1 - has-symbols: 1.0.1 - object-keys: 1.1.1 - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w== - /observable-to-promise/1.0.0: - dependencies: - is-observable: 2.0.0 - symbol-observable: 1.2.0 - dev: true - engines: - node: '>=8' - resolution: - integrity: sha512-cqnGUrNsE6vdVDTPAX9/WeVzwy/z37vdxupdQXU8vgTXRFH72KCZiZga8aca2ulRPIeem8W3vW9rQHBwfIl2WA== - /octree-helper/1.1.0_bc902020feb1935eeb21de33d862e386: + /octree-helper/1.1.6_8ca993b03224d609f7e1cb2dd634b0e9: dependencies: - sparse-octree: 6.0.1_af31dca752bc798787ace5c5a6264f3c - three: 0.112.1 + sparse-octree: 6.0.2_440ab14d8e4fcccd43d423c37cd8ed08 + three: 0.119.1 dev: true peerDependencies: iterator-result: '*' math-ds: '*' - three: '>= 0.110.0 < 0.113.0' + three: '>= 0.110.0 < 0.119.0' resolution: - integrity: sha512-ZjC8UV6CAatMNVAiLxJzUpeCXg7ITTJ9vEQh76+eupb3sxrV+ciBoh+wZVqEXUKjjxXMuJTaOUY6Rdkhem0B8w== + integrity: sha512-pkSmoSEVkMybFlniQZyFexgxFy1Tv9UPJeoPXgkadwjMXo8WDdUwPf/SgX1G/yLCt5dnNv0V1TG/bVuaTyWvpQ== /once/1.4.0: dependencies: wrappy: 1.0.2 dev: true resolution: integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E= - /onetime/2.0.1: - dependencies: - mimic-fn: 1.2.0 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ= - /onetime/5.1.0: + /onetime/5.1.2: dependencies: mimic-fn: 2.1.0 dev: true engines: node: '>=6' resolution: - integrity: sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q== + integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg== + /opener/1.5.1: + dev: true + hasBin: true + resolution: + integrity: sha512-goYSy5c2UXE4Ra1xixabeVh1guIX/ZV/YokJksb6q2lubWu6UbvPQ20p542/sFIll1nl8JnCyK9oBaOcCWXwvA== /optionator/0.8.3: dependencies: deep-is: 0.1.3 @@ -3909,66 +2821,60 @@ packages: dev: true engines: node: '>= 0.8.0' + optional: true resolution: integrity: sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA== - /ora/3.4.0: + /optionator/0.9.1: dependencies: - chalk: 2.4.2 - cli-cursor: 2.1.0 - cli-spinners: 2.2.0 - log-symbols: 2.2.0 - strip-ansi: 5.2.0 - wcwidth: 1.0.1 + deep-is: 0.1.3 + fast-levenshtein: 2.0.6 + levn: 0.4.1 + prelude-ls: 1.2.1 + type-check: 0.4.0 + word-wrap: 1.2.3 dev: true engines: - node: '>=6' + node: '>= 0.8.0' resolution: - integrity: sha512-eNwHudNbO1folBP3JsZ19v9azXWtQZjICdr3Q0TDPIaeBQ3mXLrh54wM+er0+hSp+dWKf+Z8KM58CYzEyIYxYg== - /os-tmpdir/1.0.2: + integrity: sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw== + /ora/4.1.1: + dependencies: + chalk: 3.0.0 + cli-cursor: 3.1.0 + cli-spinners: 2.4.0 + is-interactive: 1.0.0 + log-symbols: 3.0.0 + mute-stream: 0.0.8 + strip-ansi: 6.0.0 + wcwidth: 1.0.1 dev: true engines: - node: '>=0.10.0' + node: '>=8' resolution: - integrity: sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= + integrity: sha512-sjYP8QyVWBpBZWD6Vr1M/KwknSw6kJOz41tvGMlwWeClHBtYKTbHMki1PsLZnxKpXMPbTKv9b3pjQu3REib96A== /p-cancelable/1.1.0: dev: true engines: node: '>=6' resolution: integrity: sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw== - /p-finally/1.0.0: - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4= - /p-limit/1.3.0: - dependencies: - p-try: 1.0.0 + /p-defer/1.0.0: dev: true engines: node: '>=4' resolution: - integrity: sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q== - /p-limit/2.2.2: + integrity: sha1-n26xgvbJqozXQwBKfU+WsZaw+ww= + /p-limit/2.3.0: dependencies: p-try: 2.2.0 dev: true engines: node: '>=6' resolution: - integrity: sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ== - /p-locate/2.0.0: - dependencies: - p-limit: 1.3.0 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-IKAQOyIqcMj9OcwuWAaA893l7EM= + integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w== /p-locate/3.0.0: dependencies: - p-limit: 2.2.2 + p-limit: 2.3.0 dev: true engines: node: '>=6' @@ -3976,45 +2882,38 @@ packages: integrity: sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ== /p-locate/4.1.0: dependencies: - p-limit: 2.2.2 + p-limit: 2.3.0 dev: true engines: node: '>=8' resolution: integrity: sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A== - /p-map/2.1.0: + /p-map/3.0.0: + dependencies: + aggregate-error: 3.0.1 dev: true engines: - node: '>=6' + node: '>=8' resolution: - integrity: sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw== - /p-try/1.0.0: + integrity: sha512-d3qXVTF/s+W+CdJ5A29wywV2n8CQQYahlgz2bFiA+4eVNJbHJodPZ+/gXwPGh0bOqA+j8S+6+ckmvLGPk1QpxQ== + /p-map/4.0.0: + dependencies: + aggregate-error: 3.0.1 dev: true engines: - node: '>=4' + node: '>=10' resolution: - integrity: sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M= + integrity: sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ== /p-try/2.2.0: dev: true engines: node: '>=6' resolution: integrity: sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ== - /package-hash/4.0.0: - dependencies: - graceful-fs: 4.2.3 - hasha: 5.1.0 - lodash.flattendeep: 4.4.0 - release-zalgo: 1.0.0 - dev: true - engines: - node: '>=8' - resolution: - integrity: sha512-whdkPIooSu/bASggZ96BWVvZTRMOFxnyUG5PnTSGKoJE2gd5mbVNmR2Nj20QFzxYYgAXpoqC+AiXzl+UMRh7zQ== /package-json/6.5.0: dependencies: got: 9.6.0 - registry-auth-token: 4.1.0 + registry-auth-token: 4.2.0 registry-url: 5.1.0 semver: 6.3.0 dev: true @@ -4039,6 +2938,17 @@ packages: node: '>=4' resolution: integrity: sha1-vjX1Qlvh9/bHRxhPmKeIy5lHfuA= + /parse-json/5.0.1: + dependencies: + '@babel/code-frame': 7.10.4 + error-ex: 1.3.2 + json-parse-better-errors: 1.0.2 + lines-and-columns: 1.1.6 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-ztoZ4/DYeXQq4E21v169sC8qWINGpcosGv9XhTDvg9/hWvx/zrFkc9BiWxR58OJLHGk28j5BL0SDLeV2WmFZlQ== /parse-ms/2.1.0: dev: true engines: @@ -4052,7 +2962,7 @@ packages: integrity: sha1-m387DeMr543CQBsXVzzK8Pb1nZQ= /parse5/3.0.3: dependencies: - '@types/node': 13.1.8 + '@types/node': 14.6.0 dev: true resolution: integrity: sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA== @@ -4074,16 +2984,6 @@ packages: node: '>=0.10.0' resolution: integrity: sha1-F0uSaHNVNP+8es5r9TpanhtcX18= - /path-is-inside/1.0.2: - dev: true - resolution: - integrity: sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM= - /path-key/2.0.1: - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A= /path-key/3.1.1: dev: true engines: @@ -4093,15 +2993,7 @@ packages: /path-parse/1.0.6: dev: true resolution: - integrity: sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== - /path-type/3.0.0: - dependencies: - pify: 3.0.0 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg== + integrity: sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== /path-type/4.0.0: dev: true engines: @@ -4113,18 +3005,12 @@ packages: optional: true resolution: integrity: sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= - /picomatch/2.2.1: + /picomatch/2.2.2: dev: true engines: node: '>=8.6' resolution: - integrity: sha512-ISBaA8xQNmwELC7eOjqFKMESB2VIqt4PPDD0nsS95b/9dZXvVKOlz9keMSnoGGKcOHXfTvDD6WMaRoSc9UuhRA== - /pify/2.3.0: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-7RQaasBDqEnqWISY59yosVMw6Qw= + integrity: sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg== /pify/3.0.0: dev: true engines: @@ -4137,20 +3023,6 @@ packages: node: '>=6' resolution: integrity: sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g== - /pinkie-promise/2.0.1: - dependencies: - pinkie: 2.0.4 - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-ITXW36ejWMBprJsXh3YogihFD/o= - /pinkie/2.0.4: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-clVrgM+g1IqXToDnckjoDtT3+HA= /pkg-conf/3.1.0: dependencies: find-up: 3.0.0 @@ -4168,55 +3040,62 @@ packages: node: '>=8' resolution: integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ== - /plur/3.1.1: + /plur/4.0.0: dependencies: - irregular-plurals: 2.0.0 + irregular-plurals: 3.2.0 dev: true engines: - node: '>=6' + node: '>=10' + resolution: + integrity: sha512-4UGewrYgqDFw9vV6zNV+ADmPAUAfJPKtGvb/VdpQAx25X5f3xXdGdyOEVFwkl8Hl/tl7+xbeHqSEM+D5/TirUg== + /portfinder/1.0.28: + dependencies: + async: 2.6.3 + debug: 3.2.6 + mkdirp: 0.5.5 + dev: true + engines: + node: '>= 0.12.0' resolution: - integrity: sha512-t1Ax8KUvV3FFII8ltczPn2tJdjqbd1sIzu6t4JL7nQ3EyeL/lTrj5PWKb06ic5/6XYDr65rQ4uzQEGN70/6X5w== + integrity: sha512-Se+2isanIcEqf2XMHjyUKskczxbPH7dQnlMjXX6+dybayyHvAf/TCgyMRlzf/B6QDhAEFOGes0pzRo3by4AbMA== /prelude-ls/1.1.2: dev: true engines: node: '>= 0.8.0' + optional: true resolution: integrity: sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= + /prelude-ls/1.2.1: + dev: true + engines: + node: '>= 0.8.0' + resolution: + integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g== /prepend-http/2.0.0: dev: true engines: node: '>=4' resolution: integrity: sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc= - /pretty-ms/5.1.0: + /pretty-ms/7.0.0: dependencies: parse-ms: 2.1.0 dev: true engines: - node: '>=8' - resolution: - integrity: sha512-4gaK1skD2gwscCfkswYQRmddUb2GJZtzDGRjHWadVHtK/DIKFufa12MvES6/xu1tVbUYeia5bmLcwJtZJQUqnw== - /private/0.1.8: - dev: true - engines: - node: '>= 0.6' + node: '>=10' resolution: - integrity: sha512-VvivMrbvd2nKkiG38qjULzlc+4Vx4wm/whI9pQD35YrARNnhxeiRktSOhSukRLFNlzg6Br/cJPet5J/u19r/mg== + integrity: sha512-J3aPWiC5e9ZeZFuSeBraGxSkGMOvulSWsxDByOcbD1Pr75YL3LSNIKIb52WXbCLE1sS5s4inBBbryjF4Y05Ceg== /progress/2.0.3: dev: true engines: node: '>=0.4.0' resolution: integrity: sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA== - /pseudomap/1.0.2: - dev: true - resolution: - integrity: sha1-8FKijacOYYkX7wqKw0wa5aaChrM= - /psl/1.7.0: + /psl/1.8.0: dev: true optional: true resolution: - integrity: sha512-5NsSEDv8zY70ScRnOTn7bK7eanl2MvFrOrS/R6x+dBt5g1ghnj9Zv90kO8GwT8gxcu2ANyFprnFYB85IogIJOQ== + integrity: sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ== /pump/3.0.0: dependencies: end-of-stream: 1.4.4 @@ -4224,17 +3103,20 @@ packages: dev: true resolution: integrity: sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww== - /punycode/1.4.1: - dev: true - optional: true - resolution: - integrity: sha1-wNWmOycYgArY4esPpSachN1BhF4= /punycode/2.1.1: dev: true engines: node: '>=6' resolution: integrity: sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== + /pupa/2.0.1: + dependencies: + escape-goat: 2.1.1 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-hEJH0s8PXLY/cdXh66tNEQGndDrIKNqNC5xmrysZy3i5C3oEoLna7YAOad+7u125+zH1HNXUmGEkrhb3c2VriA== /qs/6.5.2: dev: true engines: @@ -4242,41 +3124,49 @@ packages: optional: true resolution: integrity: sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA== - /quick-lru/1.1.0: + /qs/6.9.4: dev: true engines: - node: '>=4' + node: '>=0.6' + resolution: + integrity: sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ== + /randombytes/2.1.0: + dependencies: + safe-buffer: 5.2.1 + dev: true resolution: - integrity: sha1-Q2CxfGETatOAeDl/8RQW4Ybc+7g= + integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ== /rc/1.2.8: dependencies: deep-extend: 0.6.0 ini: 1.3.5 - minimist: 1.2.0 + minimist: 1.2.5 strip-json-comments: 2.0.1 dev: true hasBin: true resolution: integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw== - /read-pkg-up/3.0.0: + /read-pkg/4.0.1: dependencies: - find-up: 2.1.0 - read-pkg: 3.0.0 + normalize-package-data: 2.5.0 + parse-json: 4.0.0 + pify: 3.0.0 dev: true engines: - node: '>=4' + node: '>=6' resolution: - integrity: sha1-PtSWaF26D4/hGNBpHcUfSh/5bwc= - /read-pkg/3.0.0: + integrity: sha1-ljYlN48+HE1IyFhytabsfV0JMjc= + /read-pkg/5.2.0: dependencies: - load-json-file: 4.0.0 + '@types/normalize-package-data': 2.4.0 normalize-package-data: 2.5.0 - path-type: 3.0.0 + parse-json: 5.0.1 + type-fest: 0.6.0 dev: true engines: - node: '>=4' + node: '>=8' resolution: - integrity: sha1-nLxoaXj+5l0WwA4rGcI3/Pbjg4k= + integrity: sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg== /readable-stream/1.1.14: dependencies: core-util-is: 1.0.2 @@ -4286,7 +3176,7 @@ packages: dev: true resolution: integrity: sha1-fPTFTvZI44EwhMY23SB54WbAgdk= - /readable-stream/3.5.0: + /readable-stream/3.6.0: dependencies: inherits: 2.0.4 string_decoder: 1.3.0 @@ -4295,83 +3185,58 @@ packages: engines: node: '>= 6' resolution: - integrity: sha512-gSz026xs2LfxBPudDuI41V1lka8cxg64E66SGe78zJlsUofOg/yqwezdIcdfwik6B4h8LFmWPA9ef9X3FiNFLA== - /readdirp/3.3.0: + integrity: sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== + /readdirp/3.4.0: dependencies: - picomatch: 2.2.1 + picomatch: 2.2.2 dev: true engines: node: '>=8.10.0' resolution: - integrity: sha512-zz0pAkSPOXXm1viEwygWIPSPkcBYjW1xU5j/JBh5t9bGCJwa6f9+BJa6VaB2g+b55yVrmXzqkyLf4xaWYM0IkQ== - /redent/2.0.0: - dependencies: - indent-string: 3.2.0 - strip-indent: 2.0.0 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-wbIAe0LVfrE4kHmzyDM2OdXhzKo= - /regenerate-unicode-properties/8.1.0: + integrity: sha512-0xe001vZBnJEK+uKcj8qOhyAKPzIT+gStxWr3LCB0DwcXR5NZJ3IaC+yGnHCYzB/S7ov3m3EEbZI2zeNvX+hGQ== + /regenerate-unicode-properties/8.2.0: dependencies: - regenerate: 1.4.0 + regenerate: 1.4.1 dev: true engines: node: '>=4' resolution: - integrity: sha512-LGZzkgtLY79GeXLm8Dp0BVLdQlWICzBnJz/ipWUgo59qBaZ+BHtq51P2q1uVZlppMuUAT37SDk39qUbjTWB7bA== - /regenerate/1.4.0: + integrity: sha512-F9DjY1vKLo/tPePDycuH3dn9H1OTPIkVD9Kz4LODu+F2C75mgjAJ7x/gwy6ZcSNRAAkhNlJSOHRe8k3p+K9WhA== + /regenerate/1.4.1: dev: true resolution: - integrity: sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg== + integrity: sha512-j2+C8+NtXQgEKWk49MMP5P/u2GhnahTtVkRIHr5R5lVRlbKvmQ+oS+A5aLKWp2ma5VkT8sh6v+v4hbH0YHR66A== /regenerator-runtime/0.11.1: dev: true resolution: integrity: sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg== - /regenerator-transform/0.14.1: - dependencies: - private: 0.1.8 - dev: true - resolution: - integrity: sha512-flVuee02C3FKRISbxhXl9mGzdbWUVHubl1SMaknjxkFB1/iqpJhArQUvRxOOPEc/9tAiX0BaQ28FJH10E4isSQ== - /regexp.prototype.flags/1.3.0: - dependencies: - define-properties: 1.1.3 - es-abstract: 1.17.2 + /regexpp/3.1.0: dev: true engines: - node: '>= 0.4' - resolution: - integrity: sha512-2+Q0C5g951OlYlJz6yu5/M33IcsESLlLfsyIaLJaG4FA2r4yP8MvVMJUUP/fVBkSpbbbZlS5gynbEWLipiiXiQ== - /regexpp/2.0.1: - dev: true - engines: - node: '>=6.5.0' + node: '>=8' resolution: - integrity: sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw== - /regexpu-core/4.6.0: + integrity: sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q== + /regexpu-core/4.5.4: dependencies: - regenerate: 1.4.0 - regenerate-unicode-properties: 8.1.0 - regjsgen: 0.5.1 - regjsparser: 0.6.2 + regenerate: 1.4.1 + regenerate-unicode-properties: 8.2.0 + regjsgen: 0.5.2 + regjsparser: 0.6.4 unicode-match-property-ecmascript: 1.0.4 - unicode-match-property-value-ecmascript: 1.1.0 + unicode-match-property-value-ecmascript: 1.2.0 dev: true engines: node: '>=4' resolution: - integrity: sha512-YlVaefl8P5BnFYOITTNzDvan1ulLOiXJzCNZxduTIosN17b87h3bvG9yHMoHaRuo88H4mQ06Aodj5VtYGGGiTg== - /registry-auth-token/4.1.0: + integrity: sha512-BtizvGtFQKGPUcTy56o3nk1bGRp4SZOTYrDtGNlqCQufptV5IkkLN6Emw+yunAJjzf+C9FQFtvq7IoA3+oMYHQ== + /registry-auth-token/4.2.0: dependencies: rc: 1.2.8 - safe-buffer: 5.2.0 dev: true engines: node: '>=6.0.0' resolution: - integrity: sha512-7uxS951DeOBOwsv8deX+l7HcjY2VZxaOgHtM6RKzg3HhpE+bJ0O7VbuMJLosC1T5WSFpHm0DuFIbqUl43jHpsA== + integrity: sha512-P+lWzPrsgfN+UEpDS3U8AQKg/UjZX6mQSJueZj3EK+vNESoqBSpBUD3gmu4sF9lOsjXWjF11dQKUqemf3veq1w== /registry-url/5.1.0: dependencies: rc: 1.2.8 @@ -4380,28 +3245,20 @@ packages: node: '>=8' resolution: integrity: sha512-8acYXXTI0AkQv6RAOjE3vOaIXZkT9wo4LOFbBKYQEEnnMNBpKqdUrI6S4NT0KPIo/WVvJ5tE/X5LF/TQUf0ekw== - /regjsgen/0.5.1: + /regjsgen/0.5.2: dev: true resolution: - integrity: sha512-5qxzGZjDs9w4tzT3TPhCJqWdCc3RLYwy9J2NB0nm5Lz+S273lvWcpjaTGHsT1dc6Hhfq41uSEOw8wBmxrKOuyg== - /regjsparser/0.6.2: + integrity: sha512-OFFT3MfrH90xIW8OOSyUrk6QHD5E9JOTeGodiJeBS3J6IwlgzJMNE/1bZklWz5oTg+9dCMyEetclvCVXOPoN3A== + /regjsparser/0.6.4: dependencies: jsesc: 0.5.0 dev: true hasBin: true resolution: - integrity: sha512-E9ghzUtoLwDekPT0DYCp+c4h+bvuUpe6rRHCTYn6eGoqj1LgKXxT6I0Il4WbjhQkOghzi/V+y03bPKvbllL93Q== - /release-zalgo/1.0.0: - dependencies: - es6-error: 4.1.1 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-CXALflB0Mpc5Mw5TXFqQ+2eFFzA= + integrity: sha512-64O87/dPDgfk8/RQqC4gkZoGyyWFIEUTTh80CU6CWuK5vkCGyekIx+oKcEIYtP/RAxSQltCZHCNu/mdd7fqlJw== /repeating/1.1.3: dependencies: - is-finite: 1.0.2 + is-finite: 1.1.0 dev: true engines: node: '>=0.10.0' @@ -4410,46 +3267,55 @@ packages: integrity: sha1-PUEUIYh3U3SU+X93+Xhfq4EPpKw= /repeating/2.0.1: dependencies: - is-finite: 1.0.2 + is-finite: 1.1.0 dev: true engines: node: '>=0.10.0' resolution: integrity: sha1-UhTFOpJtNVJwdSf7q0FdvAjQbdo= - /request/2.88.0: + /request/2.88.2: dependencies: aws-sign2: 0.7.0 - aws4: 1.9.1 + aws4: 1.10.1 caseless: 0.12.0 combined-stream: 1.0.8 extend: 3.0.2 forever-agent: 0.6.1 form-data: 2.3.3 - har-validator: 5.1.3 + har-validator: 5.1.5 http-signature: 1.2.0 is-typedarray: 1.0.0 isstream: 0.1.2 json-stringify-safe: 5.0.1 - mime-types: 2.1.26 + mime-types: 2.1.27 oauth-sign: 0.9.0 performance-now: 2.1.0 qs: 6.5.2 - safe-buffer: 5.2.0 - tough-cookie: 2.4.3 + safe-buffer: 5.2.1 + tough-cookie: 2.5.0 tunnel-agent: 0.6.0 uuid: 3.4.0 + deprecated: 'request has been deprecated, see https://github.com/request/request/issues/3142' dev: true engines: - node: '>= 4' + node: '>= 6' optional: true resolution: - integrity: sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg== - /require-precompiled/0.1.0: + integrity: sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw== + /require-directory/2.1.1: dev: true engines: node: '>=0.10.0' resolution: - integrity: sha1-WhtS63Dr7UPrmC6XTIWrWVceVvo= + integrity: sha1-jGStX9MNqxyXbiNE/+f3kqam30I= + /require-main-filename/2.0.0: + dev: true + resolution: + integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== + /requires-port/1.0.0: + dev: true + resolution: + integrity: sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= /resolve-cwd/3.0.0: dependencies: resolve-from: 5.0.0 @@ -4470,31 +3336,22 @@ packages: node: '>=8' resolution: integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== - /resolve/1.14.2: + /resolve/1.17.0: dependencies: path-parse: 1.0.6 dev: true resolution: - integrity: sha512-EjlOBLBO1kxsUxsKjLt7TAECyKW6fOh1VRkykQkKGzcBbjjPIxBqGh0jf7GJ3k/f5mxMqW3htMD3WdTUVtW8HQ== + integrity: sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w== /responselike/1.0.2: dependencies: lowercase-keys: 1.0.1 dev: true resolution: integrity: sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec= - /restore-cursor/2.0.0: - dependencies: - onetime: 2.0.1 - signal-exit: 3.0.2 - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-n37ih/gv0ybU/RYpI9YhKe7g368= /restore-cursor/3.1.0: dependencies: - onetime: 5.1.0 - signal-exit: 3.0.2 + onetime: 5.1.2 + signal-exit: 3.0.3 dev: true engines: node: '>=8' @@ -4514,90 +3371,57 @@ packages: hasBin: true resolution: integrity: sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA== - /rimraf/2.7.1: - dependencies: - glob: 7.1.6 - dev: true - hasBin: true - resolution: - integrity: sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w== - /rimraf/3.0.0: + /rimraf/3.0.2: dependencies: glob: 7.1.6 dev: true hasBin: true resolution: - integrity: sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg== - /rollup-plugin-babel/4.3.3_@babel+core@7.8.3+rollup@1.29.0: - dependencies: - '@babel/core': 7.8.3 - '@babel/helper-module-imports': 7.8.3 - rollup: 1.29.0 - rollup-pluginutils: 2.8.2 - dev: true - peerDependencies: - '@babel/core': 7 || ^7.0.0-rc.2 - rollup: '>=0.60.0 <2' - resolution: - integrity: sha512-tKzWOCmIJD/6aKNz0H1GMM+lW1q9KyFubbWzGiOG540zxPPifnEAHTZwjo0g991Y+DyOZcLqBgqOdqazYE5fkw== - /rollup-plugin-terser/5.2.0_rollup@1.29.0: + integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA== + /rollup-plugin-terser/7.0.0_rollup@2.26.3: dependencies: - '@babel/code-frame': 7.8.3 - jest-worker: 24.9.0 - rollup: 1.29.0 - rollup-pluginutils: 2.8.2 - serialize-javascript: 2.1.2 - terser: 4.6.3 + '@babel/code-frame': 7.10.4 + jest-worker: 26.3.0 + rollup: 2.26.3 + serialize-javascript: 4.0.0 + terser: 5.2.0 dev: true peerDependencies: - rollup: '>=0.66.0 <2' - resolution: - integrity: sha512-jQI+nYhtDBc9HFRBz8iGttQg7li9klmzR62RG2W2nN6hJ/FI2K2ItYQ7kJ7/zn+vs+BP1AEccmVRjRN989I+Nw== - /rollup-pluginutils/2.8.2: - dependencies: - estree-walker: 0.6.1 - dev: true - resolution: - integrity: sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ== - /rollup/1.29.0: - dependencies: - '@types/estree': 0.0.42 - '@types/node': 13.1.8 - acorn: 7.1.0 - dev: true - hasBin: true + rollup: ^2.0.0 resolution: - integrity: sha512-V63Iz0dSdI5qPPN5HmCN6OBRzBFhMqNWcvwgq863JtSCTU6Vdvqq6S2fYle/dSCyoPrBkIP3EIr1RVs3HTRqqg== - /run-async/2.3.0: - dependencies: - is-promise: 2.1.0 + integrity: sha512-p/N3lLiFusCjYTLfVkoaiRTOGr5AESEaljMPH12MhOtoMkmTBhIAfuadrcWy4am1U0vU4WTxO9fi0K09O4CboQ== + /rollup/2.26.3: dev: true engines: - node: '>=0.12.0' + node: '>=10.0.0' + hasBin: true + optionalDependencies: + fsevents: 2.1.3 resolution: - integrity: sha1-A3GrSuC91yDUFm19/aZP96RFpsA= + integrity: sha512-Mlt39/kL2rA9egcbQbaZV1SNVplGqYYhDDMcGgHPPE0tvM3R4GrB+IEdYy2QtTrdzMQx57ZcqDFf/KWWm8F+uw== /run-parallel/1.1.9: dev: true resolution: integrity: sha512-DEqnSRTDw/Tc3FXf49zedI638Z9onwUotBMiUFKmrO2sdFKIbXamXGQ3Axd4qgphxKB4kw/qP1w5kTxnfU1B9Q== - /rxjs/6.5.4: + /rxjs/6.6.2: dependencies: - tslib: 1.10.0 + tslib: 1.13.0 dev: true engines: npm: '>=2.0.0' resolution: - integrity: sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q== + integrity: sha512-BHdBMVoWC2sL26w//BCu3YzKT4s2jip/WhwsGEDmeKYBhKDZeYezVUnHatYB7L85v5xs0BAQmg6BEYJEKxBabg== /safe-buffer/5.1.2: dev: true resolution: integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== - /safe-buffer/5.2.0: + /safe-buffer/5.2.1: dev: true resolution: - integrity: sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg== + integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== /safer-buffer/2.1.2: dev: true + optional: true resolution: integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg== /sax/1.2.4: @@ -4605,14 +3429,18 @@ packages: optional: true resolution: integrity: sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== - /semver-diff/2.1.0: + /secure-compare/3.0.1: + dev: true + resolution: + integrity: sha1-8aAymzCLIh+uN7mXTz1XjQypmeM= + /semver-diff/3.1.1: dependencies: - semver: 5.7.1 + semver: 6.3.0 dev: true engines: - node: '>=0.10.0' + node: '>=8' resolution: - integrity: sha1-S7uEN8jTfksM8aaP1ybsbWRdbTY= + integrity: sha512-GX0Ix/CJcHyB8c4ykpHGIAvLyOwOobtM/8d+TQkAd81/bEjgPHrfba41Vpesr7jX/t8Uh+R3EX9eAS5be+jQYg== /semver/5.7.1: dev: true hasBin: true @@ -4623,29 +3451,29 @@ packages: hasBin: true resolution: integrity: sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== - /semver/7.0.0: + /semver/7.3.2: dev: true + engines: + node: '>=10' hasBin: true resolution: - integrity: sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A== + integrity: sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ== /serialize-error/2.1.0: dev: true engines: node: '>=0.10.0' resolution: integrity: sha1-ULZ51WNc34Rme9yOWa9OW4HV9go= - /serialize-javascript/2.1.2: + /serialize-javascript/4.0.0: + dependencies: + randombytes: 2.1.0 dev: true resolution: - integrity: sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ== - /shebang-command/1.2.0: - dependencies: - shebang-regex: 1.0.0 + integrity: sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw== + /set-blocking/2.0.0: dev: true - engines: - node: '>=0.10.0' resolution: - integrity: sha1-RKrGW2lbAzmJaMOfNj/uXer98eo= + integrity: sha1-BF+XgtARrppoA93TgrJDkrPYkPc= /shebang-command/2.0.0: dependencies: shebang-regex: 3.0.0 @@ -4654,22 +3482,16 @@ packages: node: '>=8' resolution: integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA== - /shebang-regex/1.0.0: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM= /shebang-regex/3.0.0: dev: true engines: node: '>=8' resolution: integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== - /signal-exit/3.0.2: + /signal-exit/3.0.3: dev: true resolution: - integrity: sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0= + integrity: sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA== /slash/3.0.0: dev: true engines: @@ -4696,13 +3518,13 @@ packages: node: '>=8' resolution: integrity: sha512-pSyv7bSTC7ig9Dcgbw9AuRNUb5k5V6oDudjZoMBSr13qpLBG7tB+zgCkARjq7xIUgdz5P1Qe8u+rSGdouOOIyQ== - /source-map-support/0.5.16: + /source-map-support/0.5.19: dependencies: buffer-from: 1.1.1 source-map: 0.6.1 dev: true resolution: - integrity: sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ== + integrity: sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw== /source-map/0.5.7: dev: true engines: @@ -4715,34 +3537,50 @@ packages: node: '>=0.10.0' resolution: integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== - /sparse-octree/6.0.1_af31dca752bc798787ace5c5a6264f3c: + /sourcemap-codec/1.4.8: + dev: true + resolution: + integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== + /sparse-octree/6.0.2_440ab14d8e4fcccd43d423c37cd8ed08: dependencies: iterator-result: 1.0.0 - math-ds: 1.1.3 + math-ds: 1.2.1 dev: true peerDependencies: - iterator-result: '>= 0.0.0 < 1.0.0' + iterator-result: '>= 0.0.0 < 2.0.0' math-ds: '>= 1.0.0 < 2.0.0' resolution: - integrity: sha512-EkCpQ0bHT/uo5gPyMsv4OZ5LTls/G2v5DMJQ34XsnAt5ZBkZXBYaCjRIJ017DYskgmm0ZSMZxqu8MbvFHT7ThQ== - /spdx-correct/3.1.0: + integrity: sha512-v6gILd8hhlmMxL0YWnLVwhVJbgO/ls9BvV2uLKZ6ZinrwQ3GRksRNy+YSKkFhOAmt/fn9G8ie3BsKCutyGWJXg== + /spatial-controls/3.0.0_three@0.119.1: + dependencies: + three: 0.119.1 + dev: true + peerDependencies: + three: '>= 0.118.0 < 0.120.0' + resolution: + integrity: sha512-7WnMm0pup3GQA3RCXajlGltetMskzneKeQQXd6FwI6O+ET65uMaLMJbrLyKW8HaJ6eLDaCmUInNw4y4eZd6gQg== + /spawn-command/0.0.2-1: + dev: true + resolution: + integrity: sha1-YvXpRmmBwbeW3Fkpk34RycaSG9A= + /spdx-correct/3.1.1: dependencies: - spdx-expression-parse: 3.0.0 + spdx-expression-parse: 3.0.1 spdx-license-ids: 3.0.5 dev: true resolution: - integrity: sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q== - /spdx-exceptions/2.2.0: + integrity: sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w== + /spdx-exceptions/2.3.0: dev: true resolution: - integrity: sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA== - /spdx-expression-parse/3.0.0: + integrity: sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A== + /spdx-expression-parse/3.0.1: dependencies: - spdx-exceptions: 2.2.0 + spdx-exceptions: 2.3.0 spdx-license-ids: 3.0.5 dev: true resolution: - integrity: sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg== + integrity: sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q== /spdx-license-ids/3.0.5: dev: true resolution: @@ -4769,21 +3607,14 @@ packages: optional: true resolution: integrity: sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg== - /stack-utils/1.0.2: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha512-MTX+MeG5U994cazkjd/9KNAapsHnibjMLnfXodlkXw76JEea0UiNzrqidzo1emMwk7w5Qhc9jd4Bn9TBb1MFwA== - /string-width/2.1.1: + /stack-utils/2.0.2: dependencies: - is-fullwidth-code-point: 2.0.0 - strip-ansi: 4.0.0 + escape-string-regexp: 2.0.0 dev: true engines: - node: '>=4' + node: '>=10' resolution: - integrity: sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw== + integrity: sha512-0H7QK2ECz3fyZMzQ8rH0j2ykpfbnd20BFtfg/SqVC2+sCTtcw0aDTGB7dk+de4U4uUeuz6nOtJcrkFFLG1B0Rg== /string-width/3.1.0: dependencies: emoji-regex: 7.0.3 @@ -4804,31 +3635,13 @@ packages: node: '>=8' resolution: integrity: sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg== - /string.prototype.trimleft/2.1.1: - dependencies: - define-properties: 1.1.3 - function-bind: 1.1.1 - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-iu2AGd3PuP5Rp7x2kEZCrB2Nf41ehzh+goo8TV7z8/XDBbsvc6HQIlUl9RjkZ4oyrW1XM5UwlGl1oVEaDjg6Ag== - /string.prototype.trimright/2.1.1: - dependencies: - define-properties: 1.1.3 - function-bind: 1.1.1 - dev: true - engines: - node: '>= 0.4' - resolution: - integrity: sha512-qFvWL3/+QIgZXVmJBfpHmxLB7xsUXz6HsUmP8+5dRaC3Q7oKUv9Vo6aMCRZC1smrtyECFsIT30PqBJ1gTjAs+g== /string_decoder/0.10.31: dev: true resolution: integrity: sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ= /string_decoder/1.3.0: dependencies: - safe-buffer: 5.2.0 + safe-buffer: 5.2.1 dev: true resolution: integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== @@ -4864,49 +3677,35 @@ packages: node: '>=8' resolution: integrity: sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w== - /strip-bom-buf/2.0.0: - dependencies: - is-utf8: 0.2.1 - dev: true - engines: - node: '>=8' - resolution: - integrity: sha512-gLFNHucd6gzb8jMsl5QmZ3QgnUJmp7qn4uUSHNwEXumAp7YizoGYw19ZUVfuq4aBOQUtyn2k8X/CwzWB73W2lQ== /strip-bom/3.0.0: dev: true engines: node: '>=4' resolution: integrity: sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM= - /strip-eof/1.0.0: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha1-u0P/VZim6wXYm1n80SnJgzE2Br8= - /strip-indent/2.0.0: + /strip-final-newline/2.0.0: dev: true engines: - node: '>=4' + node: '>=6' resolution: - integrity: sha1-XvjbKV0B5u1sv3qrlpmNeCJSe2g= + integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA== /strip-json-comments/2.0.1: dev: true engines: node: '>=0.10.0' resolution: integrity: sha1-PFMZQukIwml8DsNEhYwobHygpgo= - /strip-json-comments/3.0.1: + /strip-json-comments/3.1.1: dev: true engines: node: '>=8' resolution: - integrity: sha512-VTyMAUfdm047mwKl+u79WIdrZxtFtn+nBxHeb844XBQ9uMNTuTHdx2hc5RiAJYqwTj3wc/xe5HLSdJSkJ+WfZw== + integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig== /supertap/1.0.0: dependencies: arrify: 1.0.1 indent-string: 3.2.0 - js-yaml: 3.13.1 + js-yaml: 3.14.0 serialize-error: 2.1.0 strip-ansi: 4.0.0 dev: true @@ -4944,25 +3743,15 @@ packages: node: '>=8' resolution: integrity: sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g== - /symbol-observable/1.2.0: - dev: true - engines: - node: '>=0.10.0' - resolution: - integrity: sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ== /symbol-tree/3.2.4: dev: true optional: true resolution: integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw== - /synthetic-event/1.0.0: - dev: true - resolution: - integrity: sha512-TTghS7tuf+7ypIFvRIIoCjI3+1e3pjDDroqDqj36aEVxbvfj7oT0JRoPtBnxQYE20dJV5bYPUDxprPKCuJhp5Q== /table/5.4.6: dependencies: - ajv: 6.11.0 - lodash: 4.17.15 + ajv: 6.12.4 + lodash: 4.17.20 slice-ansi: 2.1.0 string-width: 3.1.0 dev: true @@ -4978,75 +3767,59 @@ packages: dev: true resolution: integrity: sha1-KtNxaWKUmPylvIQkMJbTzeDsOjQ= - /term-size/1.2.0: - dependencies: - execa: 0.7.0 + /temp-dir/2.0.0: dev: true engines: - node: '>=4' + node: '>=8' + resolution: + integrity: sha512-aoBAniQmmwtcKp/7BzsH8Cxzv8OL736p7v1ihGb5e9DJ9kTwGWHrQrVB5+lfVDzfGrdRzXch+ig7LHaY1JTOrg== + /term-size/2.2.0: + dev: true + engines: + node: '>=8' resolution: - integrity: sha1-RYuDiH8oj8Vtb/+/rSYuJmOO+mk= - /terser/4.6.3: + integrity: sha512-a6sumDlzyHVJWb8+YofY4TW112G6p2FCPEAFk+59gIYHv3XHRhm9ltVQ9kli4hNWeQBwSpe8cRN25x0ROunMOw== + /terser/5.2.0: dependencies: commander: 2.20.3 source-map: 0.6.1 - source-map-support: 0.5.16 + source-map-support: 0.5.19 dev: true engines: node: '>=6.0.0' hasBin: true resolution: - integrity: sha512-Lw+ieAXmY69d09IIc/yqeBqXpEQIpDGZqT34ui1QWXIUpR2RjbqEkT8X7Lgex19hslSqcWM5iMN2kM11eMsESQ== + integrity: sha512-nZ9TWhBznZdlww3borgJyfQDrxzpgd0RlRNoxR63tMVry01lIH/zKQDTTiaWRMGowydfvSHMgyiGyn6A9PSkCQ== /text-table/0.2.0: dev: true resolution: integrity: sha1-f17oI66AUgfACvLfSoTsP8+lcLQ= - /three-demo/3.15.0_6274b0b1a501bff7e0ffa21e46b83b56: + /three-demo/4.0.1_dat.gui@0.7.7+three@0.119.1: dependencies: - dat.gui: 0.7.6 - synthetic-event: 1.0.0 - three: 0.112.1 + dat.gui: 0.7.7 + three: 0.119.1 dev: true peerDependencies: dat.gui: '>= 0.0.0 < 1.0.0' - synthetic-event: '>= 0.0.0 < 2.0.0' - three: '>= 0.89.0 < 0.113.0' - resolution: - integrity: sha512-fmZ10CPCDVrDqf8gUzDpUn6Byxc+CcLIl6nsFLvKXPiGInD1g1zzE45vAzdNBhcHQaLdcFOmsCbmd4eyBcolXQ== - /three/0.112.1: - dev: true + three: '>= 0.89.0 < 0.120.0' resolution: - integrity: sha512-8I0O74hiYtKl3LgDNcPJbBGOlpekbcJ6fJnImmW3mFdeUFJ2H9Y3/UuUSW2sBdjrIlCM0gvOkaTEFlofO900TQ== - /through/2.3.8: + integrity: sha512-V7O0ChulxeO7YybgF3C4Sp88GHMXbXo+Ojq1B8jA1NnGTVfmf9ghmFBUTfE1lmvdoaLl2bQRhRB1bS1WrHA0qw== + /three/0.119.1: dev: true resolution: - integrity: sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU= + integrity: sha512-GHyh/RiUfQ5VTiWIVRRTANYoXc1PFB1y+jDVRTb649nif1uX1F06PT1TKU3k2+F/MN4UJ3PWvQB53fY2OqKqKw== /time-zone/1.0.0: dev: true engines: node: '>=4' resolution: integrity: sha1-mcW/VZWJZq9tBtg73zgA3IL67F0= - /tmp/0.0.33: - dependencies: - os-tmpdir: 1.0.2 - dev: true - engines: - node: '>=0.6.0' - resolution: - integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== /to-fast-properties/1.0.3: dev: true engines: node: '>=0.10.0' resolution: integrity: sha1-uDVx+k2MJbguIxsG46MFXeTKGkc= - /to-fast-properties/2.0.0: - dev: true - engines: - node: '>=4' - resolution: - integrity: sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4= /to-readable-stream/1.0.0: dev: true engines: @@ -5061,19 +3834,9 @@ packages: node: '>=8.0' resolution: integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ== - /tough-cookie/2.4.3: - dependencies: - psl: 1.7.0 - punycode: 1.4.1 - dev: true - engines: - node: '>=0.8' - optional: true - resolution: - integrity: sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ== /tough-cookie/2.5.0: dependencies: - psl: 1.7.0 + psl: 1.8.0 punycode: 2.1.1 dev: true engines: @@ -5086,12 +3849,11 @@ packages: optional: true resolution: integrity: sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o= - /trim-newlines/2.0.0: + /tree-kill/1.2.2: dev: true - engines: - node: '>=4' + hasBin: true resolution: - integrity: sha1-tAPQuRvlDDMd/EuC7s6yLD3hbSA= + integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A== /trim-off-newlines/1.0.1: dev: true engines: @@ -5104,13 +3866,13 @@ packages: node: '>=0.10.0' resolution: integrity: sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM= - /tslib/1.10.0: + /tslib/1.13.0: dev: true resolution: - integrity: sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== + integrity: sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q== /tunnel-agent/0.6.0: dependencies: - safe-buffer: 5.2.0 + safe-buffer: 5.2.1 dev: true optional: true resolution: @@ -5126,14 +3888,29 @@ packages: dev: true engines: node: '>= 0.8.0' + optional: true resolution: integrity: sha1-WITKtRLPHTVeP7eE8wgEsrUg23I= + /type-check/0.4.0: + dependencies: + prelude-ls: 1.2.1 + dev: true + engines: + node: '>= 0.8.0' + resolution: + integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew== /type-fest/0.3.1: dev: true engines: node: '>=6' resolution: integrity: sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ== + /type-fest/0.6.0: + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg== /type-fest/0.8.1: dev: true engines: @@ -5146,10 +3923,6 @@ packages: dev: true resolution: integrity: sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q== - /uid2/0.0.3: - dev: true - resolution: - integrity: sha1-SDEm4Rd03y9xuLY53NeZw3YWK4I= /unicode-canonical-property-names-ecmascript/1.0.4: dev: true engines: @@ -5159,73 +3932,76 @@ packages: /unicode-match-property-ecmascript/1.0.4: dependencies: unicode-canonical-property-names-ecmascript: 1.0.4 - unicode-property-aliases-ecmascript: 1.0.5 + unicode-property-aliases-ecmascript: 1.1.0 dev: true engines: node: '>=4' resolution: integrity: sha512-L4Qoh15vTfntsn4P1zqnHulG0LdXgjSO035fEpdtp6YxXhMT51Q6vgM5lYdG/5X3MjS+k/Y9Xw4SFCY9IkR0rg== - /unicode-match-property-value-ecmascript/1.1.0: + /unicode-match-property-value-ecmascript/1.2.0: dev: true engines: node: '>=4' resolution: - integrity: sha512-hDTHvaBk3RmFzvSl0UVrUmC3PuW9wKVnpoUDYH0JDkSIovzw+J5viQmeYHxVSBptubnr7PbH2e0fnpDRQnQl5g== - /unicode-property-aliases-ecmascript/1.0.5: + integrity: sha512-wjuQHGQVofmSJv1uVISKLE5zO2rNGzM/KCYZch/QQvez7C1hUhBIuZ701fYXExuufJFMPhv2SyL8CyoIfMLbIQ== + /unicode-property-aliases-ecmascript/1.1.0: dev: true engines: node: '>=4' resolution: - integrity: sha512-L5RAqCfXqAwR3RriF8pM0lU0w4Ryf/GgzONwi6KnL1taJQa7x1TCxdJnILX59WIGOwR57IVxn7Nej0fz1Ny6fw== - /unique-string/1.0.0: + integrity: sha512-PqSoPh/pWetQ2phoj5RLiaqIk4kCNwoV3CI+LfGmWLKI3rE3kl1h59XpX2BjgDrmbxD9ARtQobPGU1SguCYuQg== + /union/0.5.0: dependencies: - crypto-random-string: 1.0.0 + qs: 6.9.4 dev: true engines: - node: '>=4' + node: '>= 0.8.0' resolution: - integrity: sha1-nhBXzKhRq7kzmPizOuGHuZyuwRo= - /unique-temp-dir/1.0.0: + integrity: sha512-N6uOhuW6zO95P3Mel2I2zMsbsanvvtgn6jVqJv4vbVcz/JN0OkL9suomjQGmWtxJQXOCqUJvquc1sMeNz/IwlA== + /unique-string/2.0.0: dependencies: - mkdirp: 0.5.1 - os-tmpdir: 1.0.2 - uid2: 0.0.3 + crypto-random-string: 2.0.0 dev: true engines: - node: '>=0.10.0' + node: '>=8' resolution: - integrity: sha1-bc6VsmgcoAPuv7MEpBX5y6vMU4U= + integrity: sha512-uNaeirEPvpZWSgzwsPGtU2zVSTrn/8L5q/IexZmH0eH6SA73CmAA5U4GwORTxQAZs95TAXLNqeLoPPNO5gZfWg== /universalify/0.1.2: dev: true engines: node: '>= 4.0.0' resolution: integrity: sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== - /update-notifier/3.0.1: + /update-notifier/4.1.1: dependencies: - boxen: 3.2.0 - chalk: 2.4.2 - configstore: 4.0.0 + boxen: 4.2.0 + chalk: 3.0.0 + configstore: 5.0.1 has-yarn: 2.1.0 import-lazy: 2.1.0 is-ci: 2.0.0 - is-installed-globally: 0.1.0 - is-npm: 3.0.0 + is-installed-globally: 0.3.2 + is-npm: 4.0.0 is-yarn-global: 0.3.0 latest-version: 5.1.0 - semver-diff: 2.1.0 - xdg-basedir: 3.0.0 + pupa: 2.0.1 + semver-diff: 3.1.1 + xdg-basedir: 4.0.0 dev: true engines: node: '>=8' resolution: - integrity: sha512-grrmrB6Zb8DUiyDIaeRTBCkgISYUgETNe7NglEbVsrLWXeESnlCSP50WfRSj/GmzMPl6Uchj24S/p80nP/ZQrQ== + integrity: sha512-9y+Kds0+LoLG6yN802wVXoIfxYEwh3FlZwzMwpCZp62S2i1/Jzeqb9Eeeju3NSHccGGasfGlK5/vEHbAifYRDg== /uri-js/4.2.2: dependencies: punycode: 2.1.1 dev: true resolution: integrity: sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ== + /url-join/2.0.5: + dev: true + resolution: + integrity: sha1-WvIvGMBSoACkjXuCxenC4v7tpyg= /url-parse-lax/3.0.0: dependencies: prepend-http: 2.0.0 @@ -5244,14 +4020,14 @@ packages: optional: true resolution: integrity: sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== - /v8-compile-cache/2.1.0: + /v8-compile-cache/2.1.1: dev: true resolution: - integrity: sha512-usZBT3PW+LOjM25wbqIlZwPeJV+3OSz3M1k1Ws8snlW39dZyYL9lOGC5FgPVHfk0jKmjiDV8Z0mIbVQPiwFs7g== + integrity: sha512-8OQ9CL+VWyt3JStj7HX7/ciTL2V3Rl1Wf5OL+SNTm0yK1KvtReVulksyeRnCANHHuUxHlQig+JJDlUhBt1NQDQ== /validate-npm-package-license/3.0.4: dependencies: - spdx-correct: 3.1.0 - spdx-expression-parse: 3.0.0 + spdx-correct: 3.1.1 + spdx-expression-parse: 3.0.1 dev: true resolution: integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew== @@ -5290,13 +4066,10 @@ packages: optional: true resolution: integrity: sha1-AImBEa9om7CXVBzVpFymyHmERb8= - /which/1.3.1: - dependencies: - isexe: 2.0.0 + /which-module/2.0.0: dev: true - hasBin: true resolution: - integrity: sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ== + integrity: sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho= /which/2.0.2: dependencies: isexe: 2.0.0 @@ -5306,96 +4079,146 @@ packages: hasBin: true resolution: integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== - /widest-line/2.0.1: + /widest-line/3.1.0: dependencies: - string-width: 2.1.1 + string-width: 4.2.0 dev: true engines: - node: '>=4' + node: '>=8' resolution: - integrity: sha512-Ba5m9/Fa4Xt9eb2ELXt77JxVDV8w7qQrH0zS/TWSJdLyAwQjWoOzpzj5lwVftDz6n/EOu3tNACS84v509qwnJA== + integrity: sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg== /word-wrap/1.2.3: dev: true engines: node: '>=0.10.0' resolution: integrity: sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== - /wrappy/1.0.2: + /wrap-ansi/5.1.0: + dependencies: + ansi-styles: 3.2.1 + string-width: 3.1.0 + strip-ansi: 5.2.0 dev: true + engines: + node: '>=6' resolution: - integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= - /write-file-atomic/2.4.3: + integrity: sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q== + /wrap-ansi/6.2.0: dependencies: - graceful-fs: 4.2.3 - imurmurhash: 0.1.4 - signal-exit: 3.0.2 + ansi-styles: 4.2.1 + string-width: 4.2.0 + strip-ansi: 6.0.0 + dev: true + engines: + node: '>=8' + resolution: + integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA== + /wrappy/1.0.2: dev: true resolution: - integrity: sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ== - /write-file-atomic/3.0.1: + integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= + /write-file-atomic/3.0.3: dependencies: imurmurhash: 0.1.4 is-typedarray: 1.0.0 - signal-exit: 3.0.2 + signal-exit: 3.0.3 typedarray-to-buffer: 3.1.5 dev: true resolution: - integrity: sha512-JPStrIyyVJ6oCSz/691fAjFtefZ6q+fP6tm+OS4Qw6o+TGQxNp1ziY2PgS+X/m0V8OWhZiO/m4xSj+Pr4RrZvw== + integrity: sha512-AvHcyZ5JnSfq3ioSyjrBkH9yW4m7Ayk8/9My/DD9onKeu/94fwrMocemO2QAJFAlnnDN+ZDS+ZjAR5ua1/PV/Q== /write/1.0.3: dependencies: - mkdirp: 0.5.1 + mkdirp: 0.5.5 dev: true engines: node: '>=4' resolution: integrity: sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig== - /xdg-basedir/3.0.0: + /xdg-basedir/4.0.0: dev: true engines: - node: '>=4' + node: '>=8' resolution: - integrity: sha1-SWsswQnsqNus/i3HK2A8F8WHCtQ= + integrity: sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q== /xml-name-validator/2.0.1: dev: true optional: true resolution: integrity: sha1-TYuPHszTQZqjYgYb7O9RXh5VljU= - /xtend/4.0.2: + /y18n/4.0.0: + dev: true + resolution: + integrity: sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w== + /yargs-parser/13.1.2: + dependencies: + camelcase: 5.3.1 + decamelize: 1.2.0 + dev: true + resolution: + integrity: sha512-3lbsNRf/j+A4QuSZfDRA7HRSfWrzO0YjqTJd5kjAq37Zep1CEgaYmrH9Q3GwPiB9cHyd1Y1UwggGhJGoxipbzg== + /yargs-parser/18.1.3: + dependencies: + camelcase: 5.3.1 + decamelize: 1.2.0 dev: true engines: - node: '>=0.4' + node: '>=6' resolution: - integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ== - /yallist/2.1.2: + integrity: sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ== + /yargs/13.3.2: + dependencies: + cliui: 5.0.0 + find-up: 3.0.0 + get-caller-file: 2.0.5 + require-directory: 2.1.1 + require-main-filename: 2.0.0 + set-blocking: 2.0.0 + string-width: 3.1.0 + which-module: 2.0.0 + y18n: 4.0.0 + yargs-parser: 13.1.2 dev: true resolution: - integrity: sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI= - /yargs-parser/10.1.0: + integrity: sha512-AX3Zw5iPruN5ie6xGRIDgqkT+ZhnRlZMLMHAs8tg7nRruy2Nb+i5o9bwghAogtM08q1dpr2LVoS8KSTMYpWXUw== + /yargs/15.4.1: dependencies: - camelcase: 4.1.0 + cliui: 6.0.0 + decamelize: 1.2.0 + find-up: 4.1.0 + get-caller-file: 2.0.5 + require-directory: 2.1.1 + require-main-filename: 2.0.0 + set-blocking: 2.0.0 + string-width: 4.2.0 + which-module: 2.0.0 + y18n: 4.0.0 + yargs-parser: 18.1.3 dev: true + engines: + node: '>=8' resolution: - integrity: sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ== + integrity: sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A== specifiers: - '@babel/core': 7.8.3 - '@babel/preset-env': 7.8.3 - '@rollup/plugin-node-resolve': 7.0.0 - ava: 2.4.0 - cross-env: 6.0.3 - dat.gui: 0.7.6 - delta-controls: 2.0.4 - esdoc: 1.1.0 - esdoc-importpath-plugin: 1.0.2 - esdoc-standard-plugin: 1.0.0 - eslint: 6.8.0 - eslint-config-delta: 1.0.1 - iterator-result: 1.0.0 - math-ds: 1.1.3 - octree-helper: 1.1.0 - rimraf: 3.0.0 - rollup: 1.29.0 - rollup-plugin-babel: 4.3.3 - rollup-plugin-terser: 5.2.0 - synthetic-event: 1.0.0 - three: 0.112.1 - three-demo: 3.15.0 + '@rollup/plugin-buble': 0.x.x + '@rollup/plugin-node-resolve': 9.x.x + ava: 3.x.x + concurrently: 5.x.x + cross-env: 7.x.x + dat.gui: 0.x.x + esdoc: 1.x.x + esdoc-importpath-plugin: 1.x.x + esdoc-standard-plugin: 1.x.x + eslint: 7.x.x + eslint-config-aether: 1.x.x + eslint-watch: 7.x.x + esm: 3.x.x + http-server: 0.x.x + iterator-result: 1.x.x + math-ds: 1.x.x + octree-helper: 1.x.x + rimraf: 3.x.x + rollup: 2.x.x + rollup-plugin-terser: 7.x.x + spatial-controls: 3.x.x + three: 0.x.x + three-demo: 4.x.x diff --git a/public/demo/index.js b/public/demo/index.js index 04f7c5f..af8e330 100644 --- a/public/demo/index.js +++ b/public/demo/index.js @@ -1,8051 +1,60877 @@ -(function (three) { - 'use strict'; - - function _typeof(obj) { - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; - }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; - } - - return _typeof(obj); - } - - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - } - - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - if (staticProps) _defineProperties(Constructor, staticProps); - return Constructor; - } - - function _inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function"); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - writable: true, - configurable: true - } - }); - if (superClass) _setPrototypeOf(subClass, superClass); - } - - function _getPrototypeOf(o) { - _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { - return o.__proto__ || Object.getPrototypeOf(o); - }; - return _getPrototypeOf(o); - } - - function _setPrototypeOf(o, p) { - _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { - o.__proto__ = p; - return o; - }; - - return _setPrototypeOf(o, p); - } - - function _assertThisInitialized(self) { - if (self === void 0) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return self; - } - - function _possibleConstructorReturn(self, call) { - if (call && (typeof call === "object" || typeof call === "function")) { - return call; - } - - return _assertThisInitialized(self); - } - - function _superPropBase(object, property) { - while (!Object.prototype.hasOwnProperty.call(object, property)) { - object = _getPrototypeOf(object); - if (object === null) break; - } - - return object; - } - - function _get(target, property, receiver) { - if (typeof Reflect !== "undefined" && Reflect.get) { - _get = Reflect.get; - } else { - _get = function _get(target, property, receiver) { - var base = _superPropBase(target, property); - - if (!base) return; - var desc = Object.getOwnPropertyDescriptor(base, property); - - if (desc.get) { - return desc.get.call(receiver); - } - - return desc.value; - }; - } - - return _get(target, property, receiver || target); - } - - function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); - } - - function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) { - for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; - - return arr2; - } - } - - function _iterableToArray(iter) { - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); - } - - function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance"); - } - - var Event = function Event(type) { - _classCallCheck(this, Event); - - this.type = type; - this.target = null; - }; - - var EventTarget = function () { - function EventTarget() { - _classCallCheck(this, EventTarget); - - this.listenerFunctions = new Map(); - this.listenerObjects = new Map(); - } - - _createClass(EventTarget, [{ - key: "addEventListener", - value: function addEventListener(type, listener) { - var m = typeof listener === "function" ? this.listenerFunctions : this.listenerObjects; - - if (m.has(type)) { - m.get(type).add(listener); - } else { - m.set(type, new Set([listener])); - } - } - }, { - key: "removeEventListener", - value: function removeEventListener(type, listener) { - var m = typeof listener === "function" ? this.listenerFunctions : this.listenerObjects; - - if (m.has(type)) { - var listeners = m.get(type); - listeners["delete"](listener); - - if (listeners.size === 0) { - m["delete"](type); - } - } - } - }, { - key: "dispatchEvent", - value: function dispatchEvent(event) { - var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this; - var listenerFunctions = target.listenerFunctions; - var listenerObjects = target.listenerObjects; - var listeners, listener; - event.target = target; - - if (listenerFunctions.has(event.type)) { - listeners = listenerFunctions.get(event.type); - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = listeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - listener = _step.value; - listener.call(target, event); - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator["return"] != null) { - _iterator["return"](); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - } - - if (listenerObjects.has(event.type)) { - listeners = listenerObjects.get(event.type); - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = listeners[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - listener = _step2.value; - listener.handleEvent(event); - } - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { - _iterator2["return"](); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - } - } - }]); - - return EventTarget; - }(); - - function ___$insertStyle(css) { - if (!css) { - return; - } - - if (typeof window === 'undefined') { - return; - } - - var style = document.createElement('style'); - style.setAttribute('type', 'text/css'); - style.innerHTML = css; - document.head.appendChild(style); - return css; - } - - function colorToString(color, forceCSSHex) { - var colorFormat = color.__state.conversionName.toString(); - - var r = Math.round(color.r); - var g = Math.round(color.g); - var b = Math.round(color.b); - var a = color.a; - var h = Math.round(color.h); - var s = color.s.toFixed(1); - var v = color.v.toFixed(1); - - if (forceCSSHex || colorFormat === 'THREE_CHAR_HEX' || colorFormat === 'SIX_CHAR_HEX') { - var str = color.hex.toString(16); - - while (str.length < 6) { - str = '0' + str; - } - - return '#' + str; - } else if (colorFormat === 'CSS_RGB') { - return 'rgb(' + r + ',' + g + ',' + b + ')'; - } else if (colorFormat === 'CSS_RGBA') { - return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')'; - } else if (colorFormat === 'HEX') { - return '0x' + color.hex.toString(16); - } else if (colorFormat === 'RGB_ARRAY') { - return '[' + r + ',' + g + ',' + b + ']'; - } else if (colorFormat === 'RGBA_ARRAY') { - return '[' + r + ',' + g + ',' + b + ',' + a + ']'; - } else if (colorFormat === 'RGB_OBJ') { - return '{r:' + r + ',g:' + g + ',b:' + b + '}'; - } else if (colorFormat === 'RGBA_OBJ') { - return '{r:' + r + ',g:' + g + ',b:' + b + ',a:' + a + '}'; - } else if (colorFormat === 'HSV_OBJ') { - return '{h:' + h + ',s:' + s + ',v:' + v + '}'; - } else if (colorFormat === 'HSVA_OBJ') { - return '{h:' + h + ',s:' + s + ',v:' + v + ',a:' + a + '}'; - } - - return 'unknown format'; - } - - var ARR_EACH = Array.prototype.forEach; - var ARR_SLICE = Array.prototype.slice; - var Common = { - BREAK: {}, - extend: function extend(target) { - this.each(ARR_SLICE.call(arguments, 1), function (obj) { - var keys = this.isObject(obj) ? Object.keys(obj) : []; - keys.forEach(function (key) { - if (!this.isUndefined(obj[key])) { - target[key] = obj[key]; - } - }.bind(this)); - }, this); - return target; - }, - defaults: function defaults(target) { - this.each(ARR_SLICE.call(arguments, 1), function (obj) { - var keys = this.isObject(obj) ? Object.keys(obj) : []; - keys.forEach(function (key) { - if (this.isUndefined(target[key])) { - target[key] = obj[key]; - } - }.bind(this)); - }, this); - return target; - }, - compose: function compose() { - var toCall = ARR_SLICE.call(arguments); - return function () { - var args = ARR_SLICE.call(arguments); - - for (var i = toCall.length - 1; i >= 0; i--) { - args = [toCall[i].apply(this, args)]; - } - - return args[0]; - }; - }, - each: function each(obj, itr, scope) { - if (!obj) { - return; - } - - if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) { - obj.forEach(itr, scope); - } else if (obj.length === obj.length + 0) { - var key = void 0; - var l = void 0; - - for (key = 0, l = obj.length; key < l; key++) { - if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) { - return; - } - } - } else { - for (var _key in obj) { - if (itr.call(scope, obj[_key], _key) === this.BREAK) { - return; - } - } - } - }, - defer: function defer(fnc) { - setTimeout(fnc, 0); - }, - debounce: function debounce(func, threshold, callImmediately) { - var timeout = void 0; - return function () { - var obj = this; - var args = arguments; - - function delayed() { - timeout = null; - if (!callImmediately) func.apply(obj, args); - } - - var callNow = callImmediately || !timeout; - clearTimeout(timeout); - timeout = setTimeout(delayed, threshold); - - if (callNow) { - func.apply(obj, args); - } - }; - }, - toArray: function toArray(obj) { - if (obj.toArray) return obj.toArray(); - return ARR_SLICE.call(obj); - }, - isUndefined: function isUndefined(obj) { - return obj === undefined; - }, - isNull: function isNull(obj) { - return obj === null; - }, - isNaN: function (_isNaN) { - function isNaN(_x) { - return _isNaN.apply(this, arguments); - } - - isNaN.toString = function () { - return _isNaN.toString(); - }; - - return isNaN; - }(function (obj) { - return isNaN(obj); - }), - isArray: Array.isArray || function (obj) { - return obj.constructor === Array; - }, - isObject: function isObject(obj) { - return obj === Object(obj); - }, - isNumber: function isNumber(obj) { - return obj === obj + 0; - }, - isString: function isString(obj) { - return obj === obj + ''; - }, - isBoolean: function isBoolean(obj) { - return obj === false || obj === true; - }, - isFunction: function isFunction(obj) { - return Object.prototype.toString.call(obj) === '[object Function]'; - } - }; - var INTERPRETATIONS = [{ - litmus: Common.isString, - conversions: { - THREE_CHAR_HEX: { - read: function read(original) { - var test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i); - - if (test === null) { - return false; - } - - return { - space: 'HEX', - hex: parseInt('0x' + test[1].toString() + test[1].toString() + test[2].toString() + test[2].toString() + test[3].toString() + test[3].toString(), 0) - }; - }, - write: colorToString - }, - SIX_CHAR_HEX: { - read: function read(original) { - var test = original.match(/^#([A-F0-9]{6})$/i); - - if (test === null) { - return false; - } - - return { - space: 'HEX', - hex: parseInt('0x' + test[1].toString(), 0) - }; - }, - write: colorToString - }, - CSS_RGB: { - read: function read(original) { - var test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/); - - if (test === null) { - return false; - } - - return { - space: 'RGB', - r: parseFloat(test[1]), - g: parseFloat(test[2]), - b: parseFloat(test[3]) - }; - }, - write: colorToString - }, - CSS_RGBA: { - read: function read(original) { - var test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/); - - if (test === null) { - return false; - } - - return { - space: 'RGB', - r: parseFloat(test[1]), - g: parseFloat(test[2]), - b: parseFloat(test[3]), - a: parseFloat(test[4]) - }; - }, - write: colorToString - } - } - }, { - litmus: Common.isNumber, - conversions: { - HEX: { - read: function read(original) { - return { - space: 'HEX', - hex: original, - conversionName: 'HEX' - }; - }, - write: function write(color) { - return color.hex; - } - } - } - }, { - litmus: Common.isArray, - conversions: { - RGB_ARRAY: { - read: function read(original) { - if (original.length !== 3) { - return false; - } - - return { - space: 'RGB', - r: original[0], - g: original[1], - b: original[2] - }; - }, - write: function write(color) { - return [color.r, color.g, color.b]; - } - }, - RGBA_ARRAY: { - read: function read(original) { - if (original.length !== 4) return false; - return { - space: 'RGB', - r: original[0], - g: original[1], - b: original[2], - a: original[3] - }; - }, - write: function write(color) { - return [color.r, color.g, color.b, color.a]; - } - } - } - }, { - litmus: Common.isObject, - conversions: { - RGBA_OBJ: { - read: function read(original) { - if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b) && Common.isNumber(original.a)) { - return { - space: 'RGB', - r: original.r, - g: original.g, - b: original.b, - a: original.a - }; - } - - return false; - }, - write: function write(color) { - return { - r: color.r, - g: color.g, - b: color.b, - a: color.a - }; - } - }, - RGB_OBJ: { - read: function read(original) { - if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b)) { - return { - space: 'RGB', - r: original.r, - g: original.g, - b: original.b - }; - } - - return false; - }, - write: function write(color) { - return { - r: color.r, - g: color.g, - b: color.b - }; - } - }, - HSVA_OBJ: { - read: function read(original) { - if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v) && Common.isNumber(original.a)) { - return { - space: 'HSV', - h: original.h, - s: original.s, - v: original.v, - a: original.a - }; - } - - return false; - }, - write: function write(color) { - return { - h: color.h, - s: color.s, - v: color.v, - a: color.a - }; - } - }, - HSV_OBJ: { - read: function read(original) { - if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v)) { - return { - space: 'HSV', - h: original.h, - s: original.s, - v: original.v - }; - } - - return false; - }, - write: function write(color) { - return { - h: color.h, - s: color.s, - v: color.v - }; - } - } - } - }]; - var result = void 0; - var toReturn = void 0; - - var interpret = function interpret() { - toReturn = false; - var original = arguments.length > 1 ? Common.toArray(arguments) : arguments[0]; - Common.each(INTERPRETATIONS, function (family) { - if (family.litmus(original)) { - Common.each(family.conversions, function (conversion, conversionName) { - result = conversion.read(original); - - if (toReturn === false && result !== false) { - toReturn = result; - result.conversionName = conversionName; - result.conversion = conversion; - return Common.BREAK; - } - }); - return Common.BREAK; - } - }); - return toReturn; - }; - - var tmpComponent = void 0; - var ColorMath = { - hsv_to_rgb: function hsv_to_rgb(h, s, v) { - var hi = Math.floor(h / 60) % 6; - var f = h / 60 - Math.floor(h / 60); - var p = v * (1.0 - s); - var q = v * (1.0 - f * s); - var t = v * (1.0 - (1.0 - f) * s); - var c = [[v, t, p], [q, v, p], [p, v, t], [p, q, v], [t, p, v], [v, p, q]][hi]; - return { - r: c[0] * 255, - g: c[1] * 255, - b: c[2] * 255 - }; - }, - rgb_to_hsv: function rgb_to_hsv(r, g, b) { - var min = Math.min(r, g, b); - var max = Math.max(r, g, b); - var delta = max - min; - var h = void 0; - var s = void 0; - - if (max !== 0) { - s = delta / max; - } else { - return { - h: NaN, - s: 0, - v: 0 - }; - } - - if (r === max) { - h = (g - b) / delta; - } else if (g === max) { - h = 2 + (b - r) / delta; - } else { - h = 4 + (r - g) / delta; - } - - h /= 6; - - if (h < 0) { - h += 1; - } - - return { - h: h * 360, - s: s, - v: max / 255 - }; - }, - rgb_to_hex: function rgb_to_hex(r, g, b) { - var hex = this.hex_with_component(0, 2, r); - hex = this.hex_with_component(hex, 1, g); - hex = this.hex_with_component(hex, 0, b); - return hex; - }, - component_from_hex: function component_from_hex(hex, componentIndex) { - return hex >> componentIndex * 8 & 0xFF; - }, - hex_with_component: function hex_with_component(hex, componentIndex, value) { - return value << (tmpComponent = componentIndex * 8) | hex & ~(0xFF << tmpComponent); - } - }; - - var _typeof$1 = typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol" ? function (obj) { - return _typeof(obj); - } : function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj); - }; - - var classCallCheck = function classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); - } - }; - - var createClass = function () { - function defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); - } - } - - return function (Constructor, protoProps, staticProps) { - if (protoProps) defineProperties(Constructor.prototype, protoProps); - if (staticProps) defineProperties(Constructor, staticProps); - return Constructor; - }; - }(); - - var get = function get(object, property, receiver) { - if (object === null) object = Function.prototype; - var desc = Object.getOwnPropertyDescriptor(object, property); - - if (desc === undefined) { - var parent = Object.getPrototypeOf(object); - - if (parent === null) { - return undefined; - } else { - return get(parent, property, receiver); - } - } else if ("value" in desc) { - return desc.value; - } else { - var getter = desc.get; - - if (getter === undefined) { - return undefined; - } - - return getter.call(receiver); - } - }; - - var inherits = function inherits(subClass, superClass) { - if (typeof superClass !== "function" && superClass !== null) { - throw new TypeError("Super expression must either be null or a function, not " + _typeof(superClass)); - } - - subClass.prototype = Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - enumerable: false, - writable: true, - configurable: true - } - }); - if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; - }; - - var possibleConstructorReturn = function possibleConstructorReturn(self, call) { - if (!self) { - throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); - } - - return call && (_typeof(call) === "object" || typeof call === "function") ? call : self; - }; - - var Color = function () { - function Color() { - classCallCheck(this, Color); - this.__state = interpret.apply(this, arguments); - - if (this.__state === false) { - throw new Error('Failed to interpret color arguments'); - } - - this.__state.a = this.__state.a || 1; - } - - createClass(Color, [{ - key: 'toString', - value: function toString() { - return colorToString(this); - } - }, { - key: 'toHexString', - value: function toHexString() { - return colorToString(this, true); - } - }, { - key: 'toOriginal', - value: function toOriginal() { - return this.__state.conversion.write(this); - } - }]); - return Color; - }(); - - function defineRGBComponent(target, component, componentHexIndex) { - Object.defineProperty(target, component, { - get: function get$$1() { - if (this.__state.space === 'RGB') { - return this.__state[component]; - } - - Color.recalculateRGB(this, component, componentHexIndex); - return this.__state[component]; - }, - set: function set$$1(v) { - if (this.__state.space !== 'RGB') { - Color.recalculateRGB(this, component, componentHexIndex); - this.__state.space = 'RGB'; - } - - this.__state[component] = v; - } - }); - } - - function defineHSVComponent(target, component) { - Object.defineProperty(target, component, { - get: function get$$1() { - if (this.__state.space === 'HSV') { - return this.__state[component]; - } - - Color.recalculateHSV(this); - return this.__state[component]; - }, - set: function set$$1(v) { - if (this.__state.space !== 'HSV') { - Color.recalculateHSV(this); - this.__state.space = 'HSV'; - } - - this.__state[component] = v; - } - }); - } - - Color.recalculateRGB = function (color, component, componentHexIndex) { - if (color.__state.space === 'HEX') { - color.__state[component] = ColorMath.component_from_hex(color.__state.hex, componentHexIndex); - } else if (color.__state.space === 'HSV') { - Common.extend(color.__state, ColorMath.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v)); - } else { - throw new Error('Corrupted color state'); - } - }; - - Color.recalculateHSV = function (color) { - var result = ColorMath.rgb_to_hsv(color.r, color.g, color.b); - Common.extend(color.__state, { - s: result.s, - v: result.v - }); - - if (!Common.isNaN(result.h)) { - color.__state.h = result.h; - } else if (Common.isUndefined(color.__state.h)) { - color.__state.h = 0; - } - }; - - Color.COMPONENTS = ['r', 'g', 'b', 'h', 's', 'v', 'hex', 'a']; - defineRGBComponent(Color.prototype, 'r', 2); - defineRGBComponent(Color.prototype, 'g', 1); - defineRGBComponent(Color.prototype, 'b', 0); - defineHSVComponent(Color.prototype, 'h'); - defineHSVComponent(Color.prototype, 's'); - defineHSVComponent(Color.prototype, 'v'); - Object.defineProperty(Color.prototype, 'a', { - get: function get$$1() { - return this.__state.a; - }, - set: function set$$1(v) { - this.__state.a = v; - } - }); - Object.defineProperty(Color.prototype, 'hex', { - get: function get$$1() { - if (!this.__state.space !== 'HEX') { - this.__state.hex = ColorMath.rgb_to_hex(this.r, this.g, this.b); - } - - return this.__state.hex; - }, - set: function set$$1(v) { - this.__state.space = 'HEX'; - this.__state.hex = v; - } - }); - - var Controller = function () { - function Controller(object, property) { - classCallCheck(this, Controller); - this.initialValue = object[property]; - this.domElement = document.createElement('div'); - this.object = object; - this.property = property; - this.__onChange = undefined; - this.__onFinishChange = undefined; - } - - createClass(Controller, [{ - key: 'onChange', - value: function onChange(fnc) { - this.__onChange = fnc; - return this; - } - }, { - key: 'onFinishChange', - value: function onFinishChange(fnc) { - this.__onFinishChange = fnc; - return this; - } - }, { - key: 'setValue', - value: function setValue(newValue) { - this.object[this.property] = newValue; - - if (this.__onChange) { - this.__onChange.call(this, newValue); - } - - this.updateDisplay(); - return this; - } - }, { - key: 'getValue', - value: function getValue() { - return this.object[this.property]; - } - }, { - key: 'updateDisplay', - value: function updateDisplay() { - return this; - } - }, { - key: 'isModified', - value: function isModified() { - return this.initialValue !== this.getValue(); - } - }]); - return Controller; - }(); - - var EVENT_MAP = { - HTMLEvents: ['change'], - MouseEvents: ['click', 'mousemove', 'mousedown', 'mouseup', 'mouseover'], - KeyboardEvents: ['keydown'] - }; - var EVENT_MAP_INV = {}; - Common.each(EVENT_MAP, function (v, k) { - Common.each(v, function (e) { - EVENT_MAP_INV[e] = k; - }); - }); - var CSS_VALUE_PIXELS = /(\d+(\.\d+)?)px/; - - function cssValueToPixels(val) { - if (val === '0' || Common.isUndefined(val)) { - return 0; - } - - var match = val.match(CSS_VALUE_PIXELS); - - if (!Common.isNull(match)) { - return parseFloat(match[1]); - } - - return 0; - } - - var dom = { - makeSelectable: function makeSelectable(elem, selectable) { - if (elem === undefined || elem.style === undefined) return; - elem.onselectstart = selectable ? function () { - return false; - } : function () {}; - elem.style.MozUserSelect = selectable ? 'auto' : 'none'; - elem.style.KhtmlUserSelect = selectable ? 'auto' : 'none'; - elem.unselectable = selectable ? 'on' : 'off'; - }, - makeFullscreen: function makeFullscreen(elem, hor, vert) { - var vertical = vert; - var horizontal = hor; - - if (Common.isUndefined(horizontal)) { - horizontal = true; - } - - if (Common.isUndefined(vertical)) { - vertical = true; - } - - elem.style.position = 'absolute'; - - if (horizontal) { - elem.style.left = 0; - elem.style.right = 0; - } - - if (vertical) { - elem.style.top = 0; - elem.style.bottom = 0; - } - }, - fakeEvent: function fakeEvent(elem, eventType, pars, aux) { - var params = pars || {}; - var className = EVENT_MAP_INV[eventType]; - - if (!className) { - throw new Error('Event type ' + eventType + ' not supported.'); - } - - var evt = document.createEvent(className); - - switch (className) { - case 'MouseEvents': - { - var clientX = params.x || params.clientX || 0; - var clientY = params.y || params.clientY || 0; - evt.initMouseEvent(eventType, params.bubbles || false, params.cancelable || true, window, params.clickCount || 1, 0, 0, clientX, clientY, false, false, false, false, 0, null); - break; - } - - case 'KeyboardEvents': - { - var init = evt.initKeyboardEvent || evt.initKeyEvent; - Common.defaults(params, { - cancelable: true, - ctrlKey: false, - altKey: false, - shiftKey: false, - metaKey: false, - keyCode: undefined, - charCode: undefined - }); - init(eventType, params.bubbles || false, params.cancelable, window, params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.keyCode, params.charCode); - break; - } - - default: - { - evt.initEvent(eventType, params.bubbles || false, params.cancelable || true); - break; - } - } - - Common.defaults(evt, aux); - elem.dispatchEvent(evt); - }, - bind: function bind(elem, event, func, newBool) { - var bool = newBool || false; - - if (elem.addEventListener) { - elem.addEventListener(event, func, bool); - } else if (elem.attachEvent) { - elem.attachEvent('on' + event, func); - } - - return dom; - }, - unbind: function unbind(elem, event, func, newBool) { - var bool = newBool || false; - - if (elem.removeEventListener) { - elem.removeEventListener(event, func, bool); - } else if (elem.detachEvent) { - elem.detachEvent('on' + event, func); - } - - return dom; - }, - addClass: function addClass(elem, className) { - if (elem.className === undefined) { - elem.className = className; - } else if (elem.className !== className) { - var classes = elem.className.split(/ +/); - - if (classes.indexOf(className) === -1) { - classes.push(className); - elem.className = classes.join(' ').replace(/^\s+/, '').replace(/\s+$/, ''); - } - } - - return dom; - }, - removeClass: function removeClass(elem, className) { - if (className) { - if (elem.className === className) { - elem.removeAttribute('class'); - } else { - var classes = elem.className.split(/ +/); - var index = classes.indexOf(className); - - if (index !== -1) { - classes.splice(index, 1); - elem.className = classes.join(' '); - } - } - } else { - elem.className = undefined; - } - - return dom; - }, - hasClass: function hasClass(elem, className) { - return new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)').test(elem.className) || false; - }, - getWidth: function getWidth(elem) { - var style = getComputedStyle(elem); - return cssValueToPixels(style['border-left-width']) + cssValueToPixels(style['border-right-width']) + cssValueToPixels(style['padding-left']) + cssValueToPixels(style['padding-right']) + cssValueToPixels(style.width); - }, - getHeight: function getHeight(elem) { - var style = getComputedStyle(elem); - return cssValueToPixels(style['border-top-width']) + cssValueToPixels(style['border-bottom-width']) + cssValueToPixels(style['padding-top']) + cssValueToPixels(style['padding-bottom']) + cssValueToPixels(style.height); - }, - getOffset: function getOffset(el) { - var elem = el; - var offset = { - left: 0, - top: 0 - }; - - if (elem.offsetParent) { - do { - offset.left += elem.offsetLeft; - offset.top += elem.offsetTop; - elem = elem.offsetParent; - } while (elem); - } - - return offset; - }, - isActive: function isActive(elem) { - return elem === document.activeElement && (elem.type || elem.href); - } - }; - - var BooleanController = function (_Controller) { - inherits(BooleanController, _Controller); - - function BooleanController(object, property) { - classCallCheck(this, BooleanController); - - var _this2 = possibleConstructorReturn(this, (BooleanController.__proto__ || Object.getPrototypeOf(BooleanController)).call(this, object, property)); - - var _this = _this2; - _this2.__prev = _this2.getValue(); - _this2.__checkbox = document.createElement('input'); - - _this2.__checkbox.setAttribute('type', 'checkbox'); - - function onChange() { - _this.setValue(!_this.__prev); - } - - dom.bind(_this2.__checkbox, 'change', onChange, false); - - _this2.domElement.appendChild(_this2.__checkbox); - - _this2.updateDisplay(); - - return _this2; - } - - createClass(BooleanController, [{ - key: 'setValue', - value: function setValue(v) { - var toReturn = get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'setValue', this).call(this, v); - - if (this.__onFinishChange) { - this.__onFinishChange.call(this, this.getValue()); - } - - this.__prev = this.getValue(); - return toReturn; - } - }, { - key: 'updateDisplay', - value: function updateDisplay() { - if (this.getValue() === true) { - this.__checkbox.setAttribute('checked', 'checked'); - - this.__checkbox.checked = true; - this.__prev = true; - } else { - this.__checkbox.checked = false; - this.__prev = false; - } - - return get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'updateDisplay', this).call(this); - } - }]); - return BooleanController; - }(Controller); - - var OptionController = function (_Controller) { - inherits(OptionController, _Controller); - - function OptionController(object, property, opts) { - classCallCheck(this, OptionController); - - var _this2 = possibleConstructorReturn(this, (OptionController.__proto__ || Object.getPrototypeOf(OptionController)).call(this, object, property)); - - var options = opts; - var _this = _this2; - _this2.__select = document.createElement('select'); - - if (Common.isArray(options)) { - var map = {}; - Common.each(options, function (element) { - map[element] = element; - }); - options = map; - } - - Common.each(options, function (value, key) { - var opt = document.createElement('option'); - opt.innerHTML = key; - opt.setAttribute('value', value); - - _this.__select.appendChild(opt); - }); - - _this2.updateDisplay(); +(function () { + 'use strict'; - dom.bind(_this2.__select, 'change', function () { - var desiredValue = this.options[this.selectedIndex].value; + // Polyfills - _this.setValue(desiredValue); - }); + if ( Number.EPSILON === undefined ) { - _this2.domElement.appendChild(_this2.__select); + Number.EPSILON = Math.pow( 2, - 52 ); - return _this2; - } + } - createClass(OptionController, [{ - key: 'setValue', - value: function setValue(v) { - var toReturn = get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'setValue', this).call(this, v); + if ( Number.isInteger === undefined ) { - if (this.__onFinishChange) { - this.__onFinishChange.call(this, this.getValue()); - } + // Missing in IE + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger - return toReturn; - } - }, { - key: 'updateDisplay', - value: function updateDisplay() { - if (dom.isActive(this.__select)) return this; - this.__select.value = this.getValue(); - return get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'updateDisplay', this).call(this); - } - }]); - return OptionController; - }(Controller); - - var StringController = function (_Controller) { - inherits(StringController, _Controller); - - function StringController(object, property) { - classCallCheck(this, StringController); - - var _this2 = possibleConstructorReturn(this, (StringController.__proto__ || Object.getPrototypeOf(StringController)).call(this, object, property)); - - var _this = _this2; - - function onChange() { - _this.setValue(_this.__input.value); - } - - function onBlur() { - if (_this.__onFinishChange) { - _this.__onFinishChange.call(_this, _this.getValue()); - } - } - - _this2.__input = document.createElement('input'); - - _this2.__input.setAttribute('type', 'text'); - - dom.bind(_this2.__input, 'keyup', onChange); - dom.bind(_this2.__input, 'change', onChange); - dom.bind(_this2.__input, 'blur', onBlur); - dom.bind(_this2.__input, 'keydown', function (e) { - if (e.keyCode === 13) { - this.blur(); - } - }); - - _this2.updateDisplay(); - - _this2.domElement.appendChild(_this2.__input); - - return _this2; - } - - createClass(StringController, [{ - key: 'updateDisplay', - value: function updateDisplay() { - if (!dom.isActive(this.__input)) { - this.__input.value = this.getValue(); - } - - return get(StringController.prototype.__proto__ || Object.getPrototypeOf(StringController.prototype), 'updateDisplay', this).call(this); - } - }]); - return StringController; - }(Controller); - - function numDecimals(x) { - var _x = x.toString(); - - if (_x.indexOf('.') > -1) { - return _x.length - _x.indexOf('.') - 1; - } - - return 0; - } - - var NumberController = function (_Controller) { - inherits(NumberController, _Controller); - - function NumberController(object, property, params) { - classCallCheck(this, NumberController); - - var _this = possibleConstructorReturn(this, (NumberController.__proto__ || Object.getPrototypeOf(NumberController)).call(this, object, property)); - - var _params = params || {}; - - _this.__min = _params.min; - _this.__max = _params.max; - _this.__step = _params.step; - - if (Common.isUndefined(_this.__step)) { - if (_this.initialValue === 0) { - _this.__impliedStep = 1; - } else { - _this.__impliedStep = Math.pow(10, Math.floor(Math.log(Math.abs(_this.initialValue)) / Math.LN10)) / 10; - } - } else { - _this.__impliedStep = _this.__step; - } - - _this.__precision = numDecimals(_this.__impliedStep); - return _this; - } - - createClass(NumberController, [{ - key: 'setValue', - value: function setValue(v) { - var _v = v; - - if (this.__min !== undefined && _v < this.__min) { - _v = this.__min; - } else if (this.__max !== undefined && _v > this.__max) { - _v = this.__max; - } - - if (this.__step !== undefined && _v % this.__step !== 0) { - _v = Math.round(_v / this.__step) * this.__step; - } - - return get(NumberController.prototype.__proto__ || Object.getPrototypeOf(NumberController.prototype), 'setValue', this).call(this, _v); - } - }, { - key: 'min', - value: function min(minValue) { - this.__min = minValue; - return this; - } - }, { - key: 'max', - value: function max(maxValue) { - this.__max = maxValue; - return this; - } - }, { - key: 'step', - value: function step(stepValue) { - this.__step = stepValue; - this.__impliedStep = stepValue; - this.__precision = numDecimals(stepValue); - return this; - } - }]); - return NumberController; - }(Controller); - - function roundToDecimal(value, decimals) { - var tenTo = Math.pow(10, decimals); - return Math.round(value * tenTo) / tenTo; - } - - var NumberControllerBox = function (_NumberController) { - inherits(NumberControllerBox, _NumberController); - - function NumberControllerBox(object, property, params) { - classCallCheck(this, NumberControllerBox); - - var _this2 = possibleConstructorReturn(this, (NumberControllerBox.__proto__ || Object.getPrototypeOf(NumberControllerBox)).call(this, object, property, params)); - - _this2.__truncationSuspended = false; - var _this = _this2; - var prevY = void 0; - - function onChange() { - var attempted = parseFloat(_this.__input.value); - - if (!Common.isNaN(attempted)) { - _this.setValue(attempted); - } - } - - function onFinish() { - if (_this.__onFinishChange) { - _this.__onFinishChange.call(_this, _this.getValue()); - } - } - - function onBlur() { - onFinish(); - } - - function onMouseDrag(e) { - var diff = prevY - e.clientY; - - _this.setValue(_this.getValue() + diff * _this.__impliedStep); - - prevY = e.clientY; - } - - function onMouseUp() { - dom.unbind(window, 'mousemove', onMouseDrag); - dom.unbind(window, 'mouseup', onMouseUp); - onFinish(); - } - - function onMouseDown(e) { - dom.bind(window, 'mousemove', onMouseDrag); - dom.bind(window, 'mouseup', onMouseUp); - prevY = e.clientY; - } - - _this2.__input = document.createElement('input'); - - _this2.__input.setAttribute('type', 'text'); - - dom.bind(_this2.__input, 'change', onChange); - dom.bind(_this2.__input, 'blur', onBlur); - dom.bind(_this2.__input, 'mousedown', onMouseDown); - dom.bind(_this2.__input, 'keydown', function (e) { - if (e.keyCode === 13) { - _this.__truncationSuspended = true; - this.blur(); - _this.__truncationSuspended = false; - onFinish(); - } - }); - - _this2.updateDisplay(); - - _this2.domElement.appendChild(_this2.__input); - - return _this2; - } - - createClass(NumberControllerBox, [{ - key: 'updateDisplay', - value: function updateDisplay() { - this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision); - return get(NumberControllerBox.prototype.__proto__ || Object.getPrototypeOf(NumberControllerBox.prototype), 'updateDisplay', this).call(this); - } - }]); - return NumberControllerBox; - }(NumberController); - - function map(v, i1, i2, o1, o2) { - return o1 + (o2 - o1) * ((v - i1) / (i2 - i1)); - } - - var NumberControllerSlider = function (_NumberController) { - inherits(NumberControllerSlider, _NumberController); + Number.isInteger = function ( value ) { - function NumberControllerSlider(object, property, min, max, step) { - classCallCheck(this, NumberControllerSlider); + return typeof value === 'number' && isFinite( value ) && Math.floor( value ) === value; - var _this2 = possibleConstructorReturn(this, (NumberControllerSlider.__proto__ || Object.getPrototypeOf(NumberControllerSlider)).call(this, object, property, { - min: min, - max: max, - step: step - })); + }; - var _this = _this2; - _this2.__background = document.createElement('div'); - _this2.__foreground = document.createElement('div'); - dom.bind(_this2.__background, 'mousedown', onMouseDown); - dom.bind(_this2.__background, 'touchstart', onTouchStart); - dom.addClass(_this2.__background, 'slider'); - dom.addClass(_this2.__foreground, 'slider-fg'); + } - function onMouseDown(e) { - document.activeElement.blur(); - dom.bind(window, 'mousemove', onMouseDrag); - dom.bind(window, 'mouseup', onMouseUp); - onMouseDrag(e); - } + // - function onMouseDrag(e) { - e.preventDefault(); + if ( Math.sign === undefined ) { - var bgRect = _this.__background.getBoundingClientRect(); + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign - _this.setValue(map(e.clientX, bgRect.left, bgRect.right, _this.__min, _this.__max)); - - return false; - } + Math.sign = function ( x ) { - function onMouseUp() { - dom.unbind(window, 'mousemove', onMouseDrag); - dom.unbind(window, 'mouseup', onMouseUp); + return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x; - if (_this.__onFinishChange) { - _this.__onFinishChange.call(_this, _this.getValue()); - } - } + }; - function onTouchStart(e) { - if (e.touches.length !== 1) { - return; - } - - dom.bind(window, 'touchmove', onTouchMove); - dom.bind(window, 'touchend', onTouchEnd); - onTouchMove(e); - } - - function onTouchMove(e) { - var clientX = e.touches[0].clientX; - - var bgRect = _this.__background.getBoundingClientRect(); - - _this.setValue(map(clientX, bgRect.left, bgRect.right, _this.__min, _this.__max)); - } - - function onTouchEnd() { - dom.unbind(window, 'touchmove', onTouchMove); - dom.unbind(window, 'touchend', onTouchEnd); - - if (_this.__onFinishChange) { - _this.__onFinishChange.call(_this, _this.getValue()); - } - } - - _this2.updateDisplay(); - - _this2.__background.appendChild(_this2.__foreground); - - _this2.domElement.appendChild(_this2.__background); - - return _this2; - } - - createClass(NumberControllerSlider, [{ - key: 'updateDisplay', - value: function updateDisplay() { - var pct = (this.getValue() - this.__min) / (this.__max - this.__min); - - this.__foreground.style.width = pct * 100 + '%'; - return get(NumberControllerSlider.prototype.__proto__ || Object.getPrototypeOf(NumberControllerSlider.prototype), 'updateDisplay', this).call(this); - } - }]); - return NumberControllerSlider; - }(NumberController); - - var FunctionController = function (_Controller) { - inherits(FunctionController, _Controller); - - function FunctionController(object, property, text) { - classCallCheck(this, FunctionController); - - var _this2 = possibleConstructorReturn(this, (FunctionController.__proto__ || Object.getPrototypeOf(FunctionController)).call(this, object, property)); - - var _this = _this2; - _this2.__button = document.createElement('div'); - _this2.__button.innerHTML = text === undefined ? 'Fire' : text; - dom.bind(_this2.__button, 'click', function (e) { - e.preventDefault(); - - _this.fire(); - - return false; - }); - dom.addClass(_this2.__button, 'button'); - - _this2.domElement.appendChild(_this2.__button); - - return _this2; - } - - createClass(FunctionController, [{ - key: 'fire', - value: function fire() { - if (this.__onChange) { - this.__onChange.call(this); - } - - this.getValue().call(this.object); - - if (this.__onFinishChange) { - this.__onFinishChange.call(this, this.getValue()); - } - } - }]); - return FunctionController; - }(Controller); - - var ColorController = function (_Controller) { - inherits(ColorController, _Controller); - - function ColorController(object, property) { - classCallCheck(this, ColorController); - - var _this2 = possibleConstructorReturn(this, (ColorController.__proto__ || Object.getPrototypeOf(ColorController)).call(this, object, property)); - - _this2.__color = new Color(_this2.getValue()); - _this2.__temp = new Color(0); - var _this = _this2; - _this2.domElement = document.createElement('div'); - dom.makeSelectable(_this2.domElement, false); - _this2.__selector = document.createElement('div'); - _this2.__selector.className = 'selector'; - _this2.__saturation_field = document.createElement('div'); - _this2.__saturation_field.className = 'saturation-field'; - _this2.__field_knob = document.createElement('div'); - _this2.__field_knob.className = 'field-knob'; - _this2.__field_knob_border = '2px solid '; - _this2.__hue_knob = document.createElement('div'); - _this2.__hue_knob.className = 'hue-knob'; - _this2.__hue_field = document.createElement('div'); - _this2.__hue_field.className = 'hue-field'; - _this2.__input = document.createElement('input'); - _this2.__input.type = 'text'; - _this2.__input_textShadow = '0 1px 1px '; - dom.bind(_this2.__input, 'keydown', function (e) { - if (e.keyCode === 13) { - onBlur.call(this); - } - }); - dom.bind(_this2.__input, 'blur', onBlur); - dom.bind(_this2.__selector, 'mousedown', function () { - dom.addClass(this, 'drag').bind(window, 'mouseup', function () { - dom.removeClass(_this.__selector, 'drag'); - }); - }); - dom.bind(_this2.__selector, 'touchstart', function () { - dom.addClass(this, 'drag').bind(window, 'touchend', function () { - dom.removeClass(_this.__selector, 'drag'); - }); - }); - var valueField = document.createElement('div'); - Common.extend(_this2.__selector.style, { - width: '122px', - height: '102px', - padding: '3px', - backgroundColor: '#222', - boxShadow: '0px 1px 3px rgba(0,0,0,0.3)' - }); - Common.extend(_this2.__field_knob.style, { - position: 'absolute', - width: '12px', - height: '12px', - border: _this2.__field_knob_border + (_this2.__color.v < 0.5 ? '#fff' : '#000'), - boxShadow: '0px 1px 3px rgba(0,0,0,0.5)', - borderRadius: '12px', - zIndex: 1 - }); - Common.extend(_this2.__hue_knob.style, { - position: 'absolute', - width: '15px', - height: '2px', - borderRight: '4px solid #fff', - zIndex: 1 - }); - Common.extend(_this2.__saturation_field.style, { - width: '100px', - height: '100px', - border: '1px solid #555', - marginRight: '3px', - display: 'inline-block', - cursor: 'pointer' - }); - Common.extend(valueField.style, { - width: '100%', - height: '100%', - background: 'none' - }); - linearGradient(valueField, 'top', 'rgba(0,0,0,0)', '#000'); - Common.extend(_this2.__hue_field.style, { - width: '15px', - height: '100px', - border: '1px solid #555', - cursor: 'ns-resize', - position: 'absolute', - top: '3px', - right: '3px' - }); - hueGradient(_this2.__hue_field); - Common.extend(_this2.__input.style, { - outline: 'none', - textAlign: 'center', - color: '#fff', - border: 0, - fontWeight: 'bold', - textShadow: _this2.__input_textShadow + 'rgba(0,0,0,0.7)' - }); - dom.bind(_this2.__saturation_field, 'mousedown', fieldDown); - dom.bind(_this2.__saturation_field, 'touchstart', fieldDown); - dom.bind(_this2.__field_knob, 'mousedown', fieldDown); - dom.bind(_this2.__field_knob, 'touchstart', fieldDown); - dom.bind(_this2.__hue_field, 'mousedown', fieldDownH); - dom.bind(_this2.__hue_field, 'touchstart', fieldDownH); - - function fieldDown(e) { - setSV(e); - dom.bind(window, 'mousemove', setSV); - dom.bind(window, 'touchmove', setSV); - dom.bind(window, 'mouseup', fieldUpSV); - dom.bind(window, 'touchend', fieldUpSV); - } - - function fieldDownH(e) { - setH(e); - dom.bind(window, 'mousemove', setH); - dom.bind(window, 'touchmove', setH); - dom.bind(window, 'mouseup', fieldUpH); - dom.bind(window, 'touchend', fieldUpH); - } - - function fieldUpSV() { - dom.unbind(window, 'mousemove', setSV); - dom.unbind(window, 'touchmove', setSV); - dom.unbind(window, 'mouseup', fieldUpSV); - dom.unbind(window, 'touchend', fieldUpSV); - onFinish(); - } - - function fieldUpH() { - dom.unbind(window, 'mousemove', setH); - dom.unbind(window, 'touchmove', setH); - dom.unbind(window, 'mouseup', fieldUpH); - dom.unbind(window, 'touchend', fieldUpH); - onFinish(); - } - - function onBlur() { - var i = interpret(this.value); - - if (i !== false) { - _this.__color.__state = i; - - _this.setValue(_this.__color.toOriginal()); - } else { - this.value = _this.__color.toString(); - } - } - - function onFinish() { - if (_this.__onFinishChange) { - _this.__onFinishChange.call(_this, _this.__color.toOriginal()); - } - } - - _this2.__saturation_field.appendChild(valueField); - - _this2.__selector.appendChild(_this2.__field_knob); - - _this2.__selector.appendChild(_this2.__saturation_field); - - _this2.__selector.appendChild(_this2.__hue_field); - - _this2.__hue_field.appendChild(_this2.__hue_knob); - - _this2.domElement.appendChild(_this2.__input); - - _this2.domElement.appendChild(_this2.__selector); - - _this2.updateDisplay(); - - function setSV(e) { - if (e.type.indexOf('touch') === -1) { - e.preventDefault(); - } - - var fieldRect = _this.__saturation_field.getBoundingClientRect(); - - var _ref = e.touches && e.touches[0] || e, - clientX = _ref.clientX, - clientY = _ref.clientY; - - var s = (clientX - fieldRect.left) / (fieldRect.right - fieldRect.left); - var v = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top); - - if (v > 1) { - v = 1; - } else if (v < 0) { - v = 0; - } - - if (s > 1) { - s = 1; - } else if (s < 0) { - s = 0; - } - - _this.__color.v = v; - _this.__color.s = s; - - _this.setValue(_this.__color.toOriginal()); - - return false; - } - - function setH(e) { - if (e.type.indexOf('touch') === -1) { - e.preventDefault(); - } - - var fieldRect = _this.__hue_field.getBoundingClientRect(); - - var _ref2 = e.touches && e.touches[0] || e, - clientY = _ref2.clientY; - - var h = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top); - - if (h > 1) { - h = 1; - } else if (h < 0) { - h = 0; - } - - _this.__color.h = h * 360; - - _this.setValue(_this.__color.toOriginal()); - - return false; - } - - return _this2; - } - - createClass(ColorController, [{ - key: 'updateDisplay', - value: function updateDisplay() { - var i = interpret(this.getValue()); - - if (i !== false) { - var mismatch = false; - Common.each(Color.COMPONENTS, function (component) { - if (!Common.isUndefined(i[component]) && !Common.isUndefined(this.__color.__state[component]) && i[component] !== this.__color.__state[component]) { - mismatch = true; - return {}; - } - }, this); - - if (mismatch) { - Common.extend(this.__color.__state, i); - } - } - - Common.extend(this.__temp.__state, this.__color.__state); - this.__temp.a = 1; - var flip = this.__color.v < 0.5 || this.__color.s > 0.5 ? 255 : 0; - - var _flip = 255 - flip; - - Common.extend(this.__field_knob.style, { - marginLeft: 100 * this.__color.s - 7 + 'px', - marginTop: 100 * (1 - this.__color.v) - 7 + 'px', - backgroundColor: this.__temp.toHexString(), - border: this.__field_knob_border + 'rgb(' + flip + ',' + flip + ',' + flip + ')' - }); - this.__hue_knob.style.marginTop = (1 - this.__color.h / 360) * 100 + 'px'; - this.__temp.s = 1; - this.__temp.v = 1; - linearGradient(this.__saturation_field, 'left', '#fff', this.__temp.toHexString()); - this.__input.value = this.__color.toString(); - Common.extend(this.__input.style, { - backgroundColor: this.__color.toHexString(), - color: 'rgb(' + flip + ',' + flip + ',' + flip + ')', - textShadow: this.__input_textShadow + 'rgba(' + _flip + ',' + _flip + ',' + _flip + ',.7)' - }); - } - }]); - return ColorController; - }(Controller); - - var vendors = ['-moz-', '-o-', '-webkit-', '-ms-', '']; - - function linearGradient(elem, x, a, b) { - elem.style.background = ''; - Common.each(vendors, function (vendor) { - elem.style.cssText += 'background: ' + vendor + 'linear-gradient(' + x + ', ' + a + ' 0%, ' + b + ' 100%); '; - }); - } - - function hueGradient(elem) { - elem.style.background = ''; - elem.style.cssText += 'background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);'; - elem.style.cssText += 'background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; - elem.style.cssText += 'background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; - elem.style.cssText += 'background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; - elem.style.cssText += 'background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; - } - - var css = { - load: function load(url, indoc) { - var doc = indoc || document; - var link = doc.createElement('link'); - link.type = 'text/css'; - link.rel = 'stylesheet'; - link.href = url; - doc.getElementsByTagName('head')[0].appendChild(link); - }, - inject: function inject(cssContent, indoc) { - var doc = indoc || document; - var injected = document.createElement('style'); - injected.type = 'text/css'; - injected.innerHTML = cssContent; - var head = doc.getElementsByTagName('head')[0]; - - try { - head.appendChild(injected); - } catch (e) {} - } - }; - var saveDialogContents = "
\n\n Here's the new load parameter for your GUI's constructor:\n\n \n\n
\n\n Automatically save\n values to localStorage on exit.\n\n
The values saved to localStorage will\n override those passed to dat.GUI's constructor. This makes it\n easier to work incrementally, but localStorage is fragile,\n and your friends may not see the same values you do.\n\n
\n\n
\n\n
"; - - var ControllerFactory = function ControllerFactory(object, property) { - var initialValue = object[property]; - - if (Common.isArray(arguments[2]) || Common.isObject(arguments[2])) { - return new OptionController(object, property, arguments[2]); - } - - if (Common.isNumber(initialValue)) { - if (Common.isNumber(arguments[2]) && Common.isNumber(arguments[3])) { - if (Common.isNumber(arguments[4])) { - return new NumberControllerSlider(object, property, arguments[2], arguments[3], arguments[4]); - } - - return new NumberControllerSlider(object, property, arguments[2], arguments[3]); - } - - if (Common.isNumber(arguments[4])) { - return new NumberControllerBox(object, property, { - min: arguments[2], - max: arguments[3], - step: arguments[4] - }); - } - - return new NumberControllerBox(object, property, { - min: arguments[2], - max: arguments[3] - }); - } - - if (Common.isString(initialValue)) { - return new StringController(object, property); - } - - if (Common.isFunction(initialValue)) { - return new FunctionController(object, property, ''); - } - - if (Common.isBoolean(initialValue)) { - return new BooleanController(object, property); - } - - return null; - }; - - function requestAnimationFrame$1(callback) { - setTimeout(callback, 1000 / 60); - } - - var requestAnimationFrame$1$1 = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || requestAnimationFrame$1; - - var CenteredDiv = function () { - function CenteredDiv() { - classCallCheck(this, CenteredDiv); - this.backgroundElement = document.createElement('div'); - Common.extend(this.backgroundElement.style, { - backgroundColor: 'rgba(0,0,0,0.8)', - top: 0, - left: 0, - display: 'none', - zIndex: '1000', - opacity: 0, - WebkitTransition: 'opacity 0.2s linear', - transition: 'opacity 0.2s linear' - }); - dom.makeFullscreen(this.backgroundElement); - this.backgroundElement.style.position = 'fixed'; - this.domElement = document.createElement('div'); - Common.extend(this.domElement.style, { - position: 'fixed', - display: 'none', - zIndex: '1001', - opacity: 0, - WebkitTransition: '-webkit-transform 0.2s ease-out, opacity 0.2s linear', - transition: 'transform 0.2s ease-out, opacity 0.2s linear' - }); - document.body.appendChild(this.backgroundElement); - document.body.appendChild(this.domElement); - - var _this = this; - - dom.bind(this.backgroundElement, 'click', function () { - _this.hide(); - }); - } - - createClass(CenteredDiv, [{ - key: 'show', - value: function show() { - var _this = this; - - this.backgroundElement.style.display = 'block'; - this.domElement.style.display = 'block'; - this.domElement.style.opacity = 0; - this.domElement.style.webkitTransform = 'scale(1.1)'; - this.layout(); - Common.defer(function () { - _this.backgroundElement.style.opacity = 1; - _this.domElement.style.opacity = 1; - _this.domElement.style.webkitTransform = 'scale(1)'; - }); - } - }, { - key: 'hide', - value: function hide() { - var _this = this; - - var hide = function hide() { - _this.domElement.style.display = 'none'; - _this.backgroundElement.style.display = 'none'; - dom.unbind(_this.domElement, 'webkitTransitionEnd', hide); - dom.unbind(_this.domElement, 'transitionend', hide); - dom.unbind(_this.domElement, 'oTransitionEnd', hide); - }; - - dom.bind(this.domElement, 'webkitTransitionEnd', hide); - dom.bind(this.domElement, 'transitionend', hide); - dom.bind(this.domElement, 'oTransitionEnd', hide); - this.backgroundElement.style.opacity = 0; - this.domElement.style.opacity = 0; - this.domElement.style.webkitTransform = 'scale(1.1)'; - } - }, { - key: 'layout', - value: function layout() { - this.domElement.style.left = window.innerWidth / 2 - dom.getWidth(this.domElement) / 2 + 'px'; - this.domElement.style.top = window.innerHeight / 2 - dom.getHeight(this.domElement) / 2 + 'px'; - } - }]); - return CenteredDiv; - }(); - - var styleSheet = ___$insertStyle(".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear;border:0;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button.close-top{position:relative}.dg.main .close-button.close-bottom{position:absolute}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-y:visible}.dg.a.has-save>ul.close-top{margin-top:0}.dg.a.has-save>ul.close-bottom{margin-top:27px}.dg.a.has-save>ul.closed{margin-top:0}.dg.a .save-row{top:0;z-index:1002}.dg.a .save-row.close-top{position:relative}.dg.a .save-row.close-bottom{position:fixed}.dg li{-webkit-transition:height .1s ease-out;-o-transition:height .1s ease-out;-moz-transition:height .1s ease-out;transition:height .1s ease-out;-webkit-transition:overflow .1s linear;-o-transition:overflow .1s linear;-moz-transition:overflow .1s linear;transition:overflow .1s linear}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li>*{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px;overflow:hidden}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%;position:relative}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:7px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .cr.color{overflow:visible}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.color{border-left:3px solid}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2FA1D6}.dg .cr.number input[type=text]{color:#2FA1D6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2FA1D6;max-width:100%}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n"); - - css.inject(styleSheet); - var CSS_NAMESPACE = 'dg'; - var HIDE_KEY_CODE = 72; - var CLOSE_BUTTON_HEIGHT = 20; - var DEFAULT_DEFAULT_PRESET_NAME = 'Default'; - - var SUPPORTS_LOCAL_STORAGE = function () { - try { - return !!window.localStorage; - } catch (e) { - return false; - } - }(); - - var SAVE_DIALOGUE = void 0; - var autoPlaceVirgin = true; - var autoPlaceContainer = void 0; - var hide = false; - var hideableGuis = []; - - var GUI = function GUI(pars) { - var _this = this; - - var params = pars || {}; - this.domElement = document.createElement('div'); - this.__ul = document.createElement('ul'); - this.domElement.appendChild(this.__ul); - dom.addClass(this.domElement, CSS_NAMESPACE); - this.__folders = {}; - this.__controllers = []; - this.__rememberedObjects = []; - this.__rememberedObjectIndecesToControllers = []; - this.__listening = []; - params = Common.defaults(params, { - closeOnTop: false, - autoPlace: true, - width: GUI.DEFAULT_WIDTH - }); - params = Common.defaults(params, { - resizable: params.autoPlace, - hideable: params.autoPlace - }); - - if (!Common.isUndefined(params.load)) { - if (params.preset) { - params.load.preset = params.preset; - } - } else { - params.load = { - preset: DEFAULT_DEFAULT_PRESET_NAME - }; - } - - if (Common.isUndefined(params.parent) && params.hideable) { - hideableGuis.push(this); - } - - params.resizable = Common.isUndefined(params.parent) && params.resizable; - - if (params.autoPlace && Common.isUndefined(params.scrollable)) { - params.scrollable = true; - } - - var useLocalStorage = SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true'; - var saveToLocalStorage = void 0; - var titleRow = void 0; - Object.defineProperties(this, { - parent: { - get: function get$$1() { - return params.parent; - } - }, - scrollable: { - get: function get$$1() { - return params.scrollable; - } - }, - autoPlace: { - get: function get$$1() { - return params.autoPlace; - } - }, - closeOnTop: { - get: function get$$1() { - return params.closeOnTop; - } - }, - preset: { - get: function get$$1() { - if (_this.parent) { - return _this.getRoot().preset; - } - - return params.load.preset; - }, - set: function set$$1(v) { - if (_this.parent) { - _this.getRoot().preset = v; - } else { - params.load.preset = v; - } - - setPresetSelectIndex(this); - - _this.revert(); - } - }, - width: { - get: function get$$1() { - return params.width; - }, - set: function set$$1(v) { - params.width = v; - setWidth(_this, v); - } - }, - name: { - get: function get$$1() { - return params.name; - }, - set: function set$$1(v) { - params.name = v; - - if (titleRow) { - titleRow.innerHTML = params.name; - } - } - }, - closed: { - get: function get$$1() { - return params.closed; - }, - set: function set$$1(v) { - params.closed = v; - - if (params.closed) { - dom.addClass(_this.__ul, GUI.CLASS_CLOSED); - } else { - dom.removeClass(_this.__ul, GUI.CLASS_CLOSED); - } - - this.onResize(); - - if (_this.__closeButton) { - _this.__closeButton.innerHTML = v ? GUI.TEXT_OPEN : GUI.TEXT_CLOSED; - } - } - }, - load: { - get: function get$$1() { - return params.load; - } - }, - useLocalStorage: { - get: function get$$1() { - return useLocalStorage; - }, - set: function set$$1(bool) { - if (SUPPORTS_LOCAL_STORAGE) { - useLocalStorage = bool; - - if (bool) { - dom.bind(window, 'unload', saveToLocalStorage); - } else { - dom.unbind(window, 'unload', saveToLocalStorage); - } - - localStorage.setItem(getLocalStorageHash(_this, 'isLocal'), bool); - } - } - } - }); - - if (Common.isUndefined(params.parent)) { - this.closed = params.closed || false; - dom.addClass(this.domElement, GUI.CLASS_MAIN); - dom.makeSelectable(this.domElement, false); - - if (SUPPORTS_LOCAL_STORAGE) { - if (useLocalStorage) { - _this.useLocalStorage = true; - var savedGui = localStorage.getItem(getLocalStorageHash(this, 'gui')); - - if (savedGui) { - params.load = JSON.parse(savedGui); - } - } - } - - this.__closeButton = document.createElement('div'); - this.__closeButton.innerHTML = GUI.TEXT_CLOSED; - dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BUTTON); - - if (params.closeOnTop) { - dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_TOP); - this.domElement.insertBefore(this.__closeButton, this.domElement.childNodes[0]); - } else { - dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BOTTOM); - this.domElement.appendChild(this.__closeButton); - } - - dom.bind(this.__closeButton, 'click', function () { - _this.closed = !_this.closed; - }); - } else { - if (params.closed === undefined) { - params.closed = true; - } - - var titleRowName = document.createTextNode(params.name); - dom.addClass(titleRowName, 'controller-name'); - titleRow = addRow(_this, titleRowName); - - var onClickTitle = function onClickTitle(e) { - e.preventDefault(); - _this.closed = !_this.closed; - return false; - }; - - dom.addClass(this.__ul, GUI.CLASS_CLOSED); - dom.addClass(titleRow, 'title'); - dom.bind(titleRow, 'click', onClickTitle); - - if (!params.closed) { - this.closed = false; - } - } - - if (params.autoPlace) { - if (Common.isUndefined(params.parent)) { - if (autoPlaceVirgin) { - autoPlaceContainer = document.createElement('div'); - dom.addClass(autoPlaceContainer, CSS_NAMESPACE); - dom.addClass(autoPlaceContainer, GUI.CLASS_AUTO_PLACE_CONTAINER); - document.body.appendChild(autoPlaceContainer); - autoPlaceVirgin = false; - } - - autoPlaceContainer.appendChild(this.domElement); - dom.addClass(this.domElement, GUI.CLASS_AUTO_PLACE); - } - - if (!this.parent) { - setWidth(_this, params.width); - } - } - - this.__resizeHandler = function () { - _this.onResizeDebounced(); - }; - - dom.bind(window, 'resize', this.__resizeHandler); - dom.bind(this.__ul, 'webkitTransitionEnd', this.__resizeHandler); - dom.bind(this.__ul, 'transitionend', this.__resizeHandler); - dom.bind(this.__ul, 'oTransitionEnd', this.__resizeHandler); - this.onResize(); - - if (params.resizable) { - addResizeHandle(this); - } - - saveToLocalStorage = function saveToLocalStorage() { - if (SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(_this, 'isLocal')) === 'true') { - localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject())); - } - }; - - this.saveToLocalStorageIfPossible = saveToLocalStorage; - - function resetWidth() { - var root = _this.getRoot(); - - root.width += 1; - Common.defer(function () { - root.width -= 1; - }); - } - - if (!params.parent) { - resetWidth(); - } - }; - - GUI.toggleHide = function () { - hide = !hide; - Common.each(hideableGuis, function (gui) { - gui.domElement.style.display = hide ? 'none' : ''; - }); - }; - - GUI.CLASS_AUTO_PLACE = 'a'; - GUI.CLASS_AUTO_PLACE_CONTAINER = 'ac'; - GUI.CLASS_MAIN = 'main'; - GUI.CLASS_CONTROLLER_ROW = 'cr'; - GUI.CLASS_TOO_TALL = 'taller-than-window'; - GUI.CLASS_CLOSED = 'closed'; - GUI.CLASS_CLOSE_BUTTON = 'close-button'; - GUI.CLASS_CLOSE_TOP = 'close-top'; - GUI.CLASS_CLOSE_BOTTOM = 'close-bottom'; - GUI.CLASS_DRAG = 'drag'; - GUI.DEFAULT_WIDTH = 245; - GUI.TEXT_CLOSED = 'Close Controls'; - GUI.TEXT_OPEN = 'Open Controls'; - - GUI._keydownHandler = function (e) { - if (document.activeElement.type !== 'text' && (e.which === HIDE_KEY_CODE || e.keyCode === HIDE_KEY_CODE)) { - GUI.toggleHide(); - } - }; - - dom.bind(window, 'keydown', GUI._keydownHandler, false); - Common.extend(GUI.prototype, { - add: function add(object, property) { - return _add(this, object, property, { - factoryArgs: Array.prototype.slice.call(arguments, 2) - }); - }, - addColor: function addColor(object, property) { - return _add(this, object, property, { - color: true - }); - }, - remove: function remove(controller) { - this.__ul.removeChild(controller.__li); - - this.__controllers.splice(this.__controllers.indexOf(controller), 1); - - var _this = this; - - Common.defer(function () { - _this.onResize(); - }); - }, - destroy: function destroy() { - if (this.parent) { - throw new Error('Only the root GUI should be removed with .destroy(). ' + 'For subfolders, use gui.removeFolder(folder) instead.'); - } - - if (this.autoPlace) { - autoPlaceContainer.removeChild(this.domElement); - } - - var _this = this; - - Common.each(this.__folders, function (subfolder) { - _this.removeFolder(subfolder); - }); - dom.unbind(window, 'keydown', GUI._keydownHandler, false); - removeListeners(this); - }, - addFolder: function addFolder(name) { - if (this.__folders[name] !== undefined) { - throw new Error('You already have a folder in this GUI by the' + ' name "' + name + '"'); - } - - var newGuiParams = { - name: name, - parent: this - }; - newGuiParams.autoPlace = this.autoPlace; - - if (this.load && this.load.folders && this.load.folders[name]) { - newGuiParams.closed = this.load.folders[name].closed; - newGuiParams.load = this.load.folders[name]; - } - - var gui = new GUI(newGuiParams); - this.__folders[name] = gui; - var li = addRow(this, gui.domElement); - dom.addClass(li, 'folder'); - return gui; - }, - removeFolder: function removeFolder(folder) { - this.__ul.removeChild(folder.domElement.parentElement); - - delete this.__folders[folder.name]; - - if (this.load && this.load.folders && this.load.folders[folder.name]) { - delete this.load.folders[folder.name]; - } - - removeListeners(folder); - - var _this = this; - - Common.each(folder.__folders, function (subfolder) { - folder.removeFolder(subfolder); - }); - Common.defer(function () { - _this.onResize(); - }); - }, - open: function open() { - this.closed = false; - }, - close: function close() { - this.closed = true; - }, - hide: function hide() { - this.domElement.style.display = 'none'; - }, - show: function show() { - this.domElement.style.display = ''; - }, - onResize: function onResize() { - var root = this.getRoot(); - - if (root.scrollable) { - var top = dom.getOffset(root.__ul).top; - var h = 0; - Common.each(root.__ul.childNodes, function (node) { - if (!(root.autoPlace && node === root.__save_row)) { - h += dom.getHeight(node); - } - }); - - if (window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h) { - dom.addClass(root.domElement, GUI.CLASS_TOO_TALL); - root.__ul.style.height = window.innerHeight - top - CLOSE_BUTTON_HEIGHT + 'px'; - } else { - dom.removeClass(root.domElement, GUI.CLASS_TOO_TALL); - root.__ul.style.height = 'auto'; - } - } - - if (root.__resize_handle) { - Common.defer(function () { - root.__resize_handle.style.height = root.__ul.offsetHeight + 'px'; - }); - } - - if (root.__closeButton) { - root.__closeButton.style.width = root.width + 'px'; - } - }, - onResizeDebounced: Common.debounce(function () { - this.onResize(); - }, 50), - remember: function remember() { - if (Common.isUndefined(SAVE_DIALOGUE)) { - SAVE_DIALOGUE = new CenteredDiv(); - SAVE_DIALOGUE.domElement.innerHTML = saveDialogContents; - } - - if (this.parent) { - throw new Error('You can only call remember on a top level GUI.'); - } - - var _this = this; - - Common.each(Array.prototype.slice.call(arguments), function (object) { - if (_this.__rememberedObjects.length === 0) { - addSaveMenu(_this); - } - - if (_this.__rememberedObjects.indexOf(object) === -1) { - _this.__rememberedObjects.push(object); - } - }); - - if (this.autoPlace) { - setWidth(this, this.width); - } - }, - getRoot: function getRoot() { - var gui = this; - - while (gui.parent) { - gui = gui.parent; - } - - return gui; - }, - getSaveObject: function getSaveObject() { - var toReturn = this.load; - toReturn.closed = this.closed; - - if (this.__rememberedObjects.length > 0) { - toReturn.preset = this.preset; - - if (!toReturn.remembered) { - toReturn.remembered = {}; - } - - toReturn.remembered[this.preset] = getCurrentPreset(this); - } - - toReturn.folders = {}; - Common.each(this.__folders, function (element, key) { - toReturn.folders[key] = element.getSaveObject(); - }); - return toReturn; - }, - save: function save() { - if (!this.load.remembered) { - this.load.remembered = {}; - } - - this.load.remembered[this.preset] = getCurrentPreset(this); - markPresetModified(this, false); - this.saveToLocalStorageIfPossible(); - }, - saveAs: function saveAs(presetName) { - if (!this.load.remembered) { - this.load.remembered = {}; - this.load.remembered[DEFAULT_DEFAULT_PRESET_NAME] = getCurrentPreset(this, true); - } - - this.load.remembered[presetName] = getCurrentPreset(this); - this.preset = presetName; - addPresetOption(this, presetName, true); - this.saveToLocalStorageIfPossible(); - }, - revert: function revert(gui) { - Common.each(this.__controllers, function (controller) { - if (!this.getRoot().load.remembered) { - controller.setValue(controller.initialValue); - } else { - recallSavedValue(gui || this.getRoot(), controller); - } - - if (controller.__onFinishChange) { - controller.__onFinishChange.call(controller, controller.getValue()); - } - }, this); - Common.each(this.__folders, function (folder) { - folder.revert(folder); - }); - - if (!gui) { - markPresetModified(this.getRoot(), false); - } - }, - listen: function listen(controller) { - var init = this.__listening.length === 0; - - this.__listening.push(controller); - - if (init) { - updateDisplays(this.__listening); - } - }, - updateDisplay: function updateDisplay() { - Common.each(this.__controllers, function (controller) { - controller.updateDisplay(); - }); - Common.each(this.__folders, function (folder) { - folder.updateDisplay(); - }); - } - }); - - function addRow(gui, newDom, liBefore) { - var li = document.createElement('li'); - - if (newDom) { - li.appendChild(newDom); - } - - if (liBefore) { - gui.__ul.insertBefore(li, liBefore); - } else { - gui.__ul.appendChild(li); - } - - gui.onResize(); - return li; - } - - function removeListeners(gui) { - dom.unbind(window, 'resize', gui.__resizeHandler); - - if (gui.saveToLocalStorageIfPossible) { - dom.unbind(window, 'unload', gui.saveToLocalStorageIfPossible); - } - } - - function markPresetModified(gui, modified) { - var opt = gui.__preset_select[gui.__preset_select.selectedIndex]; - - if (modified) { - opt.innerHTML = opt.value + '*'; - } else { - opt.innerHTML = opt.value; - } - } - - function augmentController(gui, li, controller) { - controller.__li = li; - controller.__gui = gui; - Common.extend(controller, { - options: function options(_options) { - if (arguments.length > 1) { - var nextSibling = controller.__li.nextElementSibling; - controller.remove(); - return _add(gui, controller.object, controller.property, { - before: nextSibling, - factoryArgs: [Common.toArray(arguments)] - }); - } - - if (Common.isArray(_options) || Common.isObject(_options)) { - var _nextSibling = controller.__li.nextElementSibling; - controller.remove(); - return _add(gui, controller.object, controller.property, { - before: _nextSibling, - factoryArgs: [_options] - }); - } - }, - name: function name(_name) { - controller.__li.firstElementChild.firstElementChild.innerHTML = _name; - return controller; - }, - listen: function listen() { - controller.__gui.listen(controller); - - return controller; - }, - remove: function remove() { - controller.__gui.remove(controller); - - return controller; - } - }); - - if (controller instanceof NumberControllerSlider) { - var box = new NumberControllerBox(controller.object, controller.property, { - min: controller.__min, - max: controller.__max, - step: controller.__step - }); - Common.each(['updateDisplay', 'onChange', 'onFinishChange', 'step', 'min', 'max'], function (method) { - var pc = controller[method]; - var pb = box[method]; - - controller[method] = box[method] = function () { - var args = Array.prototype.slice.call(arguments); - pb.apply(box, args); - return pc.apply(controller, args); - }; - }); - dom.addClass(li, 'has-slider'); - controller.domElement.insertBefore(box.domElement, controller.domElement.firstElementChild); - } else if (controller instanceof NumberControllerBox) { - var r = function r(returned) { - if (Common.isNumber(controller.__min) && Common.isNumber(controller.__max)) { - var oldName = controller.__li.firstElementChild.firstElementChild.innerHTML; - var wasListening = controller.__gui.__listening.indexOf(controller) > -1; - controller.remove(); - - var newController = _add(gui, controller.object, controller.property, { - before: controller.__li.nextElementSibling, - factoryArgs: [controller.__min, controller.__max, controller.__step] - }); - - newController.name(oldName); - if (wasListening) newController.listen(); - return newController; - } - - return returned; - }; - - controller.min = Common.compose(r, controller.min); - controller.max = Common.compose(r, controller.max); - } else if (controller instanceof BooleanController) { - dom.bind(li, 'click', function () { - dom.fakeEvent(controller.__checkbox, 'click'); - }); - dom.bind(controller.__checkbox, 'click', function (e) { - e.stopPropagation(); - }); - } else if (controller instanceof FunctionController) { - dom.bind(li, 'click', function () { - dom.fakeEvent(controller.__button, 'click'); - }); - dom.bind(li, 'mouseover', function () { - dom.addClass(controller.__button, 'hover'); - }); - dom.bind(li, 'mouseout', function () { - dom.removeClass(controller.__button, 'hover'); - }); - } else if (controller instanceof ColorController) { - dom.addClass(li, 'color'); - controller.updateDisplay = Common.compose(function (val) { - li.style.borderLeftColor = controller.__color.toString(); - return val; - }, controller.updateDisplay); - controller.updateDisplay(); - } - - controller.setValue = Common.compose(function (val) { - if (gui.getRoot().__preset_select && controller.isModified()) { - markPresetModified(gui.getRoot(), true); - } - - return val; - }, controller.setValue); - } - - function recallSavedValue(gui, controller) { - var root = gui.getRoot(); - - var matchedIndex = root.__rememberedObjects.indexOf(controller.object); - - if (matchedIndex !== -1) { - var controllerMap = root.__rememberedObjectIndecesToControllers[matchedIndex]; - - if (controllerMap === undefined) { - controllerMap = {}; - root.__rememberedObjectIndecesToControllers[matchedIndex] = controllerMap; - } - - controllerMap[controller.property] = controller; - - if (root.load && root.load.remembered) { - var presetMap = root.load.remembered; - var preset = void 0; - - if (presetMap[gui.preset]) { - preset = presetMap[gui.preset]; - } else if (presetMap[DEFAULT_DEFAULT_PRESET_NAME]) { - preset = presetMap[DEFAULT_DEFAULT_PRESET_NAME]; - } else { - return; - } - - if (preset[matchedIndex] && preset[matchedIndex][controller.property] !== undefined) { - var value = preset[matchedIndex][controller.property]; - controller.initialValue = value; - controller.setValue(value); - } - } - } - } - - function _add(gui, object, property, params) { - if (object[property] === undefined) { - throw new Error('Object "' + object + '" has no property "' + property + '"'); - } - - var controller = void 0; - - if (params.color) { - controller = new ColorController(object, property); - } else { - var factoryArgs = [object, property].concat(params.factoryArgs); - controller = ControllerFactory.apply(gui, factoryArgs); - } - - if (params.before instanceof Controller) { - params.before = params.before.__li; - } - - recallSavedValue(gui, controller); - dom.addClass(controller.domElement, 'c'); - var name = document.createElement('span'); - dom.addClass(name, 'property-name'); - name.innerHTML = controller.property; - var container = document.createElement('div'); - container.appendChild(name); - container.appendChild(controller.domElement); - var li = addRow(gui, container, params.before); - dom.addClass(li, GUI.CLASS_CONTROLLER_ROW); - - if (controller instanceof ColorController) { - dom.addClass(li, 'color'); - } else { - dom.addClass(li, _typeof$1(controller.getValue())); - } - - augmentController(gui, li, controller); - - gui.__controllers.push(controller); - - return controller; - } - - function getLocalStorageHash(gui, key) { - return document.location.href + '.' + key; - } - - function addPresetOption(gui, name, setSelected) { - var opt = document.createElement('option'); - opt.innerHTML = name; - opt.value = name; - - gui.__preset_select.appendChild(opt); - - if (setSelected) { - gui.__preset_select.selectedIndex = gui.__preset_select.length - 1; - } - } - - function showHideExplain(gui, explain) { - explain.style.display = gui.useLocalStorage ? 'block' : 'none'; - } - - function addSaveMenu(gui) { - var div = gui.__save_row = document.createElement('li'); - dom.addClass(gui.domElement, 'has-save'); - - gui.__ul.insertBefore(div, gui.__ul.firstChild); - - dom.addClass(div, 'save-row'); - var gears = document.createElement('span'); - gears.innerHTML = ' '; - dom.addClass(gears, 'button gears'); - var button = document.createElement('span'); - button.innerHTML = 'Save'; - dom.addClass(button, 'button'); - dom.addClass(button, 'save'); - var button2 = document.createElement('span'); - button2.innerHTML = 'New'; - dom.addClass(button2, 'button'); - dom.addClass(button2, 'save-as'); - var button3 = document.createElement('span'); - button3.innerHTML = 'Revert'; - dom.addClass(button3, 'button'); - dom.addClass(button3, 'revert'); - var select = gui.__preset_select = document.createElement('select'); - - if (gui.load && gui.load.remembered) { - Common.each(gui.load.remembered, function (value, key) { - addPresetOption(gui, key, key === gui.preset); - }); - } else { - addPresetOption(gui, DEFAULT_DEFAULT_PRESET_NAME, false); - } - - dom.bind(select, 'change', function () { - for (var index = 0; index < gui.__preset_select.length; index++) { - gui.__preset_select[index].innerHTML = gui.__preset_select[index].value; - } - - gui.preset = this.value; - }); - div.appendChild(select); - div.appendChild(gears); - div.appendChild(button); - div.appendChild(button2); - div.appendChild(button3); - - if (SUPPORTS_LOCAL_STORAGE) { - var explain = document.getElementById('dg-local-explain'); - var localStorageCheckBox = document.getElementById('dg-local-storage'); - var saveLocally = document.getElementById('dg-save-locally'); - saveLocally.style.display = 'block'; - - if (localStorage.getItem(getLocalStorageHash(gui, 'isLocal')) === 'true') { - localStorageCheckBox.setAttribute('checked', 'checked'); - } - - showHideExplain(gui, explain); - dom.bind(localStorageCheckBox, 'change', function () { - gui.useLocalStorage = !gui.useLocalStorage; - showHideExplain(gui, explain); - }); - } - - var newConstructorTextArea = document.getElementById('dg-new-constructor'); - dom.bind(newConstructorTextArea, 'keydown', function (e) { - if (e.metaKey && (e.which === 67 || e.keyCode === 67)) { - SAVE_DIALOGUE.hide(); - } - }); - dom.bind(gears, 'click', function () { - newConstructorTextArea.innerHTML = JSON.stringify(gui.getSaveObject(), undefined, 2); - SAVE_DIALOGUE.show(); - newConstructorTextArea.focus(); - newConstructorTextArea.select(); - }); - dom.bind(button, 'click', function () { - gui.save(); - }); - dom.bind(button2, 'click', function () { - var presetName = prompt('Enter a new preset name.'); - - if (presetName) { - gui.saveAs(presetName); - } - }); - dom.bind(button3, 'click', function () { - gui.revert(); - }); - } - - function addResizeHandle(gui) { - var pmouseX = void 0; - gui.__resize_handle = document.createElement('div'); - Common.extend(gui.__resize_handle.style, { - width: '6px', - marginLeft: '-3px', - height: '200px', - cursor: 'ew-resize', - position: 'absolute' - }); - - function drag(e) { - e.preventDefault(); - gui.width += pmouseX - e.clientX; - gui.onResize(); - pmouseX = e.clientX; - return false; - } - - function dragStop() { - dom.removeClass(gui.__closeButton, GUI.CLASS_DRAG); - dom.unbind(window, 'mousemove', drag); - dom.unbind(window, 'mouseup', dragStop); - } - - function dragStart(e) { - e.preventDefault(); - pmouseX = e.clientX; - dom.addClass(gui.__closeButton, GUI.CLASS_DRAG); - dom.bind(window, 'mousemove', drag); - dom.bind(window, 'mouseup', dragStop); - return false; - } - - dom.bind(gui.__resize_handle, 'mousedown', dragStart); - dom.bind(gui.__closeButton, 'mousedown', dragStart); - gui.domElement.insertBefore(gui.__resize_handle, gui.domElement.firstElementChild); - } - - function setWidth(gui, w) { - gui.domElement.style.width = w + 'px'; - - if (gui.__save_row && gui.autoPlace) { - gui.__save_row.style.width = w + 'px'; - } - - if (gui.__closeButton) { - gui.__closeButton.style.width = w + 'px'; - } - } - - function getCurrentPreset(gui, useInitialValues) { - var toReturn = {}; - Common.each(gui.__rememberedObjects, function (val, index) { - var savedValues = {}; - var controllerMap = gui.__rememberedObjectIndecesToControllers[index]; - Common.each(controllerMap, function (controller, property) { - savedValues[property] = useInitialValues ? controller.initialValue : controller.getValue(); - }); - toReturn[index] = savedValues; - }); - return toReturn; - } - - function setPresetSelectIndex(gui) { - for (var index = 0; index < gui.__preset_select.length; index++) { - if (gui.__preset_select[index].value === gui.preset) { - gui.__preset_select.selectedIndex = index; - } - } - } - - function updateDisplays(controllerArray) { - if (controllerArray.length !== 0) { - requestAnimationFrame$1$1.call(window, function () { - updateDisplays(controllerArray); - }); - } - - Common.each(controllerArray, function (c) { - c.updateDisplay(); - }); - } - - var GUI$1 = GUI; - - var Demo = function () { - function Demo() { - var id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "demo"; - - _classCallCheck(this, Demo); - - this.id = id; - this.renderer = null; - this.loadingManager = new three.LoadingManager(); - this.assets = new Map(); - this.scene = new three.Scene(); - this.camera = null; - this.controls = null; - this.ready = false; - } - - _createClass(Demo, [{ - key: "setRenderer", - value: function setRenderer(renderer) { - this.renderer = renderer; - return this; - } - }, { - key: "load", - value: function load() { - return Promise.resolve(); - } - }, { - key: "initialize", - value: function initialize() {} - }, { - key: "render", - value: function render(delta) { - this.renderer.render(this.scene, this.camera); - } - }, { - key: "registerOptions", - value: function registerOptions(menu) {} - }, { - key: "reset", - value: function reset() { - this.scene = new three.Scene(); - this.camera = null; - - if (this.controls !== null) { - this.controls.dispose(); - this.controls = null; - } - - this.ready = false; - return this; - } - }]); - - return Demo; - }(); - - var DemoManagerEvent = function (_Event) { - _inherits(DemoManagerEvent, _Event); - - function DemoManagerEvent(type) { - var _this3; - - _classCallCheck(this, DemoManagerEvent); - - _this3 = _possibleConstructorReturn(this, _getPrototypeOf(DemoManagerEvent).call(this, type)); - _this3.previousDemo = null; - _this3.demo = null; - return _this3; - } - - return DemoManagerEvent; - }(Event); - - var change = new DemoManagerEvent("change"); - var load = new DemoManagerEvent("load"); - - var DemoManager = function (_EventTarget) { - _inherits(DemoManager, _EventTarget); - - function DemoManager(viewport) { - var _this4; - - var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, - _ref3$aside = _ref3.aside, - aside = _ref3$aside === void 0 ? viewport : _ref3$aside, - renderer = _ref3.renderer; - - _classCallCheck(this, DemoManager); - - _this4 = _possibleConstructorReturn(this, _getPrototypeOf(DemoManager).call(this)); - _this4.renderer = renderer !== undefined ? renderer : function () { - var renderer = new three.WebGLRenderer(); - renderer.setSize(viewport.clientWidth, viewport.clientHeight); - renderer.setPixelRatio(window.devicePixelRatio); - return renderer; - }(); - viewport.appendChild(_this4.renderer.domElement); - _this4.clock = new three.Clock(); - _this4.menu = new GUI$1({ - autoPlace: false - }); - aside.appendChild(_this4.menu.domElement); - _this4.demos = new Map(); - _this4.demo = null; - _this4.currentDemo = null; - return _this4; - } - - _createClass(DemoManager, [{ - key: "resetMenu", - value: function resetMenu() { - var _this5 = this; - - var node = this.menu.domElement.parentNode; - var menu = new GUI$1({ - autoPlace: false - }); - - if (this.demos.size > 1) { - var selection = menu.add(this, "demo", Array.from(this.demos.keys())); - selection.onChange(function () { - return _this5.loadDemo(); - }); - } - - node.removeChild(this.menu.domElement); - node.appendChild(menu.domElement); - this.menu.destroy(); - this.menu = menu; - return menu; - } - }, { - key: "startDemo", - value: function startDemo(demo) { - if (demo.id === this.demo) { - demo.initialize(); - demo.registerOptions(this.resetMenu()); - demo.ready = true; - load.demo = demo; - this.dispatchEvent(load); - } - } - }, { - key: "loadDemo", - value: function loadDemo() { - var _this6 = this; - - var nextDemo = this.demos.get(this.demo); - var currentDemo = this.currentDemo; - var renderer = this.renderer; - window.location.hash = nextDemo.id; - - if (currentDemo !== null) { - currentDemo.reset(); - } - - this.menu.domElement.style.display = "none"; - change.previousDemo = currentDemo; - change.demo = nextDemo; - this.currentDemo = nextDemo; - this.dispatchEvent(change); - renderer.clear(); - nextDemo.load().then(function () { - return _this6.startDemo(nextDemo); - })["catch"](console.error); - } - }, { - key: "addDemo", - value: function addDemo(demo) { - var hash = window.location.hash.slice(1); - var currentDemo = this.currentDemo; - this.demos.set(demo.id, demo.setRenderer(this.renderer)); - - if (this.demo === null && hash.length === 0 || demo.id === hash) { - this.demo = demo.id; - this.loadDemo(); - } - - this.resetMenu(); - - if (currentDemo !== null && currentDemo.ready) { - currentDemo.registerOptions(this.menu); - } - - return this; - } - }, { - key: "removeDemo", - value: function removeDemo(id) { - var demos = this.demos; - var firstEntry; - - if (demos.has(id)) { - demos["delete"](id); - - if (this.demo === id && demos.size > 0) { - firstEntry = demos.entries().next().value; - this.demo = firstEntry[0]; - this.currentDemo = firstEntry[1]; - this.loadDemo(); - } else { - this.demo = null; - this.currentDemo = null; - this.renderer.clear(); - } - } - - return this; - } - }, { - key: "setSize", - value: function setSize(width, height, updateStyle) { - var demo = this.currentDemo; - this.renderer.setSize(width, height, updateStyle); - - if (demo !== null && demo.camera !== null) { - var camera = demo.camera; - - if (camera instanceof three.OrthographicCamera) { - camera.left = width / -2.0; - camera.right = width / 2.0; - camera.top = height / 2.0; - camera.bottom = height / -2.0; - camera.updateProjectionMatrix(); - } else if (!(camera instanceof three.CubeCamera)) { - camera.aspect = width / height; - camera.updateProjectionMatrix(); - } - } - } - }, { - key: "render", - value: function render(now) { - var demo = this.currentDemo; - var delta = this.clock.getDelta(); - - if (demo !== null && demo.ready) { - demo.render(delta); - } - } - }]); - - return DemoManager; - }(EventTarget); - - var Action = { - MOVE_FORWARD: 0, - MOVE_LEFT: 1, - MOVE_BACKWARD: 2, - MOVE_RIGHT: 3, - MOVE_DOWN: 4, - MOVE_UP: 5, - ZOOM_OUT: 6, - ZOOM_IN: 7 - }; - - var Vector3 = function () { - function Vector3() { - var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; - - _classCallCheck(this, Vector3); - - this.x = x; - this.y = y; - this.z = z; - } - - _createClass(Vector3, [{ - key: "set", - value: function set(x, y, z) { - this.x = x; - this.y = y; - this.z = z; - return this; - } - }, { - key: "copy", - value: function copy(v) { - this.x = v.x; - this.y = v.y; - this.z = v.z; - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor(this.x, this.y, this.z); - } - }, { - key: "fromArray", - value: function fromArray(array) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - this.x = array[offset]; - this.y = array[offset + 1]; - this.z = array[offset + 2]; - return this; - } - }, { - key: "toArray", - value: function toArray() { - var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - array[offset] = this.x; - array[offset + 1] = this.y; - array[offset + 2] = this.z; - return array; - } - }, { - key: "setFromSpherical", - value: function setFromSpherical(s) { - this.setFromSphericalCoords(s.radius, s.phi, s.theta); - } - }, { - key: "setFromSphericalCoords", - value: function setFromSphericalCoords(radius, phi, theta) { - var sinPhiRadius = Math.sin(phi) * radius; - this.x = sinPhiRadius * Math.sin(theta); - this.y = Math.cos(phi) * radius; - this.z = sinPhiRadius * Math.cos(theta); - return this; - } - }, { - key: "setFromCylindrical", - value: function setFromCylindrical(c) { - this.setFromCylindricalCoords(c.radius, c.theta, c.y); - } - }, { - key: "setFromCylindricalCoords", - value: function setFromCylindricalCoords(radius, theta, y) { - this.x = radius * Math.sin(theta); - this.y = y; - this.z = radius * Math.cos(theta); - return this; - } - }, { - key: "setFromMatrixColumn", - value: function setFromMatrixColumn(m, index) { - return this.fromArray(m.elements, index * 4); - } - }, { - key: "setFromMatrixPosition", - value: function setFromMatrixPosition(m) { - var me = m.elements; - this.x = me[12]; - this.y = me[13]; - this.z = me[14]; - return this; - } - }, { - key: "setFromMatrixScale", - value: function setFromMatrixScale(m) { - var sx = this.setFromMatrixColumn(m, 0).length(); - var sy = this.setFromMatrixColumn(m, 1).length(); - var sz = this.setFromMatrixColumn(m, 2).length(); - this.x = sx; - this.y = sy; - this.z = sz; - return this; - } - }, { - key: "add", - value: function add(v) { - this.x += v.x; - this.y += v.y; - this.z += v.z; - return this; - } - }, { - key: "addScalar", - value: function addScalar(s) { - this.x += s; - this.y += s; - this.z += s; - return this; - } - }, { - key: "addVectors", - value: function addVectors(a, b) { - this.x = a.x + b.x; - this.y = a.y + b.y; - this.z = a.z + b.z; - return this; - } - }, { - key: "addScaledVector", - value: function addScaledVector(v, s) { - this.x += v.x * s; - this.y += v.y * s; - this.z += v.z * s; - return this; - } - }, { - key: "sub", - value: function sub(v) { - this.x -= v.x; - this.y -= v.y; - this.z -= v.z; - return this; - } - }, { - key: "subScalar", - value: function subScalar(s) { - this.x -= s; - this.y -= s; - this.z -= s; - return this; - } - }, { - key: "subVectors", - value: function subVectors(a, b) { - this.x = a.x - b.x; - this.y = a.y - b.y; - this.z = a.z - b.z; - return this; - } - }, { - key: "multiply", - value: function multiply(v) { - this.x *= v.x; - this.y *= v.y; - this.z *= v.z; - return this; - } - }, { - key: "multiplyScalar", - value: function multiplyScalar(s) { - this.x *= s; - this.y *= s; - this.z *= s; - return this; - } - }, { - key: "multiplyVectors", - value: function multiplyVectors(a, b) { - this.x = a.x * b.x; - this.y = a.y * b.y; - this.z = a.z * b.z; - return this; - } - }, { - key: "divide", - value: function divide(v) { - this.x /= v.x; - this.y /= v.y; - this.z /= v.z; - return this; - } - }, { - key: "divideScalar", - value: function divideScalar(s) { - this.x /= s; - this.y /= s; - this.z /= s; - return this; - } - }, { - key: "crossVectors", - value: function crossVectors(a, b) { - var ax = a.x, - ay = a.y, - az = a.z; - var bx = b.x, - by = b.y, - bz = b.z; - this.x = ay * bz - az * by; - this.y = az * bx - ax * bz; - this.z = ax * by - ay * bx; - return this; - } - }, { - key: "cross", - value: function cross(v) { - return this.crossVectors(this, v); - } - }, { - key: "transformDirection", - value: function transformDirection(m) { - var x = this.x, - y = this.y, - z = this.z; - var e = m.elements; - this.x = e[0] * x + e[4] * y + e[8] * z; - this.y = e[1] * x + e[5] * y + e[9] * z; - this.z = e[2] * x + e[6] * y + e[10] * z; - return this.normalize(); - } - }, { - key: "applyMatrix3", - value: function applyMatrix3(m) { - var x = this.x, - y = this.y, - z = this.z; - var e = m.elements; - this.x = e[0] * x + e[3] * y + e[6] * z; - this.y = e[1] * x + e[4] * y + e[7] * z; - this.z = e[2] * x + e[5] * y + e[8] * z; - return this; - } - }, { - key: "applyMatrix4", - value: function applyMatrix4(m) { - var x = this.x, - y = this.y, - z = this.z; - var e = m.elements; - this.x = e[0] * x + e[4] * y + e[8] * z + e[12]; - this.y = e[1] * x + e[5] * y + e[9] * z + e[13]; - this.z = e[2] * x + e[6] * y + e[10] * z + e[14]; - return this; - } - }, { - key: "applyQuaternion", - value: function applyQuaternion(q) { - var x = this.x, - y = this.y, - z = this.z; - var qx = q.x, - qy = q.y, - qz = q.z, - qw = q.w; - var ix = qw * x + qy * z - qz * y; - var iy = qw * y + qz * x - qx * z; - var iz = qw * z + qx * y - qy * x; - var iw = -qx * x - qy * y - qz * z; - this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy; - this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz; - this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx; - return this; - } - }, { - key: "negate", - value: function negate() { - this.x = -this.x; - this.y = -this.y; - this.z = -this.z; - return this; - } - }, { - key: "dot", - value: function dot(v) { - return this.x * v.x + this.y * v.y + this.z * v.z; - } - }, { - key: "reflect", - value: function reflect(n) { - var nx = n.x; - var ny = n.y; - var nz = n.z; - this.sub(n.multiplyScalar(2 * this.dot(n))); - n.set(nx, ny, nz); - return this; - } - }, { - key: "angleTo", - value: function angleTo(v) { - var theta = this.dot(v) / Math.sqrt(this.lengthSquared() * v.lengthSquared()); - return Math.acos(Math.min(Math.max(theta, -1), 1)); - } - }, { - key: "manhattanLength", - value: function manhattanLength() { - return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z); - } - }, { - key: "lengthSquared", - value: function lengthSquared() { - return this.x * this.x + this.y * this.y + this.z * this.z; - } - }, { - key: "length", - value: function length() { - return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); - } - }, { - key: "manhattanDistanceTo", - value: function manhattanDistanceTo(v) { - return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z); - } - }, { - key: "distanceToSquared", - value: function distanceToSquared(v) { - var dx = this.x - v.x; - var dy = this.y - v.y; - var dz = this.z - v.z; - return dx * dx + dy * dy + dz * dz; - } - }, { - key: "distanceTo", - value: function distanceTo(v) { - return Math.sqrt(this.distanceToSquared(v)); - } - }, { - key: "normalize", - value: function normalize() { - return this.divideScalar(this.length()); - } - }, { - key: "setLength", - value: function setLength(length) { - return this.normalize().multiplyScalar(length); - } - }, { - key: "min", - value: function min(v) { - this.x = Math.min(this.x, v.x); - this.y = Math.min(this.y, v.y); - this.z = Math.min(this.z, v.z); - return this; - } - }, { - key: "max", - value: function max(v) { - this.x = Math.max(this.x, v.x); - this.y = Math.max(this.y, v.y); - this.z = Math.max(this.z, v.z); - return this; - } - }, { - key: "clamp", - value: function clamp(min, max) { - this.x = Math.max(min.x, Math.min(max.x, this.x)); - this.y = Math.max(min.y, Math.min(max.y, this.y)); - this.z = Math.max(min.z, Math.min(max.z, this.z)); - return this; - } - }, { - key: "floor", - value: function floor() { - this.x = Math.floor(this.x); - this.y = Math.floor(this.y); - this.z = Math.floor(this.z); - return this; - } - }, { - key: "ceil", - value: function ceil() { - this.x = Math.ceil(this.x); - this.y = Math.ceil(this.y); - this.z = Math.ceil(this.z); - return this; - } - }, { - key: "round", - value: function round() { - this.x = Math.round(this.x); - this.y = Math.round(this.y); - this.z = Math.round(this.z); - return this; - } - }, { - key: "lerp", - value: function lerp(v, alpha) { - this.x += (v.x - this.x) * alpha; - this.y += (v.y - this.y) * alpha; - this.z += (v.z - this.z) * alpha; - return this; - } - }, { - key: "lerpVectors", - value: function lerpVectors(v1, v2, alpha) { - return this.subVectors(v2, v1).multiplyScalar(alpha).add(v1); - } - }, { - key: "equals", - value: function equals(v) { - return v.x === this.x && v.y === this.y && v.z === this.z; - } - }]); - - return Vector3; - }(); - - var v = new Vector3(); - var points = [new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3()]; - - var Box3 = function () { - function Box3() { - var min = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3(Infinity, Infinity, Infinity); - var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3(-Infinity, -Infinity, -Infinity); - - _classCallCheck(this, Box3); - - this.min = min; - this.max = max; - } - - _createClass(Box3, [{ - key: "set", - value: function set(min, max) { - this.min.copy(min); - this.max.copy(max); - return this; - } - }, { - key: "copy", - value: function copy(b) { - this.min.copy(b.min); - this.max.copy(b.max); - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }, { - key: "makeEmpty", - value: function makeEmpty() { - this.min.x = this.min.y = this.min.z = Infinity; - this.max.x = this.max.y = this.max.z = -Infinity; - return this; - } - }, { - key: "isEmpty", - value: function isEmpty() { - return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z; - } - }, { - key: "getCenter", - value: function getCenter() { - var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3(); - return !this.isEmpty() ? target.addVectors(this.min, this.max).multiplyScalar(0.5) : target.set(0, 0, 0); - } - }, { - key: "getSize", - value: function getSize() { - var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3(); - return !this.isEmpty() ? target.subVectors(this.max, this.min) : target.set(0, 0, 0); - } - }, { - key: "setFromSphere", - value: function setFromSphere(sphere) { - this.set(sphere.center, sphere.center); - this.expandByScalar(sphere.radius); - return this; - } - }, { - key: "expandByPoint", - value: function expandByPoint(p) { - this.min.min(p); - this.max.max(p); - return this; - } - }, { - key: "expandByVector", - value: function expandByVector(v) { - this.min.sub(v); - this.max.add(v); - return this; - } - }, { - key: "expandByScalar", - value: function expandByScalar(s) { - this.min.addScalar(-s); - this.max.addScalar(s); - return this; - } - }, { - key: "setFromPoints", - value: function setFromPoints(points) { - var i, l; - this.min.set(0, 0, 0); - this.max.set(0, 0, 0); - - for (i = 0, l = points.length; i < l; ++i) { - this.expandByPoint(points[i]); - } - - return this; - } - }, { - key: "setFromCenterAndSize", - value: function setFromCenterAndSize(center, size) { - var halfSize = v.copy(size).multiplyScalar(0.5); - this.min.copy(center).sub(halfSize); - this.max.copy(center).add(halfSize); - return this; - } - }, { - key: "clampPoint", - value: function clampPoint(point) { - var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3(); - return target.copy(point).clamp(this.min, this.max); - } - }, { - key: "distanceToPoint", - value: function distanceToPoint(p) { - var clampedPoint = v.copy(p).clamp(this.min, this.max); - return clampedPoint.sub(p).length(); - } - }, { - key: "applyMatrix4", - value: function applyMatrix4(m) { - var min = this.min; - var max = this.max; - - if (!this.isEmpty()) { - points[0].set(min.x, min.y, min.z).applyMatrix4(m); - points[1].set(min.x, min.y, max.z).applyMatrix4(m); - points[2].set(min.x, max.y, min.z).applyMatrix4(m); - points[3].set(min.x, max.y, max.z).applyMatrix4(m); - points[4].set(max.x, min.y, min.z).applyMatrix4(m); - points[5].set(max.x, min.y, max.z).applyMatrix4(m); - points[6].set(max.x, max.y, min.z).applyMatrix4(m); - points[7].set(max.x, max.y, max.z).applyMatrix4(m); - this.setFromPoints(points); - } - - return this; - } - }, { - key: "translate", - value: function translate(offset) { - this.min.add(offset); - this.max.add(offset); - return this; - } - }, { - key: "intersect", - value: function intersect(b) { - this.min.max(b.min); - this.max.min(b.max); - - if (this.isEmpty()) { - this.makeEmpty(); - } - - return this; - } - }, { - key: "union", - value: function union(b) { - this.min.min(b.min); - this.max.max(b.max); - return this; - } - }, { - key: "containsPoint", - value: function containsPoint(p) { - var min = this.min; - var max = this.max; - return p.x >= min.x && p.y >= min.y && p.z >= min.z && p.x <= max.x && p.y <= max.y && p.z <= max.z; - } - }, { - key: "containsBox", - value: function containsBox(b) { - var tMin = this.min; - var tMax = this.max; - var bMin = b.min; - var bMax = b.max; - return tMin.x <= bMin.x && bMax.x <= tMax.x && tMin.y <= bMin.y && bMax.y <= tMax.y && tMin.z <= bMin.z && bMax.z <= tMax.z; - } - }, { - key: "intersectsBox", - value: function intersectsBox(b) { - var tMin = this.min; - var tMax = this.max; - var bMin = b.min; - var bMax = b.max; - return bMax.x >= tMin.x && bMax.y >= tMin.y && bMax.z >= tMin.z && bMin.x <= tMax.x && bMin.y <= tMax.y && bMin.z <= tMax.z; - } - }, { - key: "intersectsSphere", - value: function intersectsSphere(s) { - var closestPoint = this.clampPoint(s.center, v); - return closestPoint.distanceToSquared(s.center) <= s.radius * s.radius; - } - }, { - key: "intersectsPlane", - value: function intersectsPlane(p) { - var min, max; - - if (p.normal.x > 0) { - min = p.normal.x * this.min.x; - max = p.normal.x * this.max.x; - } else { - min = p.normal.x * this.max.x; - max = p.normal.x * this.min.x; - } - - if (p.normal.y > 0) { - min += p.normal.y * this.min.y; - max += p.normal.y * this.max.y; - } else { - min += p.normal.y * this.max.y; - max += p.normal.y * this.min.y; - } - - if (p.normal.z > 0) { - min += p.normal.z * this.min.z; - max += p.normal.z * this.max.z; - } else { - min += p.normal.z * this.max.z; - max += p.normal.z * this.min.z; - } - - return min <= -p.constant && max >= -p.constant; - } - }, { - key: "equals", - value: function equals(b) { - return b.min.equals(this.min) && b.max.equals(this.max); - } - }]); - - return Box3; - }(); - - var Vector2 = function () { - function Vector2() { - var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; - var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - - _classCallCheck(this, Vector2); - - this.x = x; - this.y = y; - } - - _createClass(Vector2, [{ - key: "set", - value: function set(x, y) { - this.x = x; - this.y = y; - return this; - } - }, { - key: "copy", - value: function copy(v) { - this.x = v.x; - this.y = v.y; - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor(this.x, this.y); - } - }, { - key: "fromArray", - value: function fromArray(array) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - this.x = array[offset]; - this.y = array[offset + 1]; - return this; - } - }, { - key: "toArray", - value: function toArray() { - var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - array[offset] = this.x; - array[offset + 1] = this.y; - return array; - } - }, { - key: "add", - value: function add(v) { - this.x += v.x; - this.y += v.y; - return this; - } - }, { - key: "addScalar", - value: function addScalar(s) { - this.x += s; - this.y += s; - return this; - } - }, { - key: "addVectors", - value: function addVectors(a, b) { - this.x = a.x + b.x; - this.y = a.y + b.y; - return this; - } - }, { - key: "addScaledVector", - value: function addScaledVector(v, s) { - this.x += v.x * s; - this.y += v.y * s; - return this; - } - }, { - key: "sub", - value: function sub(v) { - this.x -= v.x; - this.y -= v.y; - return this; - } - }, { - key: "subScalar", - value: function subScalar(s) { - this.x -= s; - this.y -= s; - return this; - } - }, { - key: "subVectors", - value: function subVectors(a, b) { - this.x = a.x - b.x; - this.y = a.y - b.y; - return this; - } - }, { - key: "multiply", - value: function multiply(v) { - this.x *= v.x; - this.y *= v.y; - return this; - } - }, { - key: "multiplyScalar", - value: function multiplyScalar(s) { - this.x *= s; - this.y *= s; - return this; - } - }, { - key: "divide", - value: function divide(v) { - this.x /= v.x; - this.y /= v.y; - return this; - } - }, { - key: "divideScalar", - value: function divideScalar(s) { - this.x /= s; - this.y /= s; - return this; - } - }, { - key: "applyMatrix3", - value: function applyMatrix3(m) { - var x = this.x, - y = this.y; - var e = m.elements; - this.x = e[0] * x + e[3] * y + e[6]; - this.y = e[1] * x + e[4] * y + e[7]; - return this; - } - }, { - key: "dot", - value: function dot(v) { - return this.x * v.x + this.y * v.y; - } - }, { - key: "cross", - value: function cross(v) { - return this.x * v.y - this.y * v.x; - } - }, { - key: "manhattanLength", - value: function manhattanLength() { - return Math.abs(this.x) + Math.abs(this.y); - } - }, { - key: "lengthSquared", - value: function lengthSquared() { - return this.x * this.x + this.y * this.y; - } - }, { - key: "length", - value: function length() { - return Math.sqrt(this.x * this.x + this.y * this.y); - } - }, { - key: "manhattanDistanceTo", - value: function manhattanDistanceTo(v) { - return Math.abs(this.x - v.x) + Math.abs(this.y - v.y); - } - }, { - key: "distanceToSquared", - value: function distanceToSquared(v) { - var dx = this.x - v.x; - var dy = this.y - v.y; - return dx * dx + dy * dy; - } - }, { - key: "distanceTo", - value: function distanceTo(v) { - return Math.sqrt(this.distanceToSquared(v)); - } - }, { - key: "normalize", - value: function normalize() { - return this.divideScalar(this.length()); - } - }, { - key: "setLength", - value: function setLength(length) { - return this.normalize().multiplyScalar(length); - } - }, { - key: "min", - value: function min(v) { - this.x = Math.min(this.x, v.x); - this.y = Math.min(this.y, v.y); - return this; - } - }, { - key: "max", - value: function max(v) { - this.x = Math.max(this.x, v.x); - this.y = Math.max(this.y, v.y); - return this; - } - }, { - key: "clamp", - value: function clamp(min, max) { - this.x = Math.max(min.x, Math.min(max.x, this.x)); - this.y = Math.max(min.y, Math.min(max.y, this.y)); - return this; - } - }, { - key: "floor", - value: function floor() { - this.x = Math.floor(this.x); - this.y = Math.floor(this.y); - return this; - } - }, { - key: "ceil", - value: function ceil() { - this.x = Math.ceil(this.x); - this.y = Math.ceil(this.y); - return this; - } - }, { - key: "round", - value: function round() { - this.x = Math.round(this.x); - this.y = Math.round(this.y); - return this; - } - }, { - key: "negate", - value: function negate() { - this.x = -this.x; - this.y = -this.y; - return this; - } - }, { - key: "angle", - value: function angle() { - var angle = Math.atan2(this.y, this.x); - - if (angle < 0) { - angle += 2 * Math.PI; - } - - return angle; - } - }, { - key: "lerp", - value: function lerp(v, alpha) { - this.x += (v.x - this.x) * alpha; - this.y += (v.y - this.y) * alpha; - return this; - } - }, { - key: "lerpVectors", - value: function lerpVectors(v1, v2, alpha) { - return this.subVectors(v2, v1).multiplyScalar(alpha).add(v1); - } - }, { - key: "rotateAround", - value: function rotateAround(center, angle) { - var c = Math.cos(angle), - s = Math.sin(angle); - var x = this.x - center.x; - var y = this.y - center.y; - this.x = x * c - y * s + center.x; - this.y = x * s + y * c + center.y; - return this; - } - }, { - key: "equals", - value: function equals(v) { - return v.x === this.x && v.y === this.y; - } - }, { - key: "width", - get: function get() { - return this.x; - }, - set: function set(value) { - return this.x = value; - } - }, { - key: "height", - get: function get() { - return this.y; - }, - set: function set(value) { - return this.y = value; - } - }]); - - return Vector2; - }(); - - var RotationOrder = { - XYZ: "XYZ", - YZX: "YZX", - ZXY: "ZXY", - XZY: "XZY", - YXZ: "YXZ", - ZYX: "ZYX" - }; - var a$2 = new Vector3(); - var b$2 = new Vector3(); - var c = new Vector3(); - - var Matrix4 = function () { - function Matrix4() { - _classCallCheck(this, Matrix4); - - this.elements = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); - } - - _createClass(Matrix4, [{ - key: "set", - value: function set(n00, n01, n02, n03, n10, n11, n12, n13, n20, n21, n22, n23, n30, n31, n32, n33) { - var te = this.elements; - te[0] = n00; - te[4] = n01; - te[8] = n02; - te[12] = n03; - te[1] = n10; - te[5] = n11; - te[9] = n12; - te[13] = n13; - te[2] = n20; - te[6] = n21; - te[10] = n22; - te[14] = n23; - te[3] = n30; - te[7] = n31; - te[11] = n32; - te[15] = n33; - return this; - } - }, { - key: "identity", - value: function identity() { - this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); - return this; - } - }, { - key: "copy", - value: function copy(matrix) { - var me = matrix.elements; - var te = this.elements; - te[0] = me[0]; - te[1] = me[1]; - te[2] = me[2]; - te[3] = me[3]; - te[4] = me[4]; - te[5] = me[5]; - te[6] = me[6]; - te[7] = me[7]; - te[8] = me[8]; - te[9] = me[9]; - te[10] = me[10]; - te[11] = me[11]; - te[12] = me[12]; - te[13] = me[13]; - te[14] = me[14]; - te[15] = me[15]; - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().fromArray(this.elements); - } - }, { - key: "fromArray", - value: function fromArray(array) { - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - var te = this.elements; - var i; - - for (i = 0; i < 16; ++i) { - te[i] = array[i + offset]; - } - - return this; - } - }, { - key: "toArray", - value: function toArray() { - var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; - var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - var te = this.elements; - var i; - - for (i = 0; i < 16; ++i) { - array[i + offset] = te[i]; - } - - return array; - } - }, { - key: "getMaxScaleOnAxis", - value: function getMaxScaleOnAxis() { - var te = this.elements; - var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2]; - var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6]; - var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10]; - return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq)); - } - }, { - key: "copyPosition", - value: function copyPosition(matrix) { - var te = this.elements; - var me = matrix.elements; - te[12] = me[12]; - te[13] = me[13]; - te[14] = me[14]; - return this; - } - }, { - key: "setPosition", - value: function setPosition(p) { - var te = this.elements; - te[12] = p.x; - te[13] = p.y; - te[14] = p.z; - return this; - } - }, { - key: "extractBasis", - value: function extractBasis(xAxis, yAxis, zAxis) { - xAxis.setFromMatrixColumn(this, 0); - yAxis.setFromMatrixColumn(this, 1); - zAxis.setFromMatrixColumn(this, 2); - return this; - } - }, { - key: "makeBasis", - value: function makeBasis(xAxis, yAxis, zAxis) { - 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); - return this; - } - }, { - key: "extractRotation", - value: function extractRotation(m) { - var te = this.elements; - var me = m.elements; - var scaleX = 1.0 / a$2.setFromMatrixColumn(m, 0).length(); - var scaleY = 1.0 / a$2.setFromMatrixColumn(m, 1).length(); - var scaleZ = 1.0 / a$2.setFromMatrixColumn(m, 2).length(); - te[0] = me[0] * scaleX; - te[1] = me[1] * scaleX; - te[2] = me[2] * scaleX; - te[3] = 0; - te[4] = me[4] * scaleY; - te[5] = me[5] * scaleY; - te[6] = me[6] * scaleY; - te[7] = 0; - te[8] = me[8] * scaleZ; - te[9] = me[9] * scaleZ; - te[10] = me[10] * scaleZ; - te[11] = 0; - te[12] = 0; - te[13] = 0; - te[14] = 0; - te[15] = 1; - return this; - } - }, { - key: "makeRotationFromEuler", - value: function makeRotationFromEuler(euler) { - var te = this.elements; - var x = euler.x; - var y = euler.y; - var z = euler.z; - var a = Math.cos(x), - b = Math.sin(x); - var c = Math.cos(y), - d = Math.sin(y); - var e = Math.cos(z), - f = Math.sin(z); - var ae, af, be, bf; - var ce, cf, de, df; - var ac, ad, bc, bd; - - switch (euler.order) { - case RotationOrder.XYZ: - { - ae = a * e, af = a * f, be = b * e, bf = b * f; - te[0] = c * e; - te[4] = -c * f; - te[8] = d; - te[1] = af + be * d; - te[5] = ae - bf * d; - te[9] = -b * c; - te[2] = bf - ae * d; - te[6] = be + af * d; - te[10] = a * c; - break; - } - - case RotationOrder.YXZ: - { - ce = c * e, cf = c * f, de = d * e, df = d * f; - te[0] = ce + df * b; - te[4] = de * b - cf; - te[8] = a * d; - te[1] = a * f; - te[5] = a * e; - te[9] = -b; - te[2] = cf * b - de; - te[6] = df + ce * b; - te[10] = a * c; - break; - } - - case RotationOrder.ZXY: - { - ce = c * e, cf = c * f, de = d * e, df = d * f; - te[0] = ce - df * b; - te[4] = -a * f; - te[8] = de + cf * b; - te[1] = cf + de * b; - te[5] = a * e; - te[9] = df - ce * b; - te[2] = -a * d; - te[6] = b; - te[10] = a * c; - break; - } - - case RotationOrder.ZYX: - { - ae = a * e, af = a * f, be = b * e, bf = b * f; - te[0] = c * e; - te[4] = be * d - af; - te[8] = ae * d + bf; - te[1] = c * f; - te[5] = bf * d + ae; - te[9] = af * d - be; - te[2] = -d; - te[6] = b * c; - te[10] = a * c; - break; - } - - case RotationOrder.YZX: - { - ac = a * c, ad = a * d, bc = b * c, bd = b * d; - te[0] = c * e; - te[4] = bd - ac * f; - te[8] = bc * f + ad; - te[1] = f; - te[5] = a * e; - te[9] = -b * e; - te[2] = -d * e; - te[6] = ad * f + bc; - te[10] = ac - bd * f; - break; - } - - case RotationOrder.XZY: - { - ac = a * c, ad = a * d, bc = b * c, bd = b * d; - te[0] = c * e; - te[4] = -f; - te[8] = d * e; - te[1] = ac * f + bd; - te[5] = a * e; - te[9] = ad * f - bc; - te[2] = bc * f - ad; - te[6] = b * e; - te[10] = bd * f + ac; - break; - } - } - - te[3] = 0; - te[7] = 0; - te[11] = 0; - te[12] = 0; - te[13] = 0; - te[14] = 0; - te[15] = 1; - return this; - } - }, { - key: "makeRotationFromQuaternion", - value: function makeRotationFromQuaternion(q) { - return this.compose(a$2.set(0, 0, 0), q, b$2.set(1, 1, 1)); - } - }, { - key: "lookAt", - value: function lookAt(eye, target, up) { - var te = this.elements; - var x = a$2, - y = b$2, - z = c; - z.subVectors(eye, target); - - if (z.lengthSquared() === 0) { - z.z = 1; - } - - z.normalize(); - x.crossVectors(up, z); - - if (x.lengthSquared() === 0) { - if (Math.abs(up.z) === 1) { - z.x += 1e-4; - } else { - z.z += 1e-4; - } - - z.normalize(); - x.crossVectors(up, z); - } - - x.normalize(); - y.crossVectors(z, x); - te[0] = x.x; - te[4] = y.x; - te[8] = z.x; - te[1] = x.y; - te[5] = y.y; - te[9] = z.y; - te[2] = x.z; - te[6] = y.z; - te[10] = z.z; - return this; - } - }, { - key: "multiplyMatrices", - value: function multiplyMatrices(a, b) { - var te = this.elements; - var ae = a.elements; - var be = b.elements; - var a00 = ae[0], - a01 = ae[4], - a02 = ae[8], - a03 = ae[12]; - var a10 = ae[1], - a11 = ae[5], - a12 = ae[9], - a13 = ae[13]; - var a20 = ae[2], - a21 = ae[6], - a22 = ae[10], - a23 = ae[14]; - var a30 = ae[3], - a31 = ae[7], - a32 = ae[11], - a33 = ae[15]; - var b00 = be[0], - b01 = be[4], - b02 = be[8], - b03 = be[12]; - var b10 = be[1], - b11 = be[5], - b12 = be[9], - b13 = be[13]; - var b20 = be[2], - b21 = be[6], - b22 = be[10], - b23 = be[14]; - var b30 = be[3], - b31 = be[7], - b32 = be[11], - b33 = be[15]; - te[0] = a00 * b00 + a01 * b10 + a02 * b20 + a03 * b30; - te[4] = a00 * b01 + a01 * b11 + a02 * b21 + a03 * b31; - te[8] = a00 * b02 + a01 * b12 + a02 * b22 + a03 * b32; - te[12] = a00 * b03 + a01 * b13 + a02 * b23 + a03 * b33; - te[1] = a10 * b00 + a11 * b10 + a12 * b20 + a13 * b30; - te[5] = a10 * b01 + a11 * b11 + a12 * b21 + a13 * b31; - te[9] = a10 * b02 + a11 * b12 + a12 * b22 + a13 * b32; - te[13] = a10 * b03 + a11 * b13 + a12 * b23 + a13 * b33; - te[2] = a20 * b00 + a21 * b10 + a22 * b20 + a23 * b30; - te[6] = a20 * b01 + a21 * b11 + a22 * b21 + a23 * b31; - te[10] = a20 * b02 + a21 * b12 + a22 * b22 + a23 * b32; - te[14] = a20 * b03 + a21 * b13 + a22 * b23 + a23 * b33; - te[3] = a30 * b00 + a31 * b10 + a32 * b20 + a33 * b30; - te[7] = a30 * b01 + a31 * b11 + a32 * b21 + a33 * b31; - te[11] = a30 * b02 + a31 * b12 + a32 * b22 + a33 * b32; - te[15] = a30 * b03 + a31 * b13 + a32 * b23 + a33 * b33; - return this; - } - }, { - key: "multiply", - value: function multiply(m) { - return this.multiplyMatrices(this, m); - } - }, { - key: "premultiply", - value: function premultiply(m) { - return this.multiplyMatrices(m, this); - } - }, { - key: "multiplyScalar", - value: function multiplyScalar(s) { - var te = this.elements; - te[0] *= s; - te[4] *= s; - te[8] *= s; - te[12] *= s; - te[1] *= s; - te[5] *= s; - te[9] *= s; - te[13] *= s; - te[2] *= s; - te[6] *= s; - te[10] *= s; - te[14] *= s; - te[3] *= s; - te[7] *= s; - te[11] *= s; - te[15] *= s; - return this; - } - }, { - key: "determinant", - value: function determinant() { - var te = this.elements; - var n00 = te[0], - n01 = te[4], - n02 = te[8], - n03 = te[12]; - var n10 = te[1], - n11 = te[5], - n12 = te[9], - n13 = te[13]; - var n20 = te[2], - n21 = te[6], - n22 = te[10], - n23 = te[14]; - var n30 = te[3], - n31 = te[7], - n32 = te[11], - n33 = te[15]; - var n00n11 = n00 * n11, - n00n12 = n00 * n12, - n00n13 = n00 * n13; - var n01n10 = n01 * n10, - n01n12 = n01 * n12, - n01n13 = n01 * n13; - var n02n10 = n02 * n10, - n02n11 = n02 * n11, - n02n13 = n02 * n13; - var n03n10 = n03 * n10, - n03n11 = n03 * n11, - n03n12 = n03 * n12; - return n30 * (n03n12 * n21 - n02n13 * n21 - n03n11 * n22 + n01n13 * n22 + n02n11 * n23 - n01n12 * n23) + n31 * (n00n12 * n23 - n00n13 * n22 + n03n10 * n22 - n02n10 * n23 + n02n13 * n20 - n03n12 * n20) + n32 * (n00n13 * n21 - n00n11 * n23 - n03n10 * n21 + n01n10 * n23 + n03n11 * n20 - n01n13 * n20) + n33 * (-n02n11 * n20 - n00n12 * n21 + n00n11 * n22 + n02n10 * n21 - n01n10 * n22 + n01n12 * n20); - } - }, { - key: "getInverse", - value: function getInverse(matrix) { - var te = this.elements; - var me = matrix.elements; - var n00 = me[0], - n10 = me[1], - n20 = me[2], - n30 = me[3]; - var n01 = me[4], - n11 = me[5], - n21 = me[6], - n31 = me[7]; - var n02 = me[8], - n12 = me[9], - n22 = me[10], - n32 = me[11]; - var n03 = me[12], - n13 = me[13], - n23 = me[14], - n33 = me[15]; - var t00 = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33; - var t01 = n03 * n22 * n31 - n02 * n23 * n31 - n03 * n21 * n32 + n01 * n23 * n32 + n02 * n21 * n33 - n01 * n22 * n33; - var t02 = n02 * n13 * n31 - n03 * n12 * n31 + n03 * n11 * n32 - n01 * n13 * n32 - n02 * n11 * n33 + n01 * n12 * n33; - var t03 = n03 * n12 * n21 - n02 * n13 * n21 - n03 * n11 * n22 + n01 * n13 * n22 + n02 * n11 * n23 - n01 * n12 * n23; - var det = n00 * t00 + n10 * t01 + n20 * t02 + n30 * t03; - var invDet; - - if (det !== 0) { - invDet = 1.0 / det; - te[0] = t00 * invDet; - te[1] = (n13 * n22 * n30 - n12 * n23 * n30 - n13 * n20 * n32 + n10 * n23 * n32 + n12 * n20 * n33 - n10 * n22 * n33) * invDet; - te[2] = (n11 * n23 * n30 - n13 * n21 * n30 + n13 * n20 * n31 - n10 * n23 * n31 - n11 * n20 * n33 + n10 * n21 * n33) * invDet; - te[3] = (n12 * n21 * n30 - n11 * n22 * n30 - n12 * n20 * n31 + n10 * n22 * n31 + n11 * n20 * n32 - n10 * n21 * n32) * invDet; - te[4] = t01 * invDet; - te[5] = (n02 * n23 * n30 - n03 * n22 * n30 + n03 * n20 * n32 - n00 * n23 * n32 - n02 * n20 * n33 + n00 * n22 * n33) * invDet; - te[6] = (n03 * n21 * n30 - n01 * n23 * n30 - n03 * n20 * n31 + n00 * n23 * n31 + n01 * n20 * n33 - n00 * n21 * n33) * invDet; - te[7] = (n01 * n22 * n30 - n02 * n21 * n30 + n02 * n20 * n31 - n00 * n22 * n31 - n01 * n20 * n32 + n00 * n21 * n32) * invDet; - te[8] = t02 * invDet; - te[9] = (n03 * n12 * n30 - n02 * n13 * n30 - n03 * n10 * n32 + n00 * n13 * n32 + n02 * n10 * n33 - n00 * n12 * n33) * invDet; - te[10] = (n01 * n13 * n30 - n03 * n11 * n30 + n03 * n10 * n31 - n00 * n13 * n31 - n01 * n10 * n33 + n00 * n11 * n33) * invDet; - te[11] = (n02 * n11 * n30 - n01 * n12 * n30 - n02 * n10 * n31 + n00 * n12 * n31 + n01 * n10 * n32 - n00 * n11 * n32) * invDet; - te[12] = t03 * invDet; - te[13] = (n02 * n13 * n20 - n03 * n12 * n20 + n03 * n10 * n22 - n00 * n13 * n22 - n02 * n10 * n23 + n00 * n12 * n23) * invDet; - te[14] = (n03 * n11 * n20 - n01 * n13 * n20 - n03 * n10 * n21 + n00 * n13 * n21 + n01 * n10 * n23 - n00 * n11 * n23) * invDet; - te[15] = (n01 * n12 * n20 - n02 * n11 * n20 + n02 * n10 * n21 - n00 * n12 * n21 - n01 * n10 * n22 + n00 * n11 * n22) * invDet; - } else { - console.error("Can't invert matrix, determinant is zero", matrix); - this.identity(); - } - - return this; - } - }, { - key: "transpose", - value: function transpose() { - var te = this.elements; - var t; - t = te[1]; - te[1] = te[4]; - te[4] = t; - t = te[2]; - te[2] = te[8]; - te[8] = t; - t = te[6]; - te[6] = te[9]; - te[9] = t; - t = te[3]; - te[3] = te[12]; - te[12] = t; - t = te[7]; - te[7] = te[13]; - te[13] = t; - t = te[11]; - te[11] = te[14]; - te[14] = t; - return this; - } - }, { - key: "scale", - value: function scale(sx, sy, sz) { - var te = this.elements; - te[0] *= sx; - te[4] *= sy; - te[8] *= sz; - te[1] *= sx; - te[5] *= sy; - te[9] *= sz; - te[2] *= sx; - te[6] *= sy; - te[10] *= sz; - te[3] *= sx; - te[7] *= sy; - te[11] *= sz; - return this; - } - }, { - key: "makeScale", - value: function makeScale(x, y, z) { - this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1); - return this; - } - }, { - key: "makeTranslation", - value: function makeTranslation(x, y, z) { - this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1); - return this; - } - }, { - key: "makeRotationX", - value: function makeRotationX(theta) { - var c = Math.cos(theta), - s = Math.sin(theta); - this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1); - return this; - } - }, { - key: "makeRotationY", - value: function makeRotationY(theta) { - var c = Math.cos(theta), - s = Math.sin(theta); - this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1); - return this; - } - }, { - key: "makeRotationZ", - value: function makeRotationZ(theta) { - var c = Math.cos(theta), - s = Math.sin(theta); - this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); - return this; - } - }, { - key: "makeRotationAxis", - value: function makeRotationAxis(axis, angle) { - var c = Math.cos(angle); - var s = Math.sin(angle); - var t = 1.0 - c; - var x = axis.x, - y = axis.y, - z = axis.z; - var tx = t * x, - ty = t * y; - 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); - return this; - } - }, { - key: "makeShear", - value: function makeShear(x, y, z) { - this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1); - return this; - } - }, { - key: "compose", - value: function compose(position, quaternion, scale) { - var te = this.elements; - var x = quaternion.x, - y = quaternion.y, - z = quaternion.z, - w = quaternion.w; - var x2 = x + x, - y2 = y + y, - z2 = z + z; - var xx = x * x2, - xy = x * y2, - xz = x * z2; - var yy = y * y2, - yz = y * z2, - zz = z * z2; - var wx = w * x2, - wy = w * y2, - wz = w * z2; - var sx = scale.x, - sy = scale.y, - sz = scale.z; - te[0] = (1 - (yy + zz)) * sx; - te[1] = (xy + wz) * sx; - te[2] = (xz - wy) * sx; - te[3] = 0; - te[4] = (xy - wz) * sy; - te[5] = (1 - (xx + zz)) * sy; - te[6] = (yz + wx) * sy; - te[7] = 0; - te[8] = (xz + wy) * sz; - te[9] = (yz - wx) * sz; - te[10] = (1 - (xx + yy)) * sz; - te[11] = 0; - te[12] = position.x; - te[13] = position.y; - te[14] = position.z; - te[15] = 1; - return this; - } - }, { - key: "decompose", - value: function decompose(position, quaternion, scale) { - var te = this.elements; - var n00 = te[0], - n10 = te[1], - n20 = te[2]; - var n01 = te[4], - n11 = te[5], - n21 = te[6]; - var n02 = te[8], - n12 = te[9], - n22 = te[10]; - var det = this.determinant(); - var sx = a$2.set(n00, n10, n20).length() * (det < 0 ? -1 : 1); - var sy = a$2.set(n01, n11, n21).length(); - var sz = a$2.set(n02, n12, n22).length(); - var invSX = 1.0 / sx; - var invSY = 1.0 / sy; - var invSZ = 1.0 / sz; - position.x = te[12]; - position.y = te[13]; - position.z = te[14]; - te[0] *= invSX; - te[1] *= invSX; - te[2] *= invSX; - te[4] *= invSY; - te[5] *= invSY; - te[6] *= invSY; - te[8] *= invSZ; - te[9] *= invSZ; - te[10] *= invSZ; - quaternion.setFromRotationMatrix(this); - te[0] = n00; - te[1] = n10; - te[2] = n20; - te[4] = n01; - te[5] = n11; - te[6] = n21; - te[8] = n02; - te[9] = n12; - te[10] = n22; - scale.x = sx; - scale.y = sy; - scale.z = sz; - return this; - } - }, { - key: "makePerspective", - value: function makePerspective(left, right, top, bottom, near, far) { - var te = this.elements; - var x = 2 * near / (right - left); - var y = 2 * near / (top - bottom); - var a = (right + left) / (right - left); - var b = (top + bottom) / (top - bottom); - var c = -(far + near) / (far - near); - var d = -2 * far * near / (far - near); - te[0] = x; - te[4] = 0; - te[8] = a; - te[12] = 0; - te[1] = 0; - te[5] = y; - te[9] = b; - te[13] = 0; - te[2] = 0; - te[6] = 0; - te[10] = c; - te[14] = d; - te[3] = 0; - te[7] = 0; - te[11] = -1; - te[15] = 0; - return this; - } - }, { - key: "makeOrthographic", - value: function makeOrthographic(left, right, top, bottom, near, far) { - var te = this.elements; - var w = 1.0 / (right - left); - var h = 1.0 / (top - bottom); - var p = 1.0 / (far - near); - var x = (right + left) * w; - var y = (top + bottom) * h; - var z = (far + near) * p; - te[0] = 2 * w; - te[4] = 0; - te[8] = 0; - te[12] = -x; - te[1] = 0; - te[5] = 2 * h; - te[9] = 0; - te[13] = -y; - te[2] = 0; - te[6] = 0; - te[10] = -2 * p; - te[14] = -z; - te[3] = 0; - te[7] = 0; - te[11] = 0; - te[15] = 1; - return this; - } - }, { - key: "equals", - value: function equals(m) { - var te = this.elements; - var me = m.elements; - var result = true; - var i; - - for (i = 0; result && i < 16; ++i) { - if (te[i] !== me[i]) { - result = false; - } - } - - return result; - } - }]); - - return Matrix4; - }(); - - var v$4 = [new Vector3(), new Vector3(), new Vector3(), new Vector3()]; - - var Ray = function () { - function Ray() { - var origin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3(); - var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3(); - - _classCallCheck(this, Ray); - - this.origin = origin; - this.direction = direction; - } - - _createClass(Ray, [{ - key: "set", - value: function set(origin, direction) { - this.origin.copy(origin); - this.direction.copy(direction); - return this; - } - }, { - key: "copy", - value: function copy(r) { - this.origin.copy(r.origin); - this.direction.copy(r.direction); - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }, { - key: "at", - value: function at(t) { - var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3(); - return target.copy(this.direction).multiplyScalar(t).add(this.origin); - } - }, { - key: "lookAt", - value: function lookAt(target) { - this.direction.copy(target).sub(this.origin).normalize(); - return this; - } - }, { - key: "recast", - value: function recast(t) { - this.origin.copy(this.at(t, v$4[0])); - return this; - } - }, { - key: "closestPointToPoint", - value: function closestPointToPoint(p) { - var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3(); - var directionDistance = target.subVectors(p, this.origin).dot(this.direction); - return directionDistance >= 0.0 ? target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin) : target.copy(this.origin); - } - }, { - key: "distanceSquaredToPoint", - value: function distanceSquaredToPoint(p) { - var directionDistance = v$4[0].subVectors(p, this.origin).dot(this.direction); - return directionDistance < 0.0 ? this.origin.distanceToSquared(p) : v$4[0].copy(this.direction).multiplyScalar(directionDistance).add(this.origin).distanceToSquared(p); - } - }, { - key: "distanceToPoint", - value: function distanceToPoint(p) { - return Math.sqrt(this.distanceSquaredToPoint(p)); - } - }, { - key: "distanceToPlane", - value: function distanceToPlane(p) { - var denominator = p.normal.dot(this.direction); - var t = denominator !== 0.0 ? -(this.origin.dot(p.normal) + p.constant) / denominator : p.distanceToPoint(this.origin) === 0.0 ? 0.0 : -1.0; - return t >= 0.0 ? t : null; - } - }, { - key: "distanceSquaredToSegment", - value: function distanceSquaredToSegment(v0, v1, pointOnRay, pointOnSegment) { - var segCenter = v$4[0].copy(v0).add(v1).multiplyScalar(0.5); - var segDir = v$4[1].copy(v1).sub(v0).normalize(); - var diff = v$4[2].copy(this.origin).sub(segCenter); - var segExtent = v0.distanceTo(v1) * 0.5; - var a01 = -this.direction.dot(segDir); - var b0 = diff.dot(this.direction); - var b1 = -diff.dot(segDir); - var c = diff.lengthSq(); - var det = Math.abs(1.0 - a01 * a01); - var s0, s1, extDet, invDet, sqrDist; - - if (det > 0.0) { - s0 = a01 * b1 - b0; - s1 = a01 * b0 - b1; - extDet = segExtent * det; - - if (s0 >= 0.0) { - if (s1 >= -extDet) { - if (s1 <= extDet) { - invDet = 1.0 / det; - s0 *= invDet; - s1 *= invDet; - sqrDist = s0 * (s0 + a01 * s1 + 2.0 * b0) + s1 * (a01 * s0 + s1 + 2.0 * b1) + c; - } else { - s1 = segExtent; - s0 = Math.max(0.0, -(a01 * s1 + b0)); - sqrDist = -s0 * s0 + s1 * (s1 + 2.0 * b1) + c; - } - } else { - s1 = -segExtent; - s0 = Math.max(0.0, -(a01 * s1 + b0)); - sqrDist = -s0 * s0 + s1 * (s1 + 2.0 * b1) + c; - } - } else { - if (s1 <= -extDet) { - s0 = Math.max(0.0, -(-a01 * segExtent + b0)); - s1 = s0 > 0.0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent); - sqrDist = -s0 * s0 + s1 * (s1 + 2.0 * b1) + c; - } else if (s1 <= extDet) { - s0 = 0.0; - s1 = Math.min(Math.max(-segExtent, -b1), segExtent); - sqrDist = s1 * (s1 + 2.0 * b1) + c; - } else { - s0 = Math.max(0.0, -(a01 * segExtent + b0)); - s1 = s0 > 0.0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent); - sqrDist = -s0 * s0 + s1 * (s1 + 2.0 * b1) + c; - } - } - } else { - s1 = a01 > 0.0 ? -segExtent : segExtent; - s0 = Math.max(0.0, -(a01 * s1 + b0)); - sqrDist = -s0 * s0 + s1 * (s1 + 2.0 * b1) + c; - } - - if (pointOnRay !== undefined) { - pointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin); - } - - if (pointOnSegment !== undefined) { - pointOnSegment.copy(segDir).multiplyScalar(s1).add(segCenter); - } - - return sqrDist; - } - }, { - key: "intersectSphere", - value: function intersectSphere(s) { - var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3(); - var ab = v$4[0].subVectors(s.center, this.origin); - var tca = ab.dot(this.direction); - var d2 = ab.dot(ab) - tca * tca; - var radius2 = s.radius * s.radius; - var result = null; - var thc, t0, t1; - - if (d2 <= radius2) { - thc = Math.sqrt(radius2 - d2); - t0 = tca - thc; - t1 = tca + thc; - - if (t0 >= 0.0 || t1 >= 0.0) { - result = t0 < 0.0 ? this.at(t1, target) : this.at(t0, target); - } - } - - return result; - } - }, { - key: "intersectsSphere", - value: function intersectsSphere(s) { - return this.distanceSqToPoint(s.center) <= s.radius * s.radius; - } - }, { - key: "intersectPlane", - value: function intersectPlane(p) { - var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3(); - var t = this.distanceToPlane(p); - return t === null ? null : this.at(t, target); - } - }, { - key: "intersectsPlane", - value: function intersectsPlane(p) { - var distanceToPoint = p.distanceToPoint(this.origin); - return distanceToPoint === 0.0 || p.normal.dot(this.direction) * distanceToPoint < 0.0; - } - }, { - key: "intersectBox", - value: function intersectBox(b) { - var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3(); - var origin = this.origin; - var direction = this.direction; - var min = b.min; - var max = b.max; - var invDirX = 1.0 / direction.x; - var invDirY = 1.0 / direction.y; - var invDirZ = 1.0 / direction.z; - var result = null; - var tmin, tmax, tymin, tymax, tzmin, tzmax; - - if (invDirX >= 0.0) { - tmin = (min.x - origin.x) * invDirX; - tmax = (max.x - origin.x) * invDirX; - } else { - tmin = (max.x - origin.x) * invDirX; - tmax = (min.x - origin.x) * invDirX; - } - - if (invDirY >= 0.0) { - tymin = (min.y - origin.y) * invDirY; - tymax = (max.y - origin.y) * invDirY; - } else { - tymin = (max.y - origin.y) * invDirY; - tymax = (min.y - origin.y) * invDirY; - } - - if (tmin <= tymax && tymin <= tmax) { - if (tymin > tmin || tmin !== tmin) { - tmin = tymin; - } - - if (tymax < tmax || tmax !== tmax) { - tmax = tymax; - } - - if (invDirZ >= 0.0) { - tzmin = (min.z - origin.z) * invDirZ; - tzmax = (max.z - origin.z) * invDirZ; - } else { - tzmin = (max.z - origin.z) * invDirZ; - tzmax = (min.z - origin.z) * invDirZ; - } - - if (tmin <= tzmax && tzmin <= tmax) { - if (tzmin > tmin || tmin !== tmin) { - tmin = tzmin; - } - - if (tzmax < tmax || tmax !== tmax) { - tmax = tzmax; - } - - if (tmax >= 0.0) { - result = this.at(tmin >= 0.0 ? tmin : tmax, target); - } - } - } - - return result; - } - }, { - key: "intersectsBox", - value: function intersectsBox(b) { - return this.intersectBox(b, v$4[0]) !== null; - } - }, { - key: "intersectTriangle", - value: function intersectTriangle(a, b, c, backfaceCulling, target) { - var direction = this.direction; - var diff = v$4[0]; - var edge1 = v$4[1]; - var edge2 = v$4[2]; - var normal = v$4[3]; - var result = null; - var DdN, sign, DdQxE2, DdE1xQ, QdN; - edge1.subVectors(b, a); - edge2.subVectors(c, a); - normal.crossVectors(edge1, edge2); - DdN = direction.dot(normal); - - if (DdN !== 0.0 && !(backfaceCulling && DdN > 0.0)) { - if (DdN > 0.0) { - sign = 1.0; - } else { - sign = -1.0; - DdN = -DdN; - } - - diff.subVectors(this.origin, a); - DdQxE2 = sign * direction.dot(edge2.crossVectors(diff, edge2)); - - if (DdQxE2 >= 0.0) { - DdE1xQ = sign * direction.dot(edge1.cross(diff)); - - if (DdE1xQ >= 0.0 && DdQxE2 + DdE1xQ <= DdN) { - QdN = -sign * diff.dot(normal); - - if (QdN >= 0.0) { - result = this.at(QdN / DdN, target); - } - } - } - } - - return result; - } - }, { - key: "applyMatrix4", - value: function applyMatrix4(m) { - this.origin.applyMatrix4(m); - this.direction.transformDirection(m); - return this; - } - }, { - key: "equals", - value: function equals(r) { - return r.origin.equals(this.origin) && r.direction.equals(this.direction); - } - }]); - - return Ray; - }(); - - var Spherical = function () { - function Spherical() { - var radius = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; - var phi = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; - var theta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; - - _classCallCheck(this, Spherical); - - this.radius = radius; - this.phi = phi; - this.theta = theta; - } - - _createClass(Spherical, [{ - key: "set", - value: function set(radius, phi, theta) { - this.radius = radius; - this.phi = phi; - this.theta = theta; - return this; - } - }, { - key: "copy", - value: function copy(s) { - this.radius = s.radius; - this.phi = s.phi; - this.theta = s.theta; - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }, { - key: "makeSafe", - value: function makeSafe() { - this.phi = Math.max(1e-6, Math.min(Math.PI - 1e-6, this.phi)); - return this; - } - }, { - key: "setFromVector3", - value: function setFromVector3(v) { - return this.setFromCartesianCoords(v.x, v.y, v.z); - } - }, { - key: "setFromCartesianCoords", - value: function setFromCartesianCoords(x, y, z) { - this.radius = Math.sqrt(x * x + y * y + z * z); - - if (this.radius === 0) { - this.theta = 0; - this.phi = 0; - } else { - this.theta = Math.atan2(x, z); - this.phi = Math.acos(Math.min(Math.max(y / this.radius, -1), 1)); - } - - return this; - } - }]); - - return Spherical; - }(); - - var PointerButton = { - MAIN: 0, - AUXILIARY: 1, - SECONDARY: 2 - }; - var TWO_PI = Math.PI * 2; - var v$1 = new Vector3(); - var m = new Matrix4(); - - var RotationManager = function () { - function RotationManager(position, quaternion, target, settings) { - _classCallCheck(this, RotationManager); - - this.position = position; - this.quaternion = quaternion; - this.target = target; - this.settings = settings; - this.spherical = new Spherical(); - } - - _createClass(RotationManager, [{ - key: "setPosition", - value: function setPosition(position) { - this.position = position; - return this; - } - }, { - key: "setQuaternion", - value: function setQuaternion(quaternion) { - this.quaternion = quaternion; - return this; - } - }, { - key: "setTarget", - value: function setTarget(target) { - this.target = target; - return this; - } - }, { - key: "updateQuaternion", - value: function updateQuaternion() { - var settings = this.settings; - var rotation = settings.rotation; - - if (settings.general.orbit) { - m.lookAt(v$1.subVectors(this.position, this.target), rotation.pivotOffset, rotation.up); - } else { - m.lookAt(v$1.set(0, 0, 0), this.target.setFromSpherical(this.spherical), rotation.up); - } - - this.quaternion.setFromRotationMatrix(m); - return this; - } - }, { - key: "adjustSpherical", - value: function adjustSpherical(theta, phi) { - var settings = this.settings; - var orbit = settings.general.orbit; - var rotation = settings.rotation; - var s = this.spherical; - s.theta = !rotation.invertX ? s.theta - theta : s.theta + theta; - s.phi = (orbit || rotation.invertY) && !(orbit && rotation.invertY) ? s.phi - phi : s.phi + phi; - s.theta = Math.min(Math.max(s.theta, rotation.minAzimuthalAngle), rotation.maxAzimuthalAngle); - s.phi = Math.min(Math.max(s.phi, rotation.minPolarAngle), rotation.maxPolarAngle); - s.theta %= TWO_PI; - s.makeSafe(); - - if (orbit) { - this.position.setFromSpherical(s).add(this.target); - } - - return this; - } - }, { - key: "zoom", - value: function zoom(sign) { - var settings = this.settings; - var general = settings.general; - var sensitivity = settings.sensitivity; - var zoom = settings.zoom; - var s = this.spherical; - var amount, min, max; - - if (general.orbit && zoom.enabled) { - amount = sign * sensitivity.zoom; - - if (zoom.invert) { - amount = -amount; - } - - min = Math.max(zoom.minDistance, 1e-6); - max = Math.min(zoom.maxDistance, Infinity); - s.radius = Math.min(Math.max(s.radius + amount, min), max); - this.position.setFromSpherical(s).add(this.target); - } - - return this; - } - }, { - key: "update", - value: function update(delta) {} - }, { - key: "lookAt", - value: function lookAt(point) { - var spherical = this.spherical; - var position = this.position; - var target = this.target; - target.copy(point); - - if (this.settings.general.orbit) { - v$1.subVectors(position, target); - } else { - v$1.subVectors(target, position).normalize(); - } - - spherical.setFromVector3(v$1); - spherical.radius = Math.max(spherical.radius, 1e-6); - this.updateQuaternion(); - return this; - } - }, { - key: "getViewDirection", - value: function getViewDirection() { - var view = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3(); - view.setFromSpherical(this.spherical).normalize(); - - if (this.settings.general.orbit) { - view.negate(); - } - - return view; - } - }]); - - return RotationManager; - }(); - - var MovementState = function () { - function MovementState() { - _classCallCheck(this, MovementState); - - this.left = false; - this.right = false; - this.forward = false; - this.backward = false; - this.up = false; - this.down = false; - } - - _createClass(MovementState, [{ - key: "reset", - value: function reset() { - this.left = false; - this.right = false; - this.forward = false; - this.backward = false; - this.up = false; - this.down = false; - return this; - } - }]); - - return MovementState; - }(); - - var x = new Vector3(1, 0, 0); - var y = new Vector3(0, 1, 0); - var z = new Vector3(0, 0, 1); - var v$2 = new Vector3(); - - var TranslationManager = function () { - function TranslationManager(position, quaternion, target, settings) { - _classCallCheck(this, TranslationManager); - - this.position = position; - this.quaternion = quaternion; - this.target = target; - this.settings = settings; - this.movementState = new MovementState(); - } - - _createClass(TranslationManager, [{ - key: "setPosition", - value: function setPosition(position) { - this.position = position; - return this; - } - }, { - key: "setQuaternion", - value: function setQuaternion(quaternion) { - this.quaternion = quaternion; - return this; - } - }, { - key: "setTarget", - value: function setTarget(target) { - this.target = target; - return this; - } - }, { - key: "translateOnAxis", - value: function translateOnAxis(axis, distance) { - v$2.copy(axis).applyQuaternion(this.quaternion).multiplyScalar(distance); - this.position.add(v$2); - - if (this.settings.general.orbit) { - this.target.add(v$2); - } - } - }, { - key: "translate", - value: function translate(delta) { - var sensitivity = this.settings.sensitivity; - var state = this.movementState; - var step = delta * sensitivity.translation; - - if (state.backward) { - this.translateOnAxis(z, step); - } else if (state.forward) { - this.translateOnAxis(z, -step); - } - - if (state.right) { - this.translateOnAxis(x, step); - } else if (state.left) { - this.translateOnAxis(x, -step); - } - - if (state.up) { - this.translateOnAxis(y, step); - } else if (state.down) { - this.translateOnAxis(y, -step); - } - } - }, { - key: "update", - value: function update(delta) { - if (this.settings.translation.enabled) { - this.translate(delta); - } - } - }, { - key: "moveTo", - value: function moveTo(position) { - if (this.settings.general.orbit) { - this.target.copy(position); - } else { - this.position.copy(position); - } - - return this; - } - }]); - - return TranslationManager; - }(); - - var KeyCodeHandler = { - get: function get(target, name) { - return name in target ? target[name] : name.length === 1 ? name.toUpperCase().charCodeAt(0) : undefined; - } - }; - var KeyCode = new Proxy({ - BACKSPACE: 8, - TAB: 9, - ENTER: 13, - SHIFT: 16, - CTRL: 17, - ALT: 18, - PAUSE: 19, - CAPS_LOCK: 20, - ESCAPE: 27, - SPACE: 32, - PAGE_UP: 33, - PAGE_DOWN: 34, - END: 35, - HOME: 36, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40, - INSERT: 45, - DELETE: 46, - META_LEFT: 91, - META_RIGHT: 92, - SELECT: 93, - NUMPAD_0: 96, - NUMPAD_1: 97, - NUMPAD_2: 98, - NUMPAD_3: 99, - NUMPAD_4: 100, - NUMPAD_5: 101, - NUMPAD_6: 102, - NUMPAD_7: 103, - NUMPAD_8: 104, - NUMPAD_9: 105, - MULTIPLY: 106, - ADD: 107, - SUBTRACT: 109, - DECIMAL_POINT: 110, - DIVIDE: 111, - F1: 112, - F2: 113, - F3: 114, - F4: 115, - F5: 116, - F6: 117, - F7: 118, - F8: 119, - F9: 120, - F10: 121, - F11: 122, - F12: 123, - NUM_LOCK: 144, - SCROLL_LOCK: 145, - SEMICOLON: 186, - EQUAL_SIGN: 187, - COMMA: 188, - DASH: 189, - PERIOD: 190, - FORWARD_SLASH: 191, - GRAVE_ACCENT: 192, - OPEN_BRACKET: 219, - BACK_SLASH: 220, - CLOSE_BRACKET: 221, - SINGLE_QUOTE: 222 - }, KeyCodeHandler); - - var GeneralSettings = function () { - function GeneralSettings() { - _classCallCheck(this, GeneralSettings); - - this.orbit = true; - } - - _createClass(GeneralSettings, [{ - key: "copy", - value: function copy(settings) { - this.orbit = settings.orbit; - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }]); - - return GeneralSettings; - }(); - - var KeyBindings = function () { - function KeyBindings() { - _classCallCheck(this, KeyBindings); - - this.defaultActions = new Map(); - this.actions = new Map(); - } - - _createClass(KeyBindings, [{ - key: "reset", - value: function reset() { - this.actions = new Map(this.defaultActions); - return this; - } - }, { - key: "setDefault", - value: function setDefault(actions) { - this.defaultActions = actions; - return this.reset(); - } - }, { - key: "copy", - value: function copy(keyBindings) { - this.defaultActions = new Map(keyBindings.defaultActions); - this.actions = new Map(keyBindings.actions); - return this; - } - }, { - key: "clearDefault", - value: function clearDefault() { - this.defaultActions.clear(); - return this; - } - }, { - key: "clear", - value: function clear() { - this.actions.clear(); - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }, { - key: "has", - value: function has(keyCode) { - return this.actions.has(keyCode); - } - }, { - key: "get", - value: function get(keyCode) { - return this.actions.get(keyCode); - } - }, { - key: "set", - value: function set(keyCode, action) { - this.actions.set(keyCode, action); - return this; - } - }, { - key: "delete", - value: function _delete(keyCode) { - return this.actions["delete"](keyCode); - } - }, { - key: "toJSON", - value: function toJSON() { - return { - defaultActions: _toConsumableArray(this.defaultActions), - actions: _toConsumableArray(this.actions) - }; - } - }]); - - return KeyBindings; - }(); - - var PointerSettings = function () { - function PointerSettings() { - _classCallCheck(this, PointerSettings); - - this.hold = false; - this.lock = true; - } - - _createClass(PointerSettings, [{ - key: "copy", - value: function copy(settings) { - this.hold = settings.hold; - this.lock = settings.lock; - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }]); - - return PointerSettings; - }(); - - var RotationSettings = function () { - function RotationSettings() { - _classCallCheck(this, RotationSettings); - - this.up = new Vector3(); - this.up.copy(y); - this.pivotOffset = new Vector3(); - this.minAzimuthalAngle = -Infinity; - this.maxAzimuthalAngle = Infinity; - this.minPolarAngle = 0.0; - this.maxPolarAngle = Math.PI; - this.invertX = false; - this.invertY = false; - } - - _createClass(RotationSettings, [{ - key: "copy", - value: function copy(settings) { - this.up.copy(settings.up); - this.pivotOffset.copy(settings.pivotOffset); - this.minAzimuthalAngle = settings.minAzimuthalAngle !== null ? settings.minAzimuthalAngle : -Infinity; - this.maxAzimuthalAngle = settings.maxAzimuthalAngle !== null ? settings.maxAzimuthalAngle : Infinity; - this.minPolarAngle = settings.minPolarAngle; - this.maxPolarAngle = settings.maxPolarAngle; - this.invertX = settings.invertX; - this.invertY = settings.invertY; - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }]); - - return RotationSettings; - }(); - - var SensitivitySettings = function () { - function SensitivitySettings() { - _classCallCheck(this, SensitivitySettings); - - this.rotation = 0.0025; - this.translation = 1.0; - this.zoom = 0.1; - } - - _createClass(SensitivitySettings, [{ - key: "copy", - value: function copy(settings) { - this.rotation = settings.rotation; - this.translation = settings.translation; - this.zoom = settings.zoom; - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }]); - - return SensitivitySettings; - }(); - - var TranslationSettings = function () { - function TranslationSettings() { - _classCallCheck(this, TranslationSettings); - - this.enabled = true; - } - - _createClass(TranslationSettings, [{ - key: "copy", - value: function copy(settings) { - this.enabled = settings.enabled; - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }]); - - return TranslationSettings; - }(); - - var ZoomSettings = function () { - function ZoomSettings() { - _classCallCheck(this, ZoomSettings); - - this.enabled = true; - this.invert = false; - this.minDistance = 1e-6; - this.maxDistance = Infinity; - } - - _createClass(ZoomSettings, [{ - key: "copy", - value: function copy(settings) { - this.enabled = settings.enabled; - this.invert = settings.invert; - this.minDistance = settings.minDistance; - this.maxDistance = settings.maxDistance; - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }]); - - return ZoomSettings; - }(); - - var Settings = function () { - function Settings() { - _classCallCheck(this, Settings); - - this.general = new GeneralSettings(); - this.keyBindings = new KeyBindings(); - this.keyBindings.setDefault(new Map([[KeyCode.W, Action.MOVE_FORWARD], [KeyCode.UP, Action.MOVE_FORWARD], [KeyCode.A, Action.MOVE_LEFT], [KeyCode.LEFT, Action.MOVE_LEFT], [KeyCode.S, Action.MOVE_BACKWARD], [KeyCode.DOWN, Action.MOVE_BACKWARD], [KeyCode.D, Action.MOVE_RIGHT], [KeyCode.RIGHT, Action.MOVE_RIGHT], [KeyCode.X, Action.MOVE_DOWN], [KeyCode.SPACE, Action.MOVE_UP], [KeyCode.PAGE_DOWN, Action.ZOOM_OUT], [KeyCode.PAGE_UP, Action.ZOOM_IN]])); - this.pointer = new PointerSettings(); - this.rotation = new RotationSettings(); - this.sensitivity = new SensitivitySettings(); - this.translation = new TranslationSettings(); - this.zoom = new ZoomSettings(); - } - - _createClass(Settings, [{ - key: "copy", - value: function copy(settings) { - this.general.copy(settings.general); - this.keyBindings.copy(settings.keyBindings); - this.pointer.copy(settings.pointer); - this.rotation.copy(settings.rotation); - this.sensitivity.copy(settings.sensitivity); - this.translation.copy(settings.translation); - this.zoom.copy(settings.zoom); - return this; - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }, { - key: "toDataURL", - value: function toDataURL() { - return URL.createObjectURL(new Blob([JSON.stringify(this)], { - type: "text/json" - })); - } - }]); - - return Settings; - }(); - - var Strategy = function () { - function Strategy() { - _classCallCheck(this, Strategy); - } - - _createClass(Strategy, [{ - key: "execute", - value: function execute(flag) { - throw new Error("Strategy#execute method not implemented!"); - } - }]); - - return Strategy; - }(); - - var MovementStrategy = function (_Strategy) { - _inherits(MovementStrategy, _Strategy); - - function MovementStrategy(movementState, direction) { - var _this7; - - _classCallCheck(this, MovementStrategy); - - _this7 = _possibleConstructorReturn(this, _getPrototypeOf(MovementStrategy).call(this)); - _this7.movementState = movementState; - _this7.direction = direction; - return _this7; - } - - _createClass(MovementStrategy, [{ - key: "execute", - value: function execute(flag) { - var state = this.movementState; - - switch (this.direction) { - case Direction.FORWARD: - state.forward = flag; - break; - - case Direction.LEFT: - state.left = flag; - break; - - case Direction.BACKWARD: - state.backward = flag; - break; - - case Direction.RIGHT: - state.right = flag; - break; - - case Direction.DOWN: - state.down = flag; - break; - - case Direction.UP: - state.up = flag; - break; - } - } - }]); - - return MovementStrategy; - }(Strategy); - - var Direction = { - FORWARD: 0, - LEFT: 1, - BACKWARD: 2, - RIGHT: 3, - DOWN: 4, - UP: 5 - }; - - var ZoomStrategy = function (_Strategy2) { - _inherits(ZoomStrategy, _Strategy2); - - function ZoomStrategy(rotationManager, zoomIn) { - var _this8; - - _classCallCheck(this, ZoomStrategy); - - _this8 = _possibleConstructorReturn(this, _getPrototypeOf(ZoomStrategy).call(this)); - _this8.rotationManager = rotationManager; - _this8.zoomIn = zoomIn; - return _this8; - } - - _createClass(ZoomStrategy, [{ - key: "execute", - value: function execute(flag) { - if (flag) { - this.rotationManager.zoom(this.zoomIn ? -1 : 1); - } - } - }]); - - return ZoomStrategy; - }(Strategy); - - var DeltaControls = function () { - function DeltaControls() { - var position = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - var quaternion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - var dom = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.body; - - _classCallCheck(this, DeltaControls); - - this.dom = dom; - this.position = position; - this.quaternion = quaternion; - this.target = new Vector3(); - this.settings = new Settings(); - this.rotationManager = new RotationManager(position, quaternion, this.target, this.settings); - this.translationManager = new TranslationManager(position, quaternion, this.target, this.settings); - - this.strategies = function (rotationManager, translationManager) { - var state = translationManager.movementState; - return new Map([[Action.MOVE_FORWARD, new MovementStrategy(state, Direction.FORWARD)], [Action.MOVE_LEFT, new MovementStrategy(state, Direction.LEFT)], [Action.MOVE_BACKWARD, new MovementStrategy(state, Direction.BACKWARD)], [Action.MOVE_RIGHT, new MovementStrategy(state, Direction.RIGHT)], [Action.MOVE_DOWN, new MovementStrategy(state, Direction.DOWN)], [Action.MOVE_UP, new MovementStrategy(state, Direction.UP)], [Action.ZOOM_OUT, new ZoomStrategy(rotationManager, false)], [Action.ZOOM_IN, new ZoomStrategy(rotationManager, true)]]); - }(this.rotationManager, this.translationManager); - - this.lastScreenPosition = new Vector2(); - this.dragging = false; - this.enabled = false; - - if (position !== null && quaternion !== null) { - this.lookAt(this.target); - - if (dom !== null) { - this.setEnabled(); - } - } - } - - _createClass(DeltaControls, [{ - key: "getDom", - value: function getDom() { - return this.dom; - } - }, { - key: "getPosition", - value: function getPosition() { - return this.position; - } - }, { - key: "getQuaternion", - value: function getQuaternion() { - return this.quaternion; - } - }, { - key: "getTarget", - value: function getTarget() { - var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3(); - target.copy(this.target); - - if (!this.settings.general.orbit) { - target.add(this.position); - } - - return target; - } - }, { - key: "getViewDirection", - value: function getViewDirection() { - var view = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3(); - return this.rotationManager.getViewDirection(view); - } - }, { - key: "setDom", - value: function setDom(dom) { - var enabled = this.enabled; - - if (dom !== null) { - if (enabled) { - this.setEnabled(false); - } - - this.dom = dom; - this.setEnabled(enabled); - } - - return this; - } - }, { - key: "setPosition", - value: function setPosition(position) { - this.position = position; - this.rotationManager.setPosition(position); - this.translationManager.setPosition(position); - return this.lookAt(this.target); - } - }, { - key: "setQuaternion", - value: function setQuaternion(quaternion) { - this.quaternion = quaternion; - this.rotationManager.setQuaternion(quaternion); - this.translationManager.setQuaternion(quaternion); - return this.lookAt(this.target); - } - }, { - key: "setTarget", - value: function setTarget(target) { - this.target = target; - this.rotationManager.setTarget(target); - this.translationManager.setTarget(target); - return this.lookAt(this.target); - } - }, { - key: "setOrbitEnabled", - value: function setOrbitEnabled(orbit) { - var general = this.settings.general; - - if (general.orbit !== orbit) { - this.getTarget(this.target); - general.orbit = orbit; - this.lookAt(this.target); - } - - return this; - } - }, { - key: "copy", - value: function copy(controls) { - this.dom = controls.getDom(); - this.position = controls.getPosition(); - this.quaternion = controls.getQuaternion(); - this.target = controls.getTarget(); - this.settings.copy(controls.settings); - this.rotationManager.setPosition(this.position).setQuaternion(this.quaternion).setTarget(this.target); - this.translationManager.setPosition(this.position).setQuaternion(this.quaternion).setTarget(this.target); - return this.lookAt(this.target); - } - }, { - key: "clone", - value: function clone() { - return new this.constructor().copy(this); - } - }, { - key: "handlePointerMoveEvent", - value: function handlePointerMoveEvent(event) { - var settings = this.settings; - var pointer = settings.pointer; - var sensitivity = settings.sensitivity; - var rotationManager = this.rotationManager; - var lastScreenPosition = this.lastScreenPosition; - var movementX, movementY; - - if (document.pointerLockElement === this.dom) { - if (!pointer.hold || this.dragging) { - rotationManager.adjustSpherical(event.movementX * sensitivity.rotation, event.movementY * sensitivity.rotation).updateQuaternion(); - } - } else { - movementX = event.screenX - lastScreenPosition.x; - movementY = event.screenY - lastScreenPosition.y; - lastScreenPosition.set(event.screenX, event.screenY); - rotationManager.adjustSpherical(movementX * sensitivity.rotation, movementY * sensitivity.rotation).updateQuaternion(); - } - } - }, { - key: "handleTouchMoveEvent", - value: function handleTouchMoveEvent(event) { - var sensitivity = this.settings.sensitivity; - var rotationManager = this.rotationManager; - var lastScreenPosition = this.lastScreenPosition; - var touch = event.touches[0]; - var movementX = touch.screenX - lastScreenPosition.x; - var movementY = touch.screenY - lastScreenPosition.y; - lastScreenPosition.set(touch.screenX, touch.screenY); - event.preventDefault(); - rotationManager.adjustSpherical(movementX * sensitivity.rotation, movementY * sensitivity.rotation).updateQuaternion(); - } - }, { - key: "handleMainPointerButton", - value: function handleMainPointerButton(event, pressed) { - this.dragging = pressed; - - if (this.settings.pointer.lock) { - this.setPointerLocked(); - } else { - if (pressed) { - this.lastScreenPosition.set(event.screenX, event.screenY); - this.dom.addEventListener("mousemove", this); - } else { - this.dom.removeEventListener("mousemove", this); - } - } - } - }, { - key: "handleAuxiliaryPointerButton", - value: function handleAuxiliaryPointerButton(event, pressed) {} - }, { - key: "handleSecondaryPointerButton", - value: function handleSecondaryPointerButton(event, pressed) {} - }, { - key: "handlePointerButtonEvent", - value: function handlePointerButtonEvent(event, pressed) { - event.preventDefault(); - - switch (event.button) { - case PointerButton.MAIN: - this.handleMainPointerButton(event, pressed); - break; - - case PointerButton.AUXILIARY: - this.handleAuxiliaryPointerButton(event, pressed); - break; - - case PointerButton.SECONDARY: - this.handleSecondaryPointerButton(event, pressed); - break; - } - } - }, { - key: "handleTouchEvent", - value: function handleTouchEvent(event, start) { - var touch = event.touches[0]; - event.preventDefault(); - - if (start) { - this.lastScreenPosition.set(touch.screenX, touch.screenY); - this.dom.addEventListener("touchmove", this); - } else { - this.dom.removeEventListener("touchmove", this); - } - } - }, { - key: "handleKeyboardEvent", - value: function handleKeyboardEvent(event, pressed) { - var keyBindings = this.settings.keyBindings; - - if (keyBindings.has(event.keyCode)) { - event.preventDefault(); - this.strategies.get(keyBindings.get(event.keyCode)).execute(pressed); - } - } - }, { - key: "handleWheelEvent", - value: function handleWheelEvent(event) { - this.rotationManager.zoom(Math.sign(event.deltaY)); - } - }, { - key: "handlePointerLockEvent", - value: function handlePointerLockEvent() { - if (document.pointerLockElement === this.dom) { - this.dom.addEventListener("mousemove", this); - } else { - this.dom.removeEventListener("mousemove", this); - } - } - }, { - key: "handleEvent", - value: function handleEvent(event) { - switch (event.type) { - case "mousemove": - this.handlePointerMoveEvent(event); - break; - - case "touchmove": - this.handleTouchMoveEvent(event); - break; - - case "mousedown": - this.handlePointerButtonEvent(event, true); - break; - - case "mouseup": - this.handlePointerButtonEvent(event, false); - break; - - case "touchstart": - this.handleTouchEvent(event, true); - break; - - case "touchend": - this.handleTouchEvent(event, false); - break; - - case "keydown": - this.handleKeyboardEvent(event, true); - break; - - case "keyup": - this.handleKeyboardEvent(event, false); - break; - - case "wheel": - this.handleWheelEvent(event); - break; - - case "pointerlockchange": - this.handlePointerLockEvent(); - break; - } - } - }, { - key: "update", - value: function update(delta) { - this.rotationManager.update(delta); - this.translationManager.update(delta); - } - }, { - key: "moveTo", - value: function moveTo(position) { - this.rotationManager.moveTo(position); - return this; - } - }, { - key: "lookAt", - value: function lookAt(point) { - this.rotationManager.lookAt(point); - return this; - } - }, { - key: "setPointerLocked", - value: function setPointerLocked() { - var locked = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; - - if (locked) { - if (document.pointerLockElement !== this.dom && this.dom.requestPointerLock !== undefined) { - this.dom.requestPointerLock(); - } - } else if (document.exitPointerLock !== undefined) { - document.exitPointerLock(); - } - } - }, { - key: "setEnabled", - value: function setEnabled() { - var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; - var dom = this.dom; - this.translationManager.movementState.reset(); - - if (enabled && !this.enabled) { - document.addEventListener("pointerlockchange", this); - document.body.addEventListener("keyup", this); - document.body.addEventListener("keydown", this); - dom.addEventListener("mousedown", this); - dom.addEventListener("mouseup", this); - dom.addEventListener("touchstart", this); - dom.addEventListener("touchend", this); - dom.addEventListener("wheel", this); - } else if (!enabled && this.enabled) { - document.removeEventListener("pointerlockchange", this); - document.body.removeEventListener("keyup", this); - document.body.removeEventListener("keydown", this); - dom.removeEventListener("mousedown", this); - dom.removeEventListener("mouseup", this); - dom.removeEventListener("touchstart", this); - dom.removeEventListener("touchend", this); - dom.removeEventListener("wheel", this); - dom.removeEventListener("mousemove", this); - dom.removeEventListener("touchmove", this); - } - - this.setPointerLocked(false); - this.enabled = enabled; - return this; - } - }, { - key: "dispose", - value: function dispose() { - this.setEnabled(false); - } - }]); - - return DeltaControls; - }(); - - var edges = [new Uint8Array([0, 4]), new Uint8Array([1, 5]), new Uint8Array([2, 6]), new Uint8Array([3, 7]), new Uint8Array([0, 2]), new Uint8Array([1, 3]), new Uint8Array([4, 6]), new Uint8Array([5, 7]), new Uint8Array([0, 1]), new Uint8Array([2, 3]), new Uint8Array([4, 5]), new Uint8Array([6, 7])]; - var layout = [new Uint8Array([0, 0, 0]), new Uint8Array([0, 0, 1]), new Uint8Array([0, 1, 0]), new Uint8Array([0, 1, 1]), new Uint8Array([1, 0, 0]), new Uint8Array([1, 0, 1]), new Uint8Array([1, 1, 0]), new Uint8Array([1, 1, 1])]; - - var OctreeHelper = function (_Group) { - _inherits(OctreeHelper, _Group); - - function OctreeHelper() { - var _this9; - - var octree = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - - _classCallCheck(this, OctreeHelper); - - _this9 = _possibleConstructorReturn(this, _getPrototypeOf(OctreeHelper).call(this)); - _this9.name = "OctreeHelper"; - _this9.octree = octree; - - _this9.update(); - - return _this9; - } - - _createClass(OctreeHelper, [{ - key: "createLineSegments", - value: function createLineSegments(octants, octantCount) { - var maxOctants = Math.pow(2, 16) / 8 - 1; - var group = new three.Group(); - var material = new three.LineBasicMaterial({ - color: 0xffffff * Math.random() - }); - var result; - var vertexCount; - var length; - var indices, positions; - var octant, min, max; - var geometry; - var i, j, c, d, n; - var corner, edge; - - for (i = 0, length = 0, n = Math.ceil(octantCount / maxOctants); n > 0; --n) { - length += octantCount < maxOctants ? octantCount : maxOctants; - octantCount -= maxOctants; - vertexCount = length * 8; - indices = new Uint16Array(vertexCount * 3); - positions = new Float32Array(vertexCount * 3); - - for (c = 0, d = 0, result = octants.next(); !result.done && i < length;) { - octant = result.value; - min = octant.min; - max = octant.max; - - for (j = 0; j < 12; ++j) { - edge = edges[j]; - indices[d++] = c + edge[0]; - indices[d++] = c + edge[1]; - } - - for (j = 0; j < 8; ++j, ++c) { - corner = layout[j]; - positions[c * 3] = corner[0] === 0 ? min.x : max.x; - positions[c * 3 + 1] = corner[1] === 0 ? min.y : max.y; - positions[c * 3 + 2] = corner[2] === 0 ? min.z : max.z; - } - - if (++i < length) { - result = octants.next(); - } - } - - geometry = new three.BufferGeometry(); - geometry.setIndex(new three.BufferAttribute(indices, 1)); - geometry.setAttribute("position", new three.BufferAttribute(positions, 3)); - group.add(new three.LineSegments(geometry, material)); - } - - this.add(group); - } - }, { - key: "update", - value: function update() { - var depth = this.octree !== null ? this.octree.getDepth() : -1; - var level = 0; - var result; - this.dispose(); - - while (level <= depth) { - result = this.octree.findNodesByLevel(level); - this.createLineSegments(result[Symbol.iterator](), typeof result.size === "number" ? result.size : result.length); - ++level; - } - } - }, { - key: "dispose", - value: function dispose() { - var groups = this.children; - var group, children; - var i, j, il, jl; - - for (i = 0, il = groups.length; i < il; ++i) { - group = groups[i]; - children = group.children; - - for (j = 0, jl = children.length; j < jl; ++j) { - children[j].geometry.dispose(); - children[j].material.dispose(); - } - - while (children.length > 0) { - group.remove(children[0]); - } - } - - while (groups.length > 0) { - this.remove(groups[0]); - } - } - }]); - - return OctreeHelper; - }(three.Group); - - var layout$1 = [new Uint8Array([0, 0, 0]), new Uint8Array([0, 0, 1]), new Uint8Array([0, 1, 0]), new Uint8Array([0, 1, 1]), new Uint8Array([1, 0, 0]), new Uint8Array([1, 0, 1]), new Uint8Array([1, 1, 0]), new Uint8Array([1, 1, 1])]; - var c$1 = new Vector3(); - - var Octant = function () { - function Octant() { - var min = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Vector3(); - var max = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Vector3(); - - _classCallCheck(this, Octant); - - this.min = min; - this.max = max; - this.children = null; - } - - _createClass(Octant, [{ - key: "getCenter", - value: function getCenter(target) { - return target.addVectors(this.min, this.max).multiplyScalar(0.5); - } - }, { - key: "getDimensions", - value: function getDimensions(target) { - return target.subVectors(this.max, this.min); - } - }, { - key: "split", - value: function split() { - var min = this.min; - var max = this.max; - var mid = this.getCenter(c$1); - var children = this.children = [null, null, null, null, null, null, null, null]; - var i, combination; - - for (i = 0; i < 8; ++i) { - combination = layout$1[i]; - children[i] = new this.constructor(new Vector3(combination[0] === 0 ? min.x : mid.x, combination[1] === 0 ? min.y : mid.y, combination[2] === 0 ? min.z : mid.z), new Vector3(combination[0] === 0 ? mid.x : max.x, combination[1] === 0 ? mid.y : max.y, combination[2] === 0 ? mid.z : max.z)); - } - } - }]); - - return Octant; - }(); - - var RayPointIntersection = function RayPointIntersection(distance, distanceToRay, point) { - var object = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; - - _classCallCheck(this, RayPointIntersection); - - this.distance = distance; - this.distanceToRay = distanceToRay; - this.point = point; - this.object = object; - }; - - function testPoints(octants, raycaster, intersects) { - var threshold = raycaster.params.Points.threshold; - var thresholdSq = threshold * threshold; - var intersectPoint; - var distance, distanceToRay; - var rayPointDistanceSq; - var i, j, il, jl; - var octant, points, point; - - for (i = 0, il = octants.length; i < il; ++i) { - octant = octants[i]; - points = octant.points; - - if (points !== null) { - for (j = 0, jl = points.length; j < jl; ++j) { - point = points[j]; - rayPointDistanceSq = raycaster.ray.distanceSqToPoint(point); - - if (rayPointDistanceSq < thresholdSq) { - intersectPoint = raycaster.ray.closestPointToPoint(point, new Vector3()); - distance = raycaster.ray.origin.distanceTo(intersectPoint); - - if (distance >= raycaster.near && distance <= raycaster.far) { - distanceToRay = Math.sqrt(rayPointDistanceSq); - intersects.push(new RayPointIntersection(distance, distanceToRay, intersectPoint, octant.data[j])); - } - } - } - } - } - } - - var Flags = function Flags() { - _classCallCheck(this, Flags); - - this.value = 0; - }; - - function findEntryOctant(tx0, ty0, tz0, txm, tym, tzm) { - var entry = 0; - - if (tx0 > ty0 && tx0 > tz0) { - if (tym < tx0) { - entry |= 2; - } - - if (tzm < tx0) { - entry |= 1; - } - } else if (ty0 > tz0) { - if (txm < ty0) { - entry |= 4; - } - - if (tzm < ty0) { - entry |= 1; - } - } else { - if (txm < tz0) { - entry |= 4; - } - - if (tym < tz0) { - entry |= 2; - } - } - - return entry; - } - - var octantTable = [new Uint8Array([4, 2, 1]), new Uint8Array([5, 3, 8]), new Uint8Array([6, 8, 3]), new Uint8Array([7, 8, 8]), new Uint8Array([8, 6, 5]), new Uint8Array([8, 7, 8]), new Uint8Array([8, 8, 7]), new Uint8Array([8, 8, 8])]; - - function findNextOctant(currentOctant, tx1, ty1, tz1) { - var min; - var exit = 0; - - if (tx1 < ty1) { - min = tx1; - exit = 0; - } else { - min = ty1; - exit = 1; - } - - if (tz1 < min) { - exit = 2; - } - - return octantTable[currentOctant][exit]; - } - - var v$3 = new Vector3(); - var b = new Box3(); - var d = new Box3(); - var r = new Ray(); - - function _intersectOctree(octree, ray, flags) { - var min = b.min.set(0, 0, 0); - var max = b.max.subVectors(octree.max, octree.min); - var dimensions = octree.getDimensions(d.min); - var halfDimensions = d.max.copy(dimensions).multiplyScalar(0.5); - var origin = r.origin.copy(ray.origin); - var direction = r.direction.copy(ray.direction); - var invDirX, invDirY, invDirZ; - var tx0, tx1, ty0, ty1, tz0, tz1; - origin.sub(octree.getCenter(v$3)).add(halfDimensions); - flags.value = 0; - - if (direction.x < 0.0) { - origin.x = dimensions.x - origin.x; - direction.x = -direction.x; - flags.value |= 4; - } - - if (direction.y < 0.0) { - origin.y = dimensions.y - origin.y; - direction.y = -direction.y; - flags.value |= 2; - } - - if (direction.z < 0.0) { - origin.z = dimensions.z - origin.z; - direction.z = -direction.z; - flags.value |= 1; - } - - invDirX = 1.0 / direction.x; - invDirY = 1.0 / direction.y; - invDirZ = 1.0 / direction.z; - tx0 = (min.x - origin.x) * invDirX; - tx1 = (max.x - origin.x) * invDirX; - ty0 = (min.y - origin.y) * invDirY; - ty1 = (max.y - origin.y) * invDirY; - tz0 = (min.z - origin.z) * invDirZ; - tz1 = (max.z - origin.z) * invDirZ; - return Math.max(Math.max(tx0, ty0), tz0) < Math.min(Math.min(tx1, ty1), tz1) ? [tx0, ty0, tz0, tx1, ty1, tz1] : null; - } - - var flags = new Flags(); - - function raycastOctant(octant, tx0, ty0, tz0, tx1, ty1, tz1, intersects) { - if (tx1 >= 0.0 && ty1 >= 0.0 && tz1 >= 0.0) { - var children = octant.children; - - if (children === null) { - intersects.push(octant); - } else { - var txm = 0.5 * (tx0 + tx1); - var tym = 0.5 * (ty0 + ty1); - var tzm = 0.5 * (tz0 + tz1); - var f = flags.value; - var currentOctant = findEntryOctant(tx0, ty0, tz0, txm, tym, tzm); - - do { - switch (currentOctant) { - case 0: - raycastOctant(children[f], tx0, ty0, tz0, txm, tym, tzm, intersects); - currentOctant = findNextOctant(currentOctant, txm, tym, tzm); - break; - - case 1: - raycastOctant(children[f ^ 1], tx0, ty0, tzm, txm, tym, tz1, intersects); - currentOctant = findNextOctant(currentOctant, txm, tym, tz1); - break; - - case 2: - raycastOctant(children[f ^ 2], tx0, tym, tz0, txm, ty1, tzm, intersects); - currentOctant = findNextOctant(currentOctant, txm, ty1, tzm); - break; - - case 3: - raycastOctant(children[f ^ 3], tx0, tym, tzm, txm, ty1, tz1, intersects); - currentOctant = findNextOctant(currentOctant, txm, ty1, tz1); - break; - - case 4: - raycastOctant(children[f ^ 4], txm, ty0, tz0, tx1, tym, tzm, intersects); - currentOctant = findNextOctant(currentOctant, tx1, tym, tzm); - break; - - case 5: - raycastOctant(children[f ^ 5], txm, ty0, tzm, tx1, tym, tz1, intersects); - currentOctant = findNextOctant(currentOctant, tx1, tym, tz1); - break; - - case 6: - raycastOctant(children[f ^ 6], txm, tym, tz0, tx1, ty1, tzm, intersects); - currentOctant = findNextOctant(currentOctant, tx1, ty1, tzm); - break; - - case 7: - raycastOctant(children[f ^ 7], txm, tym, tzm, tx1, ty1, tz1, intersects); - currentOctant = 8; - break; - } - } while (currentOctant < 8); - } - } - } - - var OctreeRaycaster = function () { - function OctreeRaycaster() { - _classCallCheck(this, OctreeRaycaster); - } - - _createClass(OctreeRaycaster, null, [{ - key: "intersectOctree", - value: function intersectOctree(octree, ray) { - var intersects = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; - - var parameters = _intersectOctree(octree, ray, flags); - - if (parameters !== null) { - raycastOctant.apply(void 0, [octree.root].concat(_toConsumableArray(parameters), [intersects])); - } - } - }]); - - return OctreeRaycaster; - }(); - - var IteratorResult = function () { - function IteratorResult() { - var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; - var done = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; - - _classCallCheck(this, IteratorResult); - - this.value = value; - this.done = done; - } - - _createClass(IteratorResult, [{ - key: "reset", - value: function reset() { - this.value = null; - this.done = false; - } - }]); - - return IteratorResult; - }(); - - var b$1 = new Box3(); - - var OctreeIterator = function () { - function OctreeIterator(octree) { - var region = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; - - _classCallCheck(this, OctreeIterator); - - this.octree = octree; - this.region = region; - this.cull = region !== null; - this.result = new IteratorResult(); - this.trace = null; - this.indices = null; - this.reset(); - } - - _createClass(OctreeIterator, [{ - key: "reset", - value: function reset() { - var root = this.octree.root; - this.trace = []; - this.indices = []; - - if (root !== null) { - b$1.min = root.min; - b$1.max = root.max; - - if (!this.cull || this.region.intersectsBox(b$1)) { - this.trace.push(root); - this.indices.push(0); - } - } - - this.result.reset(); - return this; - } - }, { - key: "next", - value: function next() { - var cull = this.cull; - var region = this.region; - var indices = this.indices; - var trace = this.trace; - var octant = null; - var depth = trace.length - 1; - var index, children, child; - - while (octant === null && depth >= 0) { - index = indices[depth]++; - children = trace[depth].children; - - if (index < 8) { - if (children !== null) { - child = children[index]; - - if (cull) { - b$1.min = child.min; - b$1.max = child.max; - - if (!region.intersectsBox(b$1)) { - continue; - } - } - - trace.push(child); - indices.push(0); - ++depth; - } else { - octant = trace.pop(); - indices.pop(); - } - } else { - trace.pop(); - indices.pop(); - --depth; - } - } - - this.result.value = octant; - this.result.done = octant === null; - return this.result; - } - }, { - key: "return", - value: function _return(value) { - this.result.value = value; - this.result.done = true; - return this.result; - } - }, { - key: Symbol.iterator, - value: function value() { - return this; - } - }]); - - return OctreeIterator; - }(); - - var b$3 = new Box3(); - - function _getDepth(octant) { - var children = octant.children; - var result = 0; - var i, l, d; - - if (children !== null) { - for (i = 0, l = children.length; i < l; ++i) { - d = 1 + _getDepth(children[i]); - - if (d > result) { - result = d; - } - } - } - - return result; - } - - function _cull(octant, region, result) { - var children = octant.children; - var i, l; - b$3.min = octant.min; - b$3.max = octant.max; - - if (region.intersectsBox(b$3)) { - if (children !== null) { - for (i = 0, l = children.length; i < l; ++i) { - _cull(children[i], region, result); - } - } else { - result.push(octant); - } - } - } - - function _findNodesByLevel(octant, level, depth, result) { - var children = octant.children; - var i, l; - - if (depth === level) { - result.push(octant); - } else if (children !== null) { - ++depth; - - for (i = 0, l = children.length; i < l; ++i) { - _findNodesByLevel(children[i], level, depth, result); - } - } - } - - var Octree = function () { - function Octree(root) { - _classCallCheck(this, Octree); - - this.root = root; - } - - _createClass(Octree, [{ - key: "getCenter", - value: function getCenter(target) { - return this.root.getCenter(target); - } - }, { - key: "getDimensions", - value: function getDimensions(target) { - return this.root.getDimensions(target); - } - }, { - key: "cull", - value: function cull(region) { - var result = []; - - _cull(this.root, region, result); - - return result; - } - }, { - key: "getDepth", - value: function getDepth() { - return _getDepth(this.root); - } - }, { - key: "findNodesByLevel", - value: function findNodesByLevel(level) { - var result = []; - - _findNodesByLevel(this.root, level, 0, result); - - return result; - } - }, { - key: "raycast", - value: function raycast(raycaster) { - var intersects = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; - OctreeRaycaster.intersectOctree(this, raycaster.ray, intersects); - return intersects; - } - }, { - key: "leaves", - value: function leaves(region) { - return new OctreeIterator(this, region); - } - }, { - key: Symbol.iterator, - value: function value() { - return new OctreeIterator(this); - } - }, { - key: "min", - get: function get() { - return this.root.min; - } - }, { - key: "max", - get: function get() { - return this.root.max; - } - }, { - key: "children", - get: function get() { - return this.root.children; - } - }]); - - return Octree; - }(); - - var p = new Vector3(); - - var PointOctant = function (_Octant) { - _inherits(PointOctant, _Octant); - - function PointOctant(min, max) { - var _this10; - - _classCallCheck(this, PointOctant); - - _this10 = _possibleConstructorReturn(this, _getPrototypeOf(PointOctant).call(this, min, max)); - _this10.points = null; - _this10.data = null; - return _this10; - } - - _createClass(PointOctant, [{ - key: "distanceToSquared", - value: function distanceToSquared(point) { - var clampedPoint = p.copy(point).clamp(this.min, this.max); - return clampedPoint.sub(point).lengthSquared(); - } - }, { - key: "distanceToCenterSquared", - value: function distanceToCenterSquared(point) { - var center = this.getCenter(p); - var dx = point.x - center.x; - var dy = point.y - center.x; - var dz = point.z - center.z; - return dx * dx + dy * dy + dz * dz; - } - }, { - key: "contains", - value: function contains(point, bias) { - var min = this.min; - var max = this.max; - return point.x >= min.x - bias && point.y >= min.y - bias && point.z >= min.z - bias && point.x <= max.x + bias && point.y <= max.y + bias && point.z <= max.z + bias; - } - }, { - key: "redistribute", - value: function redistribute(bias) { - var children = this.children; - var points = this.points; - var data = this.data; - var i, j, il, jl; - var child, point, entry; - - if (children !== null && points !== null) { - for (i = 0, il = points.length; i < il; ++i) { - point = points[i]; - entry = data[i]; - - for (j = 0, jl = children.length; j < jl; ++j) { - child = children[j]; - - if (child.contains(point, bias)) { - if (child.points === null) { - child.points = []; - child.data = []; - } - - child.points.push(point); - child.data.push(entry); - break; - } - } - } - - this.points = null; - this.data = null; - } - } - }, { - key: "merge", - value: function merge() { - var children = this.children; - - if (children !== null) { - var _points = []; - var data = []; - var i, l, child; - - for (i = 0, l = children.length; i < l; ++i) { - child = children[i]; - - if (child.points !== null) { - _points = _points.concat(child.points); - data = data.concat(child.data); - } - } - - this.children = null; - this.points = _points; - this.data = data; - } - } - }]); - - return PointOctant; - }(Octant); - - function _countPoints(octant) { - var children = octant.children; - var result = 0; - var i, l; - - if (children !== null) { - for (i = 0, l = children.length; i < l; ++i) { - result += _countPoints(children[i]); - } - } else if (octant.points !== null) { - result = octant.points.length; - } - - return result; - } - - function _insert(point, data, octree, octant, depth) { - var children = octant.children; - var exists = false; - var done = false; - var i, l; - - if (octant.contains(point, octree.bias)) { - if (children === null) { - if (octant.points === null) { - octant.points = []; - octant.data = []; - } else { - for (i = 0, l = octant.points.length; !exists && i < l; ++i) { - exists = octant.points[i].equals(point); - } - } - - if (exists) { - octant.data[i - 1] = data; - done = true; - } else if (octant.points.length < octree.maxPoints || depth === octree.maxDepth) { - octant.points.push(point.clone()); - octant.data.push(data); - ++octree.pointCount; - done = true; - } else { - octant.split(); - octant.redistribute(octree.bias); - children = octant.children; - } - } - - if (children !== null) { - ++depth; - - for (i = 0, l = children.length; !done && i < l; ++i) { - done = _insert(point, data, octree, children[i], depth); - } - } - } - - return done; - } - - function _remove(point, octree, octant, parent) { - var children = octant.children; - var result = null; - var i, l; - var points, data, last; - - if (octant.contains(point, octree.bias)) { - if (children !== null) { - for (i = 0, l = children.length; result === null && i < l; ++i) { - result = _remove(point, octree, children[i], octant); - } - } else if (octant.points !== null) { - points = octant.points; - data = octant.data; - - for (i = 0, l = points.length; i < l; ++i) { - if (points[i].equals(point)) { - last = l - 1; - result = data[i]; - - if (i < last) { - points[i] = points[last]; - data[i] = data[last]; - } - - points.pop(); - data.pop(); - --octree.pointCount; - - if (parent !== null && _countPoints(parent) <= octree.maxPoints) { - parent.merge(); - } - - break; - } - } - } - } - - return result; - } - - function get$1(point, octree, octant) { - var children = octant.children; - var result = null; - var i, l; - var points; - - if (octant.contains(point, octree.bias)) { - if (children !== null) { - for (i = 0, l = children.length; result === null && i < l; ++i) { - result = get$1(point, octree, children[i]); - } - } else if (octant.points !== null) { - points = octant.points; - - for (i = 0, l = points.length; result === null && i < l; ++i) { - if (point.equals(points[i])) { - result = octant.data[i]; - } - } - } - } - - return result; - } - - function _move(point, position, octree, octant, parent, depth) { - var children = octant.children; - var result = null; - var i, l; - var points; - - if (octant.contains(point, octree.bias)) { - if (octant.contains(position, octree.bias)) { - if (children !== null) { - ++depth; - - for (i = 0, l = children.length; result === null && i < l; ++i) { - result = _move(point, position, octree, children[i], octant, depth); - } - } else if (octant.points !== null) { - points = octant.points; - - for (i = 0, l = points.length; i < l; ++i) { - if (point.equals(points[i])) { - points[i].copy(position); - result = octant.data[i]; - break; - } - } - } - } else { - result = _remove(point, octree, octant, parent); - - _insert(position, result, octree, parent, depth - 1); - } - } - - return result; - } - - function _findNearestPoint(point, maxDistance, skipSelf, octant) { - var result = null; - var bestDistance = maxDistance; - var i, l; - - if (octant.children !== null) { - var sortedChildren = octant.children.map(function (child) { - return { - octant: child, - distance: child.distanceToCenterSquared(point) - }; - }).sort(function (a, b) { - return a.distance - b.distance; - }); - var child, intermediateResult; - - for (i = 0, l = sortedChildren.length; i < l; ++i) { - child = sortedChildren[i].octant; - - if (child.contains(point, bestDistance)) { - intermediateResult = _findNearestPoint(point, bestDistance, skipSelf, child); - - if (intermediateResult !== null) { - bestDistance = intermediateResult.distance; - result = intermediateResult; - - if (bestDistance === 0.0) { - break; - } - } - } - } - } else if (octant.points !== null) { - var _points2 = octant.points; - var index = -1; - var distance; - - for (i = 0, l = _points2.length; i < l; ++i) { - if (_points2[i].equals(point)) { - if (!skipSelf) { - bestDistance = 0.0; - index = i; - break; - } - } else { - distance = point.distanceTo(_points2[i]); - - if (distance < bestDistance) { - bestDistance = distance; - index = i; - } - } - } - - if (index >= 0) { - result = { - point: _points2[index], - data: octant.data[index], - distance: bestDistance - }; - } - } - - return result; - } - - function _findPoints(point, radius, skipSelf, octant, result) { - var children = octant.children; - var i, l; - - if (children !== null) { - var child; - - for (i = 0, l = children.length; i < l; ++i) { - child = children[i]; - - if (child.contains(point, radius)) { - _findPoints(point, radius, skipSelf, child, result); - } - } - } else if (octant.points !== null) { - var _points3 = octant.points; - var rSq = radius * radius; - - var _p; - - for (i = 0, l = _points3.length; i < l; ++i) { - _p = _points3[i]; - - if (_p.equals(point)) { - if (!skipSelf) { - result.push({ - point: _p.clone(), - data: octant.data[i] - }); - } - } else if (_p.distanceToSquared(point) <= rSq) { - result.push({ - point: _p.clone(), - data: octant.data[i] - }); - } - } - } - } - - var PointOctree = function (_Octree) { - _inherits(PointOctree, _Octree); - - function PointOctree(min, max) { - var _this11; - - var bias = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.0; - var maxPoints = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 8; - var maxDepth = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 8; - - _classCallCheck(this, PointOctree); - - _this11 = _possibleConstructorReturn(this, _getPrototypeOf(PointOctree).call(this, new PointOctant(min, max))); - _this11.bias = Math.max(0.0, bias); - _this11.maxPoints = Math.max(1, Math.round(maxPoints)); - _this11.maxDepth = Math.max(0, Math.round(maxDepth)); - _this11.pointCount = 0; - return _this11; - } - - _createClass(PointOctree, [{ - key: "countPoints", - value: function countPoints(octant) { - return _countPoints(octant); - } - }, { - key: "insert", - value: function insert(point, data) { - return _insert(point, data, this, this.root, 0); - } - }, { - key: "remove", - value: function remove(point) { - return _remove(point, this, this.root, null); - } - }, { - key: "get", - value: function get(point) { - return get$1(point, this, this.root); - } - }, { - key: "move", - value: function move(point, position) { - return _move(point, position, this, this.root, null, 0); - } - }, { - key: "findNearestPoint", - value: function findNearestPoint(point) { - var maxDistance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity; - var skipSelf = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - - var result = _findNearestPoint(point, maxDistance, skipSelf, this.root); - - if (result !== null) { - result.point = result.point.clone(); - } - - return result; - } - }, { - key: "findPoints", - value: function findPoints(point, radius) { - var skipSelf = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; - var result = []; - - _findPoints(point, radius, skipSelf, this.root, result); - - return result; - } - }, { - key: "raycast", - value: function raycast(raycaster) { - var intersects = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; - - var octants = _get(_getPrototypeOf(PointOctree.prototype), "raycast", this).call(this, raycaster); - - if (octants.length > 0) { - testPoints(octants, raycaster, intersects); - } - - return intersects; - } - }]); - - return PointOctree; - }(Octree); - - var mouse = new three.Vector2(); - - var OctreeRaycaster$1 = function (_Raycaster) { - _inherits(OctreeRaycaster$1, _Raycaster); - - function OctreeRaycaster$1(octree, camera, object) { - var _this12; - - _classCallCheck(this, OctreeRaycaster$1); - - _this12 = _possibleConstructorReturn(this, _getPrototypeOf(OctreeRaycaster$1).call(this)); - _this12.params.Points.threshold = 1e-1; - _this12.octree = octree; - _this12.camera = camera; - _this12.object = object; - _this12.enabled = true; - _this12.delta = ""; - _this12.selectedObject = null; - _this12.selectedPoint = new three.Mesh(new three.SphereBufferGeometry(0.2, 16, 16), new three.MeshBasicMaterial({ - transparent: true, - color: 0x00ccff, - opacity: 0.75 - })); - _this12.selectedPoint.visible = false; - return _this12; - } - - _createClass(OctreeRaycaster$1, [{ - key: "handleEvent", - value: function handleEvent(event) { - switch (event.type) { - case "mousemove": - this.raycast(event); - break; - } - } - }, { - key: "raycast", - value: function raycast(event) { - var intersects; - var t0, t, x; - mouse.x = event.clientX / window.innerWidth * 2 - 1; - mouse.y = -(event.clientY / window.innerHeight) * 2 + 1; - this.setFromCamera(mouse, this.camera); - - if (this.enabled) { - t0 = performance.now(); - intersects = this.octree.raycast(this); - t = performance.now(); - } else { - t0 = performance.now(); - intersects = this.intersectObjects(this.object.children); - t = performance.now(); - } - - this.delta = (t - t0).toFixed(2) + " ms"; - - if (this.selectedObject !== null) { - this.selectedObject.material.color.setHex(0xc00000); - this.selectedObject = null; - this.selectedPoint.visible = false; - } - - if (intersects.length > 0) { - x = intersects[0]; - - if (x.object !== undefined) { - this.selectedObject = x.object; - this.selectedObject.material.color.setHex(0xccff00); - this.selectedPoint.visible = x.object.parent.visible; - this.selectedPoint.position.copy(x.point); - } else { - console.warn(intersects); - } - } - } - }, { - key: "registerOptions", - value: function registerOptions(menu) { - var folder = menu.addFolder("Raycasting"); - folder.add(this, "enabled"); - folder.add(this, "delta").listen(); - folder.open(); - } - }]); - - return OctreeRaycaster$1; - }(three.Raycaster); - - var matrix4 = new three.Matrix4(); - var frustum = new three.Frustum(); - - var FrustumCuller = function () { - function FrustumCuller(octree, scene) { - _classCallCheck(this, FrustumCuller); - - this.octree = octree; - this.scene = scene; - this.enabled = false; - this.cullCamera = new three.PerspectiveCamera(20, 1.77, 0.5, 5); - this.s = new three.Spherical(5, Math.PI / 3, Math.PI * 1.75); - this.delta = ""; - this.culledOctants = new three.Points(new three.BufferGeometry(), new three.PointsMaterial({ - color: 0xccff00, - sizeAttenuation: false, - size: 2 - })); - this.culledOctants.visible = false; - this.cameraHelper = new three.CameraHelper(this.cullCamera); - this.cameraHelper.visible = false; - } - - _createClass(FrustumCuller, [{ - key: "updateCamera", - value: function updateCamera() { - var cullCamera = this.cullCamera; - cullCamera.position.setFromSpherical(this.s); - cullCamera.lookAt(this.scene.position); - cullCamera.updateMatrixWorld(true); - frustum.setFromMatrix(matrix4.multiplyMatrices(cullCamera.projectionMatrix, cullCamera.matrixWorldInverse)); - } - }, { - key: "cull", - value: function cull() { - var culledOctants = this.culledOctants; - var t0; - var i, j, l; - var octant, octants; - var positions; - - if (this.enabled) { - this.updateCamera(); - t0 = performance.now(); - octants = this.octree.cull(frustum); - this.delta = (performance.now() - t0).toFixed(2) + " ms"; - - if (octants.length > 0) { - positions = new Float32Array(octants.length * 3 * 2); - - for (i = 0, j = 0, l = octants.length; i < l; ++i) { - octant = octants[i]; - positions[j++] = octant.min.x; - positions[j++] = octant.min.y; - positions[j++] = octant.min.z; - positions[j++] = octant.max.x; - positions[j++] = octant.max.y; - positions[j++] = octant.max.z; - } - - culledOctants.geometry.removeAttribute("position"); - culledOctants.geometry.addAttribute("position", new three.BufferAttribute(positions, 3)); - this.scene.remove(culledOctants); - this.scene.add(culledOctants); - } else { - this.scene.remove(culledOctants); - } - } - } - }, { - key: "registerOptions", - value: function registerOptions(menu) { - var _this13 = this; - - var folder = menu.addFolder("Frustum Culling"); - folder.add(this, "enabled").onChange(function () { - _this13.cameraHelper.visible = _this13.culledOctants.visible = _this13.enabled; - - _this13.cull(); - }); - folder.add(this, "delta").listen(); - folder.open(); - var subFolder = folder.addFolder("Camera Adjustment"); - subFolder.add(this.s, "radius").min(0.1).max(10.0).step(0.1).onChange(function () { - _this13.cull(); - }); - subFolder.add(this.s, "phi").min(1e-6).max(Math.PI - 1e-6).onChange(function () { - _this13.cull(); - }); - subFolder.add(this.s, "theta").min(0.0).max(Math.PI * 2.0).onChange(function () { - _this13.cull(); - }); - } - }]); - - return FrustumCuller; - }(); - - var PointOctreeDemo = function (_Demo) { - _inherits(PointOctreeDemo, _Demo); - - function PointOctreeDemo() { - var _this14; - - _classCallCheck(this, PointOctreeDemo); - - _this14 = _possibleConstructorReturn(this, _getPrototypeOf(PointOctreeDemo).call(this, "point-octree")); - _this14.points = null; - _this14.octreeHelper = null; - _this14.octreeRaycaster = null; - _this14.frustumCuller = null; - return _this14; - } - - _createClass(PointOctreeDemo, [{ - key: "initialize", - value: function initialize() { - var scene = this.scene; - var renderer = this.renderer; - var camera = new three.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 0.3, 2000); - camera.position.set(10, 6, 10); - this.camera = camera; - var controls = new DeltaControls(camera.position, camera.quaternion, renderer.domElement); - controls.settings.pointer.lock = false; - controls.settings.zoom.maxDistance = 60.0; - controls.settings.sensitivity.translation = 10.0; - controls.settings.sensitivity.zoom = 1.0; - controls.lookAt(scene.position); - this.controls = controls; - camera.updateMatrixWorld(); - scene.fog = new three.FogExp2(0x0d0d0d, 0.025); - renderer.setClearColor(scene.fog.color); - - var points = function generatePoints() { - function createPlaneGeometry(particles, n, zBase, zBias) { - var geometry = new three.BufferGeometry(); - var positions = new Float32Array(particles * 3); - var n2 = n / 2; - var x, y, z, i, l; - - for (i = 0, l = positions.length; i < l; i += 3) { - x = Math.random() * n - n2; - y = Math.random() * n - n2; - z = zBase + (Math.random() * zBias * 2 - zBias); - positions[i] = x; - positions[i + 1] = y; - positions[i + 2] = z; - } - - geometry.addAttribute("position", new three.BufferAttribute(positions, 3)); - return geometry; - } - - var points = new three.Object3D(); - var w = 256; - var h = 256; - var d = 8; - var size = 6; - var zStep = size / (d - 1); - var z = size * -0.5; - var p; - var material = new three.PointsMaterial({ - color: 0xc00000, - sizeAttenuation: false, - size: 1 - }); - console.log("Generating", w * h * d, "points..."); - - while (d-- > 0) { - p = new three.Points(createPlaneGeometry(w * h, size, z, 0.25), material); - material = material.clone(); - z += zStep; - points.add(p); - } - - return points; - }(); - - this.points = points; - scene.add(points); - - var octree = function createOctree(points) { - var v = new three.Vector3(); - var bbox = new three.Box3(); - bbox.setFromObject(scene); - var t0 = performance.now(); - var d, p, i, l; - var array; - var octree = new PointOctree(bbox.min, bbox.max, 0.0, 8, 5); - - for (d = points.children.length - 1; d >= 0; --d) { - p = points.children[d]; - array = p.geometry.getAttribute("position").array; - - for (i = 0, l = array.length; i < l; i += 3) { - octree.insert(v.fromArray(array, i), p); - } - } - - console.log("Octree:", octree, "created in", (performance.now() - t0).toFixed(2) + " ms"); - return octree; - }(points); - - var octreeHelper = function createOctreeHelper(octree) { - var t0 = performance.now(); - var octreeHelper = new OctreeHelper(octree); - octreeHelper.visible = false; - console.log("OctreeHelper:", octreeHelper, "created in", (performance.now() - t0).toFixed(2) + " ms"); - return octreeHelper; - }(octree); - - this.octreeHelper = octreeHelper; - scene.add(octreeHelper); - this.raycaster = new OctreeRaycaster$1(octree, camera, points); - renderer.domElement.addEventListener("mousemove", this.raycaster); - scene.add(this.raycaster.selectedPoint); - this.frustumCuller = new FrustumCuller(octree, scene); - scene.add(this.frustumCuller.cameraHelper); - } - }, { - key: "render", - value: function render(delta) { - this.controls.update(delta); - - _get(_getPrototypeOf(PointOctreeDemo.prototype), "render", this).call(this, delta); - } - }, { - key: "registerOptions", - value: function registerOptions(menu) { - var points = this.points; - var octreeHelper = this.octreeHelper; - this.raycaster.registerOptions(menu); - this.frustumCuller.registerOptions(menu); - var params = { - "level mask": octreeHelper.children.length - }; - var folder = menu.addFolder("Points"); - folder.add(points, "visible"); - folder.open(); - folder = menu.addFolder("Octree Helper"); - folder.add(octreeHelper, "visible"); - folder.add(params, "level mask").min(0).max(octreeHelper.children.length).step(1).onChange(function () { - var i, l; - - for (i = 0, l = octreeHelper.children.length; i < l; ++i) { - octreeHelper.children[i].visible = params["level mask"] === octreeHelper.children.length || i === params["level mask"]; - } - }); - folder.open(); - } - }, { - key: "reset", - value: function reset() { - _get(_getPrototypeOf(PointOctreeDemo.prototype), "reset", this).call(this); - - this.renderer.domElement.removeEventListener("mousemove", this.raycaster); - return this; - } - }]); - - return PointOctreeDemo; - }(Demo); - - var manager; - - function render(now) { - requestAnimationFrame(render); - manager.render(now); - } - - function onChange(event) { - document.getElementById("viewport").children[0].style.display = "initial"; - } - - function onLoad(event) { - document.getElementById("viewport").children[0].style.display = "none"; - } - - window.addEventListener("load", function main(event) { - var viewport = document.getElementById("viewport"); - var renderer = new three.WebGLRenderer({ - antialias: true - }); - renderer.setSize(viewport.clientWidth, viewport.clientHeight); - renderer.setPixelRatio(window.devicePixelRatio); - renderer.setClearColor(0x000000); - manager = new DemoManager(viewport, { - aside: document.getElementById("aside"), - renderer: renderer - }); - manager.addEventListener("change", onChange); - manager.addEventListener("load", onLoad); - var demo = new PointOctreeDemo(); - - if (demo.id !== window.location.hash.slice(1)) { - window.location.hash = ""; - } - - manager.addDemo(demo); - render(); - }); - window.addEventListener("resize", function () { - var timeoutId = 0; - - function handleResize(event) { - var width = event.target.innerWidth; - var height = event.target.innerHeight; - manager.setSize(width, height); - timeoutId = 0; - } - - return function onResize(event) { - if (timeoutId === 0) { - timeoutId = setTimeout(handleResize, 66, event); - } - }; - }()); - document.addEventListener("keydown", function onKeyDown(event) { - var aside = this.getElementById("aside"); - - if (event.altKey && aside !== null) { - event.preventDefault(); - aside.style.visibility = aside.style.visibility === "hidden" ? "visible" : "hidden"; - } - }); - -}(THREE)); + } + + if ( 'name' in Function.prototype === false ) { + + // Missing in IE + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name + + Object.defineProperty( Function.prototype, 'name', { + + get: function () { + + return this.toString().match( /^\s*function\s*([^\(\s]*)/ )[ 1 ]; + + } + + } ); + + } + + if ( Object.assign === undefined ) { + + // Missing in IE + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign + + Object.assign = function ( target ) { + var arguments$1 = arguments; + + + if ( target === undefined || target === null ) { + + throw new TypeError( 'Cannot convert undefined or null to object' ); + + } + + var output = Object( target ); + + for ( var index = 1; index < arguments.length; index ++ ) { + + var source = arguments$1[ index ]; + + if ( source !== undefined && source !== null ) { + + for ( var nextKey in source ) { + + if ( Object.prototype.hasOwnProperty.call( source, nextKey ) ) { + + output[ nextKey ] = source[ nextKey ]; + + } + + } + + } + + } + + return output; + + }; + + } + + var REVISION = '119'; + var CullFaceNone = 0; + var CullFaceBack = 1; + var CullFaceFront = 2; + var PCFShadowMap = 1; + var PCFSoftShadowMap = 2; + var VSMShadowMap = 3; + var FrontSide = 0; + var BackSide = 1; + var DoubleSide = 2; + var FlatShading = 1; + var NoBlending = 0; + var NormalBlending = 1; + var AdditiveBlending = 2; + var SubtractiveBlending = 3; + var MultiplyBlending = 4; + var CustomBlending = 5; + var AddEquation = 100; + var SubtractEquation = 101; + var ReverseSubtractEquation = 102; + var MinEquation = 103; + var MaxEquation = 104; + var ZeroFactor = 200; + var OneFactor = 201; + var SrcColorFactor = 202; + var OneMinusSrcColorFactor = 203; + var SrcAlphaFactor = 204; + var OneMinusSrcAlphaFactor = 205; + var DstAlphaFactor = 206; + var OneMinusDstAlphaFactor = 207; + var DstColorFactor = 208; + var OneMinusDstColorFactor = 209; + var SrcAlphaSaturateFactor = 210; + var NeverDepth = 0; + var AlwaysDepth = 1; + var LessDepth = 2; + var LessEqualDepth = 3; + var EqualDepth = 4; + var GreaterEqualDepth = 5; + var GreaterDepth = 6; + var NotEqualDepth = 7; + var MultiplyOperation = 0; + var MixOperation = 1; + var AddOperation = 2; + var NoToneMapping = 0; + var LinearToneMapping = 1; + var ReinhardToneMapping = 2; + var CineonToneMapping = 3; + var ACESFilmicToneMapping = 4; + var CustomToneMapping = 5; + + var UVMapping = 300; + var CubeReflectionMapping = 301; + var CubeRefractionMapping = 302; + var EquirectangularReflectionMapping = 303; + var EquirectangularRefractionMapping = 304; + var CubeUVReflectionMapping = 306; + var CubeUVRefractionMapping = 307; + var RepeatWrapping = 1000; + var ClampToEdgeWrapping = 1001; + var MirroredRepeatWrapping = 1002; + var NearestFilter = 1003; + var NearestMipmapNearestFilter = 1004; + var NearestMipmapLinearFilter = 1005; + var LinearFilter = 1006; + var LinearMipmapNearestFilter = 1007; + var LinearMipmapLinearFilter = 1008; + var UnsignedByteType = 1009; + var ByteType = 1010; + var ShortType = 1011; + var UnsignedShortType = 1012; + var IntType = 1013; + var UnsignedIntType = 1014; + var FloatType = 1015; + var HalfFloatType = 1016; + var UnsignedShort4444Type = 1017; + var UnsignedShort5551Type = 1018; + var UnsignedShort565Type = 1019; + var UnsignedInt248Type = 1020; + var AlphaFormat = 1021; + var RGBFormat = 1022; + var RGBAFormat = 1023; + var LuminanceFormat = 1024; + var LuminanceAlphaFormat = 1025; + var DepthFormat = 1026; + var DepthStencilFormat = 1027; + var RedFormat = 1028; + var RedIntegerFormat = 1029; + var RGFormat = 1030; + var RGIntegerFormat = 1031; + var RGBIntegerFormat = 1032; + var RGBAIntegerFormat = 1033; + + var RGB_S3TC_DXT1_Format = 33776; + var RGBA_S3TC_DXT1_Format = 33777; + var RGBA_S3TC_DXT3_Format = 33778; + var RGBA_S3TC_DXT5_Format = 33779; + var RGB_PVRTC_4BPPV1_Format = 35840; + var RGB_PVRTC_2BPPV1_Format = 35841; + var RGBA_PVRTC_4BPPV1_Format = 35842; + var RGBA_PVRTC_2BPPV1_Format = 35843; + var RGB_ETC1_Format = 36196; + var RGB_ETC2_Format = 37492; + var RGBA_ETC2_EAC_Format = 37496; + var RGBA_ASTC_4x4_Format = 37808; + var RGBA_ASTC_5x4_Format = 37809; + var RGBA_ASTC_5x5_Format = 37810; + var RGBA_ASTC_6x5_Format = 37811; + var RGBA_ASTC_6x6_Format = 37812; + var RGBA_ASTC_8x5_Format = 37813; + var RGBA_ASTC_8x6_Format = 37814; + var RGBA_ASTC_8x8_Format = 37815; + var RGBA_ASTC_10x5_Format = 37816; + var RGBA_ASTC_10x6_Format = 37817; + var RGBA_ASTC_10x8_Format = 37818; + var RGBA_ASTC_10x10_Format = 37819; + var RGBA_ASTC_12x10_Format = 37820; + var RGBA_ASTC_12x12_Format = 37821; + var RGBA_BPTC_Format = 36492; + var SRGB8_ALPHA8_ASTC_4x4_Format = 37840; + var SRGB8_ALPHA8_ASTC_5x4_Format = 37841; + var SRGB8_ALPHA8_ASTC_5x5_Format = 37842; + var SRGB8_ALPHA8_ASTC_6x5_Format = 37843; + var SRGB8_ALPHA8_ASTC_6x6_Format = 37844; + var SRGB8_ALPHA8_ASTC_8x5_Format = 37845; + var SRGB8_ALPHA8_ASTC_8x6_Format = 37846; + var SRGB8_ALPHA8_ASTC_8x8_Format = 37847; + var SRGB8_ALPHA8_ASTC_10x5_Format = 37848; + var SRGB8_ALPHA8_ASTC_10x6_Format = 37849; + var SRGB8_ALPHA8_ASTC_10x8_Format = 37850; + var SRGB8_ALPHA8_ASTC_10x10_Format = 37851; + var SRGB8_ALPHA8_ASTC_12x10_Format = 37852; + var SRGB8_ALPHA8_ASTC_12x12_Format = 37853; + var LoopOnce = 2200; + var LoopRepeat = 2201; + var LoopPingPong = 2202; + var InterpolateDiscrete = 2300; + var InterpolateLinear = 2301; + var InterpolateSmooth = 2302; + var ZeroCurvatureEnding = 2400; + var ZeroSlopeEnding = 2401; + var WrapAroundEnding = 2402; + var NormalAnimationBlendMode = 2500; + var AdditiveAnimationBlendMode = 2501; + var TrianglesDrawMode = 0; + var LinearEncoding = 3000; + var sRGBEncoding = 3001; + var GammaEncoding = 3007; + var RGBEEncoding = 3002; + var LogLuvEncoding = 3003; + var RGBM7Encoding = 3004; + var RGBM16Encoding = 3005; + var RGBDEncoding = 3006; + var BasicDepthPacking = 3200; + var RGBADepthPacking = 3201; + var TangentSpaceNormalMap = 0; + var ObjectSpaceNormalMap = 1; + var KeepStencilOp = 7680; + var AlwaysStencilFunc = 519; + + var StaticDrawUsage = 35044; + var DynamicDrawUsage = 35048; + + /** + * https://github.com/mrdoob/eventdispatcher.js/ + */ + + function EventDispatcher() {} + + Object.assign( EventDispatcher.prototype, { + + addEventListener: function ( type, listener ) { + + if ( this._listeners === undefined ) { this._listeners = {}; } + + var listeners = this._listeners; + + if ( listeners[ type ] === undefined ) { + + listeners[ type ] = []; + + } + + if ( listeners[ type ].indexOf( listener ) === - 1 ) { + + listeners[ type ].push( listener ); + + } + + }, + + hasEventListener: function ( type, listener ) { + + if ( this._listeners === undefined ) { return false; } + + var listeners = this._listeners; + + return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1; + + }, + + removeEventListener: function ( type, listener ) { + + if ( this._listeners === undefined ) { return; } + + var listeners = this._listeners; + var listenerArray = listeners[ type ]; + + if ( listenerArray !== undefined ) { + + var index = listenerArray.indexOf( listener ); + + if ( index !== - 1 ) { + + listenerArray.splice( index, 1 ); + + } + + } + + }, + + dispatchEvent: function ( event ) { + + if ( this._listeners === undefined ) { return; } + + var listeners = this._listeners; + var listenerArray = listeners[ event.type ]; + + if ( listenerArray !== undefined ) { + + event.target = this; + + // Make a copy, in case listeners are removed while iterating. + var array = listenerArray.slice( 0 ); + + for ( var i = 0, l = array.length; i < l; i ++ ) { + + array[ i ].call( this, event ); + + } + + } + + } + + } ); + + var _lut = []; + + for ( var i = 0; i < 256; i ++ ) { + + _lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 ); + + } + + var _seed = 1234567; + + var MathUtils = { + + DEG2RAD: Math.PI / 180, + RAD2DEG: 180 / Math.PI, + + generateUUID: function () { + + // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136 + + var d0 = Math.random() * 0xffffffff | 0; + var d1 = Math.random() * 0xffffffff | 0; + var d2 = Math.random() * 0xffffffff | 0; + var d3 = Math.random() * 0xffffffff | 0; + 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. + return uuid.toUpperCase(); + + }, + + clamp: function ( value, min, max ) { + + return Math.max( min, Math.min( max, value ) ); + + }, + + // compute euclidian modulo of m % n + // https://en.wikipedia.org/wiki/Modulo_operation + + euclideanModulo: function ( n, m ) { + + return ( ( n % m ) + m ) % m; + + }, + + // Linear mapping from range to range + + mapLinear: function ( x, a1, a2, b1, b2 ) { + + return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 ); + + }, + + // https://en.wikipedia.org/wiki/Linear_interpolation + + lerp: function ( x, y, t ) { + + return ( 1 - t ) * x + t * y; + + }, + + // http://en.wikipedia.org/wiki/Smoothstep + + smoothstep: function ( x, min, max ) { + + if ( x <= min ) { return 0; } + if ( x >= max ) { return 1; } + + x = ( x - min ) / ( max - min ); + + return x * x * ( 3 - 2 * x ); + + }, + + smootherstep: function ( x, min, max ) { + + if ( x <= min ) { return 0; } + if ( x >= max ) { return 1; } + + x = ( x - min ) / ( max - min ); + + return x * x * x * ( x * ( x * 6 - 15 ) + 10 ); + + }, + + // Random integer from interval + + randInt: function ( low, high ) { + + return low + Math.floor( Math.random() * ( high - low + 1 ) ); + + }, + + // Random float from interval + + randFloat: function ( low, high ) { + + return low + Math.random() * ( high - low ); + + }, + + // Random float from <-range/2, range/2> interval + + randFloatSpread: function ( range ) { + + return range * ( 0.5 - Math.random() ); + + }, + + // Deterministic pseudo-random float in the interval [ 0, 1 ] + + seededRandom: function ( s ) { + + if ( s !== undefined ) { _seed = s % 2147483647; } + + // Park-Miller algorithm + + _seed = _seed * 16807 % 2147483647; + + return ( _seed - 1 ) / 2147483646; + + }, + + degToRad: function ( degrees ) { + + return degrees * MathUtils.DEG2RAD; + + }, + + radToDeg: function ( radians ) { + + return radians * MathUtils.RAD2DEG; + + }, + + isPowerOfTwo: function ( value ) { + + return ( value & ( value - 1 ) ) === 0 && value !== 0; + + }, + + ceilPowerOfTwo: function ( value ) { + + return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) ); + + }, + + floorPowerOfTwo: function ( value ) { + + return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) ); + + }, + + setQuaternionFromProperEuler: function ( q, a, b, c, order ) { + + // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles + + // rotations are applied to the axes in the order specified by 'order' + // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c' + // angles are in radians + + var cos = Math.cos; + var sin = Math.sin; + + var c2 = cos( b / 2 ); + var s2 = sin( b / 2 ); + + var c13 = cos( ( a + c ) / 2 ); + var s13 = sin( ( a + c ) / 2 ); + + var c1_3 = cos( ( a - c ) / 2 ); + var s1_3 = sin( ( a - c ) / 2 ); + + var c3_1 = cos( ( c - a ) / 2 ); + var s3_1 = sin( ( c - a ) / 2 ); + + switch ( order ) { + + case 'XYX': + q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 ); + break; + + case 'YZY': + q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 ); + break; + + case 'ZXZ': + q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 ); + break; + + case 'XZX': + q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 ); + break; + + case 'YXY': + q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 ); + break; + + case 'ZYZ': + q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 ); + break; + + default: + console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order ); + + } + + } + + }; + + function Vector2( x, y ) { + if ( x === void 0 ) x = 0; + if ( y === void 0 ) y = 0; + + + this.x = x; + this.y = y; + + } + + Object.defineProperties( Vector2.prototype, { + + "width": { + + get: function () { + + return this.x; + + }, + + set: function ( value ) { + + this.x = value; + + } + + }, + + "height": { + + get: function () { + + return this.y; + + }, + + set: function ( value ) { + + this.y = value; + + } + + } + + } ); + + Object.assign( Vector2.prototype, { + + isVector2: true, + + set: function ( x, y ) { + + this.x = x; + this.y = y; + + return this; + + }, + + setScalar: function ( scalar ) { + + this.x = scalar; + this.y = scalar; + + return this; + + }, + + setX: function ( x ) { + + this.x = x; + + return this; + + }, + + setY: function ( y ) { + + this.y = y; + + return this; + + }, + + setComponent: function ( index, value ) { + + switch ( index ) { + + case 0: this.x = value; break; + case 1: this.y = value; break; + default: throw new Error( 'index is out of range: ' + index ); + + } + + return this; + + }, + + getComponent: function ( index ) { + + switch ( index ) { + + case 0: return this.x; + case 1: return this.y; + default: throw new Error( 'index is out of range: ' + index ); + + } + + }, + + clone: function () { + + return new this.constructor( this.x, this.y ); + + }, + + copy: function ( v ) { + + this.x = v.x; + this.y = v.y; + + return this; + + }, + + add: function ( v, w ) { + + if ( w !== undefined ) { + + console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' ); + return this.addVectors( v, w ); + + } + + this.x += v.x; + this.y += v.y; + + return this; + + }, + + addScalar: function ( s ) { + + this.x += s; + this.y += s; + + return this; + + }, + + addVectors: function ( a, b ) { + + this.x = a.x + b.x; + this.y = a.y + b.y; + + return this; + + }, + + addScaledVector: function ( v, s ) { + + this.x += v.x * s; + this.y += v.y * s; + + return this; + + }, + + sub: function ( v, w ) { + + if ( w !== undefined ) { + + console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' ); + return this.subVectors( v, w ); + + } + + this.x -= v.x; + this.y -= v.y; + + return this; + + }, + + subScalar: function ( s ) { + + this.x -= s; + this.y -= s; + + return this; + + }, + + subVectors: function ( a, b ) { + + this.x = a.x - b.x; + this.y = a.y - b.y; + + return this; + + }, + + multiply: function ( v ) { + + this.x *= v.x; + this.y *= v.y; + + return this; + + }, + + multiplyScalar: function ( scalar ) { + + this.x *= scalar; + this.y *= scalar; + + return this; + + }, + + divide: function ( v ) { + + this.x /= v.x; + this.y /= v.y; + + return this; + + }, + + divideScalar: function ( scalar ) { + + return this.multiplyScalar( 1 / scalar ); + + }, + + applyMatrix3: function ( m ) { + + var x = this.x, y = this.y; + var e = m.elements; + + this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ]; + this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ]; + + return this; + + }, + + min: function ( v ) { + + this.x = Math.min( this.x, v.x ); + this.y = Math.min( this.y, v.y ); + + return this; + + }, + + max: function ( v ) { + + this.x = Math.max( this.x, v.x ); + this.y = Math.max( this.y, v.y ); + + return this; + + }, + + clamp: function ( min, max ) { + + // assumes min < max, componentwise + + this.x = Math.max( min.x, Math.min( max.x, this.x ) ); + this.y = Math.max( min.y, Math.min( max.y, this.y ) ); + + return this; + + }, + + clampScalar: function ( minVal, maxVal ) { + + this.x = Math.max( minVal, Math.min( maxVal, this.x ) ); + this.y = Math.max( minVal, Math.min( maxVal, this.y ) ); + + return this; + + }, + + clampLength: function ( min, max ) { + + var length = this.length(); + + return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) ); + + }, + + floor: function () { + + this.x = Math.floor( this.x ); + this.y = Math.floor( this.y ); + + return this; + + }, + + ceil: function () { + + this.x = Math.ceil( this.x ); + this.y = Math.ceil( this.y ); + + return this; + + }, + + round: function () { + + this.x = Math.round( this.x ); + this.y = Math.round( this.y ); + + return this; + + }, + + roundToZero: function () { + + this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x ); + this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y ); + + return this; + + }, + + negate: function () { + + this.x = - this.x; + this.y = - this.y; + + return this; + + }, + + dot: function ( v ) { + + return this.x * v.x + this.y * v.y; + + }, + + cross: function ( v ) { + + return this.x * v.y - this.y * v.x; + + }, + + lengthSq: function () { + + return this.x * this.x + this.y * this.y; + + }, + + length: function () { + + return Math.sqrt( this.x * this.x + this.y * this.y ); + + }, + + manhattanLength: function () { + + return Math.abs( this.x ) + Math.abs( this.y ); + + }, + + normalize: function () { + + return this.divideScalar( this.length() || 1 ); + + }, + + angle: function () { + + // computes the angle in radians with respect to the positive x-axis + + var angle = Math.atan2( - this.y, - this.x ) + Math.PI; + + return angle; + + }, + + distanceTo: function ( v ) { + + return Math.sqrt( this.distanceToSquared( v ) ); + + }, + + distanceToSquared: function ( v ) { + + var dx = this.x - v.x, dy = this.y - v.y; + return dx * dx + dy * dy; + + }, + + manhattanDistanceTo: function ( v ) { + + return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ); + + }, + + setLength: function ( length ) { + + return this.normalize().multiplyScalar( length ); + + }, + + lerp: function ( v, alpha ) { + + this.x += ( v.x - this.x ) * alpha; + this.y += ( v.y - this.y ) * alpha; + + return this; + + }, + + lerpVectors: function ( v1, v2, alpha ) { + + this.x = v1.x + ( v2.x - v1.x ) * alpha; + this.y = v1.y + ( v2.y - v1.y ) * alpha; + + return this; + + }, + + equals: function ( v ) { + + return ( ( v.x === this.x ) && ( v.y === this.y ) ); + + }, + + fromArray: function ( array, offset ) { + + if ( offset === undefined ) { offset = 0; } + + this.x = array[ offset ]; + this.y = array[ offset + 1 ]; + + return this; + + }, + + toArray: function ( array, offset ) { + + if ( array === undefined ) { array = []; } + if ( offset === undefined ) { offset = 0; } + + array[ offset ] = this.x; + array[ offset + 1 ] = this.y; + + return array; + + }, + + fromBufferAttribute: function ( attribute, index, offset ) { + + if ( offset !== undefined ) { + + console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' ); + + } + + this.x = attribute.getX( index ); + this.y = attribute.getY( index ); + + return this; + + }, + + rotateAround: function ( center, angle ) { + + var c = Math.cos( angle ), s = Math.sin( angle ); + + var x = this.x - center.x; + var y = this.y - center.y; + + this.x = x * c - y * s + center.x; + this.y = x * s + y * c + center.y; + + return this; + + }, + + random: function () { + + this.x = Math.random(); + this.y = Math.random(); + + return this; + + } + + } ); + + function Matrix3() { + + this.elements = [ + + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + + ]; + + if ( arguments.length > 0 ) { + + console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' ); + + } + + } + + Object.assign( Matrix3.prototype, { + + isMatrix3: true, + + set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) { + + var te = this.elements; + + te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31; + te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32; + te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33; + + return this; + + }, + + identity: function () { + + this.set( + + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + + ); + + return this; + + }, + + clone: function () { + + return new this.constructor().fromArray( this.elements ); + + }, + + copy: function ( m ) { + + var te = this.elements; + var me = m.elements; + + te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; + te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; + te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ]; + + return this; + + }, + + extractBasis: function ( xAxis, yAxis, zAxis ) { + + xAxis.setFromMatrix3Column( this, 0 ); + yAxis.setFromMatrix3Column( this, 1 ); + zAxis.setFromMatrix3Column( this, 2 ); + + return this; + + }, + + setFromMatrix4: function ( m ) { + + var me = m.elements; + + this.set( + + me[ 0 ], me[ 4 ], me[ 8 ], + me[ 1 ], me[ 5 ], me[ 9 ], + me[ 2 ], me[ 6 ], me[ 10 ] + + ); + + return this; + + }, + + multiply: function ( m ) { + + return this.multiplyMatrices( this, m ); + + }, + + premultiply: function ( m ) { + + return this.multiplyMatrices( m, this ); + + }, + + multiplyMatrices: function ( a, b ) { + + var ae = a.elements; + var be = b.elements; + var te = this.elements; + + var a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ]; + var a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ]; + var a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ]; + + var b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ]; + var b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ]; + var b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ]; + + te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31; + te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32; + te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33; + + te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31; + te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32; + te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33; + + te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31; + te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32; + te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33; + + return this; + + }, + + multiplyScalar: function ( s ) { + + var te = this.elements; + + te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s; + te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s; + te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s; + + return this; + + }, + + determinant: function () { + + var te = this.elements; + + var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ], + d = te[ 3 ], e = te[ 4 ], f = te[ 5 ], + g = te[ 6 ], h = te[ 7 ], i = te[ 8 ]; + + return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g; + + }, + + getInverse: function ( matrix, throwOnDegenerate ) { + + if ( throwOnDegenerate !== undefined ) { + + console.warn( "THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate." ); + + } + + var me = matrix.elements, + te = this.elements, + + n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], + n12 = me[ 3 ], n22 = me[ 4 ], n32 = me[ 5 ], + n13 = me[ 6 ], n23 = me[ 7 ], n33 = me[ 8 ], + + t11 = n33 * n22 - n32 * n23, + t12 = n32 * n13 - n33 * n12, + t13 = n23 * n12 - n22 * n13, + + det = n11 * t11 + n21 * t12 + n31 * t13; + + if ( det === 0 ) { return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 ); } + + var detInv = 1 / det; + + te[ 0 ] = t11 * detInv; + te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv; + te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv; + + te[ 3 ] = t12 * detInv; + te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv; + te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv; + + te[ 6 ] = t13 * detInv; + te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv; + te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv; + + return this; + + }, + + transpose: function () { + + var tmp; + var m = this.elements; + + tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp; + tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp; + tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp; + + return this; + + }, + + getNormalMatrix: function ( matrix4 ) { + + return this.setFromMatrix4( matrix4 ).getInverse( this ).transpose(); + + }, + + transposeIntoArray: function ( r ) { + + var m = this.elements; + + r[ 0 ] = m[ 0 ]; + r[ 1 ] = m[ 3 ]; + r[ 2 ] = m[ 6 ]; + r[ 3 ] = m[ 1 ]; + r[ 4 ] = m[ 4 ]; + r[ 5 ] = m[ 7 ]; + r[ 6 ] = m[ 2 ]; + r[ 7 ] = m[ 5 ]; + r[ 8 ] = m[ 8 ]; + + return this; + + }, + + setUvTransform: function ( tx, ty, sx, sy, rotation, cx, cy ) { + + var c = Math.cos( rotation ); + var s = Math.sin( rotation ); + + 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 + ); + + }, + + scale: function ( sx, sy ) { + + var te = this.elements; + + te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx; + te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy; + + return this; + + }, + + rotate: function ( theta ) { + + var c = Math.cos( theta ); + var s = Math.sin( theta ); + + var te = this.elements; + + var a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ]; + var a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ]; + + te[ 0 ] = c * a11 + s * a21; + te[ 3 ] = c * a12 + s * a22; + te[ 6 ] = c * a13 + s * a23; + + te[ 1 ] = - s * a11 + c * a21; + te[ 4 ] = - s * a12 + c * a22; + te[ 7 ] = - s * a13 + c * a23; + + return this; + + }, + + translate: function ( tx, ty ) { + + var te = this.elements; + + te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ]; + te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ]; + + return this; + + }, + + equals: function ( matrix ) { + + var te = this.elements; + var me = matrix.elements; + + for ( var i = 0; i < 9; i ++ ) { + + if ( te[ i ] !== me[ i ] ) { return false; } + + } + + return true; + + }, + + fromArray: function ( array, offset ) { + + if ( offset === undefined ) { offset = 0; } + + for ( var i = 0; i < 9; i ++ ) { + + this.elements[ i ] = array[ i + offset ]; + + } + + return this; + + }, + + toArray: function ( array, offset ) { + + if ( array === undefined ) { array = []; } + if ( offset === undefined ) { offset = 0; } + + var te = this.elements; + + array[ offset ] = te[ 0 ]; + array[ offset + 1 ] = te[ 1 ]; + array[ offset + 2 ] = te[ 2 ]; + + array[ offset + 3 ] = te[ 3 ]; + array[ offset + 4 ] = te[ 4 ]; + array[ offset + 5 ] = te[ 5 ]; + + array[ offset + 6 ] = te[ 6 ]; + array[ offset + 7 ] = te[ 7 ]; + array[ offset + 8 ] = te[ 8 ]; + + return array; + + } + + } ); + + var _canvas; + + var ImageUtils = { + + getDataURL: function ( image ) { + + if ( /^data:/i.test( image.src ) ) { + + return image.src; + + } + + if ( typeof HTMLCanvasElement == 'undefined' ) { + + return image.src; + + } + + var canvas; + + if ( image instanceof HTMLCanvasElement ) { + + canvas = image; + + } else { + + if ( _canvas === undefined ) { _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ); } + + _canvas.width = image.width; + _canvas.height = image.height; + + var context = _canvas.getContext( '2d' ); + + if ( image instanceof ImageData ) { + + context.putImageData( image, 0, 0 ); + + } else { + + context.drawImage( image, 0, 0, image.width, image.height ); + + } + + canvas = _canvas; + + } + + if ( canvas.width > 2048 || canvas.height > 2048 ) { + + return canvas.toDataURL( 'image/jpeg', 0.6 ); + + } else { + + return canvas.toDataURL( 'image/png' ); + + } + + } + + }; + + var textureId = 0; + + function Texture( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) { + + Object.defineProperty( this, 'id', { value: textureId ++ } ); + + this.uuid = MathUtils.generateUUID(); + + this.name = ''; + + this.image = image !== undefined ? image : Texture.DEFAULT_IMAGE; + this.mipmaps = []; + + this.mapping = mapping !== undefined ? mapping : Texture.DEFAULT_MAPPING; + + this.wrapS = wrapS !== undefined ? wrapS : ClampToEdgeWrapping; + this.wrapT = wrapT !== undefined ? wrapT : ClampToEdgeWrapping; + + this.magFilter = magFilter !== undefined ? magFilter : LinearFilter; + this.minFilter = minFilter !== undefined ? minFilter : LinearMipmapLinearFilter; + + this.anisotropy = anisotropy !== undefined ? anisotropy : 1; + + this.format = format !== undefined ? format : RGBAFormat; + this.internalFormat = null; + this.type = type !== undefined ? type : UnsignedByteType; + + this.offset = new Vector2( 0, 0 ); + this.repeat = new Vector2( 1, 1 ); + this.center = new Vector2( 0, 0 ); + this.rotation = 0; + + this.matrixAutoUpdate = true; + this.matrix = new Matrix3(); + + this.generateMipmaps = true; + this.premultiplyAlpha = false; + this.flipY = true; + this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml) + + // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap. + // + // Also changing the encoding after already used by a Material will not automatically make the Material + // update. You need to explicitly call Material.needsUpdate to trigger it to recompile. + this.encoding = encoding !== undefined ? encoding : LinearEncoding; + + this.version = 0; + this.onUpdate = null; + + } + + Texture.DEFAULT_IMAGE = undefined; + Texture.DEFAULT_MAPPING = UVMapping; + + Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { + + constructor: Texture, + + isTexture: true, + + updateMatrix: function () { + + this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y ); + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( source ) { + + this.name = source.name; + + this.image = source.image; + this.mipmaps = source.mipmaps.slice( 0 ); + + this.mapping = source.mapping; + + this.wrapS = source.wrapS; + this.wrapT = source.wrapT; + + this.magFilter = source.magFilter; + this.minFilter = source.minFilter; + + this.anisotropy = source.anisotropy; + + this.format = source.format; + this.internalFormat = source.internalFormat; + this.type = source.type; + + this.offset.copy( source.offset ); + this.repeat.copy( source.repeat ); + this.center.copy( source.center ); + this.rotation = source.rotation; + + this.matrixAutoUpdate = source.matrixAutoUpdate; + this.matrix.copy( source.matrix ); + + this.generateMipmaps = source.generateMipmaps; + this.premultiplyAlpha = source.premultiplyAlpha; + this.flipY = source.flipY; + this.unpackAlignment = source.unpackAlignment; + this.encoding = source.encoding; + + return this; + + }, + + toJSON: function ( meta ) { + + var isRootObject = ( meta === undefined || typeof meta === 'string' ); + + if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) { + + return meta.textures[ this.uuid ]; + + } + + var output = { + + metadata: { + version: 4.5, + type: 'Texture', + generator: 'Texture.toJSON' + }, + + uuid: this.uuid, + name: this.name, + + mapping: this.mapping, + + repeat: [ this.repeat.x, this.repeat.y ], + offset: [ this.offset.x, this.offset.y ], + center: [ this.center.x, this.center.y ], + rotation: this.rotation, + + wrap: [ this.wrapS, this.wrapT ], + + format: this.format, + type: this.type, + encoding: this.encoding, + + minFilter: this.minFilter, + magFilter: this.magFilter, + anisotropy: this.anisotropy, + + flipY: this.flipY, + + premultiplyAlpha: this.premultiplyAlpha, + unpackAlignment: this.unpackAlignment + + }; + + if ( this.image !== undefined ) { + + // TODO: Move to THREE.Image + + var image = this.image; + + if ( image.uuid === undefined ) { + + image.uuid = MathUtils.generateUUID(); // UGH + + } + + if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) { + + var url; + + if ( Array.isArray( image ) ) { + + // process array of images e.g. CubeTexture + + url = []; + + for ( var i = 0, l = image.length; i < l; i ++ ) { + + url.push( ImageUtils.getDataURL( image[ i ] ) ); + + } + + } else { + + // process single image + + url = ImageUtils.getDataURL( image ); + + } + + meta.images[ image.uuid ] = { + uuid: image.uuid, + url: url + }; + + } + + output.image = image.uuid; + + } + + if ( ! isRootObject ) { + + meta.textures[ this.uuid ] = output; + + } + + return output; + + }, + + dispose: function () { + + this.dispatchEvent( { type: 'dispose' } ); + + }, + + transformUv: function ( uv ) { + + if ( this.mapping !== UVMapping ) { return uv; } + + uv.applyMatrix3( this.matrix ); + + if ( uv.x < 0 || uv.x > 1 ) { + + switch ( this.wrapS ) { + + case RepeatWrapping: + + uv.x = uv.x - Math.floor( uv.x ); + break; + + case ClampToEdgeWrapping: + + uv.x = uv.x < 0 ? 0 : 1; + break; + + case MirroredRepeatWrapping: + + if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) { + + uv.x = Math.ceil( uv.x ) - uv.x; + + } else { + + uv.x = uv.x - Math.floor( uv.x ); + + } + + break; + + } + + } + + if ( uv.y < 0 || uv.y > 1 ) { + + switch ( this.wrapT ) { + + case RepeatWrapping: + + uv.y = uv.y - Math.floor( uv.y ); + break; + + case ClampToEdgeWrapping: + + uv.y = uv.y < 0 ? 0 : 1; + break; + + case MirroredRepeatWrapping: + + if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) { + + uv.y = Math.ceil( uv.y ) - uv.y; + + } else { + + uv.y = uv.y - Math.floor( uv.y ); + + } + + break; + + } + + } + + if ( this.flipY ) { + + uv.y = 1 - uv.y; + + } + + return uv; + + } + + } ); + + Object.defineProperty( Texture.prototype, "needsUpdate", { + + set: function ( value ) { + + if ( value === true ) { this.version ++; } + + } + + } ); + + function Vector4( x, y, z, w ) { + if ( x === void 0 ) x = 0; + if ( y === void 0 ) y = 0; + if ( z === void 0 ) z = 0; + if ( w === void 0 ) w = 1; + + + this.x = x; + this.y = y; + this.z = z; + this.w = w; + + } + + Object.defineProperties( Vector4.prototype, { + + "width": { + + get: function () { + + return this.z; + + }, + + set: function ( value ) { + + this.z = value; + + } + + }, + + "height": { + + get: function () { + + return this.w; + + }, + + set: function ( value ) { + + this.w = value; + + } + + } + + } ); + + Object.assign( Vector4.prototype, { + + isVector4: true, + + set: function ( x, y, z, w ) { + + this.x = x; + this.y = y; + this.z = z; + this.w = w; + + return this; + + }, + + setScalar: function ( scalar ) { + + this.x = scalar; + this.y = scalar; + this.z = scalar; + this.w = scalar; + + return this; + + }, + + setX: function ( x ) { + + this.x = x; + + return this; + + }, + + setY: function ( y ) { + + this.y = y; + + return this; + + }, + + setZ: function ( z ) { + + this.z = z; + + return this; + + }, + + setW: function ( w ) { + + this.w = w; + + return this; + + }, + + setComponent: function ( index, value ) { + + switch ( index ) { + + case 0: this.x = value; break; + case 1: this.y = value; break; + case 2: this.z = value; break; + case 3: this.w = value; break; + default: throw new Error( 'index is out of range: ' + index ); + + } + + return this; + + }, + + getComponent: function ( index ) { + + switch ( index ) { + + case 0: return this.x; + case 1: return this.y; + case 2: return this.z; + case 3: return this.w; + default: throw new Error( 'index is out of range: ' + index ); + + } + + }, + + clone: function () { + + return new this.constructor( this.x, this.y, this.z, this.w ); + + }, + + copy: function ( v ) { + + this.x = v.x; + this.y = v.y; + this.z = v.z; + this.w = ( v.w !== undefined ) ? v.w : 1; + + return this; + + }, + + add: function ( v, w ) { + + if ( w !== undefined ) { + + console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' ); + return this.addVectors( v, w ); + + } + + this.x += v.x; + this.y += v.y; + this.z += v.z; + this.w += v.w; + + return this; + + }, + + addScalar: function ( s ) { + + this.x += s; + this.y += s; + this.z += s; + this.w += s; + + return this; + + }, + + addVectors: function ( a, b ) { + + this.x = a.x + b.x; + this.y = a.y + b.y; + this.z = a.z + b.z; + this.w = a.w + b.w; + + return this; + + }, + + addScaledVector: function ( v, s ) { + + this.x += v.x * s; + this.y += v.y * s; + this.z += v.z * s; + this.w += v.w * s; + + return this; + + }, + + sub: function ( v, w ) { + + if ( w !== undefined ) { + + console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' ); + return this.subVectors( v, w ); + + } + + this.x -= v.x; + this.y -= v.y; + this.z -= v.z; + this.w -= v.w; + + return this; + + }, + + subScalar: function ( s ) { + + this.x -= s; + this.y -= s; + this.z -= s; + this.w -= s; + + return this; + + }, + + subVectors: function ( a, b ) { + + this.x = a.x - b.x; + this.y = a.y - b.y; + this.z = a.z - b.z; + this.w = a.w - b.w; + + return this; + + }, + + multiplyScalar: function ( scalar ) { + + this.x *= scalar; + this.y *= scalar; + this.z *= scalar; + this.w *= scalar; + + return this; + + }, + + applyMatrix4: function ( m ) { + + var x = this.x, y = this.y, z = this.z, w = this.w; + var e = m.elements; + + this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w; + this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w; + this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w; + this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w; + + return this; + + }, + + divideScalar: function ( scalar ) { + + return this.multiplyScalar( 1 / scalar ); + + }, + + setAxisAngleFromQuaternion: function ( q ) { + + // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm + + // q is assumed to be normalized + + this.w = 2 * Math.acos( q.w ); + + var s = Math.sqrt( 1 - q.w * q.w ); + + if ( s < 0.0001 ) { + + this.x = 1; + this.y = 0; + this.z = 0; + + } else { + + this.x = q.x / s; + this.y = q.y / s; + this.z = q.z / s; + + } + + return this; + + }, + + setAxisAngleFromRotationMatrix: function ( m ) { + + // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm + + // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) + + var angle, x, y, z; // variables for result + var epsilon = 0.01, // margin to allow for rounding errors + epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees + + te = m.elements, + + m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ], + m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ], + m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ]; + + if ( ( Math.abs( m12 - m21 ) < epsilon ) && + ( Math.abs( m13 - m31 ) < epsilon ) && + ( Math.abs( m23 - m32 ) < epsilon ) ) { + + // singularity found + // first check for identity matrix which must have +1 for all terms + // in leading diagonal and zero in other terms + + if ( ( Math.abs( m12 + m21 ) < epsilon2 ) && + ( Math.abs( m13 + m31 ) < epsilon2 ) && + ( Math.abs( m23 + m32 ) < epsilon2 ) && + ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) { + + // this singularity is identity matrix so angle = 0 + + this.set( 1, 0, 0, 0 ); + + return this; // zero angle, arbitrary axis + + } + + // otherwise this singularity is angle = 180 + + angle = Math.PI; + + var xx = ( m11 + 1 ) / 2; + var yy = ( m22 + 1 ) / 2; + var zz = ( m33 + 1 ) / 2; + var xy = ( m12 + m21 ) / 4; + var xz = ( m13 + m31 ) / 4; + var yz = ( m23 + m32 ) / 4; + + if ( ( xx > yy ) && ( xx > zz ) ) { + + // m11 is the largest diagonal term + + if ( xx < epsilon ) { + + x = 0; + y = 0.707106781; + z = 0.707106781; + + } else { + + x = Math.sqrt( xx ); + y = xy / x; + z = xz / x; + + } + + } else if ( yy > zz ) { + + // m22 is the largest diagonal term + + if ( yy < epsilon ) { + + x = 0.707106781; + y = 0; + z = 0.707106781; + + } else { + + y = Math.sqrt( yy ); + x = xy / y; + z = yz / y; + + } + + } else { + + // m33 is the largest diagonal term so base result on this + + if ( zz < epsilon ) { + + x = 0.707106781; + y = 0.707106781; + z = 0; + + } else { + + z = Math.sqrt( zz ); + x = xz / z; + y = yz / z; + + } + + } + + this.set( x, y, z, angle ); + + return this; // return 180 deg rotation + + } + + // as we have reached here there are no singularities so we can handle normally + + var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) + + ( m13 - m31 ) * ( m13 - m31 ) + + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize + + if ( Math.abs( s ) < 0.001 ) { s = 1; } + + // prevent divide by zero, should not happen if matrix is orthogonal and should be + // caught by singularity test above, but I've left it in just in case + + this.x = ( m32 - m23 ) / s; + this.y = ( m13 - m31 ) / s; + this.z = ( m21 - m12 ) / s; + this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 ); + + return this; + + }, + + min: function ( v ) { + + this.x = Math.min( this.x, v.x ); + this.y = Math.min( this.y, v.y ); + this.z = Math.min( this.z, v.z ); + this.w = Math.min( this.w, v.w ); + + return this; + + }, + + max: function ( v ) { + + this.x = Math.max( this.x, v.x ); + this.y = Math.max( this.y, v.y ); + this.z = Math.max( this.z, v.z ); + this.w = Math.max( this.w, v.w ); + + return this; + + }, + + clamp: function ( min, max ) { + + // assumes min < max, componentwise + + this.x = Math.max( min.x, Math.min( max.x, this.x ) ); + this.y = Math.max( min.y, Math.min( max.y, this.y ) ); + this.z = Math.max( min.z, Math.min( max.z, this.z ) ); + this.w = Math.max( min.w, Math.min( max.w, this.w ) ); + + return this; + + }, + + clampScalar: function ( minVal, maxVal ) { + + this.x = Math.max( minVal, Math.min( maxVal, this.x ) ); + this.y = Math.max( minVal, Math.min( maxVal, this.y ) ); + this.z = Math.max( minVal, Math.min( maxVal, this.z ) ); + this.w = Math.max( minVal, Math.min( maxVal, this.w ) ); + + return this; + + }, + + clampLength: function ( min, max ) { + + var length = this.length(); + + return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) ); + + }, + + floor: function () { + + this.x = Math.floor( this.x ); + this.y = Math.floor( this.y ); + this.z = Math.floor( this.z ); + this.w = Math.floor( this.w ); + + return this; + + }, + + ceil: function () { + + this.x = Math.ceil( this.x ); + this.y = Math.ceil( this.y ); + this.z = Math.ceil( this.z ); + this.w = Math.ceil( this.w ); + + return this; + + }, + + round: function () { + + this.x = Math.round( this.x ); + this.y = Math.round( this.y ); + this.z = Math.round( this.z ); + this.w = Math.round( this.w ); + + return this; + + }, + + roundToZero: function () { + + this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x ); + this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y ); + this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z ); + this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w ); + + return this; + + }, + + negate: function () { + + this.x = - this.x; + this.y = - this.y; + this.z = - this.z; + this.w = - this.w; + + return this; + + }, + + dot: function ( v ) { + + return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w; + + }, + + lengthSq: function () { + + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + + }, + + length: function () { + + return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w ); + + }, + + manhattanLength: function () { + + return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w ); + + }, + + normalize: function () { + + return this.divideScalar( this.length() || 1 ); + + }, + + setLength: function ( length ) { + + return this.normalize().multiplyScalar( length ); + + }, + + lerp: function ( v, alpha ) { + + this.x += ( v.x - this.x ) * alpha; + this.y += ( v.y - this.y ) * alpha; + this.z += ( v.z - this.z ) * alpha; + this.w += ( v.w - this.w ) * alpha; + + return this; + + }, + + lerpVectors: function ( v1, v2, alpha ) { + + this.x = v1.x + ( v2.x - v1.x ) * alpha; + this.y = v1.y + ( v2.y - v1.y ) * alpha; + this.z = v1.z + ( v2.z - v1.z ) * alpha; + this.w = v1.w + ( v2.w - v1.w ) * alpha; + + return this; + + }, + + equals: function ( v ) { + + return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) ); + + }, + + fromArray: function ( array, offset ) { + + if ( offset === undefined ) { offset = 0; } + + this.x = array[ offset ]; + this.y = array[ offset + 1 ]; + this.z = array[ offset + 2 ]; + this.w = array[ offset + 3 ]; + + return this; + + }, + + toArray: function ( array, offset ) { + + if ( array === undefined ) { array = []; } + if ( offset === undefined ) { offset = 0; } + + array[ offset ] = this.x; + array[ offset + 1 ] = this.y; + array[ offset + 2 ] = this.z; + array[ offset + 3 ] = this.w; + + return array; + + }, + + fromBufferAttribute: function ( attribute, index, offset ) { + + if ( offset !== undefined ) { + + console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' ); + + } + + this.x = attribute.getX( index ); + this.y = attribute.getY( index ); + this.z = attribute.getZ( index ); + this.w = attribute.getW( index ); + + return this; + + }, + + random: function () { + + this.x = Math.random(); + this.y = Math.random(); + this.z = Math.random(); + this.w = Math.random(); + + return this; + + } + + } ); + + /* + In options, we can specify: + * Texture parameters for an auto-generated target texture + * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers + */ + function WebGLRenderTarget( width, height, options ) { + + this.width = width; + this.height = height; + + this.scissor = new Vector4( 0, 0, width, height ); + this.scissorTest = false; + + this.viewport = new Vector4( 0, 0, width, height ); + + options = options || {}; + + this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding ); + + this.texture.image = {}; + this.texture.image.width = width; + this.texture.image.height = height; + + this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false; + this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter; + + this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true; + this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true; + this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null; + + } + + WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { + + constructor: WebGLRenderTarget, + + isWebGLRenderTarget: true, + + setSize: function ( width, height ) { + + if ( this.width !== width || this.height !== height ) { + + this.width = width; + this.height = height; + + this.texture.image.width = width; + this.texture.image.height = height; + + this.dispose(); + + } + + this.viewport.set( 0, 0, width, height ); + this.scissor.set( 0, 0, width, height ); + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( source ) { + + this.width = source.width; + this.height = source.height; + + this.viewport.copy( source.viewport ); + + this.texture = source.texture.clone(); + + this.depthBuffer = source.depthBuffer; + this.stencilBuffer = source.stencilBuffer; + this.depthTexture = source.depthTexture; + + return this; + + }, + + dispose: function () { + + this.dispatchEvent( { type: 'dispose' } ); + + } + + } ); + + function WebGLMultisampleRenderTarget( width, height, options ) { + + WebGLRenderTarget.call( this, width, height, options ); + + this.samples = 4; + + } + + WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), { + + constructor: WebGLMultisampleRenderTarget, + + isWebGLMultisampleRenderTarget: true, + + copy: function ( source ) { + + WebGLRenderTarget.prototype.copy.call( this, source ); + + this.samples = source.samples; + + return this; + + } + + } ); + + function Quaternion( x, y, z, w ) { + if ( x === void 0 ) x = 0; + if ( y === void 0 ) y = 0; + if ( z === void 0 ) z = 0; + if ( w === void 0 ) w = 1; + + + this._x = x; + this._y = y; + this._z = z; + this._w = w; + + } + + Object.assign( Quaternion, { + + slerp: function ( qa, qb, qm, t ) { + + return qm.copy( qa ).slerp( qb, t ); + + }, + + slerpFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) { + + // fuzz-free, array-based Quaternion SLERP operation + + var x0 = src0[ srcOffset0 + 0 ], + y0 = src0[ srcOffset0 + 1 ], + z0 = src0[ srcOffset0 + 2 ], + w0 = src0[ srcOffset0 + 3 ]; + + var x1 = src1[ srcOffset1 + 0 ], + y1 = src1[ srcOffset1 + 1 ], + z1 = src1[ srcOffset1 + 2 ], + w1 = src1[ srcOffset1 + 3 ]; + + if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) { + + var s = 1 - t, + + cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1, + + dir = ( cos >= 0 ? 1 : - 1 ), + sqrSin = 1 - cos * cos; + + // Skip the Slerp for tiny steps to avoid numeric problems: + if ( sqrSin > Number.EPSILON ) { + + var sin = Math.sqrt( sqrSin ), + len = Math.atan2( sin, cos * dir ); + + s = Math.sin( s * len ) / sin; + t = Math.sin( t * len ) / sin; + + } + + var tDir = t * dir; + + x0 = x0 * s + x1 * tDir; + y0 = y0 * s + y1 * tDir; + z0 = z0 * s + z1 * tDir; + w0 = w0 * s + w1 * tDir; + + // Normalize in case we just did a lerp: + if ( s === 1 - t ) { + + var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 ); + + x0 *= f; + y0 *= f; + z0 *= f; + w0 *= f; + + } + + } + + dst[ dstOffset ] = x0; + dst[ dstOffset + 1 ] = y0; + dst[ dstOffset + 2 ] = z0; + dst[ dstOffset + 3 ] = w0; + + }, + + multiplyQuaternionsFlat: function ( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) { + + var x0 = src0[ srcOffset0 ]; + var y0 = src0[ srcOffset0 + 1 ]; + var z0 = src0[ srcOffset0 + 2 ]; + var w0 = src0[ srcOffset0 + 3 ]; + + var x1 = src1[ srcOffset1 ]; + var y1 = src1[ srcOffset1 + 1 ]; + var z1 = src1[ srcOffset1 + 2 ]; + var w1 = src1[ srcOffset1 + 3 ]; + + dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1; + dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1; + dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1; + dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1; + + return dst; + + } + + } ); + + Object.defineProperties( Quaternion.prototype, { + + x: { + + get: function () { + + return this._x; + + }, + + set: function ( value ) { + + this._x = value; + this._onChangeCallback(); + + } + + }, + + y: { + + get: function () { + + return this._y; + + }, + + set: function ( value ) { + + this._y = value; + this._onChangeCallback(); + + } + + }, + + z: { + + get: function () { + + return this._z; + + }, + + set: function ( value ) { + + this._z = value; + this._onChangeCallback(); + + } + + }, + + w: { + + get: function () { + + return this._w; + + }, + + set: function ( value ) { + + this._w = value; + this._onChangeCallback(); + + } + + } + + } ); + + Object.assign( Quaternion.prototype, { + + isQuaternion: true, + + set: function ( x, y, z, w ) { + + this._x = x; + this._y = y; + this._z = z; + this._w = w; + + this._onChangeCallback(); + + return this; + + }, + + clone: function () { + + return new this.constructor( this._x, this._y, this._z, this._w ); + + }, + + copy: function ( quaternion ) { + + this._x = quaternion.x; + this._y = quaternion.y; + this._z = quaternion.z; + this._w = quaternion.w; + + this._onChangeCallback(); + + return this; + + }, + + setFromEuler: function ( euler, update ) { + + if ( ! ( euler && euler.isEuler ) ) { + + throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' ); + + } + + var x = euler._x, y = euler._y, z = euler._z, order = euler.order; + + // http://www.mathworks.com/matlabcentral/fileexchange/ + // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/ + // content/SpinCalc.m + + var cos = Math.cos; + var sin = Math.sin; + + var c1 = cos( x / 2 ); + var c2 = cos( y / 2 ); + var c3 = cos( z / 2 ); + + var s1 = sin( x / 2 ); + var s2 = sin( y / 2 ); + var s3 = sin( z / 2 ); + + switch ( order ) { + + case 'XYZ': + this._x = s1 * c2 * c3 + c1 * s2 * s3; + this._y = c1 * s2 * c3 - s1 * c2 * s3; + this._z = c1 * c2 * s3 + s1 * s2 * c3; + this._w = c1 * c2 * c3 - s1 * s2 * s3; + break; + + case 'YXZ': + this._x = s1 * c2 * c3 + c1 * s2 * s3; + this._y = c1 * s2 * c3 - s1 * c2 * s3; + this._z = c1 * c2 * s3 - s1 * s2 * c3; + this._w = c1 * c2 * c3 + s1 * s2 * s3; + break; + + case 'ZXY': + this._x = s1 * c2 * c3 - c1 * s2 * s3; + this._y = c1 * s2 * c3 + s1 * c2 * s3; + this._z = c1 * c2 * s3 + s1 * s2 * c3; + this._w = c1 * c2 * c3 - s1 * s2 * s3; + break; + + case 'ZYX': + this._x = s1 * c2 * c3 - c1 * s2 * s3; + this._y = c1 * s2 * c3 + s1 * c2 * s3; + this._z = c1 * c2 * s3 - s1 * s2 * c3; + this._w = c1 * c2 * c3 + s1 * s2 * s3; + break; + + case 'YZX': + this._x = s1 * c2 * c3 + c1 * s2 * s3; + this._y = c1 * s2 * c3 + s1 * c2 * s3; + this._z = c1 * c2 * s3 - s1 * s2 * c3; + this._w = c1 * c2 * c3 - s1 * s2 * s3; + break; + + case 'XZY': + this._x = s1 * c2 * c3 - c1 * s2 * s3; + this._y = c1 * s2 * c3 - s1 * c2 * s3; + this._z = c1 * c2 * s3 + s1 * s2 * c3; + this._w = c1 * c2 * c3 + s1 * s2 * s3; + break; + + default: + console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order ); + + } + + if ( update !== false ) { this._onChangeCallback(); } + + return this; + + }, + + setFromAxisAngle: function ( axis, angle ) { + + // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm + + // assumes axis is normalized + + var halfAngle = angle / 2, s = Math.sin( halfAngle ); + + this._x = axis.x * s; + this._y = axis.y * s; + this._z = axis.z * s; + this._w = Math.cos( halfAngle ); + + this._onChangeCallback(); + + return this; + + }, + + setFromRotationMatrix: function ( m ) { + + // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm + + // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) + + var te = m.elements, + + m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ], + m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ], + m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ], + + trace = m11 + m22 + m33; + + if ( trace > 0 ) { + + var s = 0.5 / Math.sqrt( trace + 1.0 ); + + this._w = 0.25 / s; + this._x = ( m32 - m23 ) * s; + this._y = ( m13 - m31 ) * s; + this._z = ( m21 - m12 ) * s; + + } else if ( m11 > m22 && m11 > m33 ) { + + var s$1 = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 ); + + this._w = ( m32 - m23 ) / s$1; + this._x = 0.25 * s$1; + this._y = ( m12 + m21 ) / s$1; + this._z = ( m13 + m31 ) / s$1; + + } else if ( m22 > m33 ) { + + var s$2 = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 ); + + this._w = ( m13 - m31 ) / s$2; + this._x = ( m12 + m21 ) / s$2; + this._y = 0.25 * s$2; + this._z = ( m23 + m32 ) / s$2; + + } else { + + var s$3 = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 ); + + this._w = ( m21 - m12 ) / s$3; + this._x = ( m13 + m31 ) / s$3; + this._y = ( m23 + m32 ) / s$3; + this._z = 0.25 * s$3; + + } + + this._onChangeCallback(); + + return this; + + }, + + setFromUnitVectors: function ( vFrom, vTo ) { + + // assumes direction vectors vFrom and vTo are normalized + + var EPS = 0.000001; + + var r = vFrom.dot( vTo ) + 1; + + if ( r < EPS ) { + + r = 0; + + if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) { + + this._x = - vFrom.y; + this._y = vFrom.x; + this._z = 0; + this._w = r; + + } else { + + this._x = 0; + this._y = - vFrom.z; + this._z = vFrom.y; + this._w = r; + + } + + } else { + + // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3 + + this._x = vFrom.y * vTo.z - vFrom.z * vTo.y; + this._y = vFrom.z * vTo.x - vFrom.x * vTo.z; + this._z = vFrom.x * vTo.y - vFrom.y * vTo.x; + this._w = r; + + } + + return this.normalize(); + + }, + + angleTo: function ( q ) { + + return 2 * Math.acos( Math.abs( MathUtils.clamp( this.dot( q ), - 1, 1 ) ) ); + + }, + + rotateTowards: function ( q, step ) { + + var angle = this.angleTo( q ); + + if ( angle === 0 ) { return this; } + + var t = Math.min( 1, step / angle ); + + this.slerp( q, t ); + + return this; + + }, + + identity: function () { + + return this.set( 0, 0, 0, 1 ); + + }, + + inverse: function () { + + // quaternion is assumed to have unit length + + return this.conjugate(); + + }, + + conjugate: function () { + + this._x *= - 1; + this._y *= - 1; + this._z *= - 1; + + this._onChangeCallback(); + + return this; + + }, + + dot: function ( v ) { + + return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w; + + }, + + lengthSq: function () { + + return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w; + + }, + + length: function () { + + return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w ); + + }, + + normalize: function () { + + var l = this.length(); + + if ( l === 0 ) { + + this._x = 0; + this._y = 0; + this._z = 0; + this._w = 1; + + } else { + + l = 1 / l; + + this._x = this._x * l; + this._y = this._y * l; + this._z = this._z * l; + this._w = this._w * l; + + } + + this._onChangeCallback(); + + return this; + + }, + + multiply: function ( q, p ) { + + if ( p !== undefined ) { + + console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' ); + return this.multiplyQuaternions( q, p ); + + } + + return this.multiplyQuaternions( this, q ); + + }, + + premultiply: function ( q ) { + + return this.multiplyQuaternions( q, this ); + + }, + + multiplyQuaternions: function ( a, b ) { + + // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm + + var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w; + var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w; + + this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby; + this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz; + this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx; + this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz; + + this._onChangeCallback(); + + return this; + + }, + + slerp: function ( qb, t ) { + + if ( t === 0 ) { return this; } + if ( t === 1 ) { return this.copy( qb ); } + + var x = this._x, y = this._y, z = this._z, w = this._w; + + // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/ + + var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z; + + if ( cosHalfTheta < 0 ) { + + this._w = - qb._w; + this._x = - qb._x; + this._y = - qb._y; + this._z = - qb._z; + + cosHalfTheta = - cosHalfTheta; + + } else { + + this.copy( qb ); + + } + + if ( cosHalfTheta >= 1.0 ) { + + this._w = w; + this._x = x; + this._y = y; + this._z = z; + + return this; + + } + + var sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta; + + if ( sqrSinHalfTheta <= Number.EPSILON ) { + + var s = 1 - t; + this._w = s * w + t * this._w; + this._x = s * x + t * this._x; + this._y = s * y + t * this._y; + this._z = s * z + t * this._z; + + this.normalize(); + this._onChangeCallback(); + + return this; + + } + + var sinHalfTheta = Math.sqrt( sqrSinHalfTheta ); + var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta ); + var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta, + ratioB = Math.sin( t * halfTheta ) / sinHalfTheta; + + this._w = ( w * ratioA + this._w * ratioB ); + this._x = ( x * ratioA + this._x * ratioB ); + this._y = ( y * ratioA + this._y * ratioB ); + this._z = ( z * ratioA + this._z * ratioB ); + + this._onChangeCallback(); + + return this; + + }, + + equals: function ( quaternion ) { + + return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w ); + + }, + + fromArray: function ( array, offset ) { + + if ( offset === undefined ) { offset = 0; } + + this._x = array[ offset ]; + this._y = array[ offset + 1 ]; + this._z = array[ offset + 2 ]; + this._w = array[ offset + 3 ]; + + this._onChangeCallback(); + + return this; + + }, + + toArray: function ( array, offset ) { + + if ( array === undefined ) { array = []; } + if ( offset === undefined ) { offset = 0; } + + array[ offset ] = this._x; + array[ offset + 1 ] = this._y; + array[ offset + 2 ] = this._z; + array[ offset + 3 ] = this._w; + + return array; + + }, + + fromBufferAttribute: function ( attribute, index ) { + + this._x = attribute.getX( index ); + this._y = attribute.getY( index ); + this._z = attribute.getZ( index ); + this._w = attribute.getW( index ); + + return this; + + }, + + _onChange: function ( callback ) { + + this._onChangeCallback = callback; + + return this; + + }, + + _onChangeCallback: function () {} + + } ); + + var _vector = new Vector3(); + var _quaternion = new Quaternion(); + + function Vector3( x, y, z ) { + if ( x === void 0 ) x = 0; + if ( y === void 0 ) y = 0; + if ( z === void 0 ) z = 0; + + + this.x = x; + this.y = y; + this.z = z; + + } + + Object.assign( Vector3.prototype, { + + isVector3: true, + + set: function ( x, y, z ) { + + if ( z === undefined ) { z = this.z; } // sprite.scale.set(x,y) + + this.x = x; + this.y = y; + this.z = z; + + return this; + + }, + + setScalar: function ( scalar ) { + + this.x = scalar; + this.y = scalar; + this.z = scalar; + + return this; + + }, + + setX: function ( x ) { + + this.x = x; + + return this; + + }, + + setY: function ( y ) { + + this.y = y; + + return this; + + }, + + setZ: function ( z ) { + + this.z = z; + + return this; + + }, + + setComponent: function ( index, value ) { + + switch ( index ) { + + case 0: this.x = value; break; + case 1: this.y = value; break; + case 2: this.z = value; break; + default: throw new Error( 'index is out of range: ' + index ); + + } + + return this; + + }, + + getComponent: function ( index ) { + + switch ( index ) { + + case 0: return this.x; + case 1: return this.y; + case 2: return this.z; + default: throw new Error( 'index is out of range: ' + index ); + + } + + }, + + clone: function () { + + return new this.constructor( this.x, this.y, this.z ); + + }, + + copy: function ( v ) { + + this.x = v.x; + this.y = v.y; + this.z = v.z; + + return this; + + }, + + add: function ( v, w ) { + + if ( w !== undefined ) { + + console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' ); + return this.addVectors( v, w ); + + } + + this.x += v.x; + this.y += v.y; + this.z += v.z; + + return this; + + }, + + addScalar: function ( s ) { + + this.x += s; + this.y += s; + this.z += s; + + return this; + + }, + + addVectors: function ( a, b ) { + + this.x = a.x + b.x; + this.y = a.y + b.y; + this.z = a.z + b.z; + + return this; + + }, + + addScaledVector: function ( v, s ) { + + this.x += v.x * s; + this.y += v.y * s; + this.z += v.z * s; + + return this; + + }, + + sub: function ( v, w ) { + + if ( w !== undefined ) { + + console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' ); + return this.subVectors( v, w ); + + } + + this.x -= v.x; + this.y -= v.y; + this.z -= v.z; + + return this; + + }, + + subScalar: function ( s ) { + + this.x -= s; + this.y -= s; + this.z -= s; + + return this; + + }, + + subVectors: function ( a, b ) { + + this.x = a.x - b.x; + this.y = a.y - b.y; + this.z = a.z - b.z; + + return this; + + }, + + multiply: function ( v, w ) { + + if ( w !== undefined ) { + + console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' ); + return this.multiplyVectors( v, w ); + + } + + this.x *= v.x; + this.y *= v.y; + this.z *= v.z; + + return this; + + }, + + multiplyScalar: function ( scalar ) { + + this.x *= scalar; + this.y *= scalar; + this.z *= scalar; + + return this; + + }, + + multiplyVectors: function ( a, b ) { + + this.x = a.x * b.x; + this.y = a.y * b.y; + this.z = a.z * b.z; + + return this; + + }, + + applyEuler: function ( euler ) { + + if ( ! ( euler && euler.isEuler ) ) { + + console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' ); + + } + + return this.applyQuaternion( _quaternion.setFromEuler( euler ) ); + + }, + + applyAxisAngle: function ( axis, angle ) { + + return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) ); + + }, + + applyMatrix3: function ( m ) { + + var x = this.x, y = this.y, z = this.z; + var e = m.elements; + + this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z; + this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z; + this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z; + + return this; + + }, + + applyNormalMatrix: function ( m ) { + + return this.applyMatrix3( m ).normalize(); + + }, + + applyMatrix4: function ( m ) { + + var x = this.x, y = this.y, z = this.z; + var e = m.elements; + + var w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); + + this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w; + this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w; + this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w; + + return this; + + }, + + applyQuaternion: function ( q ) { + + var x = this.x, y = this.y, z = this.z; + var qx = q.x, qy = q.y, qz = q.z, qw = q.w; + + // calculate quat * vector + + var ix = qw * x + qy * z - qz * y; + var iy = qw * y + qz * x - qx * z; + var iz = qw * z + qx * y - qy * x; + var iw = - qx * x - qy * y - qz * z; + + // calculate result * inverse quat + + this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy; + this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz; + this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx; + + return this; + + }, + + project: function ( camera ) { + + return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix ); + + }, + + unproject: function ( camera ) { + + return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld ); + + }, + + transformDirection: function ( m ) { + + // input: THREE.Matrix4 affine matrix + // vector interpreted as a direction + + var x = this.x, y = this.y, z = this.z; + var e = m.elements; + + this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z; + this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z; + this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z; + + return this.normalize(); + + }, + + divide: function ( v ) { + + this.x /= v.x; + this.y /= v.y; + this.z /= v.z; + + return this; + + }, + + divideScalar: function ( scalar ) { + + return this.multiplyScalar( 1 / scalar ); + + }, + + min: function ( v ) { + + this.x = Math.min( this.x, v.x ); + this.y = Math.min( this.y, v.y ); + this.z = Math.min( this.z, v.z ); + + return this; + + }, + + max: function ( v ) { + + this.x = Math.max( this.x, v.x ); + this.y = Math.max( this.y, v.y ); + this.z = Math.max( this.z, v.z ); + + return this; + + }, + + clamp: function ( min, max ) { + + // assumes min < max, componentwise + + this.x = Math.max( min.x, Math.min( max.x, this.x ) ); + this.y = Math.max( min.y, Math.min( max.y, this.y ) ); + this.z = Math.max( min.z, Math.min( max.z, this.z ) ); + + return this; + + }, + + clampScalar: function ( minVal, maxVal ) { + + this.x = Math.max( minVal, Math.min( maxVal, this.x ) ); + this.y = Math.max( minVal, Math.min( maxVal, this.y ) ); + this.z = Math.max( minVal, Math.min( maxVal, this.z ) ); + + return this; + + }, + + clampLength: function ( min, max ) { + + var length = this.length(); + + return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) ); + + }, + + floor: function () { + + this.x = Math.floor( this.x ); + this.y = Math.floor( this.y ); + this.z = Math.floor( this.z ); + + return this; + + }, + + ceil: function () { + + this.x = Math.ceil( this.x ); + this.y = Math.ceil( this.y ); + this.z = Math.ceil( this.z ); + + return this; + + }, + + round: function () { + + this.x = Math.round( this.x ); + this.y = Math.round( this.y ); + this.z = Math.round( this.z ); + + return this; + + }, + + roundToZero: function () { + + this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x ); + this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y ); + this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z ); + + return this; + + }, + + negate: function () { + + this.x = - this.x; + this.y = - this.y; + this.z = - this.z; + + return this; + + }, + + dot: function ( v ) { + + return this.x * v.x + this.y * v.y + this.z * v.z; + + }, + + // TODO lengthSquared? + + lengthSq: function () { + + return this.x * this.x + this.y * this.y + this.z * this.z; + + }, + + length: function () { + + return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z ); + + }, + + manhattanLength: function () { + + return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ); + + }, + + normalize: function () { + + return this.divideScalar( this.length() || 1 ); + + }, + + setLength: function ( length ) { + + return this.normalize().multiplyScalar( length ); + + }, + + lerp: function ( v, alpha ) { + + this.x += ( v.x - this.x ) * alpha; + this.y += ( v.y - this.y ) * alpha; + this.z += ( v.z - this.z ) * alpha; + + return this; + + }, + + lerpVectors: function ( v1, v2, alpha ) { + + this.x = v1.x + ( v2.x - v1.x ) * alpha; + this.y = v1.y + ( v2.y - v1.y ) * alpha; + this.z = v1.z + ( v2.z - v1.z ) * alpha; + + return this; + + }, + + cross: function ( v, w ) { + + if ( w !== undefined ) { + + console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' ); + return this.crossVectors( v, w ); + + } + + return this.crossVectors( this, v ); + + }, + + crossVectors: function ( a, b ) { + + var ax = a.x, ay = a.y, az = a.z; + var bx = b.x, by = b.y, bz = b.z; + + this.x = ay * bz - az * by; + this.y = az * bx - ax * bz; + this.z = ax * by - ay * bx; + + return this; + + }, + + projectOnVector: function ( v ) { + + var denominator = v.lengthSq(); + + if ( denominator === 0 ) { return this.set( 0, 0, 0 ); } + + var scalar = v.dot( this ) / denominator; + + return this.copy( v ).multiplyScalar( scalar ); + + }, + + projectOnPlane: function ( planeNormal ) { + + _vector.copy( this ).projectOnVector( planeNormal ); + + return this.sub( _vector ); + + }, + + reflect: function ( normal ) { + + // reflect incident vector off plane orthogonal to normal + // normal is assumed to have unit length + + return this.sub( _vector.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) ); + + }, + + angleTo: function ( v ) { + + var denominator = Math.sqrt( this.lengthSq() * v.lengthSq() ); + + if ( denominator === 0 ) { return Math.PI / 2; } + + var theta = this.dot( v ) / denominator; + + // clamp, to handle numerical problems + + return Math.acos( MathUtils.clamp( theta, - 1, 1 ) ); + + }, + + distanceTo: function ( v ) { + + return Math.sqrt( this.distanceToSquared( v ) ); + + }, + + distanceToSquared: function ( v ) { + + var dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z; + + return dx * dx + dy * dy + dz * dz; + + }, + + manhattanDistanceTo: function ( v ) { + + return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z ); + + }, + + setFromSpherical: function ( s ) { + + return this.setFromSphericalCoords( s.radius, s.phi, s.theta ); + + }, + + setFromSphericalCoords: function ( radius, phi, theta ) { + + var sinPhiRadius = Math.sin( phi ) * radius; + + this.x = sinPhiRadius * Math.sin( theta ); + this.y = Math.cos( phi ) * radius; + this.z = sinPhiRadius * Math.cos( theta ); + + return this; + + }, + + setFromCylindrical: function ( c ) { + + return this.setFromCylindricalCoords( c.radius, c.theta, c.y ); + + }, + + setFromCylindricalCoords: function ( radius, theta, y ) { + + this.x = radius * Math.sin( theta ); + this.y = y; + this.z = radius * Math.cos( theta ); + + return this; + + }, + + setFromMatrixPosition: function ( m ) { + + var e = m.elements; + + this.x = e[ 12 ]; + this.y = e[ 13 ]; + this.z = e[ 14 ]; + + return this; + + }, + + setFromMatrixScale: function ( m ) { + + var sx = this.setFromMatrixColumn( m, 0 ).length(); + var sy = this.setFromMatrixColumn( m, 1 ).length(); + var sz = this.setFromMatrixColumn( m, 2 ).length(); + + this.x = sx; + this.y = sy; + this.z = sz; + + return this; + + }, + + setFromMatrixColumn: function ( m, index ) { + + return this.fromArray( m.elements, index * 4 ); + + }, + + setFromMatrix3Column: function ( m, index ) { + + return this.fromArray( m.elements, index * 3 ); + + }, + + equals: function ( v ) { + + return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) ); + + }, + + fromArray: function ( array, offset ) { + + if ( offset === undefined ) { offset = 0; } + + this.x = array[ offset ]; + this.y = array[ offset + 1 ]; + this.z = array[ offset + 2 ]; + + return this; + + }, + + toArray: function ( array, offset ) { + + if ( array === undefined ) { array = []; } + if ( offset === undefined ) { offset = 0; } + + array[ offset ] = this.x; + array[ offset + 1 ] = this.y; + array[ offset + 2 ] = this.z; + + return array; + + }, + + fromBufferAttribute: function ( attribute, index, offset ) { + + if ( offset !== undefined ) { + + console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' ); + + } + + this.x = attribute.getX( index ); + this.y = attribute.getY( index ); + this.z = attribute.getZ( index ); + + return this; + + }, + + random: function () { + + this.x = Math.random(); + this.y = Math.random(); + this.z = Math.random(); + + return this; + + } + + } ); + + var _v1 = new Vector3(); + var _m1 = new Matrix4(); + var _zero = new Vector3( 0, 0, 0 ); + var _one = new Vector3( 1, 1, 1 ); + var _x = new Vector3(); + var _y = new Vector3(); + var _z = new Vector3(); + + function Matrix4() { + + this.elements = [ + + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + + ]; + + if ( arguments.length > 0 ) { + + console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' ); + + } + + } + + Object.assign( Matrix4.prototype, { + + isMatrix4: true, + + set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) { + + var te = this.elements; + + te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14; + te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24; + te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34; + te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44; + + return this; + + }, + + identity: function () { + + this.set( + + 1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + + ); + + return this; + + }, + + clone: function () { + + return new Matrix4().fromArray( this.elements ); + + }, + + copy: function ( m ) { + + var te = this.elements; + var me = m.elements; + + te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ]; + te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; + te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ]; + te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ]; + + return this; + + }, + + copyPosition: function ( m ) { + + var te = this.elements, me = m.elements; + + te[ 12 ] = me[ 12 ]; + te[ 13 ] = me[ 13 ]; + te[ 14 ] = me[ 14 ]; + + return this; + + }, + + extractBasis: function ( xAxis, yAxis, zAxis ) { + + xAxis.setFromMatrixColumn( this, 0 ); + yAxis.setFromMatrixColumn( this, 1 ); + zAxis.setFromMatrixColumn( this, 2 ); + + return this; + + }, + + makeBasis: function ( xAxis, yAxis, zAxis ) { + + 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 + ); + + return this; + + }, + + extractRotation: function ( m ) { + + // this method does not support reflection matrices + + var te = this.elements; + var me = m.elements; + + var scaleX = 1 / _v1.setFromMatrixColumn( m, 0 ).length(); + var scaleY = 1 / _v1.setFromMatrixColumn( m, 1 ).length(); + var scaleZ = 1 / _v1.setFromMatrixColumn( m, 2 ).length(); + + te[ 0 ] = me[ 0 ] * scaleX; + te[ 1 ] = me[ 1 ] * scaleX; + te[ 2 ] = me[ 2 ] * scaleX; + te[ 3 ] = 0; + + te[ 4 ] = me[ 4 ] * scaleY; + te[ 5 ] = me[ 5 ] * scaleY; + te[ 6 ] = me[ 6 ] * scaleY; + te[ 7 ] = 0; + + te[ 8 ] = me[ 8 ] * scaleZ; + te[ 9 ] = me[ 9 ] * scaleZ; + te[ 10 ] = me[ 10 ] * scaleZ; + te[ 11 ] = 0; + + te[ 12 ] = 0; + te[ 13 ] = 0; + te[ 14 ] = 0; + te[ 15 ] = 1; + + return this; + + }, + + makeRotationFromEuler: function ( euler ) { + + if ( ! ( euler && euler.isEuler ) ) { + + console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' ); + + } + + var te = this.elements; + + var x = euler.x, y = euler.y, z = euler.z; + var a = Math.cos( x ), b = Math.sin( x ); + var c = Math.cos( y ), d = Math.sin( y ); + var e = Math.cos( z ), f = Math.sin( z ); + + if ( euler.order === 'XYZ' ) { + + var ae = a * e, af = a * f, be = b * e, bf = b * f; + + te[ 0 ] = c * e; + te[ 4 ] = - c * f; + te[ 8 ] = d; + + te[ 1 ] = af + be * d; + te[ 5 ] = ae - bf * d; + te[ 9 ] = - b * c; + + te[ 2 ] = bf - ae * d; + te[ 6 ] = be + af * d; + te[ 10 ] = a * c; + + } else if ( euler.order === 'YXZ' ) { + + var ce = c * e, cf = c * f, de = d * e, df = d * f; + + te[ 0 ] = ce + df * b; + te[ 4 ] = de * b - cf; + te[ 8 ] = a * d; + + te[ 1 ] = a * f; + te[ 5 ] = a * e; + te[ 9 ] = - b; + + te[ 2 ] = cf * b - de; + te[ 6 ] = df + ce * b; + te[ 10 ] = a * c; + + } else if ( euler.order === 'ZXY' ) { + + var ce$1 = c * e, cf$1 = c * f, de$1 = d * e, df$1 = d * f; + + te[ 0 ] = ce$1 - df$1 * b; + te[ 4 ] = - a * f; + te[ 8 ] = de$1 + cf$1 * b; + + te[ 1 ] = cf$1 + de$1 * b; + te[ 5 ] = a * e; + te[ 9 ] = df$1 - ce$1 * b; + + te[ 2 ] = - a * d; + te[ 6 ] = b; + te[ 10 ] = a * c; + + } else if ( euler.order === 'ZYX' ) { + + var ae$1 = a * e, af$1 = a * f, be$1 = b * e, bf$1 = b * f; + + te[ 0 ] = c * e; + te[ 4 ] = be$1 * d - af$1; + te[ 8 ] = ae$1 * d + bf$1; + + te[ 1 ] = c * f; + te[ 5 ] = bf$1 * d + ae$1; + te[ 9 ] = af$1 * d - be$1; + + te[ 2 ] = - d; + te[ 6 ] = b * c; + te[ 10 ] = a * c; + + } else if ( euler.order === 'YZX' ) { + + var ac = a * c, ad = a * d, bc = b * c, bd = b * d; + + te[ 0 ] = c * e; + te[ 4 ] = bd - ac * f; + te[ 8 ] = bc * f + ad; + + te[ 1 ] = f; + te[ 5 ] = a * e; + te[ 9 ] = - b * e; + + te[ 2 ] = - d * e; + te[ 6 ] = ad * f + bc; + te[ 10 ] = ac - bd * f; + + } else if ( euler.order === 'XZY' ) { + + var ac$1 = a * c, ad$1 = a * d, bc$1 = b * c, bd$1 = b * d; + + te[ 0 ] = c * e; + te[ 4 ] = - f; + te[ 8 ] = d * e; + + te[ 1 ] = ac$1 * f + bd$1; + te[ 5 ] = a * e; + te[ 9 ] = ad$1 * f - bc$1; + + te[ 2 ] = bc$1 * f - ad$1; + te[ 6 ] = b * e; + te[ 10 ] = bd$1 * f + ac$1; + + } + + // bottom row + te[ 3 ] = 0; + te[ 7 ] = 0; + te[ 11 ] = 0; + + // last column + te[ 12 ] = 0; + te[ 13 ] = 0; + te[ 14 ] = 0; + te[ 15 ] = 1; + + return this; + + }, + + makeRotationFromQuaternion: function ( q ) { + + return this.compose( _zero, q, _one ); + + }, + + lookAt: function ( eye, target, up ) { + + var te = this.elements; + + _z.subVectors( eye, target ); + + if ( _z.lengthSq() === 0 ) { + + // eye and target are in the same position + + _z.z = 1; + + } + + _z.normalize(); + _x.crossVectors( up, _z ); + + if ( _x.lengthSq() === 0 ) { + + // up and z are parallel + + if ( Math.abs( up.z ) === 1 ) { + + _z.x += 0.0001; + + } else { + + _z.z += 0.0001; + + } + + _z.normalize(); + _x.crossVectors( up, _z ); + + } + + _x.normalize(); + _y.crossVectors( _z, _x ); + + te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x; + te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y; + te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z; + + return this; + + }, + + multiply: function ( m, n ) { + + if ( n !== undefined ) { + + console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' ); + return this.multiplyMatrices( m, n ); + + } + + return this.multiplyMatrices( this, m ); + + }, + + premultiply: function ( m ) { + + return this.multiplyMatrices( m, this ); + + }, + + multiplyMatrices: function ( a, b ) { + + var ae = a.elements; + var be = b.elements; + var te = this.elements; + + var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ]; + var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ]; + var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ]; + var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ]; + + var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ]; + var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ]; + var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ]; + var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ]; + + te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41; + te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42; + te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43; + te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44; + + te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41; + te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42; + te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43; + te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44; + + te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41; + te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42; + te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43; + te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44; + + te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41; + te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42; + te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43; + te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44; + + return this; + + }, + + multiplyScalar: function ( s ) { + + var te = this.elements; + + te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s; + te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s; + te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s; + te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s; + + return this; + + }, + + determinant: function () { + + var te = this.elements; + + var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ]; + var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ]; + var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ]; + var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ]; + + //TODO: make this more efficient + //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm ) + + 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 + ) + + ); + + }, + + transpose: function () { + + var te = this.elements; + var tmp; + + tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp; + tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp; + tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp; + + tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp; + tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp; + tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp; + + return this; + + }, + + setPosition: function ( x, y, z ) { + + var te = this.elements; + + if ( x.isVector3 ) { + + te[ 12 ] = x.x; + te[ 13 ] = x.y; + te[ 14 ] = x.z; + + } else { + + te[ 12 ] = x; + te[ 13 ] = y; + te[ 14 ] = z; + + } + + return this; + + }, + + getInverse: function ( m, throwOnDegenerate ) { + + if ( throwOnDegenerate !== undefined ) { + + console.warn( "THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate." ); + + } + + // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm + var te = this.elements, + me = m.elements, + + n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ], + n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ], + n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ], + n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ], + + t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44, + t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44, + t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44, + t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34; + + var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14; + + if ( det === 0 ) { return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); } + + var detInv = 1 / det; + + te[ 0 ] = t11 * detInv; + te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv; + te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv; + te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv; + + te[ 4 ] = t12 * detInv; + te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv; + te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv; + te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv; + + te[ 8 ] = t13 * detInv; + te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv; + te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv; + te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv; + + te[ 12 ] = t14 * detInv; + te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv; + te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv; + te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv; + + return this; + + }, + + scale: function ( v ) { + + var te = this.elements; + var x = v.x, y = v.y, z = v.z; + + te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z; + te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z; + te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z; + te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z; + + return this; + + }, + + getMaxScaleOnAxis: function () { + + var te = this.elements; + + var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ]; + var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ]; + var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ]; + + return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) ); + + }, + + makeTranslation: function ( x, y, z ) { + + this.set( + + 1, 0, 0, x, + 0, 1, 0, y, + 0, 0, 1, z, + 0, 0, 0, 1 + + ); + + return this; + + }, + + makeRotationX: function ( theta ) { + + var c = Math.cos( theta ), s = Math.sin( theta ); + + this.set( + + 1, 0, 0, 0, + 0, c, - s, 0, + 0, s, c, 0, + 0, 0, 0, 1 + + ); + + return this; + + }, + + makeRotationY: function ( theta ) { + + var c = Math.cos( theta ), s = Math.sin( theta ); + + this.set( + + c, 0, s, 0, + 0, 1, 0, 0, + - s, 0, c, 0, + 0, 0, 0, 1 + + ); + + return this; + + }, + + makeRotationZ: function ( theta ) { + + var c = Math.cos( theta ), s = Math.sin( theta ); + + this.set( + + c, - s, 0, 0, + s, c, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + + ); + + return this; + + }, + + makeRotationAxis: function ( axis, angle ) { + + // Based on http://www.gamedev.net/reference/articles/article1199.asp + + var c = Math.cos( angle ); + var s = Math.sin( angle ); + var t = 1 - c; + var x = axis.x, y = axis.y, z = axis.z; + var tx = t * x, ty = t * y; + + 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 + + ); + + return this; + + }, + + makeScale: function ( x, y, z ) { + + this.set( + + x, 0, 0, 0, + 0, y, 0, 0, + 0, 0, z, 0, + 0, 0, 0, 1 + + ); + + return this; + + }, + + makeShear: function ( x, y, z ) { + + this.set( + + 1, y, z, 0, + x, 1, z, 0, + x, y, 1, 0, + 0, 0, 0, 1 + + ); + + return this; + + }, + + compose: function ( position, quaternion, scale ) { + + var te = this.elements; + + var x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w; + var x2 = x + x, y2 = y + y, z2 = z + z; + var xx = x * x2, xy = x * y2, xz = x * z2; + var yy = y * y2, yz = y * z2, zz = z * z2; + var wx = w * x2, wy = w * y2, wz = w * z2; + + var sx = scale.x, sy = scale.y, sz = scale.z; + + te[ 0 ] = ( 1 - ( yy + zz ) ) * sx; + te[ 1 ] = ( xy + wz ) * sx; + te[ 2 ] = ( xz - wy ) * sx; + te[ 3 ] = 0; + + te[ 4 ] = ( xy - wz ) * sy; + te[ 5 ] = ( 1 - ( xx + zz ) ) * sy; + te[ 6 ] = ( yz + wx ) * sy; + te[ 7 ] = 0; + + te[ 8 ] = ( xz + wy ) * sz; + te[ 9 ] = ( yz - wx ) * sz; + te[ 10 ] = ( 1 - ( xx + yy ) ) * sz; + te[ 11 ] = 0; + + te[ 12 ] = position.x; + te[ 13 ] = position.y; + te[ 14 ] = position.z; + te[ 15 ] = 1; + + return this; + + }, + + decompose: function ( position, quaternion, scale ) { + + var te = this.elements; + + var sx = _v1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length(); + var sy = _v1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length(); + var sz = _v1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length(); + + // if determine is negative, we need to invert one scale + var det = this.determinant(); + if ( det < 0 ) { sx = - sx; } + + position.x = te[ 12 ]; + position.y = te[ 13 ]; + position.z = te[ 14 ]; + + // scale the rotation part + _m1.copy( this ); + + var invSX = 1 / sx; + var invSY = 1 / sy; + var invSZ = 1 / sz; + + _m1.elements[ 0 ] *= invSX; + _m1.elements[ 1 ] *= invSX; + _m1.elements[ 2 ] *= invSX; + + _m1.elements[ 4 ] *= invSY; + _m1.elements[ 5 ] *= invSY; + _m1.elements[ 6 ] *= invSY; + + _m1.elements[ 8 ] *= invSZ; + _m1.elements[ 9 ] *= invSZ; + _m1.elements[ 10 ] *= invSZ; + + quaternion.setFromRotationMatrix( _m1 ); + + scale.x = sx; + scale.y = sy; + scale.z = sz; + + return this; + + }, + + makePerspective: function ( left, right, top, bottom, near, far ) { + + if ( far === undefined ) { + + console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' ); + + } + + var te = this.elements; + var x = 2 * near / ( right - left ); + var y = 2 * near / ( top - bottom ); + + var a = ( right + left ) / ( right - left ); + var b = ( top + bottom ) / ( top - bottom ); + var c = - ( far + near ) / ( far - near ); + var d = - 2 * far * near / ( far - near ); + + te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0; + te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0; + te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d; + te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0; + + return this; + + }, + + makeOrthographic: function ( left, right, top, bottom, near, far ) { + + var te = this.elements; + var w = 1.0 / ( right - left ); + var h = 1.0 / ( top - bottom ); + var p = 1.0 / ( far - near ); + + var x = ( right + left ) * w; + var y = ( top + bottom ) * h; + var z = ( far + near ) * p; + + te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x; + te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y; + te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z; + te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1; + + return this; + + }, + + equals: function ( matrix ) { + + var te = this.elements; + var me = matrix.elements; + + for ( var i = 0; i < 16; i ++ ) { + + if ( te[ i ] !== me[ i ] ) { return false; } + + } + + return true; + + }, + + fromArray: function ( array, offset ) { + + if ( offset === undefined ) { offset = 0; } + + for ( var i = 0; i < 16; i ++ ) { + + this.elements[ i ] = array[ i + offset ]; + + } + + return this; + + }, + + toArray: function ( array, offset ) { + + if ( array === undefined ) { array = []; } + if ( offset === undefined ) { offset = 0; } + + var te = this.elements; + + array[ offset ] = te[ 0 ]; + array[ offset + 1 ] = te[ 1 ]; + array[ offset + 2 ] = te[ 2 ]; + array[ offset + 3 ] = te[ 3 ]; + + array[ offset + 4 ] = te[ 4 ]; + array[ offset + 5 ] = te[ 5 ]; + array[ offset + 6 ] = te[ 6 ]; + array[ offset + 7 ] = te[ 7 ]; + + array[ offset + 8 ] = te[ 8 ]; + array[ offset + 9 ] = te[ 9 ]; + array[ offset + 10 ] = te[ 10 ]; + array[ offset + 11 ] = te[ 11 ]; + + array[ offset + 12 ] = te[ 12 ]; + array[ offset + 13 ] = te[ 13 ]; + array[ offset + 14 ] = te[ 14 ]; + array[ offset + 15 ] = te[ 15 ]; + + return array; + + } + + } ); + + var _matrix = new Matrix4(); + var _quaternion$1 = new Quaternion(); + + function Euler( x, y, z, order ) { + if ( x === void 0 ) x = 0; + if ( y === void 0 ) y = 0; + if ( z === void 0 ) z = 0; + if ( order === void 0 ) order = Euler.DefaultOrder; + + + this._x = x; + this._y = y; + this._z = z; + this._order = order; + + } + + Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ]; + + Euler.DefaultOrder = 'XYZ'; + + Object.defineProperties( Euler.prototype, { + + x: { + + get: function () { + + return this._x; + + }, + + set: function ( value ) { + + this._x = value; + this._onChangeCallback(); + + } + + }, + + y: { + + get: function () { + + return this._y; + + }, + + set: function ( value ) { + + this._y = value; + this._onChangeCallback(); + + } + + }, + + z: { + + get: function () { + + return this._z; + + }, + + set: function ( value ) { + + this._z = value; + this._onChangeCallback(); + + } + + }, + + order: { + + get: function () { + + return this._order; + + }, + + set: function ( value ) { + + this._order = value; + this._onChangeCallback(); + + } + + } + + } ); + + Object.assign( Euler.prototype, { + + isEuler: true, + + set: function ( x, y, z, order ) { + + this._x = x; + this._y = y; + this._z = z; + this._order = order || this._order; + + this._onChangeCallback(); + + return this; + + }, + + clone: function () { + + return new this.constructor( this._x, this._y, this._z, this._order ); + + }, + + copy: function ( euler ) { + + this._x = euler._x; + this._y = euler._y; + this._z = euler._z; + this._order = euler._order; + + this._onChangeCallback(); + + return this; + + }, + + setFromRotationMatrix: function ( m, order, update ) { + + var clamp = MathUtils.clamp; + + // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) + + var te = m.elements; + var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ]; + var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ]; + var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ]; + + order = order || this._order; + + switch ( order ) { + + case 'XYZ': + + this._y = Math.asin( clamp( m13, - 1, 1 ) ); + + if ( Math.abs( m13 ) < 0.9999999 ) { + + this._x = Math.atan2( - m23, m33 ); + this._z = Math.atan2( - m12, m11 ); + + } else { + + this._x = Math.atan2( m32, m22 ); + this._z = 0; + + } + + break; + + case 'YXZ': + + this._x = Math.asin( - clamp( m23, - 1, 1 ) ); + + if ( Math.abs( m23 ) < 0.9999999 ) { + + this._y = Math.atan2( m13, m33 ); + this._z = Math.atan2( m21, m22 ); + + } else { + + this._y = Math.atan2( - m31, m11 ); + this._z = 0; + + } + + break; + + case 'ZXY': + + this._x = Math.asin( clamp( m32, - 1, 1 ) ); + + if ( Math.abs( m32 ) < 0.9999999 ) { + + this._y = Math.atan2( - m31, m33 ); + this._z = Math.atan2( - m12, m22 ); + + } else { + + this._y = 0; + this._z = Math.atan2( m21, m11 ); + + } + + break; + + case 'ZYX': + + this._y = Math.asin( - clamp( m31, - 1, 1 ) ); + + if ( Math.abs( m31 ) < 0.9999999 ) { + + this._x = Math.atan2( m32, m33 ); + this._z = Math.atan2( m21, m11 ); + + } else { + + this._x = 0; + this._z = Math.atan2( - m12, m22 ); + + } + + break; + + case 'YZX': + + this._z = Math.asin( clamp( m21, - 1, 1 ) ); + + if ( Math.abs( m21 ) < 0.9999999 ) { + + this._x = Math.atan2( - m23, m22 ); + this._y = Math.atan2( - m31, m11 ); + + } else { + + this._x = 0; + this._y = Math.atan2( m13, m33 ); + + } + + break; + + case 'XZY': + + this._z = Math.asin( - clamp( m12, - 1, 1 ) ); + + if ( Math.abs( m12 ) < 0.9999999 ) { + + this._x = Math.atan2( m32, m22 ); + this._y = Math.atan2( m13, m11 ); + + } else { + + this._x = Math.atan2( - m23, m33 ); + this._y = 0; + + } + + break; + + default: + + console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order ); + + } + + this._order = order; + + if ( update !== false ) { this._onChangeCallback(); } + + return this; + + }, + + setFromQuaternion: function ( q, order, update ) { + + _matrix.makeRotationFromQuaternion( q ); + + return this.setFromRotationMatrix( _matrix, order, update ); + + }, + + setFromVector3: function ( v, order ) { + + return this.set( v.x, v.y, v.z, order || this._order ); + + }, + + reorder: function ( newOrder ) { + + // WARNING: this discards revolution information -bhouston + + _quaternion$1.setFromEuler( this ); + + return this.setFromQuaternion( _quaternion$1, newOrder ); + + }, + + equals: function ( euler ) { + + return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order ); + + }, + + fromArray: function ( array ) { + + this._x = array[ 0 ]; + this._y = array[ 1 ]; + this._z = array[ 2 ]; + if ( array[ 3 ] !== undefined ) { this._order = array[ 3 ]; } + + this._onChangeCallback(); + + return this; + + }, + + toArray: function ( array, offset ) { + + if ( array === undefined ) { array = []; } + if ( offset === undefined ) { offset = 0; } + + array[ offset ] = this._x; + array[ offset + 1 ] = this._y; + array[ offset + 2 ] = this._z; + array[ offset + 3 ] = this._order; + + return array; + + }, + + toVector3: function ( optionalResult ) { + + if ( optionalResult ) { + + return optionalResult.set( this._x, this._y, this._z ); + + } else { + + return new Vector3( this._x, this._y, this._z ); + + } + + }, + + _onChange: function ( callback ) { + + this._onChangeCallback = callback; + + return this; + + }, + + _onChangeCallback: function () {} + + } ); + + function Layers() { + + this.mask = 1 | 0; + + } + + Object.assign( Layers.prototype, { + + set: function ( channel ) { + + this.mask = 1 << channel | 0; + + }, + + enable: function ( channel ) { + + this.mask |= 1 << channel | 0; + + }, + + enableAll: function () { + + this.mask = 0xffffffff | 0; + + }, + + toggle: function ( channel ) { + + this.mask ^= 1 << channel | 0; + + }, + + disable: function ( channel ) { + + this.mask &= ~ ( 1 << channel | 0 ); + + }, + + disableAll: function () { + + this.mask = 0; + + }, + + test: function ( layers ) { + + return ( this.mask & layers.mask ) !== 0; + + } + + } ); + + var _object3DId = 0; + + var _v1$1 = new Vector3(); + var _q1 = new Quaternion(); + var _m1$1 = new Matrix4(); + var _target = new Vector3(); + + var _position = new Vector3(); + var _scale = new Vector3(); + var _quaternion$2 = new Quaternion(); + + var _xAxis = new Vector3( 1, 0, 0 ); + var _yAxis = new Vector3( 0, 1, 0 ); + var _zAxis = new Vector3( 0, 0, 1 ); + + var _addedEvent = { type: 'added' }; + var _removedEvent = { type: 'removed' }; + + function Object3D() { + + Object.defineProperty( this, 'id', { value: _object3DId ++ } ); + + this.uuid = MathUtils.generateUUID(); + + this.name = ''; + this.type = 'Object3D'; + + this.parent = null; + this.children = []; + + this.up = Object3D.DefaultUp.clone(); + + var position = new Vector3(); + var rotation = new Euler(); + var quaternion = new Quaternion(); + var scale = new Vector3( 1, 1, 1 ); + + function onRotationChange() { + + quaternion.setFromEuler( rotation, false ); + + } + + function onQuaternionChange() { + + rotation.setFromQuaternion( quaternion, undefined, false ); + + } + + rotation._onChange( onRotationChange ); + quaternion._onChange( onQuaternionChange ); + + Object.defineProperties( this, { + position: { + configurable: true, + enumerable: true, + value: position + }, + rotation: { + configurable: true, + enumerable: true, + value: rotation + }, + quaternion: { + configurable: true, + enumerable: true, + value: quaternion + }, + scale: { + configurable: true, + enumerable: true, + value: scale + }, + modelViewMatrix: { + value: new Matrix4() + }, + normalMatrix: { + value: new Matrix3() + } + } ); + + this.matrix = new Matrix4(); + this.matrixWorld = new Matrix4(); + + this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate; + this.matrixWorldNeedsUpdate = false; + + this.layers = new Layers(); + this.visible = true; + + this.castShadow = false; + this.receiveShadow = false; + + this.frustumCulled = true; + this.renderOrder = 0; + + this.userData = {}; + + } + + Object3D.DefaultUp = new Vector3( 0, 1, 0 ); + Object3D.DefaultMatrixAutoUpdate = true; + + Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { + + constructor: Object3D, + + isObject3D: true, + + onBeforeRender: function () {}, + onAfterRender: function () {}, + + applyMatrix4: function ( matrix ) { + + if ( this.matrixAutoUpdate ) { this.updateMatrix(); } + + this.matrix.premultiply( matrix ); + + this.matrix.decompose( this.position, this.quaternion, this.scale ); + + }, + + applyQuaternion: function ( q ) { + + this.quaternion.premultiply( q ); + + return this; + + }, + + setRotationFromAxisAngle: function ( axis, angle ) { + + // assumes axis is normalized + + this.quaternion.setFromAxisAngle( axis, angle ); + + }, + + setRotationFromEuler: function ( euler ) { + + this.quaternion.setFromEuler( euler, true ); + + }, + + setRotationFromMatrix: function ( m ) { + + // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled) + + this.quaternion.setFromRotationMatrix( m ); + + }, + + setRotationFromQuaternion: function ( q ) { + + // assumes q is normalized + + this.quaternion.copy( q ); + + }, + + rotateOnAxis: function ( axis, angle ) { + + // rotate object on axis in object space + // axis is assumed to be normalized + + _q1.setFromAxisAngle( axis, angle ); + + this.quaternion.multiply( _q1 ); + + return this; + + }, + + rotateOnWorldAxis: function ( axis, angle ) { + + // rotate object on axis in world space + // axis is assumed to be normalized + // method assumes no rotated parent + + _q1.setFromAxisAngle( axis, angle ); + + this.quaternion.premultiply( _q1 ); + + return this; + + }, + + rotateX: function ( angle ) { + + return this.rotateOnAxis( _xAxis, angle ); + + }, + + rotateY: function ( angle ) { + + return this.rotateOnAxis( _yAxis, angle ); + + }, + + rotateZ: function ( angle ) { + + return this.rotateOnAxis( _zAxis, angle ); + + }, + + translateOnAxis: function ( axis, distance ) { + + // translate object by distance along axis in object space + // axis is assumed to be normalized + + _v1$1.copy( axis ).applyQuaternion( this.quaternion ); + + this.position.add( _v1$1.multiplyScalar( distance ) ); + + return this; + + }, + + translateX: function ( distance ) { + + return this.translateOnAxis( _xAxis, distance ); + + }, + + translateY: function ( distance ) { + + return this.translateOnAxis( _yAxis, distance ); + + }, + + translateZ: function ( distance ) { + + return this.translateOnAxis( _zAxis, distance ); + + }, + + localToWorld: function ( vector ) { + + return vector.applyMatrix4( this.matrixWorld ); + + }, + + worldToLocal: function ( vector ) { + + return vector.applyMatrix4( _m1$1.getInverse( this.matrixWorld ) ); + + }, + + lookAt: function ( x, y, z ) { + + // This method does not support objects having non-uniformly-scaled parent(s) + + if ( x.isVector3 ) { + + _target.copy( x ); + + } else { + + _target.set( x, y, z ); + + } + + var parent = this.parent; + + this.updateWorldMatrix( true, false ); + + _position.setFromMatrixPosition( this.matrixWorld ); + + if ( this.isCamera || this.isLight ) { + + _m1$1.lookAt( _position, _target, this.up ); + + } else { + + _m1$1.lookAt( _target, _position, this.up ); + + } + + this.quaternion.setFromRotationMatrix( _m1$1 ); + + if ( parent ) { + + _m1$1.extractRotation( parent.matrixWorld ); + _q1.setFromRotationMatrix( _m1$1 ); + this.quaternion.premultiply( _q1.inverse() ); + + } + + }, + + add: function ( object ) { + var arguments$1 = arguments; + + + if ( arguments.length > 1 ) { + + for ( var i = 0; i < arguments.length; i ++ ) { + + this.add( arguments$1[ i ] ); + + } + + return this; + + } + + if ( object === this ) { + + console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object ); + return this; + + } + + if ( ( object && object.isObject3D ) ) { + + if ( object.parent !== null ) { + + object.parent.remove( object ); + + } + + object.parent = this; + this.children.push( object ); + + object.dispatchEvent( _addedEvent ); + + } else { + + console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object ); + + } + + return this; + + }, + + remove: function ( object ) { + var arguments$1 = arguments; + + + if ( arguments.length > 1 ) { + + for ( var i = 0; i < arguments.length; i ++ ) { + + this.remove( arguments$1[ i ] ); + + } + + return this; + + } + + var index = this.children.indexOf( object ); + + if ( index !== - 1 ) { + + object.parent = null; + this.children.splice( index, 1 ); + + object.dispatchEvent( _removedEvent ); + + } + + return this; + + }, + + attach: function ( object ) { + + // adds object as a child of this, while maintaining the object's world transform + + this.updateWorldMatrix( true, false ); + + _m1$1.getInverse( this.matrixWorld ); + + if ( object.parent !== null ) { + + object.parent.updateWorldMatrix( true, false ); + + _m1$1.multiply( object.parent.matrixWorld ); + + } + + object.applyMatrix4( _m1$1 ); + + object.updateWorldMatrix( false, false ); + + this.add( object ); + + return this; + + }, + + getObjectById: function ( id ) { + + return this.getObjectByProperty( 'id', id ); + + }, + + getObjectByName: function ( name ) { + + return this.getObjectByProperty( 'name', name ); + + }, + + getObjectByProperty: function ( name, value ) { + + if ( this[ name ] === value ) { return this; } + + for ( var i = 0, l = this.children.length; i < l; i ++ ) { + + var child = this.children[ i ]; + var object = child.getObjectByProperty( name, value ); + + if ( object !== undefined ) { + + return object; + + } + + } + + return undefined; + + }, + + getWorldPosition: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' ); + target = new Vector3(); + + } + + this.updateMatrixWorld( true ); + + return target.setFromMatrixPosition( this.matrixWorld ); + + }, + + getWorldQuaternion: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' ); + target = new Quaternion(); + + } + + this.updateMatrixWorld( true ); + + this.matrixWorld.decompose( _position, target, _scale ); + + return target; + + }, + + getWorldScale: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Object3D: .getWorldScale() target is now required' ); + target = new Vector3(); + + } + + this.updateMatrixWorld( true ); + + this.matrixWorld.decompose( _position, _quaternion$2, target ); + + return target; + + }, + + getWorldDirection: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' ); + target = new Vector3(); + + } + + this.updateMatrixWorld( true ); + + var e = this.matrixWorld.elements; + + return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize(); + + }, + + raycast: function () {}, + + traverse: function ( callback ) { + + callback( this ); + + var children = this.children; + + for ( var i = 0, l = children.length; i < l; i ++ ) { + + children[ i ].traverse( callback ); + + } + + }, + + traverseVisible: function ( callback ) { + + if ( this.visible === false ) { return; } + + callback( this ); + + var children = this.children; + + for ( var i = 0, l = children.length; i < l; i ++ ) { + + children[ i ].traverseVisible( callback ); + + } + + }, + + traverseAncestors: function ( callback ) { + + var parent = this.parent; + + if ( parent !== null ) { + + callback( parent ); + + parent.traverseAncestors( callback ); + + } + + }, + + updateMatrix: function () { + + this.matrix.compose( this.position, this.quaternion, this.scale ); + + this.matrixWorldNeedsUpdate = true; + + }, + + updateMatrixWorld: function ( force ) { + + if ( this.matrixAutoUpdate ) { this.updateMatrix(); } + + if ( this.matrixWorldNeedsUpdate || force ) { + + if ( this.parent === null ) { + + this.matrixWorld.copy( this.matrix ); + + } else { + + this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); + + } + + this.matrixWorldNeedsUpdate = false; + + force = true; + + } + + // update children + + var children = this.children; + + for ( var i = 0, l = children.length; i < l; i ++ ) { + + children[ i ].updateMatrixWorld( force ); + + } + + }, + + updateWorldMatrix: function ( updateParents, updateChildren ) { + + var parent = this.parent; + + if ( updateParents === true && parent !== null ) { + + parent.updateWorldMatrix( true, false ); + + } + + if ( this.matrixAutoUpdate ) { this.updateMatrix(); } + + if ( this.parent === null ) { + + this.matrixWorld.copy( this.matrix ); + + } else { + + this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix ); + + } + + // update children + + if ( updateChildren === true ) { + + var children = this.children; + + for ( var i = 0, l = children.length; i < l; i ++ ) { + + children[ i ].updateWorldMatrix( false, true ); + + } + + } + + }, + + toJSON: function ( meta ) { + + // meta is a string when called from JSON.stringify + var isRootObject = ( meta === undefined || typeof meta === 'string' ); + + var output = {}; + + // meta is a hash used to collect geometries, materials. + // not providing it implies that this is the root object + // being serialized. + if ( isRootObject ) { + + // initialize meta obj + meta = { + geometries: {}, + materials: {}, + textures: {}, + images: {}, + shapes: {} + }; + + output.metadata = { + version: 4.5, + type: 'Object', + generator: 'Object3D.toJSON' + }; + + } + + // standard Object3D serialization + + var object = {}; + + object.uuid = this.uuid; + object.type = this.type; + + if ( this.name !== '' ) { object.name = this.name; } + if ( this.castShadow === true ) { object.castShadow = true; } + if ( this.receiveShadow === true ) { object.receiveShadow = true; } + if ( this.visible === false ) { object.visible = false; } + if ( this.frustumCulled === false ) { object.frustumCulled = false; } + if ( this.renderOrder !== 0 ) { object.renderOrder = this.renderOrder; } + if ( JSON.stringify( this.userData ) !== '{}' ) { object.userData = this.userData; } + + object.layers = this.layers.mask; + object.matrix = this.matrix.toArray(); + + if ( this.matrixAutoUpdate === false ) { object.matrixAutoUpdate = false; } + + // object specific properties + + if ( this.isInstancedMesh ) { + + object.type = 'InstancedMesh'; + object.count = this.count; + object.instanceMatrix = this.instanceMatrix.toJSON(); + + } + + // + + function serialize( library, element ) { + + if ( library[ element.uuid ] === undefined ) { + + library[ element.uuid ] = element.toJSON( meta ); + + } + + return element.uuid; + + } + + if ( this.isMesh || this.isLine || this.isPoints ) { + + object.geometry = serialize( meta.geometries, this.geometry ); + + var parameters = this.geometry.parameters; + + if ( parameters !== undefined && parameters.shapes !== undefined ) { + + var shapes = parameters.shapes; + + if ( Array.isArray( shapes ) ) { + + for ( var i = 0, l = shapes.length; i < l; i ++ ) { + + var shape = shapes[ i ]; + + serialize( meta.shapes, shape ); + + } + + } else { + + serialize( meta.shapes, shapes ); + + } + + } + + } + + if ( this.material !== undefined ) { + + if ( Array.isArray( this.material ) ) { + + var uuids = []; + + for ( var i$1 = 0, l$1 = this.material.length; i$1 < l$1; i$1 ++ ) { + + uuids.push( serialize( meta.materials, this.material[ i$1 ] ) ); + + } + + object.material = uuids; + + } else { + + object.material = serialize( meta.materials, this.material ); + + } + + } + + // + + if ( this.children.length > 0 ) { + + object.children = []; + + for ( var i$2 = 0; i$2 < this.children.length; i$2 ++ ) { + + object.children.push( this.children[ i$2 ].toJSON( meta ).object ); + + } + + } + + if ( isRootObject ) { + + var geometries = extractFromCache( meta.geometries ); + var materials = extractFromCache( meta.materials ); + var textures = extractFromCache( meta.textures ); + var images = extractFromCache( meta.images ); + var shapes$1 = extractFromCache( meta.shapes ); + + if ( geometries.length > 0 ) { output.geometries = geometries; } + if ( materials.length > 0 ) { output.materials = materials; } + if ( textures.length > 0 ) { output.textures = textures; } + if ( images.length > 0 ) { output.images = images; } + if ( shapes$1.length > 0 ) { output.shapes = shapes$1; } + + } + + output.object = object; + + return output; + + // extract data from the cache hash + // remove metadata on each item + // and return as array + function extractFromCache( cache ) { + + var values = []; + for ( var key in cache ) { + + var data = cache[ key ]; + delete data.metadata; + values.push( data ); + + } + + return values; + + } + + }, + + clone: function ( recursive ) { + + return new this.constructor().copy( this, recursive ); + + }, + + copy: function ( source, recursive ) { + + if ( recursive === undefined ) { recursive = true; } + + this.name = source.name; + + this.up.copy( source.up ); + + this.position.copy( source.position ); + this.rotation.order = source.rotation.order; + this.quaternion.copy( source.quaternion ); + this.scale.copy( source.scale ); + + this.matrix.copy( source.matrix ); + this.matrixWorld.copy( source.matrixWorld ); + + this.matrixAutoUpdate = source.matrixAutoUpdate; + this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate; + + this.layers.mask = source.layers.mask; + this.visible = source.visible; + + this.castShadow = source.castShadow; + this.receiveShadow = source.receiveShadow; + + this.frustumCulled = source.frustumCulled; + this.renderOrder = source.renderOrder; + + this.userData = JSON.parse( JSON.stringify( source.userData ) ); + + if ( recursive === true ) { + + for ( var i = 0; i < source.children.length; i ++ ) { + + var child = source.children[ i ]; + this.add( child.clone() ); + + } + + } + + return this; + + } + + } ); + + function Scene() { + + Object3D.call( this ); + + this.type = 'Scene'; + + this.background = null; + this.environment = null; + this.fog = null; + + this.overrideMaterial = null; + + this.autoUpdate = true; // checked by the renderer + + if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) { + + __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef + + } + + } + + Scene.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: Scene, + + isScene: true, + + copy: function ( source, recursive ) { + + Object3D.prototype.copy.call( this, source, recursive ); + + if ( source.background !== null ) { this.background = source.background.clone(); } + if ( source.environment !== null ) { this.environment = source.environment.clone(); } + if ( source.fog !== null ) { this.fog = source.fog.clone(); } + + if ( source.overrideMaterial !== null ) { this.overrideMaterial = source.overrideMaterial.clone(); } + + this.autoUpdate = source.autoUpdate; + this.matrixAutoUpdate = source.matrixAutoUpdate; + + return this; + + }, + + toJSON: function ( meta ) { + + var data = Object3D.prototype.toJSON.call( this, meta ); + + if ( this.background !== null ) { data.object.background = this.background.toJSON( meta ); } + if ( this.environment !== null ) { data.object.environment = this.environment.toJSON( meta ); } + if ( this.fog !== null ) { data.object.fog = this.fog.toJSON(); } + + return data; + + }, + + dispose: function () { + + this.dispatchEvent( { type: 'dispose' } ); + + } + + } ); + + var _points = [ + new Vector3(), + new Vector3(), + new Vector3(), + new Vector3(), + new Vector3(), + new Vector3(), + new Vector3(), + new Vector3() + ]; + + var _vector$1 = new Vector3(); + + var _box = new Box3(); + + // triangle centered vertices + + var _v0 = new Vector3(); + var _v1$2 = new Vector3(); + var _v2 = new Vector3(); + + // triangle edge vectors + + var _f0 = new Vector3(); + var _f1 = new Vector3(); + var _f2 = new Vector3(); + + var _center = new Vector3(); + var _extents = new Vector3(); + var _triangleNormal = new Vector3(); + var _testAxis = new Vector3(); + + function Box3( min, max ) { + + this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity ); + this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity ); + + } + + + Object.assign( Box3.prototype, { + + isBox3: true, + + set: function ( min, max ) { + + this.min.copy( min ); + this.max.copy( max ); + + return this; + + }, + + setFromArray: function ( array ) { + + var minX = + Infinity; + var minY = + Infinity; + var minZ = + Infinity; + + var maxX = - Infinity; + var maxY = - Infinity; + var maxZ = - Infinity; + + for ( var i = 0, l = array.length; i < l; i += 3 ) { + + var x = array[ i ]; + var y = array[ i + 1 ]; + var z = array[ i + 2 ]; + + if ( x < minX ) { minX = x; } + if ( y < minY ) { minY = y; } + if ( z < minZ ) { minZ = z; } + + if ( x > maxX ) { maxX = x; } + if ( y > maxY ) { maxY = y; } + if ( z > maxZ ) { maxZ = z; } + + } + + this.min.set( minX, minY, minZ ); + this.max.set( maxX, maxY, maxZ ); + + return this; + + }, + + setFromBufferAttribute: function ( attribute ) { + + var minX = + Infinity; + var minY = + Infinity; + var minZ = + Infinity; + + var maxX = - Infinity; + var maxY = - Infinity; + var maxZ = - Infinity; + + for ( var i = 0, l = attribute.count; i < l; i ++ ) { + + var x = attribute.getX( i ); + var y = attribute.getY( i ); + var z = attribute.getZ( i ); + + if ( x < minX ) { minX = x; } + if ( y < minY ) { minY = y; } + if ( z < minZ ) { minZ = z; } + + if ( x > maxX ) { maxX = x; } + if ( y > maxY ) { maxY = y; } + if ( z > maxZ ) { maxZ = z; } + + } + + this.min.set( minX, minY, minZ ); + this.max.set( maxX, maxY, maxZ ); + + return this; + + }, + + setFromPoints: function ( points ) { + + this.makeEmpty(); + + for ( var i = 0, il = points.length; i < il; i ++ ) { + + this.expandByPoint( points[ i ] ); + + } + + return this; + + }, + + setFromCenterAndSize: function ( center, size ) { + + var halfSize = _vector$1.copy( size ).multiplyScalar( 0.5 ); + + this.min.copy( center ).sub( halfSize ); + this.max.copy( center ).add( halfSize ); + + return this; + + }, + + setFromObject: function ( object ) { + + this.makeEmpty(); + + return this.expandByObject( object ); + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( box ) { + + this.min.copy( box.min ); + this.max.copy( box.max ); + + return this; + + }, + + makeEmpty: function () { + + this.min.x = this.min.y = this.min.z = + Infinity; + this.max.x = this.max.y = this.max.z = - Infinity; + + return this; + + }, + + isEmpty: function () { + + // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes + + return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z ); + + }, + + getCenter: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Box3: .getCenter() target is now required' ); + target = new Vector3(); + + } + + return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 ); + + }, + + getSize: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Box3: .getSize() target is now required' ); + target = new Vector3(); + + } + + return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min ); + + }, + + expandByPoint: function ( point ) { + + this.min.min( point ); + this.max.max( point ); + + return this; + + }, + + expandByVector: function ( vector ) { + + this.min.sub( vector ); + this.max.add( vector ); + + return this; + + }, + + expandByScalar: function ( scalar ) { + + this.min.addScalar( - scalar ); + this.max.addScalar( scalar ); + + return this; + + }, + + expandByObject: function ( object ) { + + // Computes the world-axis-aligned bounding box of an object (including its children), + // accounting for both the object's, and children's, world transforms + + object.updateWorldMatrix( false, false ); + + var geometry = object.geometry; + + if ( geometry !== undefined ) { + + if ( geometry.boundingBox === null ) { + + geometry.computeBoundingBox(); + + } + + _box.copy( geometry.boundingBox ); + _box.applyMatrix4( object.matrixWorld ); + + this.union( _box ); + + } + + var children = object.children; + + for ( var i = 0, l = children.length; i < l; i ++ ) { + + this.expandByObject( children[ i ] ); + + } + + return this; + + }, + + containsPoint: function ( point ) { + + 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; + + }, + + containsBox: function ( box ) { + + 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; + + }, + + getParameter: function ( point, target ) { + + // This can potentially have a divide by zero if the box + // has a size dimension of 0. + + if ( target === undefined ) { + + console.warn( 'THREE.Box3: .getParameter() target is now required' ); + target = new Vector3(); + + } + + 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 ) + ); + + }, + + intersectsBox: function ( box ) { + + // using 6 splitting planes to rule out intersections. + 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; + + }, + + intersectsSphere: function ( sphere ) { + + // Find the point on the AABB closest to the sphere center. + this.clampPoint( sphere.center, _vector$1 ); + + // If that point is inside the sphere, the AABB and sphere intersect. + return _vector$1.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius ); + + }, + + intersectsPlane: function ( plane ) { + + // We compute the minimum and maximum dot product values. If those values + // are on the same side (back or front) of the plane, then there is no intersection. + + var min, max; + + if ( plane.normal.x > 0 ) { + + min = plane.normal.x * this.min.x; + max = plane.normal.x * this.max.x; + + } else { + + min = plane.normal.x * this.max.x; + max = plane.normal.x * this.min.x; + + } + + if ( plane.normal.y > 0 ) { + + min += plane.normal.y * this.min.y; + max += plane.normal.y * this.max.y; + + } else { + + min += plane.normal.y * this.max.y; + max += plane.normal.y * this.min.y; + + } + + if ( plane.normal.z > 0 ) { + + min += plane.normal.z * this.min.z; + max += plane.normal.z * this.max.z; + + } else { + + min += plane.normal.z * this.max.z; + max += plane.normal.z * this.min.z; + + } + + return ( min <= - plane.constant && max >= - plane.constant ); + + }, + + intersectsTriangle: function ( triangle ) { + + if ( this.isEmpty() ) { + + return false; + + } + + // compute box center and extents + this.getCenter( _center ); + _extents.subVectors( this.max, _center ); + + // translate triangle to aabb origin + _v0.subVectors( triangle.a, _center ); + _v1$2.subVectors( triangle.b, _center ); + _v2.subVectors( triangle.c, _center ); + + // compute edge vectors for triangle + _f0.subVectors( _v1$2, _v0 ); + _f1.subVectors( _v2, _v1$2 ); + _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 + // 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 + // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned) + 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 + ]; + if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) { + + return false; + + } + + // test 3 face normals from the aabb + axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ]; + if ( ! satForAxes( axes, _v0, _v1$2, _v2, _extents ) ) { + + return false; + + } + + // finally testing the face normal of the triangle + // use already existing triangle edge vectors here + _triangleNormal.crossVectors( _f0, _f1 ); + axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ]; + + return satForAxes( axes, _v0, _v1$2, _v2, _extents ); + + }, + + clampPoint: function ( point, target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Box3: .clampPoint() target is now required' ); + target = new Vector3(); + + } + + return target.copy( point ).clamp( this.min, this.max ); + + }, + + distanceToPoint: function ( point ) { + + var clampedPoint = _vector$1.copy( point ).clamp( this.min, this.max ); + + return clampedPoint.sub( point ).length(); + + }, + + getBoundingSphere: function ( target ) { + + if ( target === undefined ) { + + console.error( 'THREE.Box3: .getBoundingSphere() target is now required' ); + //target = new Sphere(); // removed to avoid cyclic dependency + + } + + this.getCenter( target.center ); + + target.radius = this.getSize( _vector$1 ).length() * 0.5; + + return target; + + }, + + intersect: function ( box ) { + + this.min.max( box.min ); + 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. + if ( this.isEmpty() ) { this.makeEmpty(); } + + return this; + + }, + + union: function ( box ) { + + this.min.min( box.min ); + this.max.max( box.max ); + + return this; + + }, + + applyMatrix4: function ( matrix ) { + + // transform of empty box is an empty box. + if ( this.isEmpty() ) { return this; } + + // NOTE: I am using a binary pattern to specify all 2^3 combinations below + _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000 + _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001 + _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010 + _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011 + _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100 + _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101 + _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110 + _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111 + + this.setFromPoints( _points ); + + return this; + + }, + + translate: function ( offset ) { + + this.min.add( offset ); + this.max.add( offset ); + + return this; + + }, + + equals: function ( box ) { + + return box.min.equals( this.min ) && box.max.equals( this.max ); + + } + + } ); + + function satForAxes( axes, v0, v1, v2, extents ) { + + for ( var i = 0, j = axes.length - 3; i <= j; i += 3 ) { + + _testAxis.fromArray( axes, i ); + // project the aabb onto the seperating axis + 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 + var p0 = v0.dot( _testAxis ); + var p1 = v1.dot( _testAxis ); + var p2 = v2.dot( _testAxis ); + // actual test, basically see if either of the most extreme of the triangle points intersects r + if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) { + + // points of the projected triangle are outside the projected half-length of the aabb + // the axis is seperating and we can exit + return false; + + } + + } + + return true; + + } + + var _box$1 = new Box3(); + + function Sphere( center, radius ) { + + this.center = ( center !== undefined ) ? center : new Vector3(); + this.radius = ( radius !== undefined ) ? radius : - 1; + + } + + Object.assign( Sphere.prototype, { + + set: function ( center, radius ) { + + this.center.copy( center ); + this.radius = radius; + + return this; + + }, + + setFromPoints: function ( points, optionalCenter ) { + + var center = this.center; + + if ( optionalCenter !== undefined ) { + + center.copy( optionalCenter ); + + } else { + + _box$1.setFromPoints( points ).getCenter( center ); + + } + + var maxRadiusSq = 0; + + for ( var i = 0, il = points.length; i < il; i ++ ) { + + maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) ); + + } + + this.radius = Math.sqrt( maxRadiusSq ); + + return this; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( sphere ) { + + this.center.copy( sphere.center ); + this.radius = sphere.radius; + + return this; + + }, + + isEmpty: function () { + + return ( this.radius < 0 ); + + }, + + makeEmpty: function () { + + this.center.set( 0, 0, 0 ); + this.radius = - 1; + + return this; + + }, + + containsPoint: function ( point ) { + + return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) ); + + }, + + distanceToPoint: function ( point ) { + + return ( point.distanceTo( this.center ) - this.radius ); + + }, + + intersectsSphere: function ( sphere ) { + + var radiusSum = this.radius + sphere.radius; + + return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum ); + + }, + + intersectsBox: function ( box ) { + + return box.intersectsSphere( this ); + + }, + + intersectsPlane: function ( plane ) { + + return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius; + + }, + + clampPoint: function ( point, target ) { + + var deltaLengthSq = this.center.distanceToSquared( point ); + + if ( target === undefined ) { + + console.warn( 'THREE.Sphere: .clampPoint() target is now required' ); + target = new Vector3(); + + } + + target.copy( point ); + + if ( deltaLengthSq > ( this.radius * this.radius ) ) { + + target.sub( this.center ).normalize(); + target.multiplyScalar( this.radius ).add( this.center ); + + } + + return target; + + }, + + getBoundingBox: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' ); + target = new Box3(); + + } + + if ( this.isEmpty() ) { + + // Empty sphere produces empty bounding box + target.makeEmpty(); + return target; + + } + + target.set( this.center, this.center ); + target.expandByScalar( this.radius ); + + return target; + + }, + + applyMatrix4: function ( matrix ) { + + this.center.applyMatrix4( matrix ); + this.radius = this.radius * matrix.getMaxScaleOnAxis(); + + return this; + + }, + + translate: function ( offset ) { + + this.center.add( offset ); + + return this; + + }, + + equals: function ( sphere ) { + + return sphere.center.equals( this.center ) && ( sphere.radius === this.radius ); + + } + + } ); + + var _vector$2 = new Vector3(); + var _segCenter = new Vector3(); + var _segDir = new Vector3(); + var _diff = new Vector3(); + + var _edge1 = new Vector3(); + var _edge2 = new Vector3(); + var _normal = new Vector3(); + + function Ray( origin, direction ) { + + this.origin = ( origin !== undefined ) ? origin : new Vector3(); + this.direction = ( direction !== undefined ) ? direction : new Vector3( 0, 0, - 1 ); + + } + + Object.assign( Ray.prototype, { + + set: function ( origin, direction ) { + + this.origin.copy( origin ); + this.direction.copy( direction ); + + return this; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( ray ) { + + this.origin.copy( ray.origin ); + this.direction.copy( ray.direction ); + + return this; + + }, + + at: function ( t, target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Ray: .at() target is now required' ); + target = new Vector3(); + + } + + return target.copy( this.direction ).multiplyScalar( t ).add( this.origin ); + + }, + + lookAt: function ( v ) { + + this.direction.copy( v ).sub( this.origin ).normalize(); + + return this; + + }, + + recast: function ( t ) { + + this.origin.copy( this.at( t, _vector$2 ) ); + + return this; + + }, + + closestPointToPoint: function ( point, target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' ); + target = new Vector3(); + + } + + target.subVectors( point, this.origin ); + + var directionDistance = target.dot( this.direction ); + + if ( directionDistance < 0 ) { + + return target.copy( this.origin ); + + } + + return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin ); + + }, + + distanceToPoint: function ( point ) { + + return Math.sqrt( this.distanceSqToPoint( point ) ); + + }, + + distanceSqToPoint: function ( point ) { + + var directionDistance = _vector$2.subVectors( point, this.origin ).dot( this.direction ); + + // point behind the ray + + if ( directionDistance < 0 ) { + + return this.origin.distanceToSquared( point ); + + } + + _vector$2.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin ); + + return _vector$2.distanceToSquared( point ); + + }, + + distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) { + + // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h + // It returns the min distance between the ray and the segment + // defined by v0 and v1 + // It can also set two optional targets : + // - The closest point on the ray + // - The closest point on the segment + + _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 ); + _segDir.copy( v1 ).sub( v0 ).normalize(); + _diff.copy( this.origin ).sub( _segCenter ); + + var segExtent = v0.distanceTo( v1 ) * 0.5; + var a01 = - this.direction.dot( _segDir ); + var b0 = _diff.dot( this.direction ); + var b1 = - _diff.dot( _segDir ); + var c = _diff.lengthSq(); + var det = Math.abs( 1 - a01 * a01 ); + var s0, s1, sqrDist, extDet; + + if ( det > 0 ) { + + // The ray and segment are not parallel. + + s0 = a01 * b1 - b0; + s1 = a01 * b0 - b1; + extDet = segExtent * det; + + if ( s0 >= 0 ) { + + if ( s1 >= - extDet ) { + + if ( s1 <= extDet ) { + + // region 0 + // Minimum at interior points of ray and segment. + + var invDet = 1 / det; + s0 *= invDet; + s1 *= invDet; + sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c; + + } else { + + // region 1 + + s1 = segExtent; + s0 = Math.max( 0, - ( a01 * s1 + b0 ) ); + sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c; + + } + + } else { + + // region 5 + + s1 = - segExtent; + s0 = Math.max( 0, - ( a01 * s1 + b0 ) ); + sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c; + + } + + } else { + + if ( s1 <= - extDet ) { + + // region 4 + + s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) ); + s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent ); + sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c; + + } else if ( s1 <= extDet ) { + + // region 3 + + s0 = 0; + s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent ); + sqrDist = s1 * ( s1 + 2 * b1 ) + c; + + } else { + + // region 2 + + s0 = Math.max( 0, - ( a01 * segExtent + b0 ) ); + s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent ); + sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c; + + } + + } + + } else { + + // Ray and segment are parallel. + + s1 = ( a01 > 0 ) ? - segExtent : segExtent; + s0 = Math.max( 0, - ( a01 * s1 + b0 ) ); + sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c; + + } + + if ( optionalPointOnRay ) { + + optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin ); + + } + + if ( optionalPointOnSegment ) { + + optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter ); + + } + + return sqrDist; + + }, + + intersectSphere: function ( sphere, target ) { + + _vector$2.subVectors( sphere.center, this.origin ); + var tca = _vector$2.dot( this.direction ); + var d2 = _vector$2.dot( _vector$2 ) - tca * tca; + var radius2 = sphere.radius * sphere.radius; + + if ( d2 > radius2 ) { return null; } + + var thc = Math.sqrt( radius2 - d2 ); + + // t0 = first intersect point - entrance on front of sphere + var t0 = tca - thc; + + // t1 = second intersect point - exit point on back of sphere + var t1 = tca + thc; + + // test to see if both t0 and t1 are behind the ray - if so, return null + if ( t0 < 0 && t1 < 0 ) { return null; } + + // test to see if t0 is behind the ray: + // if it is, the ray is inside the sphere, so return the second exit point scaled by t1, + // in order to always return an intersect point that is in front of the ray. + 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 + return this.at( t0, target ); + + }, + + intersectsSphere: function ( sphere ) { + + return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius ); + + }, + + distanceToPlane: function ( plane ) { + + var denominator = plane.normal.dot( this.direction ); + + if ( denominator === 0 ) { + + // line is coplanar, return origin + if ( plane.distanceToPoint( this.origin ) === 0 ) { + + return 0; + + } + + // Null is preferable to undefined since undefined means.... it is undefined + + return null; + + } + + var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator; + + // Return if the ray never intersects the plane + + return t >= 0 ? t : null; + + }, + + intersectPlane: function ( plane, target ) { + + var t = this.distanceToPlane( plane ); + + if ( t === null ) { + + return null; + + } + + return this.at( t, target ); + + }, + + intersectsPlane: function ( plane ) { + + // check if the ray lies on the plane first + + var distToPoint = plane.distanceToPoint( this.origin ); + + if ( distToPoint === 0 ) { + + return true; + + } + + var denominator = plane.normal.dot( this.direction ); + + if ( denominator * distToPoint < 0 ) { + + return true; + + } + + // ray origin is behind the plane (and is pointing behind it) + + return false; + + }, + + intersectBox: function ( box, target ) { + + var tmin, tmax, tymin, tymax, tzmin, tzmax; + + var invdirx = 1 / this.direction.x, + invdiry = 1 / this.direction.y, + invdirz = 1 / this.direction.z; + + var origin = this.origin; + + if ( invdirx >= 0 ) { + + tmin = ( box.min.x - origin.x ) * invdirx; + tmax = ( box.max.x - origin.x ) * invdirx; + + } else { + + tmin = ( box.max.x - origin.x ) * invdirx; + tmax = ( box.min.x - origin.x ) * invdirx; + + } + + if ( invdiry >= 0 ) { + + tymin = ( box.min.y - origin.y ) * invdiry; + tymax = ( box.max.y - origin.y ) * invdiry; + + } else { + + tymin = ( box.max.y - origin.y ) * invdiry; + tymax = ( box.min.y - origin.y ) * invdiry; + + } + + if ( ( tmin > tymax ) || ( tymin > tmax ) ) { return null; } + + // These lines also handle the case where tmin or tmax is NaN + // (result of 0 * Infinity). x !== x returns true if x is NaN + + if ( tymin > tmin || tmin !== tmin ) { tmin = tymin; } + + if ( tymax < tmax || tmax !== tmax ) { tmax = tymax; } + + if ( invdirz >= 0 ) { + + tzmin = ( box.min.z - origin.z ) * invdirz; + tzmax = ( box.max.z - origin.z ) * invdirz; + + } else { + + tzmin = ( box.max.z - origin.z ) * invdirz; + tzmax = ( box.min.z - origin.z ) * invdirz; + + } + + if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) { return null; } + + if ( tzmin > tmin || tmin !== tmin ) { tmin = tzmin; } + + if ( tzmax < tmax || tmax !== tmax ) { tmax = tzmax; } + + //return point closest to the ray (positive side) + + if ( tmax < 0 ) { return null; } + + return this.at( tmin >= 0 ? tmin : tmax, target ); + + }, + + intersectsBox: function ( box ) { + + return this.intersectBox( box, _vector$2 ) !== null; + + }, + + intersectTriangle: function ( a, b, c, backfaceCulling, target ) { + + // Compute the offset origin, edges, and normal. + + // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h + + _edge1.subVectors( b, a ); + _edge2.subVectors( c, a ); + _normal.crossVectors( _edge1, _edge2 ); + + // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction, + // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by + // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2)) + // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q)) + // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N) + var DdN = this.direction.dot( _normal ); + var sign; + + if ( DdN > 0 ) { + + if ( backfaceCulling ) { return null; } + sign = 1; + + } else if ( DdN < 0 ) { + + sign = - 1; + DdN = - DdN; + + } else { + + return null; + + } + + _diff.subVectors( this.origin, a ); + var DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) ); + + // b1 < 0, no intersection + if ( DdQxE2 < 0 ) { + + return null; + + } + + var DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) ); + + // b2 < 0, no intersection + if ( DdE1xQ < 0 ) { + + return null; + + } + + // b1+b2 > 1, no intersection + if ( DdQxE2 + DdE1xQ > DdN ) { + + return null; + + } + + // Line intersects triangle, check if ray does. + var QdN = - sign * _diff.dot( _normal ); + + // t < 0, no intersection + if ( QdN < 0 ) { + + return null; + + } + + // Ray intersects triangle. + return this.at( QdN / DdN, target ); + + }, + + applyMatrix4: function ( matrix4 ) { + + this.origin.applyMatrix4( matrix4 ); + this.direction.transformDirection( matrix4 ); + + return this; + + }, + + equals: function ( ray ) { + + return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction ); + + } + + } ); + + var _vector1 = new Vector3(); + var _vector2 = new Vector3(); + var _normalMatrix = new Matrix3(); + + function Plane( normal, constant ) { + + // normal is assumed to be normalized + + this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 ); + this.constant = ( constant !== undefined ) ? constant : 0; + + } + + Object.assign( Plane.prototype, { + + isPlane: true, + + set: function ( normal, constant ) { + + this.normal.copy( normal ); + this.constant = constant; + + return this; + + }, + + setComponents: function ( x, y, z, w ) { + + this.normal.set( x, y, z ); + this.constant = w; + + return this; + + }, + + setFromNormalAndCoplanarPoint: function ( normal, point ) { + + this.normal.copy( normal ); + this.constant = - point.dot( this.normal ); + + return this; + + }, + + setFromCoplanarPoints: function ( a, b, c ) { + + 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)? + + this.setFromNormalAndCoplanarPoint( normal, a ); + + return this; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( plane ) { + + this.normal.copy( plane.normal ); + this.constant = plane.constant; + + return this; + + }, + + normalize: function () { + + // Note: will lead to a divide by zero if the plane is invalid. + + var inverseNormalLength = 1.0 / this.normal.length(); + this.normal.multiplyScalar( inverseNormalLength ); + this.constant *= inverseNormalLength; + + return this; + + }, + + negate: function () { + + this.constant *= - 1; + this.normal.negate(); + + return this; + + }, + + distanceToPoint: function ( point ) { + + return this.normal.dot( point ) + this.constant; + + }, + + distanceToSphere: function ( sphere ) { + + return this.distanceToPoint( sphere.center ) - sphere.radius; + + }, + + projectPoint: function ( point, target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Plane: .projectPoint() target is now required' ); + target = new Vector3(); + + } + + return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point ); + + }, + + intersectLine: function ( line, target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Plane: .intersectLine() target is now required' ); + target = new Vector3(); + + } + + var direction = line.delta( _vector1 ); + + var denominator = this.normal.dot( direction ); + + if ( denominator === 0 ) { + + // line is coplanar, return origin + if ( this.distanceToPoint( line.start ) === 0 ) { + + return target.copy( line.start ); + + } + + // Unsure if this is the correct method to handle this case. + return undefined; + + } + + var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator; + + if ( t < 0 || t > 1 ) { + + return undefined; + + } + + return target.copy( direction ).multiplyScalar( t ).add( line.start ); + + }, + + intersectsLine: function ( line ) { + + // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it. + + var startSign = this.distanceToPoint( line.start ); + var endSign = this.distanceToPoint( line.end ); + + return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 ); + + }, + + intersectsBox: function ( box ) { + + return box.intersectsPlane( this ); + + }, + + intersectsSphere: function ( sphere ) { + + return sphere.intersectsPlane( this ); + + }, + + coplanarPoint: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Plane: .coplanarPoint() target is now required' ); + target = new Vector3(); + + } + + return target.copy( this.normal ).multiplyScalar( - this.constant ); + + }, + + applyMatrix4: function ( matrix, optionalNormalMatrix ) { + + var normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix ); + + var referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix ); + + var normal = this.normal.applyMatrix3( normalMatrix ).normalize(); + + this.constant = - referencePoint.dot( normal ); + + return this; + + }, + + translate: function ( offset ) { + + this.constant -= offset.dot( this.normal ); + + return this; + + }, + + equals: function ( plane ) { + + return plane.normal.equals( this.normal ) && ( plane.constant === this.constant ); + + } + + } ); + + var _v0$1 = new Vector3(); + var _v1$3 = new Vector3(); + var _v2$1 = new Vector3(); + var _v3 = new Vector3(); + + var _vab = new Vector3(); + var _vac = new Vector3(); + var _vbc = new Vector3(); + var _vap = new Vector3(); + var _vbp = new Vector3(); + var _vcp = new Vector3(); + + function Triangle( a, b, c ) { + + this.a = ( a !== undefined ) ? a : new Vector3(); + this.b = ( b !== undefined ) ? b : new Vector3(); + this.c = ( c !== undefined ) ? c : new Vector3(); + + } + + Object.assign( Triangle, { + + getNormal: function ( a, b, c, target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Triangle: .getNormal() target is now required' ); + target = new Vector3(); + + } + + target.subVectors( c, b ); + _v0$1.subVectors( a, b ); + target.cross( _v0$1 ); + + var targetLengthSq = target.lengthSq(); + if ( targetLengthSq > 0 ) { + + return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) ); + + } + + return target.set( 0, 0, 0 ); + + }, + + // static/instance method to calculate barycentric coordinates + // based on: http://www.blackpawn.com/texts/pointinpoly/default.html + getBarycoord: function ( point, a, b, c, target ) { + + _v0$1.subVectors( c, a ); + _v1$3.subVectors( b, a ); + _v2$1.subVectors( point, a ); + + var dot00 = _v0$1.dot( _v0$1 ); + var dot01 = _v0$1.dot( _v1$3 ); + var dot02 = _v0$1.dot( _v2$1 ); + var dot11 = _v1$3.dot( _v1$3 ); + var dot12 = _v1$3.dot( _v2$1 ); + + var denom = ( dot00 * dot11 - dot01 * dot01 ); + + if ( target === undefined ) { + + console.warn( 'THREE.Triangle: .getBarycoord() target is now required' ); + target = new Vector3(); + + } + + // collinear or singular triangle + if ( denom === 0 ) { + + // arbitrary location outside of triangle? + // not sure if this is the best idea, maybe should be returning undefined + return target.set( - 2, - 1, - 1 ); + + } + + var invDenom = 1 / denom; + var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom; + var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom; + + // barycentric coordinates must always sum to 1 + return target.set( 1 - u - v, v, u ); + + }, + + containsPoint: function ( point, a, b, c ) { + + Triangle.getBarycoord( point, a, b, c, _v3 ); + + return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 ); + + }, + + getUV: function ( point, p1, p2, p3, uv1, uv2, uv3, target ) { + + this.getBarycoord( point, p1, p2, p3, _v3 ); + + target.set( 0, 0 ); + target.addScaledVector( uv1, _v3.x ); + target.addScaledVector( uv2, _v3.y ); + target.addScaledVector( uv3, _v3.z ); + + return target; + + }, + + isFrontFacing: function ( a, b, c, direction ) { + + _v0$1.subVectors( c, b ); + _v1$3.subVectors( a, b ); + + // strictly front facing + return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false; + + } + + } ); + + Object.assign( Triangle.prototype, { + + set: function ( a, b, c ) { + + this.a.copy( a ); + this.b.copy( b ); + this.c.copy( c ); + + return this; + + }, + + setFromPointsAndIndices: function ( points, i0, i1, i2 ) { + + this.a.copy( points[ i0 ] ); + this.b.copy( points[ i1 ] ); + this.c.copy( points[ i2 ] ); + + return this; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( triangle ) { + + this.a.copy( triangle.a ); + this.b.copy( triangle.b ); + this.c.copy( triangle.c ); + + return this; + + }, + + getArea: function () { + + _v0$1.subVectors( this.c, this.b ); + _v1$3.subVectors( this.a, this.b ); + + return _v0$1.cross( _v1$3 ).length() * 0.5; + + }, + + getMidpoint: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Triangle: .getMidpoint() target is now required' ); + target = new Vector3(); + + } + + return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 ); + + }, + + getNormal: function ( target ) { + + return Triangle.getNormal( this.a, this.b, this.c, target ); + + }, + + getPlane: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Triangle: .getPlane() target is now required' ); + target = new Plane(); + + } + + return target.setFromCoplanarPoints( this.a, this.b, this.c ); + + }, + + getBarycoord: function ( point, target ) { + + return Triangle.getBarycoord( point, this.a, this.b, this.c, target ); + + }, + + getUV: function ( point, uv1, uv2, uv3, target ) { + + return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target ); + + }, + + containsPoint: function ( point ) { + + return Triangle.containsPoint( point, this.a, this.b, this.c ); + + }, + + isFrontFacing: function ( direction ) { + + return Triangle.isFrontFacing( this.a, this.b, this.c, direction ); + + }, + + intersectsBox: function ( box ) { + + return box.intersectsTriangle( this ); + + }, + + closestPointToPoint: function ( p, target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' ); + target = new Vector3(); + + } + + var a = this.a, b = this.b, c = this.c; + var v, w; + + // algorithm thanks to Real-Time Collision Detection by Christer Ericson, + // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc., + // under the accompanying license; see chapter 5.1.5 for detailed explanation. + // basically, we're distinguishing which of the voronoi regions of the triangle + // the point lies in with the minimum amount of redundant computation. + + _vab.subVectors( b, a ); + _vac.subVectors( c, a ); + _vap.subVectors( p, a ); + var d1 = _vab.dot( _vap ); + var d2 = _vac.dot( _vap ); + if ( d1 <= 0 && d2 <= 0 ) { + + // vertex region of A; barycentric coords (1, 0, 0) + return target.copy( a ); + + } + + _vbp.subVectors( p, b ); + var d3 = _vab.dot( _vbp ); + var d4 = _vac.dot( _vbp ); + if ( d3 >= 0 && d4 <= d3 ) { + + // vertex region of B; barycentric coords (0, 1, 0) + return target.copy( b ); + + } + + var vc = d1 * d4 - d3 * d2; + if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) { + + v = d1 / ( d1 - d3 ); + // edge region of AB; barycentric coords (1-v, v, 0) + return target.copy( a ).addScaledVector( _vab, v ); + + } + + _vcp.subVectors( p, c ); + var d5 = _vab.dot( _vcp ); + var d6 = _vac.dot( _vcp ); + if ( d6 >= 0 && d5 <= d6 ) { + + // vertex region of C; barycentric coords (0, 0, 1) + return target.copy( c ); + + } + + var vb = d5 * d2 - d1 * d6; + if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) { + + w = d2 / ( d2 - d6 ); + // edge region of AC; barycentric coords (1-w, 0, w) + return target.copy( a ).addScaledVector( _vac, w ); + + } + + var va = d3 * d6 - d5 * d4; + if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) { + + _vbc.subVectors( c, b ); + w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) ); + // edge region of BC; barycentric coords (0, 1-w, w) + return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC + + } + + // face region + var denom = 1 / ( va + vb + vc ); + // u = va * denom + v = vb * denom; + w = vc * denom; + + return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w ); + + }, + + equals: function ( triangle ) { + + return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c ); + + } + + } ); + + var _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF, + 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2, + 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50, + 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B, + 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B, + 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F, + 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3, + 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222, + 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700, + 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4, + 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00, + 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3, + 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA, + 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32, + 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3, + 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC, + 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD, + 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6, + 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9, + 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F, + 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE, + 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA, + 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0, + 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 }; + + var _hslA = { h: 0, s: 0, l: 0 }; + var _hslB = { h: 0, s: 0, l: 0 }; + + function Color( r, g, b ) { + + if ( g === undefined && b === undefined ) { + + // r is THREE.Color, hex or string + return this.set( r ); + + } + + return this.setRGB( r, g, b ); + + } + + function hue2rgb( p, q, t ) { + + if ( t < 0 ) { t += 1; } + if ( t > 1 ) { t -= 1; } + if ( t < 1 / 6 ) { return p + ( q - p ) * 6 * t; } + if ( t < 1 / 2 ) { return q; } + if ( t < 2 / 3 ) { return p + ( q - p ) * 6 * ( 2 / 3 - t ); } + return p; + + } + + function SRGBToLinear( c ) { + + return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 ); + + } + + function LinearToSRGB( c ) { + + return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055; + + } + + Object.assign( Color.prototype, { + + isColor: true, + + r: 1, g: 1, b: 1, + + set: function ( value ) { + + if ( value && value.isColor ) { + + this.copy( value ); + + } else if ( typeof value === 'number' ) { + + this.setHex( value ); + + } else if ( typeof value === 'string' ) { + + this.setStyle( value ); + + } + + return this; + + }, + + setScalar: function ( scalar ) { + + this.r = scalar; + this.g = scalar; + this.b = scalar; + + return this; + + }, + + setHex: function ( hex ) { + + hex = Math.floor( hex ); + + this.r = ( hex >> 16 & 255 ) / 255; + this.g = ( hex >> 8 & 255 ) / 255; + this.b = ( hex & 255 ) / 255; + + return this; + + }, + + setRGB: function ( r, g, b ) { + + this.r = r; + this.g = g; + this.b = b; + + return this; + + }, + + setHSL: function ( h, s, l ) { + + // h,s,l ranges are in 0.0 - 1.0 + h = MathUtils.euclideanModulo( h, 1 ); + s = MathUtils.clamp( s, 0, 1 ); + l = MathUtils.clamp( l, 0, 1 ); + + if ( s === 0 ) { + + this.r = this.g = this.b = l; + + } else { + + var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s ); + var q = ( 2 * l ) - p; + + this.r = hue2rgb( q, p, h + 1 / 3 ); + this.g = hue2rgb( q, p, h ); + this.b = hue2rgb( q, p, h - 1 / 3 ); + + } + + return this; + + }, + + setStyle: function ( style ) { + + function handleAlpha( string ) { + + if ( string === undefined ) { return; } + + if ( parseFloat( string ) < 1 ) { + + console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' ); + + } + + } + + + var m; + + if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) { + + // rgb / hsl + + var color; + var name = m[ 1 ]; + var components = m[ 2 ]; + + switch ( name ) { + + case 'rgb': + case 'rgba': + + if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) { + + // rgb(255,0,0) rgba(255,0,0,0.5) + this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255; + this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255; + this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255; + + handleAlpha( color[ 5 ] ); + + return this; + + } + + if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) { + + // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5) + this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100; + this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100; + this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100; + + handleAlpha( color[ 5 ] ); + + return this; + + } + + break; + + case 'hsl': + case 'hsla': + + if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) { + + // hsl(120,50%,50%) hsla(120,50%,50%,0.5) + var h = parseFloat( color[ 1 ] ) / 360; + var s = parseInt( color[ 2 ], 10 ) / 100; + var l = parseInt( color[ 3 ], 10 ) / 100; + + handleAlpha( color[ 5 ] ); + + return this.setHSL( h, s, l ); + + } + + break; + + } + + } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) { + + // hex color + + var hex = m[ 1 ]; + var size = hex.length; + + if ( size === 3 ) { + + // #ff0 + this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255; + this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255; + this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255; + + return this; + + } else if ( size === 6 ) { + + // #ff0000 + this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255; + this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255; + this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255; + + return this; + + } + + } + + if ( style && style.length > 0 ) { + + return this.setColorName( style ); + + } + + return this; + + }, + + setColorName: function ( style ) { + + // color keywords + var hex = _colorKeywords[ style ]; + + if ( hex !== undefined ) { + + // red + this.setHex( hex ); + + } else { + + // unknown color + console.warn( 'THREE.Color: Unknown color ' + style ); + + } + + return this; + + }, + + clone: function () { + + return new this.constructor( this.r, this.g, this.b ); + + }, + + copy: function ( color ) { + + this.r = color.r; + this.g = color.g; + this.b = color.b; + + return this; + + }, + + copyGammaToLinear: function ( color, gammaFactor ) { + + if ( gammaFactor === undefined ) { gammaFactor = 2.0; } + + this.r = Math.pow( color.r, gammaFactor ); + this.g = Math.pow( color.g, gammaFactor ); + this.b = Math.pow( color.b, gammaFactor ); + + return this; + + }, + + copyLinearToGamma: function ( color, gammaFactor ) { + + if ( gammaFactor === undefined ) { gammaFactor = 2.0; } + + var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0; + + this.r = Math.pow( color.r, safeInverse ); + this.g = Math.pow( color.g, safeInverse ); + this.b = Math.pow( color.b, safeInverse ); + + return this; + + }, + + convertGammaToLinear: function ( gammaFactor ) { + + this.copyGammaToLinear( this, gammaFactor ); + + return this; + + }, + + convertLinearToGamma: function ( gammaFactor ) { + + this.copyLinearToGamma( this, gammaFactor ); + + return this; + + }, + + copySRGBToLinear: function ( color ) { + + this.r = SRGBToLinear( color.r ); + this.g = SRGBToLinear( color.g ); + this.b = SRGBToLinear( color.b ); + + return this; + + }, + + copyLinearToSRGB: function ( color ) { + + this.r = LinearToSRGB( color.r ); + this.g = LinearToSRGB( color.g ); + this.b = LinearToSRGB( color.b ); + + return this; + + }, + + convertSRGBToLinear: function () { + + this.copySRGBToLinear( this ); + + return this; + + }, + + convertLinearToSRGB: function () { + + this.copyLinearToSRGB( this ); + + return this; + + }, + + getHex: function () { + + return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0; + + }, + + getHexString: function () { + + return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 ); + + }, + + getHSL: function ( target ) { + + // h,s,l ranges are in 0.0 - 1.0 + + if ( target === undefined ) { + + console.warn( 'THREE.Color: .getHSL() target is now required' ); + target = { h: 0, s: 0, l: 0 }; + + } + + var r = this.r, g = this.g, b = this.b; + + var max = Math.max( r, g, b ); + var min = Math.min( r, g, b ); + + var hue, saturation; + var lightness = ( min + max ) / 2.0; + + if ( min === max ) { + + hue = 0; + saturation = 0; + + } else { + + var delta = max - min; + + saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min ); + + switch ( max ) { + + case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break; + case g: hue = ( b - r ) / delta + 2; break; + case b: hue = ( r - g ) / delta + 4; break; + + } + + hue /= 6; + + } + + target.h = hue; + target.s = saturation; + target.l = lightness; + + return target; + + }, + + getStyle: function () { + + return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')'; + + }, + + offsetHSL: function ( h, s, l ) { + + this.getHSL( _hslA ); + + _hslA.h += h; _hslA.s += s; _hslA.l += l; + + this.setHSL( _hslA.h, _hslA.s, _hslA.l ); + + return this; + + }, + + add: function ( color ) { + + this.r += color.r; + this.g += color.g; + this.b += color.b; + + return this; + + }, + + addColors: function ( color1, color2 ) { + + this.r = color1.r + color2.r; + this.g = color1.g + color2.g; + this.b = color1.b + color2.b; + + return this; + + }, + + addScalar: function ( s ) { + + this.r += s; + this.g += s; + this.b += s; + + return this; + + }, + + sub: function ( color ) { + + this.r = Math.max( 0, this.r - color.r ); + this.g = Math.max( 0, this.g - color.g ); + this.b = Math.max( 0, this.b - color.b ); + + return this; + + }, + + multiply: function ( color ) { + + this.r *= color.r; + this.g *= color.g; + this.b *= color.b; + + return this; + + }, + + multiplyScalar: function ( s ) { + + this.r *= s; + this.g *= s; + this.b *= s; + + return this; + + }, + + lerp: function ( color, alpha ) { + + this.r += ( color.r - this.r ) * alpha; + this.g += ( color.g - this.g ) * alpha; + this.b += ( color.b - this.b ) * alpha; + + return this; + + }, + + lerpHSL: function ( color, alpha ) { + + this.getHSL( _hslA ); + color.getHSL( _hslB ); + + var h = MathUtils.lerp( _hslA.h, _hslB.h, alpha ); + var s = MathUtils.lerp( _hslA.s, _hslB.s, alpha ); + var l = MathUtils.lerp( _hslA.l, _hslB.l, alpha ); + + this.setHSL( h, s, l ); + + return this; + + }, + + equals: function ( c ) { + + return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b ); + + }, + + fromArray: function ( array, offset ) { + + if ( offset === undefined ) { offset = 0; } + + this.r = array[ offset ]; + this.g = array[ offset + 1 ]; + this.b = array[ offset + 2 ]; + + return this; + + }, + + toArray: function ( array, offset ) { + + if ( array === undefined ) { array = []; } + if ( offset === undefined ) { offset = 0; } + + array[ offset ] = this.r; + array[ offset + 1 ] = this.g; + array[ offset + 2 ] = this.b; + + return array; + + }, + + fromBufferAttribute: function ( attribute, index ) { + + this.r = attribute.getX( index ); + this.g = attribute.getY( index ); + this.b = attribute.getZ( index ); + + if ( attribute.normalized === true ) { + + // assuming Uint8Array + + this.r /= 255; + this.g /= 255; + this.b /= 255; + + } + + return this; + + }, + + toJSON: function () { + + return this.getHex(); + + } + + } ); + + Color.NAMES = _colorKeywords; + + function Face3( a, b, c, normal, color, materialIndex ) { + + this.a = a; + this.b = b; + this.c = c; + + this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3(); + this.vertexNormals = Array.isArray( normal ) ? normal : []; + + this.color = ( color && color.isColor ) ? color : new Color(); + this.vertexColors = Array.isArray( color ) ? color : []; + + this.materialIndex = materialIndex !== undefined ? materialIndex : 0; + + } + + Object.assign( Face3.prototype, { + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( source ) { + + this.a = source.a; + this.b = source.b; + this.c = source.c; + + this.normal.copy( source.normal ); + this.color.copy( source.color ); + + this.materialIndex = source.materialIndex; + + for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) { + + this.vertexNormals[ i ] = source.vertexNormals[ i ].clone(); + + } + + for ( var i$1 = 0, il$1 = source.vertexColors.length; i$1 < il$1; i$1 ++ ) { + + this.vertexColors[ i$1 ] = source.vertexColors[ i$1 ].clone(); + + } + + return this; + + } + + } ); + + var materialId = 0; + + function Material() { + + Object.defineProperty( this, 'id', { value: materialId ++ } ); + + this.uuid = MathUtils.generateUUID(); + + this.name = ''; + this.type = 'Material'; + + this.fog = true; + + this.blending = NormalBlending; + this.side = FrontSide; + this.flatShading = false; + this.vertexColors = false; + + this.opacity = 1; + this.transparent = false; + + this.blendSrc = SrcAlphaFactor; + this.blendDst = OneMinusSrcAlphaFactor; + this.blendEquation = AddEquation; + this.blendSrcAlpha = null; + this.blendDstAlpha = null; + this.blendEquationAlpha = null; + + this.depthFunc = LessEqualDepth; + this.depthTest = true; + this.depthWrite = true; + + this.stencilWriteMask = 0xff; + this.stencilFunc = AlwaysStencilFunc; + this.stencilRef = 0; + this.stencilFuncMask = 0xff; + this.stencilFail = KeepStencilOp; + this.stencilZFail = KeepStencilOp; + this.stencilZPass = KeepStencilOp; + this.stencilWrite = false; + + this.clippingPlanes = null; + this.clipIntersection = false; + this.clipShadows = false; + + this.shadowSide = null; + + this.colorWrite = true; + + this.precision = null; // override the renderer's default precision for this material + + this.polygonOffset = false; + this.polygonOffsetFactor = 0; + this.polygonOffsetUnits = 0; + + this.dithering = false; + + this.alphaTest = 0; + this.premultipliedAlpha = false; + + this.visible = true; + + this.toneMapped = true; + + this.userData = {}; + + this.version = 0; + + } + + Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { + + constructor: Material, + + isMaterial: true, + + onBeforeCompile: function ( /* shaderobject, renderer */ ) {}, + + customProgramCacheKey: function () { + + return this.onBeforeCompile.toString(); + + }, + + setValues: function ( values ) { + + if ( values === undefined ) { return; } + + for ( var key in values ) { + + var newValue = values[ key ]; + + if ( newValue === undefined ) { + + console.warn( "THREE.Material: '" + key + "' parameter is undefined." ); + continue; + + } + + // for backward compatability if shading is set in the constructor + if ( key === 'shading' ) { + + console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' ); + this.flatShading = ( newValue === FlatShading ) ? true : false; + continue; + + } + + var currentValue = this[ key ]; + + if ( currentValue === undefined ) { + + console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." ); + continue; + + } + + if ( currentValue && currentValue.isColor ) { + + currentValue.set( newValue ); + + } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) { + + currentValue.copy( newValue ); + + } else { + + this[ key ] = newValue; + + } + + } + + }, + + toJSON: function ( meta ) { + + var isRoot = ( meta === undefined || typeof meta === 'string' ); + + if ( isRoot ) { + + meta = { + textures: {}, + images: {} + }; + + } + + var data = { + metadata: { + version: 4.5, + type: 'Material', + generator: 'Material.toJSON' + } + }; + + // standard Material serialization + data.uuid = this.uuid; + data.type = this.type; + + if ( this.name !== '' ) { data.name = this.name; } + + if ( this.color && this.color.isColor ) { data.color = this.color.getHex(); } + + if ( this.roughness !== undefined ) { data.roughness = this.roughness; } + if ( this.metalness !== undefined ) { data.metalness = this.metalness; } + + if ( this.sheen && this.sheen.isColor ) { data.sheen = this.sheen.getHex(); } + if ( this.emissive && this.emissive.isColor ) { data.emissive = this.emissive.getHex(); } + if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) { data.emissiveIntensity = this.emissiveIntensity; } + + if ( this.specular && this.specular.isColor ) { data.specular = this.specular.getHex(); } + if ( this.shininess !== undefined ) { data.shininess = this.shininess; } + if ( this.clearcoat !== undefined ) { data.clearcoat = this.clearcoat; } + if ( this.clearcoatRoughness !== undefined ) { data.clearcoatRoughness = this.clearcoatRoughness; } + + if ( this.clearcoatMap && this.clearcoatMap.isTexture ) { + + data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid; + + } + + if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) { + + data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid; + + } + + if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) { + + data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid; + data.clearcoatNormalScale = this.clearcoatNormalScale.toArray(); + + } + + if ( this.map && this.map.isTexture ) { data.map = this.map.toJSON( meta ).uuid; } + if ( this.matcap && this.matcap.isTexture ) { data.matcap = this.matcap.toJSON( meta ).uuid; } + if ( this.alphaMap && this.alphaMap.isTexture ) { data.alphaMap = this.alphaMap.toJSON( meta ).uuid; } + if ( this.lightMap && this.lightMap.isTexture ) { data.lightMap = this.lightMap.toJSON( meta ).uuid; } + + if ( this.aoMap && this.aoMap.isTexture ) { + + data.aoMap = this.aoMap.toJSON( meta ).uuid; + data.aoMapIntensity = this.aoMapIntensity; + + } + + if ( this.bumpMap && this.bumpMap.isTexture ) { + + data.bumpMap = this.bumpMap.toJSON( meta ).uuid; + data.bumpScale = this.bumpScale; + + } + + if ( this.normalMap && this.normalMap.isTexture ) { + + data.normalMap = this.normalMap.toJSON( meta ).uuid; + data.normalMapType = this.normalMapType; + data.normalScale = this.normalScale.toArray(); + + } + + if ( this.displacementMap && this.displacementMap.isTexture ) { + + data.displacementMap = this.displacementMap.toJSON( meta ).uuid; + data.displacementScale = this.displacementScale; + data.displacementBias = this.displacementBias; + + } + + if ( this.roughnessMap && this.roughnessMap.isTexture ) { data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid; } + if ( this.metalnessMap && this.metalnessMap.isTexture ) { data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid; } + + if ( this.emissiveMap && this.emissiveMap.isTexture ) { data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid; } + if ( this.specularMap && this.specularMap.isTexture ) { data.specularMap = this.specularMap.toJSON( meta ).uuid; } + + if ( this.envMap && this.envMap.isTexture ) { + + data.envMap = this.envMap.toJSON( meta ).uuid; + data.reflectivity = this.reflectivity; // Scale behind envMap + data.refractionRatio = this.refractionRatio; + + if ( this.combine !== undefined ) { data.combine = this.combine; } + if ( this.envMapIntensity !== undefined ) { data.envMapIntensity = this.envMapIntensity; } + + } + + if ( this.gradientMap && this.gradientMap.isTexture ) { + + data.gradientMap = this.gradientMap.toJSON( meta ).uuid; + + } + + if ( this.size !== undefined ) { data.size = this.size; } + if ( this.sizeAttenuation !== undefined ) { data.sizeAttenuation = this.sizeAttenuation; } + + if ( this.blending !== NormalBlending ) { data.blending = this.blending; } + if ( this.flatShading === true ) { data.flatShading = this.flatShading; } + if ( this.side !== FrontSide ) { data.side = this.side; } + if ( this.vertexColors ) { data.vertexColors = true; } + + if ( this.opacity < 1 ) { data.opacity = this.opacity; } + if ( this.transparent === true ) { data.transparent = this.transparent; } + + data.depthFunc = this.depthFunc; + data.depthTest = this.depthTest; + data.depthWrite = this.depthWrite; + + data.stencilWrite = this.stencilWrite; + data.stencilWriteMask = this.stencilWriteMask; + data.stencilFunc = this.stencilFunc; + data.stencilRef = this.stencilRef; + data.stencilFuncMask = this.stencilFuncMask; + data.stencilFail = this.stencilFail; + data.stencilZFail = this.stencilZFail; + data.stencilZPass = this.stencilZPass; + + // rotation (SpriteMaterial) + if ( this.rotation && this.rotation !== 0 ) { data.rotation = this.rotation; } + + if ( this.polygonOffset === true ) { data.polygonOffset = true; } + if ( this.polygonOffsetFactor !== 0 ) { data.polygonOffsetFactor = this.polygonOffsetFactor; } + if ( this.polygonOffsetUnits !== 0 ) { data.polygonOffsetUnits = this.polygonOffsetUnits; } + + if ( this.linewidth && this.linewidth !== 1 ) { data.linewidth = this.linewidth; } + if ( this.dashSize !== undefined ) { data.dashSize = this.dashSize; } + if ( this.gapSize !== undefined ) { data.gapSize = this.gapSize; } + if ( this.scale !== undefined ) { data.scale = this.scale; } + + if ( this.dithering === true ) { data.dithering = true; } + + if ( this.alphaTest > 0 ) { data.alphaTest = this.alphaTest; } + if ( this.premultipliedAlpha === true ) { data.premultipliedAlpha = this.premultipliedAlpha; } + + if ( this.wireframe === true ) { data.wireframe = this.wireframe; } + if ( this.wireframeLinewidth > 1 ) { data.wireframeLinewidth = this.wireframeLinewidth; } + if ( this.wireframeLinecap !== 'round' ) { data.wireframeLinecap = this.wireframeLinecap; } + if ( this.wireframeLinejoin !== 'round' ) { data.wireframeLinejoin = this.wireframeLinejoin; } + + if ( this.morphTargets === true ) { data.morphTargets = true; } + if ( this.morphNormals === true ) { data.morphNormals = true; } + if ( this.skinning === true ) { data.skinning = true; } + + if ( this.visible === false ) { data.visible = false; } + + if ( this.toneMapped === false ) { data.toneMapped = false; } + + if ( JSON.stringify( this.userData ) !== '{}' ) { data.userData = this.userData; } + + // TODO: Copied from Object3D.toJSON + + function extractFromCache( cache ) { + + var values = []; + + for ( var key in cache ) { + + var data = cache[ key ]; + delete data.metadata; + values.push( data ); + + } + + return values; + + } + + if ( isRoot ) { + + var textures = extractFromCache( meta.textures ); + var images = extractFromCache( meta.images ); + + if ( textures.length > 0 ) { data.textures = textures; } + if ( images.length > 0 ) { data.images = images; } + + } + + return data; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( source ) { + + this.name = source.name; + + this.fog = source.fog; + + this.blending = source.blending; + this.side = source.side; + this.flatShading = source.flatShading; + this.vertexColors = source.vertexColors; + + this.opacity = source.opacity; + this.transparent = source.transparent; + + this.blendSrc = source.blendSrc; + this.blendDst = source.blendDst; + this.blendEquation = source.blendEquation; + this.blendSrcAlpha = source.blendSrcAlpha; + this.blendDstAlpha = source.blendDstAlpha; + this.blendEquationAlpha = source.blendEquationAlpha; + + this.depthFunc = source.depthFunc; + this.depthTest = source.depthTest; + this.depthWrite = source.depthWrite; + + this.stencilWriteMask = source.stencilWriteMask; + this.stencilFunc = source.stencilFunc; + this.stencilRef = source.stencilRef; + this.stencilFuncMask = source.stencilFuncMask; + this.stencilFail = source.stencilFail; + this.stencilZFail = source.stencilZFail; + this.stencilZPass = source.stencilZPass; + this.stencilWrite = source.stencilWrite; + + var srcPlanes = source.clippingPlanes; + var dstPlanes = null; + + if ( srcPlanes !== null ) { + + var n = srcPlanes.length; + dstPlanes = new Array( n ); + + for ( var i = 0; i !== n; ++ i ) { + + dstPlanes[ i ] = srcPlanes[ i ].clone(); + + } + + } + + this.clippingPlanes = dstPlanes; + this.clipIntersection = source.clipIntersection; + this.clipShadows = source.clipShadows; + + this.shadowSide = source.shadowSide; + + this.colorWrite = source.colorWrite; + + this.precision = source.precision; + + this.polygonOffset = source.polygonOffset; + this.polygonOffsetFactor = source.polygonOffsetFactor; + this.polygonOffsetUnits = source.polygonOffsetUnits; + + this.dithering = source.dithering; + + this.alphaTest = source.alphaTest; + this.premultipliedAlpha = source.premultipliedAlpha; + + this.visible = source.visible; + + this.toneMapped = source.toneMapped; + + this.userData = JSON.parse( JSON.stringify( source.userData ) ); + + return this; + + }, + + dispose: function () { + + this.dispatchEvent( { type: 'dispose' } ); + + } + + } ); + + Object.defineProperty( Material.prototype, 'needsUpdate', { + + set: function ( value ) { + + if ( value === true ) { this.version ++; } + + } + + } ); + + /** + * parameters = { + * color: , + * opacity: , + * map: new THREE.Texture( ), + * + * lightMap: new THREE.Texture( ), + * lightMapIntensity: + * + * aoMap: new THREE.Texture( ), + * aoMapIntensity: + * + * specularMap: new THREE.Texture( ), + * + * alphaMap: new THREE.Texture( ), + * + * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ), + * combine: THREE.Multiply, + * reflectivity: , + * refractionRatio: , + * + * depthTest: , + * depthWrite: , + * + * wireframe: , + * wireframeLinewidth: , + * + * skinning: , + * morphTargets: + * } + */ + + function MeshBasicMaterial( parameters ) { + + Material.call( this ); + + this.type = 'MeshBasicMaterial'; + + this.color = new Color( 0xffffff ); // emissive + + this.map = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.specularMap = null; + + this.alphaMap = null; + + this.envMap = null; + this.combine = MultiplyOperation; + this.reflectivity = 1; + this.refractionRatio = 0.98; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.skinning = false; + this.morphTargets = false; + + this.setValues( parameters ); + + } + + MeshBasicMaterial.prototype = Object.create( Material.prototype ); + MeshBasicMaterial.prototype.constructor = MeshBasicMaterial; + + MeshBasicMaterial.prototype.isMeshBasicMaterial = true; + + MeshBasicMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.color.copy( source.color ); + + this.map = source.map; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.specularMap = source.specularMap; + + this.alphaMap = source.alphaMap; + + this.envMap = source.envMap; + this.combine = source.combine; + this.reflectivity = source.reflectivity; + this.refractionRatio = source.refractionRatio; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + + return this; + + }; + + var _vector$3 = new Vector3(); + var _vector2$1 = new Vector2(); + + function BufferAttribute( array, itemSize, normalized ) { + + if ( Array.isArray( array ) ) { + + throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' ); + + } + + this.name = ''; + + this.array = array; + this.itemSize = itemSize; + this.count = array !== undefined ? array.length / itemSize : 0; + this.normalized = normalized === true; + + this.usage = StaticDrawUsage; + this.updateRange = { offset: 0, count: - 1 }; + + this.version = 0; + + } + + Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', { + + set: function ( value ) { + + if ( value === true ) { this.version ++; } + + } + + } ); + + Object.assign( BufferAttribute.prototype, { + + isBufferAttribute: true, + + onUploadCallback: function () {}, + + setUsage: function ( value ) { + + this.usage = value; + + return this; + + }, + + copy: function ( source ) { + + this.name = source.name; + this.array = new source.array.constructor( source.array ); + this.itemSize = source.itemSize; + this.count = source.count; + this.normalized = source.normalized; + + this.usage = source.usage; + + return this; + + }, + + copyAt: function ( index1, attribute, index2 ) { + + index1 *= this.itemSize; + index2 *= attribute.itemSize; + + for ( var i = 0, l = this.itemSize; i < l; i ++ ) { + + this.array[ index1 + i ] = attribute.array[ index2 + i ]; + + } + + return this; + + }, + + copyArray: function ( array ) { + + this.array.set( array ); + + return this; + + }, + + copyColorsArray: function ( colors ) { + + var array = this.array; + var offset = 0; + + for ( var i = 0, l = colors.length; i < l; i ++ ) { + + var color = colors[ i ]; + + if ( color === undefined ) { + + console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i ); + color = new Color(); + + } + + array[ offset ++ ] = color.r; + array[ offset ++ ] = color.g; + array[ offset ++ ] = color.b; + + } + + return this; + + }, + + copyVector2sArray: function ( vectors ) { + + var array = this.array; + var offset = 0; + + for ( var i = 0, l = vectors.length; i < l; i ++ ) { + + var vector = vectors[ i ]; + + if ( vector === undefined ) { + + console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i ); + vector = new Vector2(); + + } + + array[ offset ++ ] = vector.x; + array[ offset ++ ] = vector.y; + + } + + return this; + + }, + + copyVector3sArray: function ( vectors ) { + + var array = this.array; + var offset = 0; + + for ( var i = 0, l = vectors.length; i < l; i ++ ) { + + var vector = vectors[ i ]; + + if ( vector === undefined ) { + + console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i ); + vector = new Vector3(); + + } + + array[ offset ++ ] = vector.x; + array[ offset ++ ] = vector.y; + array[ offset ++ ] = vector.z; + + } + + return this; + + }, + + copyVector4sArray: function ( vectors ) { + + var array = this.array; + var offset = 0; + + for ( var i = 0, l = vectors.length; i < l; i ++ ) { + + var vector = vectors[ i ]; + + if ( vector === undefined ) { + + console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i ); + vector = new Vector4(); + + } + + array[ offset ++ ] = vector.x; + array[ offset ++ ] = vector.y; + array[ offset ++ ] = vector.z; + array[ offset ++ ] = vector.w; + + } + + return this; + + }, + + applyMatrix3: function ( m ) { + + if ( this.itemSize === 2 ) { + + for ( var i = 0, l = this.count; i < l; i ++ ) { + + _vector2$1.fromBufferAttribute( this, i ); + _vector2$1.applyMatrix3( m ); + + this.setXY( i, _vector2$1.x, _vector2$1.y ); + + } + + } else if ( this.itemSize === 3 ) { + + for ( var i$1 = 0, l$1 = this.count; i$1 < l$1; i$1 ++ ) { + + _vector$3.fromBufferAttribute( this, i$1 ); + _vector$3.applyMatrix3( m ); + + this.setXYZ( i$1, _vector$3.x, _vector$3.y, _vector$3.z ); + + } + + } + + return this; + + }, + + applyMatrix4: function ( m ) { + + for ( var i = 0, l = this.count; i < l; i ++ ) { + + _vector$3.x = this.getX( i ); + _vector$3.y = this.getY( i ); + _vector$3.z = this.getZ( i ); + + _vector$3.applyMatrix4( m ); + + this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z ); + + } + + return this; + + }, + + applyNormalMatrix: function ( m ) { + + for ( var i = 0, l = this.count; i < l; i ++ ) { + + _vector$3.x = this.getX( i ); + _vector$3.y = this.getY( i ); + _vector$3.z = this.getZ( i ); + + _vector$3.applyNormalMatrix( m ); + + this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z ); + + } + + return this; + + }, + + transformDirection: function ( m ) { + + for ( var i = 0, l = this.count; i < l; i ++ ) { + + _vector$3.x = this.getX( i ); + _vector$3.y = this.getY( i ); + _vector$3.z = this.getZ( i ); + + _vector$3.transformDirection( m ); + + this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z ); + + } + + return this; + + }, + + set: function ( value, offset ) { + + if ( offset === undefined ) { offset = 0; } + + this.array.set( value, offset ); + + return this; + + }, + + getX: function ( index ) { + + return this.array[ index * this.itemSize ]; + + }, + + setX: function ( index, x ) { + + this.array[ index * this.itemSize ] = x; + + return this; + + }, + + getY: function ( index ) { + + return this.array[ index * this.itemSize + 1 ]; + + }, + + setY: function ( index, y ) { + + this.array[ index * this.itemSize + 1 ] = y; + + return this; + + }, + + getZ: function ( index ) { + + return this.array[ index * this.itemSize + 2 ]; + + }, + + setZ: function ( index, z ) { + + this.array[ index * this.itemSize + 2 ] = z; + + return this; + + }, + + getW: function ( index ) { + + return this.array[ index * this.itemSize + 3 ]; + + }, + + setW: function ( index, w ) { + + this.array[ index * this.itemSize + 3 ] = w; + + return this; + + }, + + setXY: function ( index, x, y ) { + + index *= this.itemSize; + + this.array[ index + 0 ] = x; + this.array[ index + 1 ] = y; + + return this; + + }, + + setXYZ: function ( index, x, y, z ) { + + index *= this.itemSize; + + this.array[ index + 0 ] = x; + this.array[ index + 1 ] = y; + this.array[ index + 2 ] = z; + + return this; + + }, + + setXYZW: function ( index, x, y, z, w ) { + + index *= this.itemSize; + + this.array[ index + 0 ] = x; + this.array[ index + 1 ] = y; + this.array[ index + 2 ] = z; + this.array[ index + 3 ] = w; + + return this; + + }, + + onUpload: function ( callback ) { + + this.onUploadCallback = callback; + + return this; + + }, + + clone: function () { + + return new this.constructor( this.array, this.itemSize ).copy( this ); + + }, + + toJSON: function () { + + return { + itemSize: this.itemSize, + type: this.array.constructor.name, + array: Array.prototype.slice.call( this.array ), + normalized: this.normalized + }; + + } + + } ); + + // + + function Int8BufferAttribute( array, itemSize, normalized ) { + + BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized ); + + } + + Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); + Int8BufferAttribute.prototype.constructor = Int8BufferAttribute; + + + function Uint8BufferAttribute( array, itemSize, normalized ) { + + BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized ); + + } + + Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); + Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute; + + + function Uint8ClampedBufferAttribute( array, itemSize, normalized ) { + + BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized ); + + } + + Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype ); + Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute; + + + function Int16BufferAttribute( array, itemSize, normalized ) { + + BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized ); + + } + + Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); + Int16BufferAttribute.prototype.constructor = Int16BufferAttribute; + + + function Uint16BufferAttribute( array, itemSize, normalized ) { + + BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized ); + + } + + Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); + Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute; + + + function Int32BufferAttribute( array, itemSize, normalized ) { + + BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized ); + + } + + Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); + Int32BufferAttribute.prototype.constructor = Int32BufferAttribute; + + + function Uint32BufferAttribute( array, itemSize, normalized ) { + + BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized ); + + } + + Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); + Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute; + + + function Float32BufferAttribute( array, itemSize, normalized ) { + + BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized ); + + } + + Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); + Float32BufferAttribute.prototype.constructor = Float32BufferAttribute; + + + function Float64BufferAttribute( array, itemSize, normalized ) { + + BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized ); + + } + + Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype ); + Float64BufferAttribute.prototype.constructor = Float64BufferAttribute; + + function DirectGeometry() { + + this.vertices = []; + this.normals = []; + this.colors = []; + this.uvs = []; + this.uvs2 = []; + + this.groups = []; + + this.morphTargets = {}; + + this.skinWeights = []; + this.skinIndices = []; + + // this.lineDistances = []; + + this.boundingBox = null; + this.boundingSphere = null; + + // update flags + + this.verticesNeedUpdate = false; + this.normalsNeedUpdate = false; + this.colorsNeedUpdate = false; + this.uvsNeedUpdate = false; + this.groupsNeedUpdate = false; + + } + + Object.assign( DirectGeometry.prototype, { + + computeGroups: function ( geometry ) { + + var groups = []; + + var group, i; + var materialIndex = undefined; + + var faces = geometry.faces; + + for ( i = 0; i < faces.length; i ++ ) { + + var face = faces[ i ]; + + // materials + + if ( face.materialIndex !== materialIndex ) { + + materialIndex = face.materialIndex; + + if ( group !== undefined ) { + + group.count = ( i * 3 ) - group.start; + groups.push( group ); + + } + + group = { + start: i * 3, + materialIndex: materialIndex + }; + + } + + } + + if ( group !== undefined ) { + + group.count = ( i * 3 ) - group.start; + groups.push( group ); + + } + + this.groups = groups; + + }, + + fromGeometry: function ( geometry ) { + + var faces = geometry.faces; + var vertices = geometry.vertices; + var faceVertexUvs = geometry.faceVertexUvs; + + var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0; + var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0; + + // morphs + + var morphTargets = geometry.morphTargets; + var morphTargetsLength = morphTargets.length; + + var morphTargetsPosition; + + if ( morphTargetsLength > 0 ) { + + morphTargetsPosition = []; + + for ( var i = 0; i < morphTargetsLength; i ++ ) { + + morphTargetsPosition[ i ] = { + name: morphTargets[ i ].name, + data: [] + }; + + } + + this.morphTargets.position = morphTargetsPosition; + + } + + var morphNormals = geometry.morphNormals; + var morphNormalsLength = morphNormals.length; + + var morphTargetsNormal; + + if ( morphNormalsLength > 0 ) { + + morphTargetsNormal = []; + + for ( var i$1 = 0; i$1 < morphNormalsLength; i$1 ++ ) { + + morphTargetsNormal[ i$1 ] = { + name: morphNormals[ i$1 ].name, + data: [] + }; + + } + + this.morphTargets.normal = morphTargetsNormal; + + } + + // skins + + var skinIndices = geometry.skinIndices; + var skinWeights = geometry.skinWeights; + + var hasSkinIndices = skinIndices.length === vertices.length; + var hasSkinWeights = skinWeights.length === vertices.length; + + // + + if ( vertices.length > 0 && faces.length === 0 ) { + + console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' ); + + } + + for ( var i$2 = 0; i$2 < faces.length; i$2 ++ ) { + + var face = faces[ i$2 ]; + + this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] ); + + var vertexNormals = face.vertexNormals; + + if ( vertexNormals.length === 3 ) { + + this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] ); + + } else { + + var normal = face.normal; + + this.normals.push( normal, normal, normal ); + + } + + var vertexColors = face.vertexColors; + + if ( vertexColors.length === 3 ) { + + this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] ); + + } else { + + var color = face.color; + + this.colors.push( color, color, color ); + + } + + if ( hasFaceVertexUv === true ) { + + var vertexUvs = faceVertexUvs[ 0 ][ i$2 ]; + + if ( vertexUvs !== undefined ) { + + this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] ); + + } else { + + console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i$2 ); + + this.uvs.push( new Vector2(), new Vector2(), new Vector2() ); + + } + + } + + if ( hasFaceVertexUv2 === true ) { + + var vertexUvs$1 = faceVertexUvs[ 1 ][ i$2 ]; + + if ( vertexUvs$1 !== undefined ) { + + this.uvs2.push( vertexUvs$1[ 0 ], vertexUvs$1[ 1 ], vertexUvs$1[ 2 ] ); + + } else { + + console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i$2 ); + + this.uvs2.push( new Vector2(), new Vector2(), new Vector2() ); + + } + + } + + // morphs + + for ( var j = 0; j < morphTargetsLength; j ++ ) { + + var morphTarget = morphTargets[ j ].vertices; + + morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] ); + + } + + for ( var j$1 = 0; j$1 < morphNormalsLength; j$1 ++ ) { + + var morphNormal = morphNormals[ j$1 ].vertexNormals[ i$2 ]; + + morphTargetsNormal[ j$1 ].data.push( morphNormal.a, morphNormal.b, morphNormal.c ); + + } + + // skins + + if ( hasSkinIndices ) { + + this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] ); + + } + + if ( hasSkinWeights ) { + + this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] ); + + } + + } + + this.computeGroups( geometry ); + + this.verticesNeedUpdate = geometry.verticesNeedUpdate; + this.normalsNeedUpdate = geometry.normalsNeedUpdate; + this.colorsNeedUpdate = geometry.colorsNeedUpdate; + this.uvsNeedUpdate = geometry.uvsNeedUpdate; + this.groupsNeedUpdate = geometry.groupsNeedUpdate; + + if ( geometry.boundingSphere !== null ) { + + this.boundingSphere = geometry.boundingSphere.clone(); + + } + + if ( geometry.boundingBox !== null ) { + + this.boundingBox = geometry.boundingBox.clone(); + + } + + return this; + + } + + } ); + + function arrayMax( array ) { + + if ( array.length === 0 ) { return - Infinity; } + + var max = array[ 0 ]; + + for ( var i = 1, l = array.length; i < l; ++ i ) { + + if ( array[ i ] > max ) { max = array[ i ]; } + + } + + return max; + + } + + var _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id + + var _m1$2 = new Matrix4(); + var _obj = new Object3D(); + var _offset = new Vector3(); + var _box$2 = new Box3(); + var _boxMorphTargets = new Box3(); + var _vector$4 = new Vector3(); + + function BufferGeometry() { + + Object.defineProperty( this, 'id', { value: _bufferGeometryId += 2 } ); + + this.uuid = MathUtils.generateUUID(); + + this.name = ''; + this.type = 'BufferGeometry'; + + this.index = null; + this.attributes = {}; + + this.morphAttributes = {}; + this.morphTargetsRelative = false; + + this.groups = []; + + this.boundingBox = null; + this.boundingSphere = null; + + this.drawRange = { start: 0, count: Infinity }; + + this.userData = {}; + + } + + BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { + + constructor: BufferGeometry, + + isBufferGeometry: true, + + getIndex: function () { + + return this.index; + + }, + + setIndex: function ( index ) { + + if ( Array.isArray( index ) ) { + + this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 ); + + } else { + + this.index = index; + + } + + }, + + getAttribute: function ( name ) { + + return this.attributes[ name ]; + + }, + + setAttribute: function ( name, attribute ) { + + this.attributes[ name ] = attribute; + + return this; + + }, + + deleteAttribute: function ( name ) { + + delete this.attributes[ name ]; + + return this; + + }, + + addGroup: function ( start, count, materialIndex ) { + + this.groups.push( { + + start: start, + count: count, + materialIndex: materialIndex !== undefined ? materialIndex : 0 + + } ); + + }, + + clearGroups: function () { + + this.groups = []; + + }, + + setDrawRange: function ( start, count ) { + + this.drawRange.start = start; + this.drawRange.count = count; + + }, + + applyMatrix4: function ( matrix ) { + + var position = this.attributes.position; + + if ( position !== undefined ) { + + position.applyMatrix4( matrix ); + + position.needsUpdate = true; + + } + + var normal = this.attributes.normal; + + if ( normal !== undefined ) { + + var normalMatrix = new Matrix3().getNormalMatrix( matrix ); + + normal.applyNormalMatrix( normalMatrix ); + + normal.needsUpdate = true; + + } + + var tangent = this.attributes.tangent; + + if ( tangent !== undefined ) { + + tangent.transformDirection( matrix ); + + tangent.needsUpdate = true; + + } + + if ( this.boundingBox !== null ) { + + this.computeBoundingBox(); + + } + + if ( this.boundingSphere !== null ) { + + this.computeBoundingSphere(); + + } + + return this; + + }, + + rotateX: function ( angle ) { + + // rotate geometry around world x-axis + + _m1$2.makeRotationX( angle ); + + this.applyMatrix4( _m1$2 ); + + return this; + + }, + + rotateY: function ( angle ) { + + // rotate geometry around world y-axis + + _m1$2.makeRotationY( angle ); + + this.applyMatrix4( _m1$2 ); + + return this; + + }, + + rotateZ: function ( angle ) { + + // rotate geometry around world z-axis + + _m1$2.makeRotationZ( angle ); + + this.applyMatrix4( _m1$2 ); + + return this; + + }, + + translate: function ( x, y, z ) { + + // translate geometry + + _m1$2.makeTranslation( x, y, z ); + + this.applyMatrix4( _m1$2 ); + + return this; + + }, + + scale: function ( x, y, z ) { + + // scale geometry + + _m1$2.makeScale( x, y, z ); + + this.applyMatrix4( _m1$2 ); + + return this; + + }, + + lookAt: function ( vector ) { + + _obj.lookAt( vector ); + + _obj.updateMatrix(); + + this.applyMatrix4( _obj.matrix ); + + return this; + + }, + + center: function () { + + this.computeBoundingBox(); + + this.boundingBox.getCenter( _offset ).negate(); + + this.translate( _offset.x, _offset.y, _offset.z ); + + return this; + + }, + + setFromObject: function ( object ) { + + // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this ); + + var geometry = object.geometry; + + if ( object.isPoints || object.isLine ) { + + var positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 ); + var colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 ); + + this.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) ); + this.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) ); + + if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) { + + var lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 ); + + this.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) ); + + } + + if ( geometry.boundingSphere !== null ) { + + this.boundingSphere = geometry.boundingSphere.clone(); + + } + + if ( geometry.boundingBox !== null ) { + + this.boundingBox = geometry.boundingBox.clone(); + + } + + } else if ( object.isMesh ) { + + if ( geometry && geometry.isGeometry ) { + + this.fromGeometry( geometry ); + + } + + } + + return this; + + }, + + setFromPoints: function ( points ) { + + var position = []; + + for ( var i = 0, l = points.length; i < l; i ++ ) { + + var point = points[ i ]; + position.push( point.x, point.y, point.z || 0 ); + + } + + this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) ); + + return this; + + }, + + updateFromObject: function ( object ) { + + var geometry = object.geometry; + + if ( object.isMesh ) { + + var direct = geometry.__directGeometry; + + if ( geometry.elementsNeedUpdate === true ) { + + direct = undefined; + geometry.elementsNeedUpdate = false; + + } + + if ( direct === undefined ) { + + return this.fromGeometry( geometry ); + + } + + direct.verticesNeedUpdate = geometry.verticesNeedUpdate; + direct.normalsNeedUpdate = geometry.normalsNeedUpdate; + direct.colorsNeedUpdate = geometry.colorsNeedUpdate; + direct.uvsNeedUpdate = geometry.uvsNeedUpdate; + direct.groupsNeedUpdate = geometry.groupsNeedUpdate; + + geometry.verticesNeedUpdate = false; + geometry.normalsNeedUpdate = false; + geometry.colorsNeedUpdate = false; + geometry.uvsNeedUpdate = false; + geometry.groupsNeedUpdate = false; + + geometry = direct; + + } + + if ( geometry.verticesNeedUpdate === true ) { + + var attribute = this.attributes.position; + + if ( attribute !== undefined ) { + + attribute.copyVector3sArray( geometry.vertices ); + attribute.needsUpdate = true; + + } + + geometry.verticesNeedUpdate = false; + + } + + if ( geometry.normalsNeedUpdate === true ) { + + var attribute$1 = this.attributes.normal; + + if ( attribute$1 !== undefined ) { + + attribute$1.copyVector3sArray( geometry.normals ); + attribute$1.needsUpdate = true; + + } + + geometry.normalsNeedUpdate = false; + + } + + if ( geometry.colorsNeedUpdate === true ) { + + var attribute$2 = this.attributes.color; + + if ( attribute$2 !== undefined ) { + + attribute$2.copyColorsArray( geometry.colors ); + attribute$2.needsUpdate = true; + + } + + geometry.colorsNeedUpdate = false; + + } + + if ( geometry.uvsNeedUpdate ) { + + var attribute$3 = this.attributes.uv; + + if ( attribute$3 !== undefined ) { + + attribute$3.copyVector2sArray( geometry.uvs ); + attribute$3.needsUpdate = true; + + } + + geometry.uvsNeedUpdate = false; + + } + + if ( geometry.lineDistancesNeedUpdate ) { + + var attribute$4 = this.attributes.lineDistance; + + if ( attribute$4 !== undefined ) { + + attribute$4.copyArray( geometry.lineDistances ); + attribute$4.needsUpdate = true; + + } + + geometry.lineDistancesNeedUpdate = false; + + } + + if ( geometry.groupsNeedUpdate ) { + + geometry.computeGroups( object.geometry ); + this.groups = geometry.groups; + + geometry.groupsNeedUpdate = false; + + } + + return this; + + }, + + fromGeometry: function ( geometry ) { + + geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry ); + + return this.fromDirectGeometry( geometry.__directGeometry ); + + }, + + fromDirectGeometry: function ( geometry ) { + + var positions = new Float32Array( geometry.vertices.length * 3 ); + this.setAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) ); + + if ( geometry.normals.length > 0 ) { + + var normals = new Float32Array( geometry.normals.length * 3 ); + this.setAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) ); + + } + + if ( geometry.colors.length > 0 ) { + + var colors = new Float32Array( geometry.colors.length * 3 ); + this.setAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) ); + + } + + if ( geometry.uvs.length > 0 ) { + + var uvs = new Float32Array( geometry.uvs.length * 2 ); + this.setAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) ); + + } + + if ( geometry.uvs2.length > 0 ) { + + var uvs2 = new Float32Array( geometry.uvs2.length * 2 ); + this.setAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) ); + + } + + // groups + + this.groups = geometry.groups; + + // morphs + + for ( var name in geometry.morphTargets ) { + + var array = []; + var morphTargets = geometry.morphTargets[ name ]; + + for ( var i = 0, l = morphTargets.length; i < l; i ++ ) { + + var morphTarget = morphTargets[ i ]; + + var attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 ); + attribute.name = morphTarget.name; + + array.push( attribute.copyVector3sArray( morphTarget.data ) ); + + } + + this.morphAttributes[ name ] = array; + + } + + // skinning + + if ( geometry.skinIndices.length > 0 ) { + + var skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 ); + this.setAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) ); + + } + + if ( geometry.skinWeights.length > 0 ) { + + var skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 ); + this.setAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) ); + + } + + // + + if ( geometry.boundingSphere !== null ) { + + this.boundingSphere = geometry.boundingSphere.clone(); + + } + + if ( geometry.boundingBox !== null ) { + + this.boundingBox = geometry.boundingBox.clone(); + + } + + return this; + + }, + + computeBoundingBox: function () { + + if ( this.boundingBox === null ) { + + this.boundingBox = new Box3(); + + } + + var position = this.attributes.position; + var morphAttributesPosition = this.morphAttributes.position; + + if ( position !== undefined ) { + + this.boundingBox.setFromBufferAttribute( position ); + + // process morph attributes if present + + if ( morphAttributesPosition ) { + + for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) { + + var morphAttribute = morphAttributesPosition[ i ]; + _box$2.setFromBufferAttribute( morphAttribute ); + + if ( this.morphTargetsRelative ) { + + _vector$4.addVectors( this.boundingBox.min, _box$2.min ); + this.boundingBox.expandByPoint( _vector$4 ); + + _vector$4.addVectors( this.boundingBox.max, _box$2.max ); + this.boundingBox.expandByPoint( _vector$4 ); + + } else { + + this.boundingBox.expandByPoint( _box$2.min ); + this.boundingBox.expandByPoint( _box$2.max ); + + } + + } + + } + + } else { + + this.boundingBox.makeEmpty(); + + } + + if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) { + + console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this ); + + } + + }, + + computeBoundingSphere: function () { + + if ( this.boundingSphere === null ) { + + this.boundingSphere = new Sphere(); + + } + + var position = this.attributes.position; + var morphAttributesPosition = this.morphAttributes.position; + + if ( position ) { + + // first, find the center of the bounding sphere + + var center = this.boundingSphere.center; + + _box$2.setFromBufferAttribute( position ); + + // process morph attributes if present + + if ( morphAttributesPosition ) { + + for ( var i = 0, il = morphAttributesPosition.length; i < il; i ++ ) { + + var morphAttribute = morphAttributesPosition[ i ]; + _boxMorphTargets.setFromBufferAttribute( morphAttribute ); + + if ( this.morphTargetsRelative ) { + + _vector$4.addVectors( _box$2.min, _boxMorphTargets.min ); + _box$2.expandByPoint( _vector$4 ); + + _vector$4.addVectors( _box$2.max, _boxMorphTargets.max ); + _box$2.expandByPoint( _vector$4 ); + + } else { + + _box$2.expandByPoint( _boxMorphTargets.min ); + _box$2.expandByPoint( _boxMorphTargets.max ); + + } + + } + + } + + _box$2.getCenter( center ); + + // second, try to find a boundingSphere with a radius smaller than the + // boundingSphere of the boundingBox: sqrt(3) smaller in the best case + + var maxRadiusSq = 0; + + for ( var i$1 = 0, il$1 = position.count; i$1 < il$1; i$1 ++ ) { + + _vector$4.fromBufferAttribute( position, i$1 ); + + maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) ); + + } + + // process morph attributes if present + + if ( morphAttributesPosition ) { + + for ( var i$2 = 0, il$2 = morphAttributesPosition.length; i$2 < il$2; i$2 ++ ) { + + var morphAttribute$1 = morphAttributesPosition[ i$2 ]; + var morphTargetsRelative = this.morphTargetsRelative; + + for ( var j = 0, jl = morphAttribute$1.count; j < jl; j ++ ) { + + _vector$4.fromBufferAttribute( morphAttribute$1, j ); + + if ( morphTargetsRelative ) { + + _offset.fromBufferAttribute( position, j ); + _vector$4.add( _offset ); + + } + + maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) ); + + } + + } + + } + + this.boundingSphere.radius = Math.sqrt( maxRadiusSq ); + + if ( isNaN( this.boundingSphere.radius ) ) { + + console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this ); + + } + + } + + }, + + computeFaceNormals: function () { + + // backwards compatibility + + }, + + computeVertexNormals: function () { + + var index = this.index; + var positionAttribute = this.getAttribute( 'position' ); + + if ( positionAttribute !== undefined ) { + + var normalAttribute = this.getAttribute( 'normal' ); + + if ( normalAttribute === undefined ) { + + normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 ); + this.setAttribute( 'normal', normalAttribute ); + + } else { + + // reset existing normals to zero + + for ( var i = 0, il = normalAttribute.count; i < il; i ++ ) { + + normalAttribute.setXYZ( i, 0, 0, 0 ); + + } + + } + + var pA = new Vector3(), pB = new Vector3(), pC = new Vector3(); + var nA = new Vector3(), nB = new Vector3(), nC = new Vector3(); + var cb = new Vector3(), ab = new Vector3(); + + // indexed elements + + if ( index ) { + + for ( var i$1 = 0, il$1 = index.count; i$1 < il$1; i$1 += 3 ) { + + var vA = index.getX( i$1 + 0 ); + var vB = index.getX( i$1 + 1 ); + var vC = index.getX( i$1 + 2 ); + + pA.fromBufferAttribute( positionAttribute, vA ); + pB.fromBufferAttribute( positionAttribute, vB ); + pC.fromBufferAttribute( positionAttribute, vC ); + + cb.subVectors( pC, pB ); + ab.subVectors( pA, pB ); + cb.cross( ab ); + + nA.fromBufferAttribute( normalAttribute, vA ); + nB.fromBufferAttribute( normalAttribute, vB ); + nC.fromBufferAttribute( normalAttribute, vC ); + + nA.add( cb ); + nB.add( cb ); + nC.add( cb ); + + normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z ); + normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z ); + normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z ); + + } + + } else { + + // non-indexed elements (unconnected triangle soup) + + for ( var i$2 = 0, il$2 = positionAttribute.count; i$2 < il$2; i$2 += 3 ) { + + pA.fromBufferAttribute( positionAttribute, i$2 + 0 ); + pB.fromBufferAttribute( positionAttribute, i$2 + 1 ); + pC.fromBufferAttribute( positionAttribute, i$2 + 2 ); + + cb.subVectors( pC, pB ); + ab.subVectors( pA, pB ); + cb.cross( ab ); + + normalAttribute.setXYZ( i$2 + 0, cb.x, cb.y, cb.z ); + normalAttribute.setXYZ( i$2 + 1, cb.x, cb.y, cb.z ); + normalAttribute.setXYZ( i$2 + 2, cb.x, cb.y, cb.z ); + + } + + } + + this.normalizeNormals(); + + normalAttribute.needsUpdate = true; + + } + + }, + + merge: function ( geometry, offset ) { + + if ( ! ( geometry && geometry.isBufferGeometry ) ) { + + console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry ); + return; + + } + + if ( offset === undefined ) { + + offset = 0; + + console.warn( + 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. ' + + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.' + ); + + } + + var attributes = this.attributes; + + for ( var key in attributes ) { + + if ( geometry.attributes[ key ] === undefined ) { continue; } + + var attribute1 = attributes[ key ]; + var attributeArray1 = attribute1.array; + + var attribute2 = geometry.attributes[ key ]; + var attributeArray2 = attribute2.array; + + var attributeOffset = attribute2.itemSize * offset; + var length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset ); + + for ( var i = 0, j = attributeOffset; i < length; i ++, j ++ ) { + + attributeArray1[ j ] = attributeArray2[ i ]; + + } + + } + + return this; + + }, + + normalizeNormals: function () { + + var normals = this.attributes.normal; + + for ( var i = 0, il = normals.count; i < il; i ++ ) { + + _vector$4.fromBufferAttribute( normals, i ); + + _vector$4.normalize(); + + normals.setXYZ( i, _vector$4.x, _vector$4.y, _vector$4.z ); + + } + + }, + + toNonIndexed: function () { + + function convertBufferAttribute( attribute, indices ) { + + var array = attribute.array; + var itemSize = attribute.itemSize; + var normalized = attribute.normalized; + + var array2 = new array.constructor( indices.length * itemSize ); + + var index = 0, index2 = 0; + + for ( var i = 0, l = indices.length; i < l; i ++ ) { + + index = indices[ i ] * itemSize; + + for ( var j = 0; j < itemSize; j ++ ) { + + array2[ index2 ++ ] = array[ index ++ ]; + + } + + } + + return new BufferAttribute( array2, itemSize, normalized ); + + } + + // + + if ( this.index === null ) { + + console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' ); + return this; + + } + + var geometry2 = new BufferGeometry(); + + var indices = this.index.array; + var attributes = this.attributes; + + // attributes + + for ( var name in attributes ) { + + var attribute = attributes[ name ]; + + var newAttribute = convertBufferAttribute( attribute, indices ); + + geometry2.setAttribute( name, newAttribute ); + + } + + // morph attributes + + var morphAttributes = this.morphAttributes; + + for ( var name$1 in morphAttributes ) { + + var morphArray = []; + var morphAttribute = morphAttributes[ name$1 ]; // morphAttribute: array of Float32BufferAttributes + + for ( var i = 0, il = morphAttribute.length; i < il; i ++ ) { + + var attribute$1 = morphAttribute[ i ]; + + var newAttribute$1 = convertBufferAttribute( attribute$1, indices ); + + morphArray.push( newAttribute$1 ); + + } + + geometry2.morphAttributes[ name$1 ] = morphArray; + + } + + geometry2.morphTargetsRelative = this.morphTargetsRelative; + + // groups + + var groups = this.groups; + + for ( var i$1 = 0, l = groups.length; i$1 < l; i$1 ++ ) { + + var group = groups[ i$1 ]; + geometry2.addGroup( group.start, group.count, group.materialIndex ); + + } + + return geometry2; + + }, + + toJSON: function () { + + var data = { + metadata: { + version: 4.5, + type: 'BufferGeometry', + generator: 'BufferGeometry.toJSON' + } + }; + + // standard BufferGeometry serialization + + data.uuid = this.uuid; + data.type = this.type; + if ( this.name !== '' ) { data.name = this.name; } + if ( Object.keys( this.userData ).length > 0 ) { data.userData = this.userData; } + + if ( this.parameters !== undefined ) { + + var parameters = this.parameters; + + for ( var key in parameters ) { + + if ( parameters[ key ] !== undefined ) { data[ key ] = parameters[ key ]; } + + } + + return data; + + } + + data.data = { attributes: {} }; + + var index = this.index; + + if ( index !== null ) { + + data.data.index = { + type: index.array.constructor.name, + array: Array.prototype.slice.call( index.array ) + }; + + } + + var attributes = this.attributes; + + for ( var key$1 in attributes ) { + + var attribute = attributes[ key$1 ]; + + var attributeData = attribute.toJSON( data.data ); + + if ( attribute.name !== '' ) { attributeData.name = attribute.name; } + + data.data.attributes[ key$1 ] = attributeData; + + } + + var morphAttributes = {}; + var hasMorphAttributes = false; + + for ( var key$2 in this.morphAttributes ) { + + var attributeArray = this.morphAttributes[ key$2 ]; + + var array = []; + + for ( var i = 0, il = attributeArray.length; i < il; i ++ ) { + + var attribute$1 = attributeArray[ i ]; + + var attributeData$1 = attribute$1.toJSON( data.data ); + + if ( attribute$1.name !== '' ) { attributeData$1.name = attribute$1.name; } + + array.push( attributeData$1 ); + + } + + if ( array.length > 0 ) { + + morphAttributes[ key$2 ] = array; + + hasMorphAttributes = true; + + } + + } + + if ( hasMorphAttributes ) { + + data.data.morphAttributes = morphAttributes; + data.data.morphTargetsRelative = this.morphTargetsRelative; + + } + + var groups = this.groups; + + if ( groups.length > 0 ) { + + data.data.groups = JSON.parse( JSON.stringify( groups ) ); + + } + + var boundingSphere = this.boundingSphere; + + if ( boundingSphere !== null ) { + + data.data.boundingSphere = { + center: boundingSphere.center.toArray(), + radius: boundingSphere.radius + }; + + } + + return data; + + }, + + clone: function () { + + /* + // Handle primitives + + const parameters = this.parameters; + + if ( parameters !== undefined ) { + + const values = []; + + for ( const key in parameters ) { + + values.push( parameters[ key ] ); + + } + + const geometry = Object.create( this.constructor.prototype ); + this.constructor.apply( geometry, values ); + return geometry; + + } + + return new this.constructor().copy( this ); + */ + + return new BufferGeometry().copy( this ); + + }, + + copy: function ( source ) { + + // reset + + this.index = null; + this.attributes = {}; + this.morphAttributes = {}; + this.groups = []; + this.boundingBox = null; + this.boundingSphere = null; + + // used for storing cloned, shared data + + var data = {}; + + // name + + this.name = source.name; + + // index + + var index = source.index; + + if ( index !== null ) { + + this.setIndex( index.clone( data ) ); + + } + + // attributes + + var attributes = source.attributes; + + for ( var name in attributes ) { + + var attribute = attributes[ name ]; + this.setAttribute( name, attribute.clone( data ) ); + + } + + // morph attributes + + var morphAttributes = source.morphAttributes; + + for ( var name$1 in morphAttributes ) { + + var array = []; + var morphAttribute = morphAttributes[ name$1 ]; // morphAttribute: array of Float32BufferAttributes + + for ( var i = 0, l = morphAttribute.length; i < l; i ++ ) { + + array.push( morphAttribute[ i ].clone( data ) ); + + } + + this.morphAttributes[ name$1 ] = array; + + } + + this.morphTargetsRelative = source.morphTargetsRelative; + + // groups + + var groups = source.groups; + + for ( var i$1 = 0, l$1 = groups.length; i$1 < l$1; i$1 ++ ) { + + var group = groups[ i$1 ]; + this.addGroup( group.start, group.count, group.materialIndex ); + + } + + // bounding box + + var boundingBox = source.boundingBox; + + if ( boundingBox !== null ) { + + this.boundingBox = boundingBox.clone(); + + } + + // bounding sphere + + var boundingSphere = source.boundingSphere; + + if ( boundingSphere !== null ) { + + this.boundingSphere = boundingSphere.clone(); + + } + + // draw range + + this.drawRange.start = source.drawRange.start; + this.drawRange.count = source.drawRange.count; + + // user data + + this.userData = source.userData; + + return this; + + }, + + dispose: function () { + + this.dispatchEvent( { type: 'dispose' } ); + + } + + } ); + + var _inverseMatrix = new Matrix4(); + var _ray = new Ray(); + var _sphere = new Sphere(); + + var _vA = new Vector3(); + var _vB = new Vector3(); + var _vC = new Vector3(); + + var _tempA = new Vector3(); + var _tempB = new Vector3(); + var _tempC = new Vector3(); + + var _morphA = new Vector3(); + var _morphB = new Vector3(); + var _morphC = new Vector3(); + + var _uvA = new Vector2(); + var _uvB = new Vector2(); + var _uvC = new Vector2(); + + var _intersectionPoint = new Vector3(); + var _intersectionPointWorld = new Vector3(); + + function Mesh( geometry, material ) { + + Object3D.call( this ); + + this.type = 'Mesh'; + + this.geometry = geometry !== undefined ? geometry : new BufferGeometry(); + this.material = material !== undefined ? material : new MeshBasicMaterial(); + + this.updateMorphTargets(); + + } + + Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: Mesh, + + isMesh: true, + + copy: function ( source ) { + + Object3D.prototype.copy.call( this, source ); + + if ( source.morphTargetInfluences !== undefined ) { + + this.morphTargetInfluences = source.morphTargetInfluences.slice(); + + } + + if ( source.morphTargetDictionary !== undefined ) { + + this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary ); + + } + + this.material = source.material; + this.geometry = source.geometry; + + return this; + + }, + + updateMorphTargets: function () { + + var geometry = this.geometry; + + if ( geometry.isBufferGeometry ) { + + var morphAttributes = geometry.morphAttributes; + var keys = Object.keys( morphAttributes ); + + if ( keys.length > 0 ) { + + var morphAttribute = morphAttributes[ keys[ 0 ] ]; + + if ( morphAttribute !== undefined ) { + + this.morphTargetInfluences = []; + this.morphTargetDictionary = {}; + + for ( var m = 0, ml = morphAttribute.length; m < ml; m ++ ) { + + var name = morphAttribute[ m ].name || String( m ); + + this.morphTargetInfluences.push( 0 ); + this.morphTargetDictionary[ name ] = m; + + } + + } + + } + + } else { + + var morphTargets = geometry.morphTargets; + + if ( morphTargets !== undefined && morphTargets.length > 0 ) { + + console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' ); + + } + + } + + }, + + raycast: function ( raycaster, intersects ) { + + var geometry = this.geometry; + var material = this.material; + var matrixWorld = this.matrixWorld; + + if ( material === undefined ) { return; } + + // Checking boundingSphere distance to ray + + if ( geometry.boundingSphere === null ) { geometry.computeBoundingSphere(); } + + _sphere.copy( geometry.boundingSphere ); + _sphere.applyMatrix4( matrixWorld ); + + if ( raycaster.ray.intersectsSphere( _sphere ) === false ) { return; } + + // + + _inverseMatrix.getInverse( matrixWorld ); + _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix ); + + // Check boundingBox before continuing + + if ( geometry.boundingBox !== null ) { + + if ( _ray.intersectsBox( geometry.boundingBox ) === false ) { return; } + + } + + var intersection; + + if ( geometry.isBufferGeometry ) { + + var index = geometry.index; + var position = geometry.attributes.position; + var morphPosition = geometry.morphAttributes.position; + var morphTargetsRelative = geometry.morphTargetsRelative; + var uv = geometry.attributes.uv; + var uv2 = geometry.attributes.uv2; + var groups = geometry.groups; + var drawRange = geometry.drawRange; + + if ( index !== null ) { + + // indexed buffer geometry + + if ( Array.isArray( material ) ) { + + for ( var i = 0, il = groups.length; i < il; i ++ ) { + + var group = groups[ i ]; + var groupMaterial = material[ group.materialIndex ]; + + var start = Math.max( group.start, drawRange.start ); + var end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ); + + for ( var j = start, jl = end; j < jl; j += 3 ) { + + var a = index.getX( j ); + var b = index.getX( j + 1 ); + var c = index.getX( j + 2 ); + + intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ); + + if ( intersection ) { + + intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics + intersection.face.materialIndex = group.materialIndex; + intersects.push( intersection ); + + } + + } + + } + + } else { + + var start$1 = Math.max( 0, drawRange.start ); + var end$1 = Math.min( index.count, ( drawRange.start + drawRange.count ) ); + + for ( var i$1 = start$1, il$1 = end$1; i$1 < il$1; i$1 += 3 ) { + + var a$1 = index.getX( i$1 ); + var b$1 = index.getX( i$1 + 1 ); + var c$1 = index.getX( i$1 + 2 ); + + intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a$1, b$1, c$1 ); + + if ( intersection ) { + + intersection.faceIndex = Math.floor( i$1 / 3 ); // triangle number in indexed buffer semantics + intersects.push( intersection ); + + } + + } + + } + + } else if ( position !== undefined ) { + + // non-indexed buffer geometry + + if ( Array.isArray( material ) ) { + + for ( var i$2 = 0, il$2 = groups.length; i$2 < il$2; i$2 ++ ) { + + var group$1 = groups[ i$2 ]; + var groupMaterial$1 = material[ group$1.materialIndex ]; + + var start$2 = Math.max( group$1.start, drawRange.start ); + var end$2 = Math.min( ( group$1.start + group$1.count ), ( drawRange.start + drawRange.count ) ); + + for ( var j$1 = start$2, jl$1 = end$2; j$1 < jl$1; j$1 += 3 ) { + + var a$2 = j$1; + var b$2 = j$1 + 1; + var c$2 = j$1 + 2; + + intersection = checkBufferGeometryIntersection( this, groupMaterial$1, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a$2, b$2, c$2 ); + + if ( intersection ) { + + intersection.faceIndex = Math.floor( j$1 / 3 ); // triangle number in non-indexed buffer semantics + intersection.face.materialIndex = group$1.materialIndex; + intersects.push( intersection ); + + } + + } + + } + + } else { + + var start$3 = Math.max( 0, drawRange.start ); + var end$3 = Math.min( position.count, ( drawRange.start + drawRange.count ) ); + + for ( var i$3 = start$3, il$3 = end$3; i$3 < il$3; i$3 += 3 ) { + + var a$3 = i$3; + var b$3 = i$3 + 1; + var c$3 = i$3 + 2; + + intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a$3, b$3, c$3 ); + + if ( intersection ) { + + intersection.faceIndex = Math.floor( i$3 / 3 ); // triangle number in non-indexed buffer semantics + intersects.push( intersection ); + + } + + } + + } + + } + + } else if ( geometry.isGeometry ) { + + var isMultiMaterial = Array.isArray( material ); + + var vertices = geometry.vertices; + var faces = geometry.faces; + var uvs; + + var faceVertexUvs = geometry.faceVertexUvs[ 0 ]; + if ( faceVertexUvs.length > 0 ) { uvs = faceVertexUvs; } + + for ( var f = 0, fl = faces.length; f < fl; f ++ ) { + + var face = faces[ f ]; + var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material; + + if ( faceMaterial === undefined ) { continue; } + + var fvA = vertices[ face.a ]; + var fvB = vertices[ face.b ]; + var fvC = vertices[ face.c ]; + + intersection = checkIntersection( this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint ); + + if ( intersection ) { + + if ( uvs && uvs[ f ] ) { + + var uvs_f = uvs[ f ]; + _uvA.copy( uvs_f[ 0 ] ); + _uvB.copy( uvs_f[ 1 ] ); + _uvC.copy( uvs_f[ 2 ] ); + + intersection.uv = Triangle.getUV( _intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2() ); + + } + + intersection.face = face; + intersection.faceIndex = f; + intersects.push( intersection ); + + } + + } + + } + + } + + } ); + + function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) { + + var intersect; + + if ( material.side === BackSide ) { + + intersect = ray.intersectTriangle( pC, pB, pA, true, point ); + + } else { + + intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point ); + + } + + if ( intersect === null ) { return null; } + + _intersectionPointWorld.copy( point ); + _intersectionPointWorld.applyMatrix4( object.matrixWorld ); + + var distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld ); + + if ( distance < raycaster.near || distance > raycaster.far ) { return null; } + + return { + distance: distance, + point: _intersectionPointWorld.clone(), + object: object + }; + + } + + function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) { + + _vA.fromBufferAttribute( position, a ); + _vB.fromBufferAttribute( position, b ); + _vC.fromBufferAttribute( position, c ); + + var morphInfluences = object.morphTargetInfluences; + + if ( material.morphTargets && morphPosition && morphInfluences ) { + + _morphA.set( 0, 0, 0 ); + _morphB.set( 0, 0, 0 ); + _morphC.set( 0, 0, 0 ); + + for ( var i = 0, il = morphPosition.length; i < il; i ++ ) { + + var influence = morphInfluences[ i ]; + var morphAttribute = morphPosition[ i ]; + + if ( influence === 0 ) { continue; } + + _tempA.fromBufferAttribute( morphAttribute, a ); + _tempB.fromBufferAttribute( morphAttribute, b ); + _tempC.fromBufferAttribute( morphAttribute, c ); + + if ( morphTargetsRelative ) { + + _morphA.addScaledVector( _tempA, influence ); + _morphB.addScaledVector( _tempB, influence ); + _morphC.addScaledVector( _tempC, influence ); + + } else { + + _morphA.addScaledVector( _tempA.sub( _vA ), influence ); + _morphB.addScaledVector( _tempB.sub( _vB ), influence ); + _morphC.addScaledVector( _tempC.sub( _vC ), influence ); + + } + + } + + _vA.add( _morphA ); + _vB.add( _morphB ); + _vC.add( _morphC ); + + } + + if ( object.isSkinnedMesh ) { + + object.boneTransform( a, _vA ); + object.boneTransform( b, _vB ); + object.boneTransform( c, _vC ); + + } + + var intersection = checkIntersection( object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint ); + + if ( intersection ) { + + if ( uv ) { + + _uvA.fromBufferAttribute( uv, a ); + _uvB.fromBufferAttribute( uv, b ); + _uvC.fromBufferAttribute( uv, c ); + + intersection.uv = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() ); + + } + + if ( uv2 ) { + + _uvA.fromBufferAttribute( uv2, a ); + _uvB.fromBufferAttribute( uv2, b ); + _uvC.fromBufferAttribute( uv2, c ); + + intersection.uv2 = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() ); + + } + + var face = new Face3( a, b, c ); + Triangle.getNormal( _vA, _vB, _vC, face.normal ); + + intersection.face = face; + + } + + return intersection; + + } + + var _geometryId = 0; // Geometry uses even numbers as Id + var _m1$3 = new Matrix4(); + var _obj$1 = new Object3D(); + var _offset$1 = new Vector3(); + + function Geometry() { + + Object.defineProperty( this, 'id', { value: _geometryId += 2 } ); + + this.uuid = MathUtils.generateUUID(); + + this.name = ''; + this.type = 'Geometry'; + + this.vertices = []; + this.colors = []; + this.faces = []; + this.faceVertexUvs = [[]]; + + this.morphTargets = []; + this.morphNormals = []; + + this.skinWeights = []; + this.skinIndices = []; + + this.lineDistances = []; + + this.boundingBox = null; + this.boundingSphere = null; + + // update flags + + this.elementsNeedUpdate = false; + this.verticesNeedUpdate = false; + this.uvsNeedUpdate = false; + this.normalsNeedUpdate = false; + this.colorsNeedUpdate = false; + this.lineDistancesNeedUpdate = false; + this.groupsNeedUpdate = false; + + } + + Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { + + constructor: Geometry, + + isGeometry: true, + + applyMatrix4: function ( matrix ) { + + var normalMatrix = new Matrix3().getNormalMatrix( matrix ); + + for ( var i = 0, il = this.vertices.length; i < il; i ++ ) { + + var vertex = this.vertices[ i ]; + vertex.applyMatrix4( matrix ); + + } + + for ( var i$1 = 0, il$1 = this.faces.length; i$1 < il$1; i$1 ++ ) { + + var face = this.faces[ i$1 ]; + face.normal.applyMatrix3( normalMatrix ).normalize(); + + for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) { + + face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize(); + + } + + } + + if ( this.boundingBox !== null ) { + + this.computeBoundingBox(); + + } + + if ( this.boundingSphere !== null ) { + + this.computeBoundingSphere(); + + } + + this.verticesNeedUpdate = true; + this.normalsNeedUpdate = true; + + return this; + + }, + + rotateX: function ( angle ) { + + // rotate geometry around world x-axis + + _m1$3.makeRotationX( angle ); + + this.applyMatrix4( _m1$3 ); + + return this; + + }, + + rotateY: function ( angle ) { + + // rotate geometry around world y-axis + + _m1$3.makeRotationY( angle ); + + this.applyMatrix4( _m1$3 ); + + return this; + + }, + + rotateZ: function ( angle ) { + + // rotate geometry around world z-axis + + _m1$3.makeRotationZ( angle ); + + this.applyMatrix4( _m1$3 ); + + return this; + + }, + + translate: function ( x, y, z ) { + + // translate geometry + + _m1$3.makeTranslation( x, y, z ); + + this.applyMatrix4( _m1$3 ); + + return this; + + }, + + scale: function ( x, y, z ) { + + // scale geometry + + _m1$3.makeScale( x, y, z ); + + this.applyMatrix4( _m1$3 ); + + return this; + + }, + + lookAt: function ( vector ) { + + _obj$1.lookAt( vector ); + + _obj$1.updateMatrix(); + + this.applyMatrix4( _obj$1.matrix ); + + return this; + + }, + + fromBufferGeometry: function ( geometry ) { + + var scope = this; + + var index = geometry.index !== null ? geometry.index : undefined; + var attributes = geometry.attributes; + + if ( attributes.position === undefined ) { + + console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' ); + return this; + + } + + var position = attributes.position; + var normal = attributes.normal; + var color = attributes.color; + var uv = attributes.uv; + var uv2 = attributes.uv2; + + if ( uv2 !== undefined ) { this.faceVertexUvs[ 1 ] = []; } + + for ( var i = 0; i < position.count; i ++ ) { + + scope.vertices.push( new Vector3().fromBufferAttribute( position, i ) ); + + if ( color !== undefined ) { + + scope.colors.push( new Color().fromBufferAttribute( color, i ) ); + + } + + } + + function addFace( a, b, c, materialIndex ) { + + var vertexColors = ( color === undefined ) ? [] : [ + scope.colors[ a ].clone(), + scope.colors[ b ].clone(), + scope.colors[ c ].clone() + ]; + + var vertexNormals = ( normal === undefined ) ? [] : [ + new Vector3().fromBufferAttribute( normal, a ), + new Vector3().fromBufferAttribute( normal, b ), + new Vector3().fromBufferAttribute( normal, c ) + ]; + + var face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex ); + + scope.faces.push( face ); + + if ( uv !== undefined ) { + + scope.faceVertexUvs[ 0 ].push( [ + new Vector2().fromBufferAttribute( uv, a ), + new Vector2().fromBufferAttribute( uv, b ), + new Vector2().fromBufferAttribute( uv, c ) + ] ); + + } + + if ( uv2 !== undefined ) { + + scope.faceVertexUvs[ 1 ].push( [ + new Vector2().fromBufferAttribute( uv2, a ), + new Vector2().fromBufferAttribute( uv2, b ), + new Vector2().fromBufferAttribute( uv2, c ) + ] ); + + } + + } + + var groups = geometry.groups; + + if ( groups.length > 0 ) { + + for ( var i$1 = 0; i$1 < groups.length; i$1 ++ ) { + + var group = groups[ i$1 ]; + + var start = group.start; + var count = group.count; + + for ( var j = start, jl = start + count; j < jl; j += 3 ) { + + if ( index !== undefined ) { + + addFace( index.getX( j ), index.getX( j + 1 ), index.getX( j + 2 ), group.materialIndex ); + + } else { + + addFace( j, j + 1, j + 2, group.materialIndex ); + + } + + } + + } + + } else { + + if ( index !== undefined ) { + + for ( var i$2 = 0; i$2 < index.count; i$2 += 3 ) { + + addFace( index.getX( i$2 ), index.getX( i$2 + 1 ), index.getX( i$2 + 2 ) ); + + } + + } else { + + for ( var i$3 = 0; i$3 < position.count; i$3 += 3 ) { + + addFace( i$3, i$3 + 1, i$3 + 2 ); + + } + + } + + } + + this.computeFaceNormals(); + + if ( geometry.boundingBox !== null ) { + + this.boundingBox = geometry.boundingBox.clone(); + + } + + if ( geometry.boundingSphere !== null ) { + + this.boundingSphere = geometry.boundingSphere.clone(); + + } + + return this; + + }, + + center: function () { + + this.computeBoundingBox(); + + this.boundingBox.getCenter( _offset$1 ).negate(); + + this.translate( _offset$1.x, _offset$1.y, _offset$1.z ); + + return this; + + }, + + normalize: function () { + + this.computeBoundingSphere(); + + var center = this.boundingSphere.center; + var radius = this.boundingSphere.radius; + + var s = radius === 0 ? 1 : 1.0 / radius; + + var matrix = new Matrix4(); + matrix.set( + s, 0, 0, - s * center.x, + 0, s, 0, - s * center.y, + 0, 0, s, - s * center.z, + 0, 0, 0, 1 + ); + + this.applyMatrix4( matrix ); + + return this; + + }, + + computeFaceNormals: function () { + + var cb = new Vector3(), ab = new Vector3(); + + for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) { + + var face = this.faces[ f ]; + + var vA = this.vertices[ face.a ]; + var vB = this.vertices[ face.b ]; + var vC = this.vertices[ face.c ]; + + cb.subVectors( vC, vB ); + ab.subVectors( vA, vB ); + cb.cross( ab ); + + cb.normalize(); + + face.normal.copy( cb ); + + } + + }, + + computeVertexNormals: function ( areaWeighted ) { + + if ( areaWeighted === undefined ) { areaWeighted = true; } + + var vertices = new Array( this.vertices.length ); + + for ( var v = 0, vl = this.vertices.length; v < vl; v ++ ) { + + vertices[ v ] = new Vector3(); + + } + + if ( areaWeighted ) { + + // vertex normals weighted by triangle areas + // http://www.iquilezles.org/www/articles/normals/normals.htm + + var cb = new Vector3(), ab = new Vector3(); + + for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) { + + var face = this.faces[ f ]; + + var vA = this.vertices[ face.a ]; + var vB = this.vertices[ face.b ]; + var vC = this.vertices[ face.c ]; + + cb.subVectors( vC, vB ); + ab.subVectors( vA, vB ); + cb.cross( ab ); + + vertices[ face.a ].add( cb ); + vertices[ face.b ].add( cb ); + vertices[ face.c ].add( cb ); + + } + + } else { + + this.computeFaceNormals(); + + for ( var f$1 = 0, fl$1 = this.faces.length; f$1 < fl$1; f$1 ++ ) { + + var face$1 = this.faces[ f$1 ]; + + vertices[ face$1.a ].add( face$1.normal ); + vertices[ face$1.b ].add( face$1.normal ); + vertices[ face$1.c ].add( face$1.normal ); + + } + + } + + for ( var v$1 = 0, vl$1 = this.vertices.length; v$1 < vl$1; v$1 ++ ) { + + vertices[ v$1 ].normalize(); + + } + + for ( var f$2 = 0, fl$2 = this.faces.length; f$2 < fl$2; f$2 ++ ) { + + var face$2 = this.faces[ f$2 ]; + + var vertexNormals = face$2.vertexNormals; + + if ( vertexNormals.length === 3 ) { + + vertexNormals[ 0 ].copy( vertices[ face$2.a ] ); + vertexNormals[ 1 ].copy( vertices[ face$2.b ] ); + vertexNormals[ 2 ].copy( vertices[ face$2.c ] ); + + } else { + + vertexNormals[ 0 ] = vertices[ face$2.a ].clone(); + vertexNormals[ 1 ] = vertices[ face$2.b ].clone(); + vertexNormals[ 2 ] = vertices[ face$2.c ].clone(); + + } + + } + + if ( this.faces.length > 0 ) { + + this.normalsNeedUpdate = true; + + } + + }, + + computeFlatVertexNormals: function () { + + this.computeFaceNormals(); + + for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) { + + var face = this.faces[ f ]; + + var vertexNormals = face.vertexNormals; + + if ( vertexNormals.length === 3 ) { + + vertexNormals[ 0 ].copy( face.normal ); + vertexNormals[ 1 ].copy( face.normal ); + vertexNormals[ 2 ].copy( face.normal ); + + } else { + + vertexNormals[ 0 ] = face.normal.clone(); + vertexNormals[ 1 ] = face.normal.clone(); + vertexNormals[ 2 ] = face.normal.clone(); + + } + + } + + if ( this.faces.length > 0 ) { + + this.normalsNeedUpdate = true; + + } + + }, + + computeMorphNormals: function () { + + // save original normals + // - create temp variables on first access + // otherwise just copy (for faster repeated calls) + + for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) { + + var face = this.faces[ f ]; + + if ( ! face.__originalFaceNormal ) { + + face.__originalFaceNormal = face.normal.clone(); + + } else { + + face.__originalFaceNormal.copy( face.normal ); + + } + + if ( ! face.__originalVertexNormals ) { face.__originalVertexNormals = []; } + + for ( var i = 0, il = face.vertexNormals.length; i < il; i ++ ) { + + if ( ! face.__originalVertexNormals[ i ] ) { + + face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone(); + + } else { + + face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] ); + + } + + } + + } + + // use temp geometry to compute face and vertex normals for each morph + + var tmpGeo = new Geometry(); + tmpGeo.faces = this.faces; + + for ( var i$1 = 0, il$1 = this.morphTargets.length; i$1 < il$1; i$1 ++ ) { + + // create on first access + + if ( ! this.morphNormals[ i$1 ] ) { + + this.morphNormals[ i$1 ] = {}; + this.morphNormals[ i$1 ].faceNormals = []; + this.morphNormals[ i$1 ].vertexNormals = []; + + var dstNormalsFace = this.morphNormals[ i$1 ].faceNormals; + var dstNormalsVertex = this.morphNormals[ i$1 ].vertexNormals; + + for ( var f$1 = 0, fl$1 = this.faces.length; f$1 < fl$1; f$1 ++ ) { + + var faceNormal = new Vector3(); + var vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() }; + + dstNormalsFace.push( faceNormal ); + dstNormalsVertex.push( vertexNormals ); + + } + + } + + var morphNormals = this.morphNormals[ i$1 ]; + + // set vertices to morph target + + tmpGeo.vertices = this.morphTargets[ i$1 ].vertices; + + // compute morph normals + + tmpGeo.computeFaceNormals(); + tmpGeo.computeVertexNormals(); + + // store morph normals + + for ( var f$2 = 0, fl$2 = this.faces.length; f$2 < fl$2; f$2 ++ ) { + + var face$1 = this.faces[ f$2 ]; + + var faceNormal$1 = morphNormals.faceNormals[ f$2 ]; + var vertexNormals$1 = morphNormals.vertexNormals[ f$2 ]; + + faceNormal$1.copy( face$1.normal ); + + vertexNormals$1.a.copy( face$1.vertexNormals[ 0 ] ); + vertexNormals$1.b.copy( face$1.vertexNormals[ 1 ] ); + vertexNormals$1.c.copy( face$1.vertexNormals[ 2 ] ); + + } + + } + + // restore original normals + + for ( var f$3 = 0, fl$3 = this.faces.length; f$3 < fl$3; f$3 ++ ) { + + var face$2 = this.faces[ f$3 ]; + + face$2.normal = face$2.__originalFaceNormal; + face$2.vertexNormals = face$2.__originalVertexNormals; + + } + + }, + + computeBoundingBox: function () { + + if ( this.boundingBox === null ) { + + this.boundingBox = new Box3(); + + } + + this.boundingBox.setFromPoints( this.vertices ); + + }, + + computeBoundingSphere: function () { + + if ( this.boundingSphere === null ) { + + this.boundingSphere = new Sphere(); + + } + + this.boundingSphere.setFromPoints( this.vertices ); + + }, + + merge: function ( geometry, matrix, materialIndexOffset ) { + + if ( ! ( geometry && geometry.isGeometry ) ) { + + console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry ); + return; + + } + + var normalMatrix, + vertexOffset = this.vertices.length, + vertices1 = this.vertices, + vertices2 = geometry.vertices, + faces1 = this.faces, + faces2 = geometry.faces, + colors1 = this.colors, + colors2 = geometry.colors; + + if ( materialIndexOffset === undefined ) { materialIndexOffset = 0; } + + if ( matrix !== undefined ) { + + normalMatrix = new Matrix3().getNormalMatrix( matrix ); + + } + + // vertices + + for ( var i = 0, il = vertices2.length; i < il; i ++ ) { + + var vertex = vertices2[ i ]; + + var vertexCopy = vertex.clone(); + + if ( matrix !== undefined ) { vertexCopy.applyMatrix4( matrix ); } + + vertices1.push( vertexCopy ); + + } + + // colors + + for ( var i$1 = 0, il$1 = colors2.length; i$1 < il$1; i$1 ++ ) { + + colors1.push( colors2[ i$1 ].clone() ); + + } + + // faces + + for ( var i$2 = 0, il$2 = faces2.length; i$2 < il$2; i$2 ++ ) { + + var face = faces2[ i$2 ], faceCopy = (void 0), normal = (void 0), color = (void 0), + faceVertexNormals = face.vertexNormals, + faceVertexColors = face.vertexColors; + + faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset ); + faceCopy.normal.copy( face.normal ); + + if ( normalMatrix !== undefined ) { + + faceCopy.normal.applyMatrix3( normalMatrix ).normalize(); + + } + + for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) { + + normal = faceVertexNormals[ j ].clone(); + + if ( normalMatrix !== undefined ) { + + normal.applyMatrix3( normalMatrix ).normalize(); + + } + + faceCopy.vertexNormals.push( normal ); + + } + + faceCopy.color.copy( face.color ); + + for ( var j$1 = 0, jl$1 = faceVertexColors.length; j$1 < jl$1; j$1 ++ ) { + + color = faceVertexColors[ j$1 ]; + faceCopy.vertexColors.push( color.clone() ); + + } + + faceCopy.materialIndex = face.materialIndex + materialIndexOffset; + + faces1.push( faceCopy ); + + } + + // uvs + + for ( var i$3 = 0, il$3 = geometry.faceVertexUvs.length; i$3 < il$3; i$3 ++ ) { + + var faceVertexUvs2 = geometry.faceVertexUvs[ i$3 ]; + + if ( this.faceVertexUvs[ i$3 ] === undefined ) { this.faceVertexUvs[ i$3 ] = []; } + + for ( var j$2 = 0, jl$2 = faceVertexUvs2.length; j$2 < jl$2; j$2 ++ ) { + + var uvs2 = faceVertexUvs2[ j$2 ], uvsCopy = []; + + for ( var k = 0, kl = uvs2.length; k < kl; k ++ ) { + + uvsCopy.push( uvs2[ k ].clone() ); + + } + + this.faceVertexUvs[ i$3 ].push( uvsCopy ); + + } + + } + + }, + + mergeMesh: function ( mesh ) { + + if ( ! ( mesh && mesh.isMesh ) ) { + + console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh ); + return; + + } + + if ( mesh.matrixAutoUpdate ) { mesh.updateMatrix(); } + + this.merge( mesh.geometry, mesh.matrix ); + + }, + + /* + * Checks for duplicate vertices with hashmap. + * Duplicated vertices are removed + * and faces' vertices are updated. + */ + + mergeVertices: function () { + + var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique) + var unique = [], changes = []; + + var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001 + var precision = Math.pow( 10, precisionPoints ); + + for ( var i = 0, il = this.vertices.length; i < il; i ++ ) { + + var v = this.vertices[ i ]; + var key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision ); + + if ( verticesMap[ key ] === undefined ) { + + verticesMap[ key ] = i; + unique.push( this.vertices[ i ] ); + changes[ i ] = unique.length - 1; + + } else { + + //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]); + changes[ i ] = changes[ verticesMap[ key ] ]; + + } + + } + + + // if faces are completely degenerate after merging vertices, we + // have to remove them from the geometry. + var faceIndicesToRemove = []; + + for ( var i$1 = 0, il$1 = this.faces.length; i$1 < il$1; i$1 ++ ) { + + var face = this.faces[ i$1 ]; + + face.a = changes[ face.a ]; + face.b = changes[ face.b ]; + face.c = changes[ face.c ]; + + var indices = [ face.a, face.b, face.c ]; + + // if any duplicate vertices are found in a Face3 + // we have to remove the face as nothing can be saved + for ( var n = 0; n < 3; n ++ ) { + + if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) { + + faceIndicesToRemove.push( i$1 ); + break; + + } + + } + + } + + for ( var i$2 = faceIndicesToRemove.length - 1; i$2 >= 0; i$2 -- ) { + + var idx = faceIndicesToRemove[ i$2 ]; + + this.faces.splice( idx, 1 ); + + for ( var j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) { + + this.faceVertexUvs[ j ].splice( idx, 1 ); + + } + + } + + // Use unique set of vertices + + var diff = this.vertices.length - unique.length; + this.vertices = unique; + return diff; + + }, + + setFromPoints: function ( points ) { + + this.vertices = []; + + for ( var i = 0, l = points.length; i < l; i ++ ) { + + var point = points[ i ]; + this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) ); + + } + + return this; + + }, + + sortFacesByMaterialIndex: function () { + + var faces = this.faces; + var length = faces.length; + + // tag faces + + for ( var i = 0; i < length; i ++ ) { + + faces[ i ]._id = i; + + } + + // sort faces + + function materialIndexSort( a, b ) { + + return a.materialIndex - b.materialIndex; + + } + + faces.sort( materialIndexSort ); + + // sort uvs + + var uvs1 = this.faceVertexUvs[ 0 ]; + var uvs2 = this.faceVertexUvs[ 1 ]; + + var newUvs1, newUvs2; + + if ( uvs1 && uvs1.length === length ) { newUvs1 = []; } + if ( uvs2 && uvs2.length === length ) { newUvs2 = []; } + + for ( var i$1 = 0; i$1 < length; i$1 ++ ) { + + var id = faces[ i$1 ]._id; + + if ( newUvs1 ) { newUvs1.push( uvs1[ id ] ); } + if ( newUvs2 ) { newUvs2.push( uvs2[ id ] ); } + + } + + if ( newUvs1 ) { this.faceVertexUvs[ 0 ] = newUvs1; } + if ( newUvs2 ) { this.faceVertexUvs[ 1 ] = newUvs2; } + + }, + + toJSON: function () { + + var data = { + metadata: { + version: 4.5, + type: 'Geometry', + generator: 'Geometry.toJSON' + } + }; + + // standard Geometry serialization + + data.uuid = this.uuid; + data.type = this.type; + if ( this.name !== '' ) { data.name = this.name; } + + if ( this.parameters !== undefined ) { + + var parameters = this.parameters; + + for ( var key in parameters ) { + + if ( parameters[ key ] !== undefined ) { data[ key ] = parameters[ key ]; } + + } + + return data; + + } + + var vertices = []; + + for ( var i = 0; i < this.vertices.length; i ++ ) { + + var vertex = this.vertices[ i ]; + vertices.push( vertex.x, vertex.y, vertex.z ); + + } + + var faces = []; + var normals = []; + var normalsHash = {}; + var colors = []; + var colorsHash = {}; + var uvs = []; + var uvsHash = {}; + + for ( var i$1 = 0; i$1 < this.faces.length; i$1 ++ ) { + + var face = this.faces[ i$1 ]; + + var hasMaterial = true; + var hasFaceUv = false; // deprecated + var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i$1 ] !== undefined; + var hasFaceNormal = face.normal.length() > 0; + var hasFaceVertexNormal = face.vertexNormals.length > 0; + var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1; + var hasFaceVertexColor = face.vertexColors.length > 0; + + var faceType = 0; + + faceType = setBit( faceType, 0, 0 ); // isQuad + faceType = setBit( faceType, 1, hasMaterial ); + faceType = setBit( faceType, 2, hasFaceUv ); + faceType = setBit( faceType, 3, hasFaceVertexUv ); + faceType = setBit( faceType, 4, hasFaceNormal ); + faceType = setBit( faceType, 5, hasFaceVertexNormal ); + faceType = setBit( faceType, 6, hasFaceColor ); + faceType = setBit( faceType, 7, hasFaceVertexColor ); + + faces.push( faceType ); + faces.push( face.a, face.b, face.c ); + faces.push( face.materialIndex ); + + if ( hasFaceVertexUv ) { + + var faceVertexUvs = this.faceVertexUvs[ 0 ][ i$1 ]; + + faces.push( + getUvIndex( faceVertexUvs[ 0 ] ), + getUvIndex( faceVertexUvs[ 1 ] ), + getUvIndex( faceVertexUvs[ 2 ] ) + ); + + } + + if ( hasFaceNormal ) { + + faces.push( getNormalIndex( face.normal ) ); + + } + + if ( hasFaceVertexNormal ) { + + var vertexNormals = face.vertexNormals; + + faces.push( + getNormalIndex( vertexNormals[ 0 ] ), + getNormalIndex( vertexNormals[ 1 ] ), + getNormalIndex( vertexNormals[ 2 ] ) + ); + + } + + if ( hasFaceColor ) { + + faces.push( getColorIndex( face.color ) ); + + } + + if ( hasFaceVertexColor ) { + + var vertexColors = face.vertexColors; + + faces.push( + getColorIndex( vertexColors[ 0 ] ), + getColorIndex( vertexColors[ 1 ] ), + getColorIndex( vertexColors[ 2 ] ) + ); + + } + + } + + function setBit( value, position, enabled ) { + + return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) ); + + } + + function getNormalIndex( normal ) { + + var hash = normal.x.toString() + normal.y.toString() + normal.z.toString(); + + if ( normalsHash[ hash ] !== undefined ) { + + return normalsHash[ hash ]; + + } + + normalsHash[ hash ] = normals.length / 3; + normals.push( normal.x, normal.y, normal.z ); + + return normalsHash[ hash ]; + + } + + function getColorIndex( color ) { + + var hash = color.r.toString() + color.g.toString() + color.b.toString(); + + if ( colorsHash[ hash ] !== undefined ) { + + return colorsHash[ hash ]; + + } + + colorsHash[ hash ] = colors.length; + colors.push( color.getHex() ); + + return colorsHash[ hash ]; + + } + + function getUvIndex( uv ) { + + var hash = uv.x.toString() + uv.y.toString(); + + if ( uvsHash[ hash ] !== undefined ) { + + return uvsHash[ hash ]; + + } + + uvsHash[ hash ] = uvs.length / 2; + uvs.push( uv.x, uv.y ); + + return uvsHash[ hash ]; + + } + + data.data = {}; + + data.data.vertices = vertices; + data.data.normals = normals; + if ( colors.length > 0 ) { data.data.colors = colors; } + if ( uvs.length > 0 ) { data.data.uvs = [ uvs ]; } // temporal backward compatibility + data.data.faces = faces; + + return data; + + }, + + clone: function () { + + /* + // Handle primitives + + const parameters = this.parameters; + + if ( parameters !== undefined ) { + + const values = []; + + for ( const key in parameters ) { + + values.push( parameters[ key ] ); + + } + + const geometry = Object.create( this.constructor.prototype ); + this.constructor.apply( geometry, values ); + return geometry; + + } + + return new this.constructor().copy( this ); + */ + + return new Geometry().copy( this ); + + }, + + copy: function ( source ) { + + // reset + + this.vertices = []; + this.colors = []; + this.faces = []; + this.faceVertexUvs = [[]]; + this.morphTargets = []; + this.morphNormals = []; + this.skinWeights = []; + this.skinIndices = []; + this.lineDistances = []; + this.boundingBox = null; + this.boundingSphere = null; + + // name + + this.name = source.name; + + // vertices + + var vertices = source.vertices; + + for ( var i = 0, il = vertices.length; i < il; i ++ ) { + + this.vertices.push( vertices[ i ].clone() ); + + } + + // colors + + var colors = source.colors; + + for ( var i$1 = 0, il$1 = colors.length; i$1 < il$1; i$1 ++ ) { + + this.colors.push( colors[ i$1 ].clone() ); + + } + + // faces + + var faces = source.faces; + + for ( var i$2 = 0, il$2 = faces.length; i$2 < il$2; i$2 ++ ) { + + this.faces.push( faces[ i$2 ].clone() ); + + } + + // face vertex uvs + + for ( var i$3 = 0, il$3 = source.faceVertexUvs.length; i$3 < il$3; i$3 ++ ) { + + var faceVertexUvs = source.faceVertexUvs[ i$3 ]; + + if ( this.faceVertexUvs[ i$3 ] === undefined ) { + + this.faceVertexUvs[ i$3 ] = []; + + } + + for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) { + + var uvs = faceVertexUvs[ j ], uvsCopy = []; + + for ( var k = 0, kl = uvs.length; k < kl; k ++ ) { + + var uv = uvs[ k ]; + + uvsCopy.push( uv.clone() ); + + } + + this.faceVertexUvs[ i$3 ].push( uvsCopy ); + + } + + } + + // morph targets + + var morphTargets = source.morphTargets; + + for ( var i$4 = 0, il$4 = morphTargets.length; i$4 < il$4; i$4 ++ ) { + + var morphTarget = {}; + morphTarget.name = morphTargets[ i$4 ].name; + + // vertices + + if ( morphTargets[ i$4 ].vertices !== undefined ) { + + morphTarget.vertices = []; + + for ( var j$1 = 0, jl$1 = morphTargets[ i$4 ].vertices.length; j$1 < jl$1; j$1 ++ ) { + + morphTarget.vertices.push( morphTargets[ i$4 ].vertices[ j$1 ].clone() ); + + } + + } + + // normals + + if ( morphTargets[ i$4 ].normals !== undefined ) { + + morphTarget.normals = []; + + for ( var j$2 = 0, jl$2 = morphTargets[ i$4 ].normals.length; j$2 < jl$2; j$2 ++ ) { + + morphTarget.normals.push( morphTargets[ i$4 ].normals[ j$2 ].clone() ); + + } + + } + + this.morphTargets.push( morphTarget ); + + } + + // morph normals + + var morphNormals = source.morphNormals; + + for ( var i$5 = 0, il$5 = morphNormals.length; i$5 < il$5; i$5 ++ ) { + + var morphNormal = {}; + + // vertex normals + + if ( morphNormals[ i$5 ].vertexNormals !== undefined ) { + + morphNormal.vertexNormals = []; + + for ( var j$3 = 0, jl$3 = morphNormals[ i$5 ].vertexNormals.length; j$3 < jl$3; j$3 ++ ) { + + var srcVertexNormal = morphNormals[ i$5 ].vertexNormals[ j$3 ]; + var destVertexNormal = {}; + + destVertexNormal.a = srcVertexNormal.a.clone(); + destVertexNormal.b = srcVertexNormal.b.clone(); + destVertexNormal.c = srcVertexNormal.c.clone(); + + morphNormal.vertexNormals.push( destVertexNormal ); + + } + + } + + // face normals + + if ( morphNormals[ i$5 ].faceNormals !== undefined ) { + + morphNormal.faceNormals = []; + + for ( var j$4 = 0, jl$4 = morphNormals[ i$5 ].faceNormals.length; j$4 < jl$4; j$4 ++ ) { + + morphNormal.faceNormals.push( morphNormals[ i$5 ].faceNormals[ j$4 ].clone() ); + + } + + } + + this.morphNormals.push( morphNormal ); + + } + + // skin weights + + var skinWeights = source.skinWeights; + + for ( var i$6 = 0, il$6 = skinWeights.length; i$6 < il$6; i$6 ++ ) { + + this.skinWeights.push( skinWeights[ i$6 ].clone() ); + + } + + // skin indices + + var skinIndices = source.skinIndices; + + for ( var i$7 = 0, il$7 = skinIndices.length; i$7 < il$7; i$7 ++ ) { + + this.skinIndices.push( skinIndices[ i$7 ].clone() ); + + } + + // line distances + + var lineDistances = source.lineDistances; + + for ( var i$8 = 0, il$8 = lineDistances.length; i$8 < il$8; i$8 ++ ) { + + this.lineDistances.push( lineDistances[ i$8 ] ); + + } + + // bounding box + + var boundingBox = source.boundingBox; + + if ( boundingBox !== null ) { + + this.boundingBox = boundingBox.clone(); + + } + + // bounding sphere + + var boundingSphere = source.boundingSphere; + + if ( boundingSphere !== null ) { + + this.boundingSphere = boundingSphere.clone(); + + } + + // update flags + + this.elementsNeedUpdate = source.elementsNeedUpdate; + this.verticesNeedUpdate = source.verticesNeedUpdate; + this.uvsNeedUpdate = source.uvsNeedUpdate; + this.normalsNeedUpdate = source.normalsNeedUpdate; + this.colorsNeedUpdate = source.colorsNeedUpdate; + this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate; + this.groupsNeedUpdate = source.groupsNeedUpdate; + + return this; + + }, + + dispose: function () { + + this.dispatchEvent( { type: 'dispose' } ); + + } + + } ); + + // BoxGeometry + + var BoxGeometry = /*@__PURE__*/(function (Geometry) { + function BoxGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) { + + Geometry.call(this); + + this.type = 'BoxGeometry'; + + this.parameters = { + width: width, + height: height, + depth: depth, + widthSegments: widthSegments, + heightSegments: heightSegments, + depthSegments: depthSegments + }; + + this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) ); + this.mergeVertices(); + + } + + if ( Geometry ) BoxGeometry.__proto__ = Geometry; + BoxGeometry.prototype = Object.create( Geometry && Geometry.prototype ); + BoxGeometry.prototype.constructor = BoxGeometry; + + return BoxGeometry; + }(Geometry)); + + // BoxBufferGeometry + + var BoxBufferGeometry = /*@__PURE__*/(function (BufferGeometry) { + function BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) { + if ( width === void 0 ) width = 1; + if ( height === void 0 ) height = 1; + if ( depth === void 0 ) depth = 1; + if ( widthSegments === void 0 ) widthSegments = 1; + if ( heightSegments === void 0 ) heightSegments = 1; + if ( depthSegments === void 0 ) depthSegments = 1; + + + BufferGeometry.call(this); + + this.type = 'BoxBufferGeometry'; + + this.parameters = { + width: width, + height: height, + depth: depth, + widthSegments: widthSegments, + heightSegments: heightSegments, + depthSegments: depthSegments + }; + + var scope = this; + + // segments + + widthSegments = Math.floor( widthSegments ); + heightSegments = Math.floor( heightSegments ); + depthSegments = Math.floor( depthSegments ); + + // buffers + + var indices = []; + var vertices = []; + var normals = []; + var uvs = []; + + // helper variables + + var numberOfVertices = 0; + var groupStart = 0; + + // build each side of the box geometry + + buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px + buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx + buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py + buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny + buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz + buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) { + + var segmentWidth = width / gridX; + var segmentHeight = height / gridY; + + var widthHalf = width / 2; + var heightHalf = height / 2; + var depthHalf = depth / 2; + + var gridX1 = gridX + 1; + var gridY1 = gridY + 1; + + var vertexCounter = 0; + var groupCount = 0; + + var vector = new Vector3(); + + // generate vertices, normals and uvs + + for ( var iy = 0; iy < gridY1; iy ++ ) { + + var y = iy * segmentHeight - heightHalf; + + for ( var ix = 0; ix < gridX1; ix ++ ) { + + var x = ix * segmentWidth - widthHalf; + + // set values to correct vector component + + vector[ u ] = x * udir; + vector[ v ] = y * vdir; + vector[ w ] = depthHalf; + + // now apply vector to vertex buffer + + vertices.push( vector.x, vector.y, vector.z ); + + // set values to correct vector component + + vector[ u ] = 0; + vector[ v ] = 0; + vector[ w ] = depth > 0 ? 1 : - 1; + + // now apply vector to normal buffer + + normals.push( vector.x, vector.y, vector.z ); + + // uvs + + uvs.push( ix / gridX ); + uvs.push( 1 - ( iy / gridY ) ); + + // counters + + vertexCounter += 1; + + } + + } + + // indices + + // 1. you need three indices to draw a single face + // 2. a single segment consists of two faces + // 3. so we need to generate six (2*3) indices per segment + + for ( var iy$1 = 0; iy$1 < gridY; iy$1 ++ ) { + + for ( var ix$1 = 0; ix$1 < gridX; ix$1 ++ ) { + + var a = numberOfVertices + ix$1 + gridX1 * iy$1; + var b = numberOfVertices + ix$1 + gridX1 * ( iy$1 + 1 ); + var c = numberOfVertices + ( ix$1 + 1 ) + gridX1 * ( iy$1 + 1 ); + var d = numberOfVertices + ( ix$1 + 1 ) + gridX1 * iy$1; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + // increase counter + + groupCount += 6; + + } + + } + + // add a group to the geometry. this will ensure multi material support + + scope.addGroup( groupStart, groupCount, materialIndex ); + + // calculate new start value for groups + + groupStart += groupCount; + + // update total number of vertices + + numberOfVertices += vertexCounter; + + } + + } + + if ( BufferGeometry ) BoxBufferGeometry.__proto__ = BufferGeometry; + BoxBufferGeometry.prototype = Object.create( BufferGeometry && BufferGeometry.prototype ); + BoxBufferGeometry.prototype.constructor = BoxBufferGeometry; + + return BoxBufferGeometry; + }(BufferGeometry)); + + /** + * Uniform Utilities + */ + + function cloneUniforms( src ) { + + var dst = {}; + + for ( var u in src ) { + + dst[ u ] = {}; + + for ( var p in src[ u ] ) { + + var property = src[ u ][ p ]; + + if ( property && ( property.isColor || + property.isMatrix3 || property.isMatrix4 || + property.isVector2 || property.isVector3 || property.isVector4 || + property.isTexture ) ) { + + dst[ u ][ p ] = property.clone(); + + } else if ( Array.isArray( property ) ) { + + dst[ u ][ p ] = property.slice(); + + } else { + + dst[ u ][ p ] = property; + + } + + } + + } + + return dst; + + } + + function mergeUniforms( uniforms ) { + + var merged = {}; + + for ( var u = 0; u < uniforms.length; u ++ ) { + + var tmp = cloneUniforms( uniforms[ u ] ); + + for ( var p in tmp ) { + + merged[ p ] = tmp[ p ]; + + } + + } + + return merged; + + } + + // Legacy + + var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms }; + + var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"; + + var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}"; + + /** + * parameters = { + * defines: { "label" : "value" }, + * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } }, + * + * fragmentShader: , + * vertexShader: , + * + * wireframe: , + * wireframeLinewidth: , + * + * lights: , + * + * skinning: , + * morphTargets: , + * morphNormals: + * } + */ + + function ShaderMaterial( parameters ) { + + Material.call( this ); + + this.type = 'ShaderMaterial'; + + this.defines = {}; + this.uniforms = {}; + + this.vertexShader = default_vertex; + this.fragmentShader = default_fragment; + + this.linewidth = 1; + + this.wireframe = false; + this.wireframeLinewidth = 1; + + this.fog = false; // set to use scene fog + this.lights = false; // set to use scene lights + this.clipping = false; // set to use user-defined clipping planes + + this.skinning = false; // set to use skinning attribute streams + this.morphTargets = false; // set to use morph targets + this.morphNormals = false; // set to use morph normals + + this.extensions = { + derivatives: false, // set to use derivatives + fragDepth: false, // set to use fragment depth values + drawBuffers: false, // set to use draw buffers + shaderTextureLOD: false // set to use shader texture LOD + }; + + // When rendered geometry doesn't include these attributes but the material does, + // use these default values in WebGL. This avoids errors when buffer data is missing. + this.defaultAttributeValues = { + 'color': [ 1, 1, 1 ], + 'uv': [ 0, 0 ], + 'uv2': [ 0, 0 ] + }; + + this.index0AttributeName = undefined; + this.uniformsNeedUpdate = false; + + if ( parameters !== undefined ) { + + if ( parameters.attributes !== undefined ) { + + console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' ); + + } + + this.setValues( parameters ); + + } + + } + + ShaderMaterial.prototype = Object.create( Material.prototype ); + ShaderMaterial.prototype.constructor = ShaderMaterial; + + ShaderMaterial.prototype.isShaderMaterial = true; + + ShaderMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.fragmentShader = source.fragmentShader; + this.vertexShader = source.vertexShader; + + this.uniforms = cloneUniforms( source.uniforms ); + + this.defines = Object.assign( {}, source.defines ); + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + + this.lights = source.lights; + this.clipping = source.clipping; + + this.skinning = source.skinning; + + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; + + this.extensions = Object.assign( {}, source.extensions ); + + return this; + + }; + + ShaderMaterial.prototype.toJSON = function ( meta ) { + + var data = Material.prototype.toJSON.call( this, meta ); + + data.uniforms = {}; + + for ( var name in this.uniforms ) { + + var uniform = this.uniforms[ name ]; + var value = uniform.value; + + if ( value && value.isTexture ) { + + data.uniforms[ name ] = { + type: 't', + value: value.toJSON( meta ).uuid + }; + + } else if ( value && value.isColor ) { + + data.uniforms[ name ] = { + type: 'c', + value: value.getHex() + }; + + } else if ( value && value.isVector2 ) { + + data.uniforms[ name ] = { + type: 'v2', + value: value.toArray() + }; + + } else if ( value && value.isVector3 ) { + + data.uniforms[ name ] = { + type: 'v3', + value: value.toArray() + }; + + } else if ( value && value.isVector4 ) { + + data.uniforms[ name ] = { + type: 'v4', + value: value.toArray() + }; + + } else if ( value && value.isMatrix3 ) { + + data.uniforms[ name ] = { + type: 'm3', + value: value.toArray() + }; + + } else if ( value && value.isMatrix4 ) { + + data.uniforms[ name ] = { + type: 'm4', + value: value.toArray() + }; + + } else { + + data.uniforms[ name ] = { + value: value + }; + + // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far + + } + + } + + if ( Object.keys( this.defines ).length > 0 ) { data.defines = this.defines; } + + data.vertexShader = this.vertexShader; + data.fragmentShader = this.fragmentShader; + + var extensions = {}; + + for ( var key in this.extensions ) { + + if ( this.extensions[ key ] === true ) { extensions[ key ] = true; } + + } + + if ( Object.keys( extensions ).length > 0 ) { data.extensions = extensions; } + + return data; + + }; + + function Camera() { + + Object3D.call( this ); + + this.type = 'Camera'; + + this.matrixWorldInverse = new Matrix4(); + + this.projectionMatrix = new Matrix4(); + this.projectionMatrixInverse = new Matrix4(); + + } + + Camera.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: Camera, + + isCamera: true, + + copy: function ( source, recursive ) { + + Object3D.prototype.copy.call( this, source, recursive ); + + this.matrixWorldInverse.copy( source.matrixWorldInverse ); + + this.projectionMatrix.copy( source.projectionMatrix ); + this.projectionMatrixInverse.copy( source.projectionMatrixInverse ); + + return this; + + }, + + getWorldDirection: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Camera: .getWorldDirection() target is now required' ); + target = new Vector3(); + + } + + this.updateMatrixWorld( true ); + + var e = this.matrixWorld.elements; + + return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize(); + + }, + + updateMatrixWorld: function ( force ) { + + Object3D.prototype.updateMatrixWorld.call( this, force ); + + this.matrixWorldInverse.getInverse( this.matrixWorld ); + + }, + + updateWorldMatrix: function ( updateParents, updateChildren ) { + + Object3D.prototype.updateWorldMatrix.call( this, updateParents, updateChildren ); + + this.matrixWorldInverse.getInverse( this.matrixWorld ); + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + } + + } ); + + function PerspectiveCamera( fov, aspect, near, far ) { + + Camera.call( this ); + + this.type = 'PerspectiveCamera'; + + this.fov = fov !== undefined ? fov : 50; + this.zoom = 1; + + this.near = near !== undefined ? near : 0.1; + this.far = far !== undefined ? far : 2000; + this.focus = 10; + + this.aspect = aspect !== undefined ? aspect : 1; + this.view = null; + + this.filmGauge = 35; // width of the film (default in millimeters) + this.filmOffset = 0; // horizontal film offset (same unit as gauge) + + this.updateProjectionMatrix(); + + } + + PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), { + + constructor: PerspectiveCamera, + + isPerspectiveCamera: true, + + copy: function ( source, recursive ) { + + Camera.prototype.copy.call( this, source, recursive ); + + this.fov = source.fov; + this.zoom = source.zoom; + + this.near = source.near; + this.far = source.far; + this.focus = source.focus; + + this.aspect = source.aspect; + this.view = source.view === null ? null : Object.assign( {}, source.view ); + + this.filmGauge = source.filmGauge; + this.filmOffset = source.filmOffset; + + return this; + + }, + + /** + * Sets the FOV by focal length in respect to the current .filmGauge. + * + * The default film gauge is 35, so that the focal length can be specified for + * a 35mm (full frame) camera. + * + * Values for focal length and film gauge must have the same unit. + */ + setFocalLength: function ( focalLength ) { + + // see http://www.bobatkins.com/photography/technical/field_of_view.html + var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength; + + this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope ); + this.updateProjectionMatrix(); + + }, + + /** + * Calculates the focal length from the current .fov and .filmGauge. + */ + getFocalLength: function () { + + var vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ); + + return 0.5 * this.getFilmHeight() / vExtentSlope; + + }, + + getEffectiveFOV: function () { + + return MathUtils.RAD2DEG * 2 * Math.atan( + Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom ); + + }, + + getFilmWidth: function () { + + // film not completely covered in portrait format (aspect < 1) + return this.filmGauge * Math.min( this.aspect, 1 ); + + }, + + getFilmHeight: function () { + + // film not completely covered in landscape format (aspect > 1) + return this.filmGauge / Math.max( this.aspect, 1 ); + + }, + + /** + * Sets an offset in a larger frustum. This is useful for multi-window or + * multi-monitor/multi-machine setups. + * + * For example, if you have 3x2 monitors and each monitor is 1920x1080 and + * the monitors are in grid like this + * + * +---+---+---+ + * | A | B | C | + * +---+---+---+ + * | D | E | F | + * +---+---+---+ + * + * then for each monitor you would call it like this + * + * const w = 1920; + * const h = 1080; + * const fullWidth = w * 3; + * const fullHeight = h * 2; + * + * --A-- + * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h ); + * --B-- + * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h ); + * --C-- + * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h ); + * --D-- + * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h ); + * --E-- + * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h ); + * --F-- + * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h ); + * + * Note there is no reason monitors have to be the same size or in a grid. + */ + setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) { + + this.aspect = fullWidth / fullHeight; + + if ( this.view === null ) { + + this.view = { + enabled: true, + fullWidth: 1, + fullHeight: 1, + offsetX: 0, + offsetY: 0, + width: 1, + height: 1 + }; + + } + + this.view.enabled = true; + this.view.fullWidth = fullWidth; + this.view.fullHeight = fullHeight; + this.view.offsetX = x; + this.view.offsetY = y; + this.view.width = width; + this.view.height = height; + + this.updateProjectionMatrix(); + + }, + + clearViewOffset: function () { + + if ( this.view !== null ) { + + this.view.enabled = false; + + } + + this.updateProjectionMatrix(); + + }, + + updateProjectionMatrix: function () { + + var near = this.near, + top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom, + height = 2 * top, + width = this.aspect * height, + left = - 0.5 * width, + view = this.view; + + if ( this.view !== null && this.view.enabled ) { + + var fullWidth = view.fullWidth, + fullHeight = view.fullHeight; + + left += view.offsetX * width / fullWidth; + top -= view.offsetY * height / fullHeight; + width *= view.width / fullWidth; + height *= view.height / fullHeight; + + } + + var skew = this.filmOffset; + if ( skew !== 0 ) { left += near * skew / this.getFilmWidth(); } + + this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far ); + + this.projectionMatrixInverse.getInverse( this.projectionMatrix ); + + }, + + toJSON: function ( meta ) { + + var data = Object3D.prototype.toJSON.call( this, meta ); + + data.object.fov = this.fov; + data.object.zoom = this.zoom; + + data.object.near = this.near; + data.object.far = this.far; + data.object.focus = this.focus; + + data.object.aspect = this.aspect; + + if ( this.view !== null ) { data.object.view = Object.assign( {}, this.view ); } + + data.object.filmGauge = this.filmGauge; + data.object.filmOffset = this.filmOffset; + + return data; + + } + + } ); + + var fov = 90, aspect = 1; + + function CubeCamera( near, far, renderTarget ) { + + Object3D.call( this ); + + this.type = 'CubeCamera'; + + if ( renderTarget.isWebGLCubeRenderTarget !== true ) { + + console.error( 'THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.' ); + return; + + } + + this.renderTarget = renderTarget; + + var cameraPX = new PerspectiveCamera( fov, aspect, near, far ); + cameraPX.layers = this.layers; + cameraPX.up.set( 0, - 1, 0 ); + cameraPX.lookAt( new Vector3( 1, 0, 0 ) ); + this.add( cameraPX ); + + var cameraNX = new PerspectiveCamera( fov, aspect, near, far ); + cameraNX.layers = this.layers; + cameraNX.up.set( 0, - 1, 0 ); + cameraNX.lookAt( new Vector3( - 1, 0, 0 ) ); + this.add( cameraNX ); + + var cameraPY = new PerspectiveCamera( fov, aspect, near, far ); + cameraPY.layers = this.layers; + cameraPY.up.set( 0, 0, 1 ); + cameraPY.lookAt( new Vector3( 0, 1, 0 ) ); + this.add( cameraPY ); + + var cameraNY = new PerspectiveCamera( fov, aspect, near, far ); + cameraNY.layers = this.layers; + cameraNY.up.set( 0, 0, - 1 ); + cameraNY.lookAt( new Vector3( 0, - 1, 0 ) ); + this.add( cameraNY ); + + var cameraPZ = new PerspectiveCamera( fov, aspect, near, far ); + cameraPZ.layers = this.layers; + cameraPZ.up.set( 0, - 1, 0 ); + cameraPZ.lookAt( new Vector3( 0, 0, 1 ) ); + this.add( cameraPZ ); + + var cameraNZ = new PerspectiveCamera( fov, aspect, near, far ); + cameraNZ.layers = this.layers; + cameraNZ.up.set( 0, - 1, 0 ); + cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) ); + this.add( cameraNZ ); + + this.update = function ( renderer, scene ) { + + if ( this.parent === null ) { this.updateMatrixWorld(); } + + var currentXrEnabled = renderer.xr.enabled; + var currentRenderTarget = renderer.getRenderTarget(); + + renderer.xr.enabled = false; + + var generateMipmaps = renderTarget.texture.generateMipmaps; + + renderTarget.texture.generateMipmaps = false; + + renderer.setRenderTarget( renderTarget, 0 ); + renderer.render( scene, cameraPX ); + + renderer.setRenderTarget( renderTarget, 1 ); + renderer.render( scene, cameraNX ); + + renderer.setRenderTarget( renderTarget, 2 ); + renderer.render( scene, cameraPY ); + + renderer.setRenderTarget( renderTarget, 3 ); + renderer.render( scene, cameraNY ); + + renderer.setRenderTarget( renderTarget, 4 ); + renderer.render( scene, cameraPZ ); + + renderTarget.texture.generateMipmaps = generateMipmaps; + + renderer.setRenderTarget( renderTarget, 5 ); + renderer.render( scene, cameraNZ ); + + renderer.setRenderTarget( currentRenderTarget ); + + renderer.xr.enabled = currentXrEnabled; + + }; + + this.clear = function ( renderer, color, depth, stencil ) { + + var currentRenderTarget = renderer.getRenderTarget(); + + for ( var i = 0; i < 6; i ++ ) { + + renderer.setRenderTarget( renderTarget, i ); + + renderer.clear( color, depth, stencil ); + + } + + renderer.setRenderTarget( currentRenderTarget ); + + }; + + } + + CubeCamera.prototype = Object.create( Object3D.prototype ); + CubeCamera.prototype.constructor = CubeCamera; + + function WebGLCubeRenderTarget( size, options, dummy ) { + + if ( Number.isInteger( options ) ) { + + console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' ); + + options = dummy; + + } + + WebGLRenderTarget.call( this, size, size, options ); + + } + + WebGLCubeRenderTarget.prototype = Object.create( WebGLRenderTarget.prototype ); + WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget; + + WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true; + + WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer, texture ) { + + this.texture.type = texture.type; + this.texture.format = RGBAFormat; // see #18859 + this.texture.encoding = texture.encoding; + + this.texture.generateMipmaps = texture.generateMipmaps; + this.texture.minFilter = texture.minFilter; + this.texture.magFilter = texture.magFilter; + + var scene = new Scene(); + + var shader = { + + uniforms: { + tEquirect: { value: null }, + }, + + vertexShader: /* glsl */"\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 \n\t\t\t\t#include \n\n\t\t\t}\n\t\t", + + fragmentShader: /* glsl */"\n\n\t\t\tuniform sampler2D tEquirect;\n\n\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t#include \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" + }; + + var material = new ShaderMaterial( { + + name: 'CubemapFromEquirect', + + uniforms: cloneUniforms( shader.uniforms ), + vertexShader: shader.vertexShader, + fragmentShader: shader.fragmentShader, + side: BackSide, + blending: NoBlending + + } ); + + material.uniforms.tEquirect.value = texture; + + var mesh = new Mesh( new BoxBufferGeometry( 5, 5, 5 ), material ); + + scene.add( mesh ); + + var camera = new CubeCamera( 1, 10, this ); + camera.update( renderer, scene ); + + mesh.geometry.dispose(); + mesh.material.dispose(); + + return this; + + }; + + function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) { + + Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ); + + this.image = { data: data || null, width: width || 1, height: height || 1 }; + + this.magFilter = magFilter !== undefined ? magFilter : NearestFilter; + this.minFilter = minFilter !== undefined ? minFilter : NearestFilter; + + this.generateMipmaps = false; + this.flipY = false; + this.unpackAlignment = 1; + + this.needsUpdate = true; + + } + + DataTexture.prototype = Object.create( Texture.prototype ); + DataTexture.prototype.constructor = DataTexture; + + DataTexture.prototype.isDataTexture = true; + + var _sphere$1 = new Sphere(); + var _vector$5 = new Vector3(); + + function Frustum( p0, p1, p2, p3, p4, p5 ) { + + 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() + + ]; + + } + + Object.assign( Frustum.prototype, { + + set: function ( p0, p1, p2, p3, p4, p5 ) { + + var planes = this.planes; + + planes[ 0 ].copy( p0 ); + planes[ 1 ].copy( p1 ); + planes[ 2 ].copy( p2 ); + planes[ 3 ].copy( p3 ); + planes[ 4 ].copy( p4 ); + planes[ 5 ].copy( p5 ); + + return this; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( frustum ) { + + var planes = this.planes; + + for ( var i = 0; i < 6; i ++ ) { + + planes[ i ].copy( frustum.planes[ i ] ); + + } + + return this; + + }, + + setFromProjectionMatrix: function ( m ) { + + var planes = this.planes; + var me = m.elements; + var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ]; + var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ]; + var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ]; + var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ]; + + planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize(); + planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize(); + planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize(); + planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize(); + planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize(); + planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize(); + + return this; + + }, + + intersectsObject: function ( object ) { + + var geometry = object.geometry; + + if ( geometry.boundingSphere === null ) { geometry.computeBoundingSphere(); } + + _sphere$1.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld ); + + return this.intersectsSphere( _sphere$1 ); + + }, + + intersectsSprite: function ( sprite ) { + + _sphere$1.center.set( 0, 0, 0 ); + _sphere$1.radius = 0.7071067811865476; + _sphere$1.applyMatrix4( sprite.matrixWorld ); + + return this.intersectsSphere( _sphere$1 ); + + }, + + intersectsSphere: function ( sphere ) { + + var planes = this.planes; + var center = sphere.center; + var negRadius = - sphere.radius; + + for ( var i = 0; i < 6; i ++ ) { + + var distance = planes[ i ].distanceToPoint( center ); + + if ( distance < negRadius ) { + + return false; + + } + + } + + return true; + + }, + + intersectsBox: function ( box ) { + + var planes = this.planes; + + for ( var i = 0; i < 6; i ++ ) { + + var plane = planes[ i ]; + + // corner at max distance + + _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x; + _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y; + _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z; + + if ( plane.distanceToPoint( _vector$5 ) < 0 ) { + + return false; + + } + + } + + return true; + + }, + + containsPoint: function ( point ) { + + var planes = this.planes; + + for ( var i = 0; i < 6; i ++ ) { + + if ( planes[ i ].distanceToPoint( point ) < 0 ) { + + return false; + + } + + } + + return true; + + } + + } ); + + /** + * Uniforms library for shared webgl shaders + */ + + var UniformsLib = { + + common: { + + diffuse: { value: new Color( 0xeeeeee ) }, + opacity: { value: 1.0 }, + + map: { value: null }, + uvTransform: { value: new Matrix3() }, + uv2Transform: { value: new Matrix3() }, + + alphaMap: { value: null }, + + }, + + specularmap: { + + specularMap: { value: null }, + + }, + + envmap: { + + envMap: { value: null }, + flipEnvMap: { value: - 1 }, + reflectivity: { value: 1.0 }, + refractionRatio: { value: 0.98 }, + maxMipLevel: { value: 0 } + + }, + + aomap: { + + aoMap: { value: null }, + aoMapIntensity: { value: 1 } + + }, + + lightmap: { + + lightMap: { value: null }, + lightMapIntensity: { value: 1 } + + }, + + emissivemap: { + + emissiveMap: { value: null } + + }, + + bumpmap: { + + bumpMap: { value: null }, + bumpScale: { value: 1 } + + }, + + normalmap: { + + normalMap: { value: null }, + normalScale: { value: new Vector2( 1, 1 ) } + + }, + + displacementmap: { + + displacementMap: { value: null }, + displacementScale: { value: 1 }, + displacementBias: { value: 0 } + + }, + + roughnessmap: { + + roughnessMap: { value: null } + + }, + + metalnessmap: { + + metalnessMap: { value: null } + + }, + + gradientmap: { + + gradientMap: { value: null } + + }, + + fog: { + + fogDensity: { value: 0.00025 }, + fogNear: { value: 1 }, + fogFar: { value: 2000 }, + fogColor: { value: new Color( 0xffffff ) } + + }, + + lights: { + + ambientLightColor: { value: [] }, + + lightProbe: { value: [] }, + + directionalLights: { value: [], properties: { + direction: {}, + color: {} + } }, + + directionalLightShadows: { value: [], properties: { + shadowBias: {}, + shadowNormalBias: {}, + shadowRadius: {}, + shadowMapSize: {} + } }, + + directionalShadowMap: { value: [] }, + directionalShadowMatrix: { value: [] }, + + spotLights: { value: [], properties: { + color: {}, + position: {}, + direction: {}, + distance: {}, + coneCos: {}, + penumbraCos: {}, + decay: {} + } }, + + spotLightShadows: { value: [], properties: { + shadowBias: {}, + shadowNormalBias: {}, + shadowRadius: {}, + shadowMapSize: {} + } }, + + spotShadowMap: { value: [] }, + spotShadowMatrix: { value: [] }, + + pointLights: { value: [], properties: { + color: {}, + position: {}, + decay: {}, + distance: {} + } }, + + pointLightShadows: { value: [], properties: { + shadowBias: {}, + shadowNormalBias: {}, + shadowRadius: {}, + shadowMapSize: {}, + shadowCameraNear: {}, + shadowCameraFar: {} + } }, + + pointShadowMap: { value: [] }, + pointShadowMatrix: { value: [] }, + + hemisphereLights: { value: [], properties: { + direction: {}, + skyColor: {}, + groundColor: {} + } }, + + // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src + rectAreaLights: { value: [], properties: { + color: {}, + position: {}, + width: {}, + height: {} + } } + + }, + + points: { + + diffuse: { value: new Color( 0xeeeeee ) }, + opacity: { value: 1.0 }, + size: { value: 1.0 }, + scale: { value: 1.0 }, + map: { value: null }, + alphaMap: { value: null }, + uvTransform: { value: new Matrix3() } + + }, + + sprite: { + + diffuse: { value: new Color( 0xeeeeee ) }, + opacity: { value: 1.0 }, + center: { value: new Vector2( 0.5, 0.5 ) }, + rotation: { value: 0.0 }, + map: { value: null }, + alphaMap: { value: null }, + uvTransform: { value: new Matrix3() } + + } + + }; + + function WebGLAnimation() { + + var context = null; + var isAnimating = false; + var animationLoop = null; + var requestId = null; + + function onAnimationFrame( time, frame ) { + + animationLoop( time, frame ); + + requestId = context.requestAnimationFrame( onAnimationFrame ); + + } + + return { + + start: function () { + + if ( isAnimating === true ) { return; } + if ( animationLoop === null ) { return; } + + requestId = context.requestAnimationFrame( onAnimationFrame ); + + isAnimating = true; + + }, + + stop: function () { + + context.cancelAnimationFrame( requestId ); + + isAnimating = false; + + }, + + setAnimationLoop: function ( callback ) { + + animationLoop = callback; + + }, + + setContext: function ( value ) { + + context = value; + + } + + }; + + } + + function WebGLAttributes( gl, capabilities ) { + + var isWebGL2 = capabilities.isWebGL2; + + var buffers = new WeakMap(); + + function createBuffer( attribute, bufferType ) { + + var array = attribute.array; + var usage = attribute.usage; + + var buffer = gl.createBuffer(); + + gl.bindBuffer( bufferType, buffer ); + gl.bufferData( bufferType, array, usage ); + + attribute.onUploadCallback(); + + var type = 5126; + + if ( array instanceof Float32Array ) { + + type = 5126; + + } else if ( array instanceof Float64Array ) { + + console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' ); + + } else if ( array instanceof Uint16Array ) { + + type = 5123; + + } else if ( array instanceof Int16Array ) { + + type = 5122; + + } else if ( array instanceof Uint32Array ) { + + type = 5125; + + } else if ( array instanceof Int32Array ) { + + type = 5124; + + } else if ( array instanceof Int8Array ) { + + type = 5120; + + } else if ( array instanceof Uint8Array ) { + + type = 5121; + + } + + return { + buffer: buffer, + type: type, + bytesPerElement: array.BYTES_PER_ELEMENT, + version: attribute.version + }; + + } + + function updateBuffer( buffer, attribute, bufferType ) { + + var array = attribute.array; + var updateRange = attribute.updateRange; + + gl.bindBuffer( bufferType, buffer ); + + if ( updateRange.count === - 1 ) { + + // Not using update ranges + + gl.bufferSubData( bufferType, 0, array ); + + } else { + + if ( isWebGL2 ) { + + gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, + array, updateRange.offset, updateRange.count ); + + } else { + + gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, + array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) ); + + } + + updateRange.count = - 1; // reset range + + } + + } + + // + + function get( attribute ) { + + if ( attribute.isInterleavedBufferAttribute ) { attribute = attribute.data; } + + return buffers.get( attribute ); + + } + + function remove( attribute ) { + + if ( attribute.isInterleavedBufferAttribute ) { attribute = attribute.data; } + + var data = buffers.get( attribute ); + + if ( data ) { + + gl.deleteBuffer( data.buffer ); + + buffers.delete( attribute ); + + } + + } + + function update( attribute, bufferType ) { + + if ( attribute.isInterleavedBufferAttribute ) { attribute = attribute.data; } + + var data = buffers.get( attribute ); + + if ( data === undefined ) { + + buffers.set( attribute, createBuffer( attribute, bufferType ) ); + + } else if ( data.version < attribute.version ) { + + updateBuffer( data.buffer, attribute, bufferType ); + + data.version = attribute.version; + + } + + } + + return { + + get: get, + remove: remove, + update: update + + }; + + } + + // PlaneGeometry + + function PlaneGeometry( width, height, widthSegments, heightSegments ) { + + Geometry.call( this ); + + this.type = 'PlaneGeometry'; + + this.parameters = { + width: width, + height: height, + widthSegments: widthSegments, + heightSegments: heightSegments + }; + + this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) ); + this.mergeVertices(); + + } + + PlaneGeometry.prototype = Object.create( Geometry.prototype ); + PlaneGeometry.prototype.constructor = PlaneGeometry; + + // PlaneBufferGeometry + + function PlaneBufferGeometry( width, height, widthSegments, heightSegments ) { + + BufferGeometry.call( this ); + + this.type = 'PlaneBufferGeometry'; + + this.parameters = { + width: width, + height: height, + widthSegments: widthSegments, + heightSegments: heightSegments + }; + + width = width || 1; + height = height || 1; + + var width_half = width / 2; + var height_half = height / 2; + + var gridX = Math.floor( widthSegments ) || 1; + var gridY = Math.floor( heightSegments ) || 1; + + var gridX1 = gridX + 1; + var gridY1 = gridY + 1; + + var segment_width = width / gridX; + var segment_height = height / gridY; + + // buffers + + var indices = []; + var vertices = []; + var normals = []; + var uvs = []; + + // generate vertices, normals and uvs + + for ( var iy = 0; iy < gridY1; iy ++ ) { + + var y = iy * segment_height - height_half; + + for ( var ix = 0; ix < gridX1; ix ++ ) { + + var x = ix * segment_width - width_half; + + vertices.push( x, - y, 0 ); + + normals.push( 0, 0, 1 ); + + uvs.push( ix / gridX ); + uvs.push( 1 - ( iy / gridY ) ); + + } + + } + + // indices + + for ( var iy$1 = 0; iy$1 < gridY; iy$1 ++ ) { + + for ( var ix$1 = 0; ix$1 < gridX; ix$1 ++ ) { + + var a = ix$1 + gridX1 * iy$1; + var b = ix$1 + gridX1 * ( iy$1 + 1 ); + var c = ( ix$1 + 1 ) + gridX1 * ( iy$1 + 1 ); + var d = ( ix$1 + 1 ) + gridX1 * iy$1; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + PlaneBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + PlaneBufferGeometry.prototype.constructor = PlaneBufferGeometry; + + var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif"; + + var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif"; + + var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif"; + + 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"; + + var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif"; + + var begin_vertex = "vec3 transformed = vec3( position );"; + + var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif"; + + 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"; + + 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"; + + 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"; + + var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif"; + + var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif"; + + var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif"; + + var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif"; + + var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif"; + + var color_pars_vertex = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif"; + + var color_vertex = "#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif"; + + 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}"; + + var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_maxMipLevel 8.0\n#define cubeUV_minMipLevel 4.0\n#define cubeUV_maxTileSize 256.0\n#define cubeUV_minTileSize 16.0\nfloat getFace(vec3 direction) {\n vec3 absDirection = abs(direction);\n float face = -1.0;\n if (absDirection.x > absDirection.z) {\n if (absDirection.x > absDirection.y)\n face = direction.x > 0.0 ? 0.0 : 3.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n } else {\n if (absDirection.z > absDirection.y)\n face = direction.z > 0.0 ? 2.0 : 5.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n }\n return face;\n}\nvec2 getUV(vec3 direction, float face) {\n vec2 uv;\n if (face == 0.0) {\n uv = vec2(direction.z, direction.y) / abs(direction.x); } else if (face == 1.0) {\n uv = vec2(-direction.x, -direction.z) / abs(direction.y); } else if (face == 2.0) {\n uv = vec2(-direction.x, direction.y) / abs(direction.z); } else if (face == 3.0) {\n uv = vec2(-direction.z, direction.y) / abs(direction.x); } else if (face == 4.0) {\n uv = vec2(-direction.x, direction.z) / abs(direction.y); } else {\n uv = vec2(direction.x, direction.y) / abs(direction.z); }\n return 0.5 * (uv + 1.0);\n}\nvec3 bilinearCubeUV(sampler2D envMap, vec3 direction, float mipInt) {\n float face = getFace(direction);\n float filterInt = max(cubeUV_minMipLevel - mipInt, 0.0);\n mipInt = max(mipInt, cubeUV_minMipLevel);\n float faceSize = exp2(mipInt);\n float texelSize = 1.0 / (3.0 * cubeUV_maxTileSize);\n vec2 uv = getUV(direction, face) * (faceSize - 1.0);\n vec2 f = fract(uv);\n uv += 0.5 - f;\n if (face > 2.0) {\n uv.y += faceSize;\n face -= 3.0;\n }\n uv.x += face * faceSize;\n if(mipInt < cubeUV_maxMipLevel){\n uv.y += 2.0 * cubeUV_maxTileSize;\n }\n uv.y += filterInt * 2.0 * cubeUV_minTileSize;\n uv.x += 3.0 * max(0.0, cubeUV_maxTileSize - 2.0 * faceSize);\n uv *= texelSize;\n vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.x += texelSize;\n vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.y += texelSize;\n vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.x -= texelSize;\n vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n vec3 tm = mix(tl, tr, f.x);\n vec3 bm = mix(bl, br, f.x);\n return mix(tm, bm, f.y);\n}\n#define r0 1.0\n#define v0 0.339\n#define m0 -2.0\n#define r1 0.8\n#define v1 0.276\n#define m1 -1.0\n#define r4 0.4\n#define v4 0.046\n#define m4 2.0\n#define r5 0.305\n#define v5 0.016\n#define m5 3.0\n#define r6 0.21\n#define v6 0.0038\n#define m6 4.0\nfloat roughnessToMip(float roughness) {\n float mip = 0.0;\n if (roughness >= r1) {\n mip = (r0 - roughness) * (m1 - m0) / (r0 - r1) + m0;\n } else if (roughness >= r4) {\n mip = (r1 - roughness) * (m4 - m1) / (r1 - r4) + m1;\n } else if (roughness >= r5) {\n mip = (r4 - roughness) * (m5 - m4) / (r4 - r5) + m4;\n } else if (roughness >= r6) {\n mip = (r5 - roughness) * (m6 - m5) / (r5 - r6) + m5;\n } else {\n mip = -2.0 * log2(1.16 * roughness); }\n return mip;\n}\nvec4 textureCubeUV(sampler2D envMap, vec3 sampleDir, float roughness) {\n float mip = clamp(roughnessToMip(roughness), m0, cubeUV_maxMipLevel);\n float mipF = fract(mip);\n float mipInt = floor(mip);\n vec3 color0 = bilinearCubeUV(envMap, sampleDir, mipInt);\n if (mipF == 0.0) {\n return vec4(color0, 1.0);\n } else {\n vec3 color1 = bilinearCubeUV(envMap, sampleDir, mipInt + 1.0);\n return vec4(mix(color0, color1, mipF), 1.0);\n }\n}\n#endif"; + + 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"; + + var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif"; + + var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif"; + + var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif"; + + var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif"; + + var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );"; + + 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}"; + + var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\t\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#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\treflectVec = normalize( reflectVec );\n\t\tvec2 sampleUV = equirectUv( reflectVec );\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\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"; + + 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"; + + 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"; + + 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"; + + 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"; + + var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif"; + + var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif"; + + 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"; + + 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"; + + 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}"; + + var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif"; + + var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif"; + + 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"; + + 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"; + + 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 vec3 reflectVec = reflect( -viewDir, normal );\n\t\t reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t vec3 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#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV = equirectUv( reflectVec );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif"; + + var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;"; + + 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)"; + + var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;"; + + 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)"; + + 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"; + + 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}"; + + 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"; + + 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"; + + 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"; + + 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"; + + 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"; + + 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"; + + 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"; + + var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif"; + + var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif"; + + 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"; + + 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"; + + var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif"; + + var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif"; + + 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"; + + 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"; + + 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"; + + 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;"; + + 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"; + + 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"; + + var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif"; + + 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"; + + 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"; + + 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}"; + + var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif"; + + 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;"; + + var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif"; + + 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"; + + var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif"; + + var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif"; + + 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"; + + 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"; + + 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"; + + 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}"; + + 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"; + + 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"; + + 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"; + + 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"; + + 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"; + + var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif"; + + var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif"; + + 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; }"; + + var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif"; + + var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif"; + + var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif"; + + 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"; + + var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif"; + + var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif"; + + 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"; + + var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif"; + + 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"; + + 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 \n\t#include \n}"; + + 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}"; + + var cube_frag = "#include \nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include \n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include \n\t#include \n}"; + + var cube_vert = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n\tgl_Position.z = gl_Position.w;\n}"; + + var depth_frag = "#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include \n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \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}"; + + var depth_vert = "#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvHighPrecisionZW = gl_Position.zw;\n}"; + + var distanceRGBA_frag = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main () {\n\t#include \n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include \n\t#include \n\t#include \n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}"; + + var distanceRGBA_vert = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvWorldPosition = worldPosition.xyz;\n}"; + + var equirect_frag = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include \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 \n\t#include \n}"; + + var equirect_vert = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n}"; + + var linedashed_frag = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + var linedashed_vert = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + var meshbasic_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \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 \n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include \n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + var meshbasic_vert = "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_ENVMAP\n\t#include \n\t#include \n\t#include \n\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + 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 \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \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 \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 \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include \n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + 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 \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + 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 \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + var meshmatcap_vert = "#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n}"; + + var meshtoon_frag = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + var meshtoon_vert = "#define TOON\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n}"; + + var meshphong_frag = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include \n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + var meshphong_vert = "#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + 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 \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#ifdef TRANSMISSION\n\t\tdiffuseColor.a *= saturate( 1. - totalTransmission + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) );\n\t#endif\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + 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 \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n}"; + + 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 \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}"; + + 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 \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}"; + + var points_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + var points_vert = "uniform float size;\nuniform float scale;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \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 \n\t#include \n\t#include \n\t#include \n}"; + + var shadow_frag = "uniform vec3 color;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include \n\t#include \n\t#include \n}"; + + var shadow_vert = "#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}"; + + var sprite_frag = "uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n}"; + + var sprite_vert = "uniform float rotation;\nuniform vec2 center;\n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\t#include \n}"; + + var ShaderChunk = { + alphamap_fragment: alphamap_fragment, + alphamap_pars_fragment: alphamap_pars_fragment, + alphatest_fragment: alphatest_fragment, + aomap_fragment: aomap_fragment, + aomap_pars_fragment: aomap_pars_fragment, + begin_vertex: begin_vertex, + beginnormal_vertex: beginnormal_vertex, + bsdfs: bsdfs, + bumpmap_pars_fragment: bumpmap_pars_fragment, + clipping_planes_fragment: clipping_planes_fragment, + clipping_planes_pars_fragment: clipping_planes_pars_fragment, + clipping_planes_pars_vertex: clipping_planes_pars_vertex, + clipping_planes_vertex: clipping_planes_vertex, + color_fragment: color_fragment, + color_pars_fragment: color_pars_fragment, + color_pars_vertex: color_pars_vertex, + color_vertex: color_vertex, + common: common, + cube_uv_reflection_fragment: cube_uv_reflection_fragment, + defaultnormal_vertex: defaultnormal_vertex, + displacementmap_pars_vertex: displacementmap_pars_vertex, + displacementmap_vertex: displacementmap_vertex, + emissivemap_fragment: emissivemap_fragment, + emissivemap_pars_fragment: emissivemap_pars_fragment, + encodings_fragment: encodings_fragment, + encodings_pars_fragment: encodings_pars_fragment, + envmap_fragment: envmap_fragment, + envmap_common_pars_fragment: envmap_common_pars_fragment, + envmap_pars_fragment: envmap_pars_fragment, + envmap_pars_vertex: envmap_pars_vertex, + envmap_physical_pars_fragment: envmap_physical_pars_fragment, + envmap_vertex: envmap_vertex, + fog_vertex: fog_vertex, + fog_pars_vertex: fog_pars_vertex, + fog_fragment: fog_fragment, + fog_pars_fragment: fog_pars_fragment, + gradientmap_pars_fragment: gradientmap_pars_fragment, + lightmap_fragment: lightmap_fragment, + lightmap_pars_fragment: lightmap_pars_fragment, + lights_lambert_vertex: lights_lambert_vertex, + lights_pars_begin: lights_pars_begin, + lights_toon_fragment: lights_toon_fragment, + lights_toon_pars_fragment: lights_toon_pars_fragment, + lights_phong_fragment: lights_phong_fragment, + lights_phong_pars_fragment: lights_phong_pars_fragment, + lights_physical_fragment: lights_physical_fragment, + lights_physical_pars_fragment: lights_physical_pars_fragment, + lights_fragment_begin: lights_fragment_begin, + lights_fragment_maps: lights_fragment_maps, + lights_fragment_end: lights_fragment_end, + logdepthbuf_fragment: logdepthbuf_fragment, + logdepthbuf_pars_fragment: logdepthbuf_pars_fragment, + logdepthbuf_pars_vertex: logdepthbuf_pars_vertex, + logdepthbuf_vertex: logdepthbuf_vertex, + map_fragment: map_fragment, + map_pars_fragment: map_pars_fragment, + map_particle_fragment: map_particle_fragment, + map_particle_pars_fragment: map_particle_pars_fragment, + metalnessmap_fragment: metalnessmap_fragment, + metalnessmap_pars_fragment: metalnessmap_pars_fragment, + morphnormal_vertex: morphnormal_vertex, + morphtarget_pars_vertex: morphtarget_pars_vertex, + morphtarget_vertex: morphtarget_vertex, + normal_fragment_begin: normal_fragment_begin, + normal_fragment_maps: normal_fragment_maps, + normalmap_pars_fragment: normalmap_pars_fragment, + clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin, + clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps, + clearcoat_pars_fragment: clearcoat_pars_fragment, + packing: packing, + premultiplied_alpha_fragment: premultiplied_alpha_fragment, + project_vertex: project_vertex, + dithering_fragment: dithering_fragment, + dithering_pars_fragment: dithering_pars_fragment, + roughnessmap_fragment: roughnessmap_fragment, + roughnessmap_pars_fragment: roughnessmap_pars_fragment, + shadowmap_pars_fragment: shadowmap_pars_fragment, + shadowmap_pars_vertex: shadowmap_pars_vertex, + shadowmap_vertex: shadowmap_vertex, + shadowmask_pars_fragment: shadowmask_pars_fragment, + skinbase_vertex: skinbase_vertex, + skinning_pars_vertex: skinning_pars_vertex, + skinning_vertex: skinning_vertex, + skinnormal_vertex: skinnormal_vertex, + specularmap_fragment: specularmap_fragment, + specularmap_pars_fragment: specularmap_pars_fragment, + tonemapping_fragment: tonemapping_fragment, + tonemapping_pars_fragment: tonemapping_pars_fragment, + transmissionmap_fragment: transmissionmap_fragment, + transmissionmap_pars_fragment: transmissionmap_pars_fragment, + uv_pars_fragment: uv_pars_fragment, + uv_pars_vertex: uv_pars_vertex, + uv_vertex: uv_vertex, + uv2_pars_fragment: uv2_pars_fragment, + uv2_pars_vertex: uv2_pars_vertex, + uv2_vertex: uv2_vertex, + worldpos_vertex: worldpos_vertex, + + background_frag: background_frag, + background_vert: background_vert, + cube_frag: cube_frag, + cube_vert: cube_vert, + depth_frag: depth_frag, + depth_vert: depth_vert, + distanceRGBA_frag: distanceRGBA_frag, + distanceRGBA_vert: distanceRGBA_vert, + equirect_frag: equirect_frag, + equirect_vert: equirect_vert, + linedashed_frag: linedashed_frag, + linedashed_vert: linedashed_vert, + meshbasic_frag: meshbasic_frag, + meshbasic_vert: meshbasic_vert, + meshlambert_frag: meshlambert_frag, + meshlambert_vert: meshlambert_vert, + meshmatcap_frag: meshmatcap_frag, + meshmatcap_vert: meshmatcap_vert, + meshtoon_frag: meshtoon_frag, + meshtoon_vert: meshtoon_vert, + meshphong_frag: meshphong_frag, + meshphong_vert: meshphong_vert, + meshphysical_frag: meshphysical_frag, + meshphysical_vert: meshphysical_vert, + normal_frag: normal_frag, + normal_vert: normal_vert, + points_frag: points_frag, + points_vert: points_vert, + shadow_frag: shadow_frag, + shadow_vert: shadow_vert, + sprite_frag: sprite_frag, + sprite_vert: sprite_vert + }; + + var ShaderLib = { + + basic: { + + uniforms: mergeUniforms( [ + UniformsLib.common, + UniformsLib.specularmap, + UniformsLib.envmap, + UniformsLib.aomap, + UniformsLib.lightmap, + UniformsLib.fog + ] ), + + vertexShader: ShaderChunk.meshbasic_vert, + fragmentShader: ShaderChunk.meshbasic_frag + + }, + + lambert: { + + uniforms: mergeUniforms( [ + UniformsLib.common, + UniformsLib.specularmap, + UniformsLib.envmap, + UniformsLib.aomap, + UniformsLib.lightmap, + UniformsLib.emissivemap, + UniformsLib.fog, + UniformsLib.lights, + { + emissive: { value: new Color( 0x000000 ) } + } + ] ), + + vertexShader: ShaderChunk.meshlambert_vert, + fragmentShader: ShaderChunk.meshlambert_frag + + }, + + phong: { + + uniforms: mergeUniforms( [ + UniformsLib.common, + UniformsLib.specularmap, + UniformsLib.envmap, + UniformsLib.aomap, + UniformsLib.lightmap, + UniformsLib.emissivemap, + UniformsLib.bumpmap, + UniformsLib.normalmap, + UniformsLib.displacementmap, + UniformsLib.fog, + UniformsLib.lights, + { + emissive: { value: new Color( 0x000000 ) }, + specular: { value: new Color( 0x111111 ) }, + shininess: { value: 30 } + } + ] ), + + vertexShader: ShaderChunk.meshphong_vert, + fragmentShader: ShaderChunk.meshphong_frag + + }, + + standard: { + + 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, + { + emissive: { value: new Color( 0x000000 ) }, + roughness: { value: 1.0 }, + metalness: { value: 0.0 }, + envMapIntensity: { value: 1 } // temporary + } + ] ), + + vertexShader: ShaderChunk.meshphysical_vert, + fragmentShader: ShaderChunk.meshphysical_frag + + }, + + toon: { + + uniforms: mergeUniforms( [ + UniformsLib.common, + UniformsLib.aomap, + UniformsLib.lightmap, + UniformsLib.emissivemap, + UniformsLib.bumpmap, + UniformsLib.normalmap, + UniformsLib.displacementmap, + UniformsLib.gradientmap, + UniformsLib.fog, + UniformsLib.lights, + { + emissive: { value: new Color( 0x000000 ) } + } + ] ), + + vertexShader: ShaderChunk.meshtoon_vert, + fragmentShader: ShaderChunk.meshtoon_frag + + }, + + matcap: { + + uniforms: mergeUniforms( [ + UniformsLib.common, + UniformsLib.bumpmap, + UniformsLib.normalmap, + UniformsLib.displacementmap, + UniformsLib.fog, + { + matcap: { value: null } + } + ] ), + + vertexShader: ShaderChunk.meshmatcap_vert, + fragmentShader: ShaderChunk.meshmatcap_frag + + }, + + points: { + + uniforms: mergeUniforms( [ + UniformsLib.points, + UniformsLib.fog + ] ), + + vertexShader: ShaderChunk.points_vert, + fragmentShader: ShaderChunk.points_frag + + }, + + dashed: { + + uniforms: mergeUniforms( [ + UniformsLib.common, + UniformsLib.fog, + { + scale: { value: 1 }, + dashSize: { value: 1 }, + totalSize: { value: 2 } + } + ] ), + + vertexShader: ShaderChunk.linedashed_vert, + fragmentShader: ShaderChunk.linedashed_frag + + }, + + depth: { + + uniforms: mergeUniforms( [ + UniformsLib.common, + UniformsLib.displacementmap + ] ), + + vertexShader: ShaderChunk.depth_vert, + fragmentShader: ShaderChunk.depth_frag + + }, + + normal: { + + uniforms: mergeUniforms( [ + UniformsLib.common, + UniformsLib.bumpmap, + UniformsLib.normalmap, + UniformsLib.displacementmap, + { + opacity: { value: 1.0 } + } + ] ), + + vertexShader: ShaderChunk.normal_vert, + fragmentShader: ShaderChunk.normal_frag + + }, + + sprite: { + + uniforms: mergeUniforms( [ + UniformsLib.sprite, + UniformsLib.fog + ] ), + + vertexShader: ShaderChunk.sprite_vert, + fragmentShader: ShaderChunk.sprite_frag + + }, + + background: { + + uniforms: { + uvTransform: { value: new Matrix3() }, + t2D: { value: null }, + }, + + vertexShader: ShaderChunk.background_vert, + fragmentShader: ShaderChunk.background_frag + + }, + /* ------------------------------------------------------------------------- + // Cube map shader + ------------------------------------------------------------------------- */ + + cube: { + + uniforms: mergeUniforms( [ + UniformsLib.envmap, + { + opacity: { value: 1.0 } + } + ] ), + + vertexShader: ShaderChunk.cube_vert, + fragmentShader: ShaderChunk.cube_frag + + }, + + equirect: { + + uniforms: { + tEquirect: { value: null }, + }, + + vertexShader: ShaderChunk.equirect_vert, + fragmentShader: ShaderChunk.equirect_frag + + }, + + distanceRGBA: { + + uniforms: mergeUniforms( [ + UniformsLib.common, + UniformsLib.displacementmap, + { + referencePosition: { value: new Vector3() }, + nearDistance: { value: 1 }, + farDistance: { value: 1000 } + } + ] ), + + vertexShader: ShaderChunk.distanceRGBA_vert, + fragmentShader: ShaderChunk.distanceRGBA_frag + + }, + + shadow: { + + uniforms: mergeUniforms( [ + UniformsLib.lights, + UniformsLib.fog, + { + color: { value: new Color( 0x00000 ) }, + opacity: { value: 1.0 } + } ] ), + + vertexShader: ShaderChunk.shadow_vert, + fragmentShader: ShaderChunk.shadow_frag + + } + + }; + + ShaderLib.physical = { + + uniforms: mergeUniforms( [ + ShaderLib.standard.uniforms, + { + clearcoat: { value: 0 }, + clearcoatMap: { value: null }, + clearcoatRoughness: { value: 0 }, + clearcoatRoughnessMap: { value: null }, + clearcoatNormalScale: { value: new Vector2( 1, 1 ) }, + clearcoatNormalMap: { value: null }, + sheen: { value: new Color( 0x000000 ) }, + transmission: { value: 0 }, + transmissionMap: { value: null }, + } + ] ), + + vertexShader: ShaderChunk.meshphysical_vert, + fragmentShader: ShaderChunk.meshphysical_frag + + }; + + function WebGLBackground( renderer, state, objects, premultipliedAlpha ) { + + var clearColor = new Color( 0x000000 ); + var clearAlpha = 0; + + var planeMesh; + var boxMesh; + + var currentBackground = null; + var currentBackgroundVersion = 0; + var currentTonemapping = null; + + function render( renderList, scene, camera, forceClear ) { + + var background = scene.isScene === true ? scene.background : null; + + // Ignore background in AR + // TODO: Reconsider this. + + var xr = renderer.xr; + var session = xr.getSession && xr.getSession(); + + if ( session && session.environmentBlendMode === 'additive' ) { + + background = null; + + } + + if ( background === null ) { + + setClear( clearColor, clearAlpha ); + + } else if ( background && background.isColor ) { + + setClear( background, 1 ); + forceClear = true; + + } + + if ( renderer.autoClear || forceClear ) { + + renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil ); + + } + + if ( background && ( background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping ) ) { + + if ( boxMesh === undefined ) { + + boxMesh = new Mesh( + new BoxBufferGeometry( 1, 1, 1 ), + new ShaderMaterial( { + name: 'BackgroundCubeMaterial', + uniforms: cloneUniforms( ShaderLib.cube.uniforms ), + vertexShader: ShaderLib.cube.vertexShader, + fragmentShader: ShaderLib.cube.fragmentShader, + side: BackSide, + depthTest: false, + depthWrite: false, + fog: false + } ) + ); + + boxMesh.geometry.deleteAttribute( 'normal' ); + boxMesh.geometry.deleteAttribute( 'uv' ); + + boxMesh.onBeforeRender = function ( renderer, scene, camera ) { + + this.matrixWorld.copyPosition( camera.matrixWorld ); + + }; + + // enable code injection for non-built-in material + Object.defineProperty( boxMesh.material, 'envMap', { + + get: function () { + + return this.uniforms.envMap.value; + + } + + } ); + + objects.update( boxMesh ); + + } + + var texture = background.isWebGLCubeRenderTarget ? background.texture : background; + + boxMesh.material.uniforms.envMap.value = texture; + boxMesh.material.uniforms.flipEnvMap.value = texture.isCubeTexture ? - 1 : 1; + + if ( currentBackground !== background || + currentBackgroundVersion !== texture.version || + currentTonemapping !== renderer.toneMapping ) { + + boxMesh.material.needsUpdate = true; + + currentBackground = background; + currentBackgroundVersion = texture.version; + currentTonemapping = renderer.toneMapping; + + } + + // push to the pre-sorted opaque render list + renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null ); + + } else if ( background && background.isTexture ) { + + if ( planeMesh === undefined ) { + + planeMesh = new Mesh( + new PlaneBufferGeometry( 2, 2 ), + new ShaderMaterial( { + name: 'BackgroundMaterial', + uniforms: cloneUniforms( ShaderLib.background.uniforms ), + vertexShader: ShaderLib.background.vertexShader, + fragmentShader: ShaderLib.background.fragmentShader, + side: FrontSide, + depthTest: false, + depthWrite: false, + fog: false + } ) + ); + + planeMesh.geometry.deleteAttribute( 'normal' ); + + // enable code injection for non-built-in material + Object.defineProperty( planeMesh.material, 'map', { + + get: function () { + + return this.uniforms.t2D.value; + + } + + } ); + + objects.update( planeMesh ); + + } + + planeMesh.material.uniforms.t2D.value = background; + + if ( background.matrixAutoUpdate === true ) { + + background.updateMatrix(); + + } + + planeMesh.material.uniforms.uvTransform.value.copy( background.matrix ); + + if ( currentBackground !== background || + currentBackgroundVersion !== background.version || + currentTonemapping !== renderer.toneMapping ) { + + planeMesh.material.needsUpdate = true; + + currentBackground = background; + currentBackgroundVersion = background.version; + currentTonemapping = renderer.toneMapping; + + } + + + // push to the pre-sorted opaque render list + renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null ); + + } + + } + + function setClear( color, alpha ) { + + state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha ); + + } + + return { + + getClearColor: function () { + + return clearColor; + + }, + setClearColor: function ( color, alpha ) { + + clearColor.set( color ); + clearAlpha = alpha !== undefined ? alpha : 1; + setClear( clearColor, clearAlpha ); + + }, + getClearAlpha: function () { + + return clearAlpha; + + }, + setClearAlpha: function ( alpha ) { + + clearAlpha = alpha; + setClear( clearColor, clearAlpha ); + + }, + render: render + + }; + + } + + function WebGLBindingStates( gl, extensions, attributes, capabilities ) { + + var maxVertexAttributes = gl.getParameter( 34921 ); + + var extension = capabilities.isWebGL2 ? null : extensions.get( 'OES_vertex_array_object' ); + var vaoAvailable = capabilities.isWebGL2 || extension !== null; + + var bindingStates = {}; + + var defaultState = createBindingState( null ); + var currentState = defaultState; + + function setup( object, material, program, geometry, index ) { + + var updateBuffers = false; + + if ( vaoAvailable ) { + + var state = getBindingState( geometry, program, material ); + + if ( currentState !== state ) { + + currentState = state; + bindVertexArrayObject( currentState.object ); + + } + + updateBuffers = needsUpdate( geometry ); + + if ( updateBuffers ) { saveCache( geometry ); } + + } else { + + var wireframe = ( material.wireframe === true ); + + if ( currentState.geometry !== geometry.id || + currentState.program !== program.id || + currentState.wireframe !== wireframe ) { + + currentState.geometry = geometry.id; + currentState.program = program.id; + currentState.wireframe = wireframe; + + updateBuffers = true; + + } + + } + + if ( object.isInstancedMesh === true ) { + + updateBuffers = true; + + } + + if ( index !== null ) { + + attributes.update( index, 34963 ); + + } + + if ( updateBuffers ) { + + setupVertexAttributes( object, material, program, geometry ); + + if ( index !== null ) { + + gl.bindBuffer( 34963, attributes.get( index ).buffer ); + + } + + } + + } + + function createVertexArrayObject() { + + if ( capabilities.isWebGL2 ) { return gl.createVertexArray(); } + + return extension.createVertexArrayOES(); + + } + + function bindVertexArrayObject( vao ) { + + if ( capabilities.isWebGL2 ) { return gl.bindVertexArray( vao ); } + + return extension.bindVertexArrayOES( vao ); + + } + + function deleteVertexArrayObject( vao ) { + + if ( capabilities.isWebGL2 ) { return gl.deleteVertexArray( vao ); } + + return extension.deleteVertexArrayOES( vao ); + + } + + function getBindingState( geometry, program, material ) { + + var wireframe = ( material.wireframe === true ); + + var programMap = bindingStates[ geometry.id ]; + + if ( programMap === undefined ) { + + programMap = {}; + bindingStates[ geometry.id ] = programMap; + + } + + var stateMap = programMap[ program.id ]; + + if ( stateMap === undefined ) { + + stateMap = {}; + programMap[ program.id ] = stateMap; + + } + + var state = stateMap[ wireframe ]; + + if ( state === undefined ) { + + state = createBindingState( createVertexArrayObject() ); + stateMap[ wireframe ] = state; + + } + + return state; + + } + + function createBindingState( vao ) { + + var newAttributes = []; + var enabledAttributes = []; + var attributeDivisors = []; + + for ( var i = 0; i < maxVertexAttributes; i ++ ) { + + newAttributes[ i ] = 0; + enabledAttributes[ i ] = 0; + attributeDivisors[ i ] = 0; + + } + + return { + + // for backward compatibility on non-VAO support browser + geometry: null, + program: null, + wireframe: false, + + newAttributes: newAttributes, + enabledAttributes: enabledAttributes, + attributeDivisors: attributeDivisors, + object: vao, + attributes: {} + + }; + + } + + function needsUpdate( geometry ) { + + var cachedAttributes = currentState.attributes; + var geometryAttributes = geometry.attributes; + + if ( Object.keys( cachedAttributes ).length !== Object.keys( geometryAttributes ).length ) { return true; } + + for ( var key in geometryAttributes ) { + + var cachedAttribute = cachedAttributes[ key ]; + var geometryAttribute = geometryAttributes[ key ]; + + if ( cachedAttribute.attribute !== geometryAttribute ) { return true; } + + if ( cachedAttribute.data !== geometryAttribute.data ) { return true; } + + } + + return false; + + } + + function saveCache( geometry ) { + + var cache = {}; + var attributes = geometry.attributes; + + for ( var key in attributes ) { + + var attribute = attributes[ key ]; + + var data = {}; + data.attribute = attribute; + + if ( attribute.data ) { + + data.data = attribute.data; + + } + + cache[ key ] = data; + + } + + currentState.attributes = cache; + + } + + function initAttributes() { + + var newAttributes = currentState.newAttributes; + + for ( var i = 0, il = newAttributes.length; i < il; i ++ ) { + + newAttributes[ i ] = 0; + + } + + } + + function enableAttribute( attribute ) { + + enableAttributeAndDivisor( attribute, 0 ); + + } + + function enableAttributeAndDivisor( attribute, meshPerAttribute ) { + + var newAttributes = currentState.newAttributes; + var enabledAttributes = currentState.enabledAttributes; + var attributeDivisors = currentState.attributeDivisors; + + newAttributes[ attribute ] = 1; + + if ( enabledAttributes[ attribute ] === 0 ) { + + gl.enableVertexAttribArray( attribute ); + enabledAttributes[ attribute ] = 1; + + } + + if ( attributeDivisors[ attribute ] !== meshPerAttribute ) { + + var extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' ); + + extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute ); + attributeDivisors[ attribute ] = meshPerAttribute; + + } + + } + + function disableUnusedAttributes() { + + var newAttributes = currentState.newAttributes; + var enabledAttributes = currentState.enabledAttributes; + + for ( var i = 0, il = enabledAttributes.length; i < il; i ++ ) { + + if ( enabledAttributes[ i ] !== newAttributes[ i ] ) { + + gl.disableVertexAttribArray( i ); + enabledAttributes[ i ] = 0; + + } + + } + + } + + function vertexAttribPointer( index, size, type, normalized, stride, offset ) { + + if ( capabilities.isWebGL2 === true && ( type === 5124 || type === 5125 ) ) { + + gl.vertexAttribIPointer( index, size, type, stride, offset ); + + } else { + + gl.vertexAttribPointer( index, size, type, normalized, stride, offset ); + + } + + } + + function setupVertexAttributes( object, material, program, geometry ) { + + if ( capabilities.isWebGL2 === false && ( object.isInstancedMesh || geometry.isInstancedBufferGeometry ) ) { + + if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) { return; } + + } + + initAttributes(); + + var geometryAttributes = geometry.attributes; + + var programAttributes = program.getAttributes(); + + var materialDefaultAttributeValues = material.defaultAttributeValues; + + for ( var name in programAttributes ) { + + var programAttribute = programAttributes[ name ]; + + if ( programAttribute >= 0 ) { + + var geometryAttribute = geometryAttributes[ name ]; + + if ( geometryAttribute !== undefined ) { + + var normalized = geometryAttribute.normalized; + var size = geometryAttribute.itemSize; + + var attribute = attributes.get( geometryAttribute ); + + // TODO Attribute may not be available on context restore + + if ( attribute === undefined ) { continue; } + + var buffer = attribute.buffer; + var type = attribute.type; + var bytesPerElement = attribute.bytesPerElement; + + if ( geometryAttribute.isInterleavedBufferAttribute ) { + + var data = geometryAttribute.data; + var stride = data.stride; + var offset = geometryAttribute.offset; + + if ( data && data.isInstancedInterleavedBuffer ) { + + enableAttributeAndDivisor( programAttribute, data.meshPerAttribute ); + + if ( geometry._maxInstanceCount === undefined ) { + + geometry._maxInstanceCount = data.meshPerAttribute * data.count; + + } + + } else { + + enableAttribute( programAttribute ); + + } + + gl.bindBuffer( 34962, buffer ); + vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement ); + + } else { + + if ( geometryAttribute.isInstancedBufferAttribute ) { + + enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute ); + + if ( geometry._maxInstanceCount === undefined ) { + + geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count; + + } + + } else { + + enableAttribute( programAttribute ); + + } + + gl.bindBuffer( 34962, buffer ); + vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 ); + + } + + } else if ( name === 'instanceMatrix' ) { + + var attribute$1 = attributes.get( object.instanceMatrix ); + + // TODO Attribute may not be available on context restore + + if ( attribute$1 === undefined ) { continue; } + + var buffer$1 = attribute$1.buffer; + var type$1 = attribute$1.type; + + enableAttributeAndDivisor( programAttribute + 0, 1 ); + enableAttributeAndDivisor( programAttribute + 1, 1 ); + enableAttributeAndDivisor( programAttribute + 2, 1 ); + enableAttributeAndDivisor( programAttribute + 3, 1 ); + + gl.bindBuffer( 34962, buffer$1 ); + + gl.vertexAttribPointer( programAttribute + 0, 4, type$1, false, 64, 0 ); + gl.vertexAttribPointer( programAttribute + 1, 4, type$1, false, 64, 16 ); + gl.vertexAttribPointer( programAttribute + 2, 4, type$1, false, 64, 32 ); + gl.vertexAttribPointer( programAttribute + 3, 4, type$1, false, 64, 48 ); + + } else if ( materialDefaultAttributeValues !== undefined ) { + + var value = materialDefaultAttributeValues[ name ]; + + if ( value !== undefined ) { + + switch ( value.length ) { + + case 2: + gl.vertexAttrib2fv( programAttribute, value ); + break; + + case 3: + gl.vertexAttrib3fv( programAttribute, value ); + break; + + case 4: + gl.vertexAttrib4fv( programAttribute, value ); + break; + + default: + gl.vertexAttrib1fv( programAttribute, value ); + + } + + } + + } + + } + + } + + disableUnusedAttributes(); + + } + + function dispose() { + + reset(); + + for ( var geometryId in bindingStates ) { + + var programMap = bindingStates[ geometryId ]; + + for ( var programId in programMap ) { + + var stateMap = programMap[ programId ]; + + for ( var wireframe in stateMap ) { + + deleteVertexArrayObject( stateMap[ wireframe ].object ); + + delete stateMap[ wireframe ]; + + } + + delete programMap[ programId ]; + + } + + delete bindingStates[ geometryId ]; + + } + + } + + function releaseStatesOfGeometry( geometry ) { + + if ( bindingStates[ geometry.id ] === undefined ) { return; } + + var programMap = bindingStates[ geometry.id ]; + + for ( var programId in programMap ) { + + var stateMap = programMap[ programId ]; + + for ( var wireframe in stateMap ) { + + deleteVertexArrayObject( stateMap[ wireframe ].object ); + + delete stateMap[ wireframe ]; + + } + + delete programMap[ programId ]; + + } + + delete bindingStates[ geometry.id ]; + + } + + function releaseStatesOfProgram( program ) { + + for ( var geometryId in bindingStates ) { + + var programMap = bindingStates[ geometryId ]; + + if ( programMap[ program.id ] === undefined ) { continue; } + + var stateMap = programMap[ program.id ]; + + for ( var wireframe in stateMap ) { + + deleteVertexArrayObject( stateMap[ wireframe ].object ); + + delete stateMap[ wireframe ]; + + } + + delete programMap[ program.id ]; + + } + + } + + function reset() { + + resetDefaultState(); + + if ( currentState === defaultState ) { return; } + + currentState = defaultState; + bindVertexArrayObject( currentState.object ); + + } + + // for backward-compatilibity + + function resetDefaultState() { + + defaultState.geometry = null; + defaultState.program = null; + defaultState.wireframe = false; + + } + + return { + + setup: setup, + reset: reset, + resetDefaultState: resetDefaultState, + dispose: dispose, + releaseStatesOfGeometry: releaseStatesOfGeometry, + releaseStatesOfProgram: releaseStatesOfProgram, + + initAttributes: initAttributes, + enableAttribute: enableAttribute, + disableUnusedAttributes: disableUnusedAttributes + + }; + + } + + function WebGLBufferRenderer( gl, extensions, info, capabilities ) { + + var isWebGL2 = capabilities.isWebGL2; + + var mode; + + function setMode( value ) { + + mode = value; + + } + + function render( start, count ) { + + gl.drawArrays( mode, start, count ); + + info.update( count, mode, 1 ); + + } + + function renderInstances( start, count, primcount ) { + + if ( primcount === 0 ) { return; } + + var extension, methodName; + + if ( isWebGL2 ) { + + extension = gl; + methodName = 'drawArraysInstanced'; + + } else { + + extension = extensions.get( 'ANGLE_instanced_arrays' ); + methodName = 'drawArraysInstancedANGLE'; + + if ( extension === null ) { + + console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' ); + return; + + } + + } + + extension[ methodName ]( mode, start, count, primcount ); + + info.update( count, mode, primcount ); + + } + + // + + this.setMode = setMode; + this.render = render; + this.renderInstances = renderInstances; + + } + + function WebGLCapabilities( gl, extensions, parameters ) { + + var maxAnisotropy; + + function getMaxAnisotropy() { + + if ( maxAnisotropy !== undefined ) { return maxAnisotropy; } + + var extension = extensions.get( 'EXT_texture_filter_anisotropic' ); + + if ( extension !== null ) { + + maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT ); + + } else { + + maxAnisotropy = 0; + + } + + return maxAnisotropy; + + } + + function getMaxPrecision( precision ) { + + if ( precision === 'highp' ) { + + if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 && + gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) { + + return 'highp'; + + } + + precision = 'mediump'; + + } + + if ( precision === 'mediump' ) { + + if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 && + gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) { + + return 'mediump'; + + } + + } + + return 'lowp'; + + } + + /* eslint-disable no-undef */ + var isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) || + ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext ); + /* eslint-enable no-undef */ + + var precision = parameters.precision !== undefined ? parameters.precision : 'highp'; + var maxPrecision = getMaxPrecision( precision ); + + if ( maxPrecision !== precision ) { + + console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' ); + precision = maxPrecision; + + } + + var logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true; + + var maxTextures = gl.getParameter( 34930 ); + var maxVertexTextures = gl.getParameter( 35660 ); + var maxTextureSize = gl.getParameter( 3379 ); + var maxCubemapSize = gl.getParameter( 34076 ); + + var maxAttributes = gl.getParameter( 34921 ); + var maxVertexUniforms = gl.getParameter( 36347 ); + var maxVaryings = gl.getParameter( 36348 ); + var maxFragmentUniforms = gl.getParameter( 36349 ); + + var vertexTextures = maxVertexTextures > 0; + var floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' ); + var floatVertexTextures = vertexTextures && floatFragmentTextures; + + var maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0; + + return { + + isWebGL2: isWebGL2, + + getMaxAnisotropy: getMaxAnisotropy, + getMaxPrecision: getMaxPrecision, + + precision: precision, + logarithmicDepthBuffer: logarithmicDepthBuffer, + + maxTextures: maxTextures, + maxVertexTextures: maxVertexTextures, + maxTextureSize: maxTextureSize, + maxCubemapSize: maxCubemapSize, + + maxAttributes: maxAttributes, + maxVertexUniforms: maxVertexUniforms, + maxVaryings: maxVaryings, + maxFragmentUniforms: maxFragmentUniforms, + + vertexTextures: vertexTextures, + floatFragmentTextures: floatFragmentTextures, + floatVertexTextures: floatVertexTextures, + + maxSamples: maxSamples + + }; + + } + + function WebGLClipping() { + + var scope = this; + + var globalState = null, + numGlobalPlanes = 0, + localClippingEnabled = false, + renderingShadows = false; + + var plane = new Plane(), + viewNormalMatrix = new Matrix3(), + + uniform = { value: null, needsUpdate: false }; + + this.uniform = uniform; + this.numPlanes = 0; + this.numIntersection = 0; + + this.init = function ( planes, enableLocalClipping, camera ) { + + var enabled = + planes.length !== 0 || + enableLocalClipping || + // enable state of previous frame - the clipping code has to + // run another frame in order to reset the state: + numGlobalPlanes !== 0 || + localClippingEnabled; + + localClippingEnabled = enableLocalClipping; + + globalState = projectPlanes( planes, camera, 0 ); + numGlobalPlanes = planes.length; + + return enabled; + + }; + + this.beginShadows = function () { + + renderingShadows = true; + projectPlanes( null ); + + }; + + this.endShadows = function () { + + renderingShadows = false; + resetGlobalState(); + + }; + + this.setState = function ( planes, clipIntersection, clipShadows, camera, cache, fromCache ) { + + if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) { + + // there's no local clipping + + if ( renderingShadows ) { + + // there's no global clipping + + projectPlanes( null ); + + } else { + + resetGlobalState(); + + } + + } else { + + var nGlobal = renderingShadows ? 0 : numGlobalPlanes, + lGlobal = nGlobal * 4; + + var dstArray = cache.clippingState || null; + + uniform.value = dstArray; // ensure unique state + + dstArray = projectPlanes( planes, camera, lGlobal, fromCache ); + + for ( var i = 0; i !== lGlobal; ++ i ) { + + dstArray[ i ] = globalState[ i ]; + + } + + cache.clippingState = dstArray; + this.numIntersection = clipIntersection ? this.numPlanes : 0; + this.numPlanes += nGlobal; + + } + + + }; + + function resetGlobalState() { + + if ( uniform.value !== globalState ) { + + uniform.value = globalState; + uniform.needsUpdate = numGlobalPlanes > 0; + + } + + scope.numPlanes = numGlobalPlanes; + scope.numIntersection = 0; + + } + + function projectPlanes( planes, camera, dstOffset, skipTransform ) { + + var nPlanes = planes !== null ? planes.length : 0, + dstArray = null; + + if ( nPlanes !== 0 ) { + + dstArray = uniform.value; + + if ( skipTransform !== true || dstArray === null ) { + + var flatSize = dstOffset + nPlanes * 4, + viewMatrix = camera.matrixWorldInverse; + + viewNormalMatrix.getNormalMatrix( viewMatrix ); + + if ( dstArray === null || dstArray.length < flatSize ) { + + dstArray = new Float32Array( flatSize ); + + } + + for ( var i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) { + + plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix ); + + plane.normal.toArray( dstArray, i4 ); + dstArray[ i4 + 3 ] = plane.constant; + + } + + } + + uniform.value = dstArray; + uniform.needsUpdate = true; + + } + + scope.numPlanes = nPlanes; + scope.numIntersection = 0; + + return dstArray; + + } + + } + + function WebGLExtensions( gl ) { + + var extensions = {}; + + return { + + has: function ( name ) { + + if ( extensions[ name ] !== undefined ) { + + return extensions[ name ]; + + } + + var extension; + + switch ( name ) { + + case 'WEBGL_depth_texture': + extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' ); + break; + + case 'EXT_texture_filter_anisotropic': + extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' ); + break; + + case 'WEBGL_compressed_texture_s3tc': + extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' ); + break; + + case 'WEBGL_compressed_texture_pvrtc': + extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' ); + break; + + default: + extension = gl.getExtension( name ); + + } + + extensions[ name ] = extension; + + return !! extension; + + }, + + get: function ( name ) { + + if ( ! this.has( name ) ) { + + console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' ); + + } + + return extensions[ name ]; + + } + + }; + + } + + function WebGLGeometries( gl, attributes, info, bindingStates ) { + + var geometries = new WeakMap(); + var wireframeAttributes = new WeakMap(); + + function onGeometryDispose( event ) { + + var geometry = event.target; + var buffergeometry = geometries.get( geometry ); + + if ( buffergeometry.index !== null ) { + + attributes.remove( buffergeometry.index ); + + } + + for ( var name in buffergeometry.attributes ) { + + attributes.remove( buffergeometry.attributes[ name ] ); + + } + + geometry.removeEventListener( 'dispose', onGeometryDispose ); + + geometries.delete( geometry ); + + var attribute = wireframeAttributes.get( buffergeometry ); + + if ( attribute ) { + + attributes.remove( attribute ); + wireframeAttributes.delete( buffergeometry ); + + } + + bindingStates.releaseStatesOfGeometry( geometry ); + + if ( geometry.isInstancedBufferGeometry === true ) { + + delete geometry._maxInstanceCount; + + } + + // + + info.memory.geometries --; + + } + + function get( object, geometry ) { + + var buffergeometry = geometries.get( geometry ); + + if ( buffergeometry ) { return buffergeometry; } + + geometry.addEventListener( 'dispose', onGeometryDispose ); + + if ( geometry.isBufferGeometry ) { + + buffergeometry = geometry; + + } else if ( geometry.isGeometry ) { + + if ( geometry._bufferGeometry === undefined ) { + + geometry._bufferGeometry = new BufferGeometry().setFromObject( object ); + + } + + buffergeometry = geometry._bufferGeometry; + + } + + geometries.set( geometry, buffergeometry ); + + info.memory.geometries ++; + + return buffergeometry; + + } + + function update( geometry ) { + + var geometryAttributes = geometry.attributes; + + // Updating index buffer in VAO now. See WebGLBindingStates. + + for ( var name in geometryAttributes ) { + + attributes.update( geometryAttributes[ name ], 34962 ); + + } + + // morph targets + + var morphAttributes = geometry.morphAttributes; + + for ( var name$1 in morphAttributes ) { + + var array = morphAttributes[ name$1 ]; + + for ( var i = 0, l = array.length; i < l; i ++ ) { + + attributes.update( array[ i ], 34962 ); + + } + + } + + } + + function updateWireframeAttribute( geometry ) { + + var indices = []; + + var geometryIndex = geometry.index; + var geometryPosition = geometry.attributes.position; + var version = 0; + + if ( geometryIndex !== null ) { + + var array = geometryIndex.array; + version = geometryIndex.version; + + for ( var i = 0, l = array.length; i < l; i += 3 ) { + + var a = array[ i + 0 ]; + var b = array[ i + 1 ]; + var c = array[ i + 2 ]; + + indices.push( a, b, b, c, c, a ); + + } + + } else { + + var array$1 = geometryPosition.array; + version = geometryPosition.version; + + for ( var i$1 = 0, l$1 = ( array$1.length / 3 ) - 1; i$1 < l$1; i$1 += 3 ) { + + var a$1 = i$1 + 0; + var b$1 = i$1 + 1; + var c$1 = i$1 + 2; + + indices.push( a$1, b$1, b$1, c$1, c$1, a$1 ); + + } + + } + + var attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 ); + attribute.version = version; + + // Updating index buffer in VAO now. See WebGLBindingStates + + // + + var previousAttribute = wireframeAttributes.get( geometry ); + + if ( previousAttribute ) { attributes.remove( previousAttribute ); } + + // + + wireframeAttributes.set( geometry, attribute ); + + } + + function getWireframeAttribute( geometry ) { + + var currentAttribute = wireframeAttributes.get( geometry ); + + if ( currentAttribute ) { + + var geometryIndex = geometry.index; + + if ( geometryIndex !== null ) { + + // if the attribute is obsolete, create a new one + + if ( currentAttribute.version < geometryIndex.version ) { + + updateWireframeAttribute( geometry ); + + } + + } + + } else { + + updateWireframeAttribute( geometry ); + + } + + return wireframeAttributes.get( geometry ); + + } + + return { + + get: get, + update: update, + + getWireframeAttribute: getWireframeAttribute + + }; + + } + + function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) { + + var isWebGL2 = capabilities.isWebGL2; + + var mode; + + function setMode( value ) { + + mode = value; + + } + + var type, bytesPerElement; + + function setIndex( value ) { + + type = value.type; + bytesPerElement = value.bytesPerElement; + + } + + function render( start, count ) { + + gl.drawElements( mode, count, type, start * bytesPerElement ); + + info.update( count, mode, 1 ); + + } + + function renderInstances( start, count, primcount ) { + + if ( primcount === 0 ) { return; } + + var extension, methodName; + + if ( isWebGL2 ) { + + extension = gl; + methodName = 'drawElementsInstanced'; + + } else { + + extension = extensions.get( 'ANGLE_instanced_arrays' ); + methodName = 'drawElementsInstancedANGLE'; + + if ( extension === null ) { + + console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' ); + return; + + } + + } + + extension[ methodName ]( mode, count, type, start * bytesPerElement, primcount ); + + info.update( count, mode, primcount ); + + } + + // + + this.setMode = setMode; + this.setIndex = setIndex; + this.render = render; + this.renderInstances = renderInstances; + + } + + function WebGLInfo( gl ) { + + var memory = { + geometries: 0, + textures: 0 + }; + + var render = { + frame: 0, + calls: 0, + triangles: 0, + points: 0, + lines: 0 + }; + + function update( count, mode, instanceCount ) { + + render.calls ++; + + switch ( mode ) { + + case 4: + render.triangles += instanceCount * ( count / 3 ); + break; + + case 1: + render.lines += instanceCount * ( count / 2 ); + break; + + case 3: + render.lines += instanceCount * ( count - 1 ); + break; + + case 2: + render.lines += instanceCount * count; + break; + + case 0: + render.points += instanceCount * count; + break; + + default: + console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode ); + break; + + } + + } + + function reset() { + + render.frame ++; + render.calls = 0; + render.triangles = 0; + render.points = 0; + render.lines = 0; + + } + + return { + memory: memory, + render: render, + programs: null, + autoReset: true, + reset: reset, + update: update + }; + + } + + function numericalSort( a, b ) { + + return a[ 0 ] - b[ 0 ]; + + } + + function absNumericalSort( a, b ) { + + return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] ); + + } + + function WebGLMorphtargets( gl ) { + + var influencesList = {}; + var morphInfluences = new Float32Array( 8 ); + + var workInfluences = []; + + for ( var i = 0; i < 8; i ++ ) { + + workInfluences[ i ] = [ i, 0 ]; + + } + + function update( object, geometry, material, program ) { + + var objectInfluences = object.morphTargetInfluences; + + // When object doesn't have morph target influences defined, we treat it as a 0-length array + // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences + + var length = objectInfluences === undefined ? 0 : objectInfluences.length; + + var influences = influencesList[ geometry.id ]; + + if ( influences === undefined ) { + + // initialise list + + influences = []; + + for ( var i = 0; i < length; i ++ ) { + + influences[ i ] = [ i, 0 ]; + + } + + influencesList[ geometry.id ] = influences; + + } + + // Collect influences + + for ( var i$1 = 0; i$1 < length; i$1 ++ ) { + + var influence = influences[ i$1 ]; + + influence[ 0 ] = i$1; + influence[ 1 ] = objectInfluences[ i$1 ]; + + } + + influences.sort( absNumericalSort ); + + for ( var i$2 = 0; i$2 < 8; i$2 ++ ) { + + if ( i$2 < length && influences[ i$2 ][ 1 ] ) { + + workInfluences[ i$2 ][ 0 ] = influences[ i$2 ][ 0 ]; + workInfluences[ i$2 ][ 1 ] = influences[ i$2 ][ 1 ]; + + } else { + + workInfluences[ i$2 ][ 0 ] = Number.MAX_SAFE_INTEGER; + workInfluences[ i$2 ][ 1 ] = 0; + + } + + } + + workInfluences.sort( numericalSort ); + + var morphTargets = material.morphTargets && geometry.morphAttributes.position; + var morphNormals = material.morphNormals && geometry.morphAttributes.normal; + + var morphInfluencesSum = 0; + + for ( var i$3 = 0; i$3 < 8; i$3 ++ ) { + + var influence$1 = workInfluences[ i$3 ]; + var index = influence$1[ 0 ]; + var value = influence$1[ 1 ]; + + if ( index !== Number.MAX_SAFE_INTEGER && value ) { + + if ( morphTargets && geometry.getAttribute( 'morphTarget' + i$3 ) !== morphTargets[ index ] ) { + + geometry.setAttribute( 'morphTarget' + i$3, morphTargets[ index ] ); + + } + + if ( morphNormals && geometry.getAttribute( 'morphNormal' + i$3 ) !== morphNormals[ index ] ) { + + geometry.setAttribute( 'morphNormal' + i$3, morphNormals[ index ] ); + + } + + morphInfluences[ i$3 ] = value; + morphInfluencesSum += value; + + } else { + + if ( morphTargets && geometry.getAttribute( 'morphTarget' + i$3 ) !== undefined ) { + + geometry.deleteAttribute( 'morphTarget' + i$3 ); + + } + + if ( morphNormals && geometry.getAttribute( 'morphNormal' + i$3 ) !== undefined ) { + + geometry.deleteAttribute( 'morphNormal' + i$3 ); + + } + + morphInfluences[ i$3 ] = 0; + + } + + } + + // GLSL shader uses formula baseinfluence * base + sum(target * influence) + // This allows us to switch between absolute morphs and relative morphs without changing shader code + // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence) + var morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum; + + program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence ); + program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences ); + + } + + return { + + update: update + + }; + + } + + function WebGLObjects( gl, geometries, attributes, info ) { + + var updateMap = new WeakMap(); + + function update( object ) { + + var frame = info.render.frame; + + var geometry = object.geometry; + var buffergeometry = geometries.get( object, geometry ); + + // Update once per frame + + if ( updateMap.get( buffergeometry ) !== frame ) { + + if ( geometry.isGeometry ) { + + buffergeometry.updateFromObject( object ); + + } + + geometries.update( buffergeometry ); + + updateMap.set( buffergeometry, frame ); + + } + + if ( object.isInstancedMesh ) { + + attributes.update( object.instanceMatrix, 34962 ); + + } + + return buffergeometry; + + } + + function dispose() { + + updateMap = new WeakMap(); + + } + + return { + + update: update, + dispose: dispose + + }; + + } + + function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) { + + images = images !== undefined ? images : []; + mapping = mapping !== undefined ? mapping : CubeReflectionMapping; + format = format !== undefined ? format : RGBFormat; + + Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ); + + this.flipY = false; + + } + + CubeTexture.prototype = Object.create( Texture.prototype ); + CubeTexture.prototype.constructor = CubeTexture; + + CubeTexture.prototype.isCubeTexture = true; + + Object.defineProperty( CubeTexture.prototype, 'images', { + + get: function () { + + return this.image; + + }, + + set: function ( value ) { + + this.image = value; + + } + + } ); + + function DataTexture2DArray( data, width, height, depth ) { + + Texture.call( this, null ); + + this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 }; + + this.magFilter = NearestFilter; + this.minFilter = NearestFilter; + + this.wrapR = ClampToEdgeWrapping; + + this.generateMipmaps = false; + this.flipY = false; + + this.needsUpdate = true; + + } + + DataTexture2DArray.prototype = Object.create( Texture.prototype ); + DataTexture2DArray.prototype.constructor = DataTexture2DArray; + DataTexture2DArray.prototype.isDataTexture2DArray = true; + + function DataTexture3D( data, width, height, depth ) { + + // We're going to add .setXXX() methods for setting properties later. + // Users can still set in DataTexture3D directly. + // + // const texture = new THREE.DataTexture3D( data, width, height, depth ); + // texture.anisotropy = 16; + // + // See #14839 + + Texture.call( this, null ); + + this.image = { data: data || null, width: width || 1, height: height || 1, depth: depth || 1 }; + + this.magFilter = NearestFilter; + this.minFilter = NearestFilter; + + this.wrapR = ClampToEdgeWrapping; + + this.generateMipmaps = false; + this.flipY = false; + + this.needsUpdate = true; + + + } + + DataTexture3D.prototype = Object.create( Texture.prototype ); + DataTexture3D.prototype.constructor = DataTexture3D; + DataTexture3D.prototype.isDataTexture3D = true; + + /** + * Uniforms of a program. + * Those form a tree structure with a special top-level container for the root, + * which you get by calling 'new WebGLUniforms( gl, program )'. + * + * + * Properties of inner nodes including the top-level container: + * + * .seq - array of nested uniforms + * .map - nested uniforms by name + * + * + * Methods of all nodes except the top-level container: + * + * .setValue( gl, value, [textures] ) + * + * uploads a uniform value(s) + * the 'textures' parameter is needed for sampler uniforms + * + * + * Static methods of the top-level container (textures factorizations): + * + * .upload( gl, seq, values, textures ) + * + * sets uniforms in 'seq' to 'values[id].value' + * + * .seqWithValue( seq, values ) : filteredSeq + * + * filters 'seq' entries with corresponding entry in values + * + * + * Methods of the top-level container (textures factorizations): + * + * .setValue( gl, name, value, textures ) + * + * sets uniform with name 'name' to 'value' + * + * .setOptional( gl, obj, prop ) + * + * like .set for an optional property of the object + * + */ + + var emptyTexture = new Texture(); + var emptyTexture2dArray = new DataTexture2DArray(); + var emptyTexture3d = new DataTexture3D(); + var emptyCubeTexture = new CubeTexture(); + + // --- Utilities --- + + // Array Caches (provide typed arrays for temporary by size) + + var arrayCacheF32 = []; + var arrayCacheI32 = []; + + // Float32Array caches used for uploading Matrix uniforms + + var mat4array = new Float32Array( 16 ); + var mat3array = new Float32Array( 9 ); + var mat2array = new Float32Array( 4 ); + + // Flattening for arrays of vectors and matrices + + function flatten( array, nBlocks, blockSize ) { + + var firstElem = array[ 0 ]; + + if ( firstElem <= 0 || firstElem > 0 ) { return array; } + // unoptimized: ! isNaN( firstElem ) + // see http://jacksondunstan.com/articles/983 + + var n = nBlocks * blockSize, + r = arrayCacheF32[ n ]; + + if ( r === undefined ) { + + r = new Float32Array( n ); + arrayCacheF32[ n ] = r; + + } + + if ( nBlocks !== 0 ) { + + firstElem.toArray( r, 0 ); + + for ( var i = 1, offset = 0; i !== nBlocks; ++ i ) { + + offset += blockSize; + array[ i ].toArray( r, offset ); + + } + + } + + return r; + + } + + function arraysEqual( a, b ) { + + if ( a.length !== b.length ) { return false; } + + for ( var i = 0, l = a.length; i < l; i ++ ) { + + if ( a[ i ] !== b[ i ] ) { return false; } + + } + + return true; + + } + + function copyArray( a, b ) { + + for ( var i = 0, l = b.length; i < l; i ++ ) { + + a[ i ] = b[ i ]; + + } + + } + + // Texture unit allocation + + function allocTexUnits( textures, n ) { + + var r = arrayCacheI32[ n ]; + + if ( r === undefined ) { + + r = new Int32Array( n ); + arrayCacheI32[ n ] = r; + + } + + for ( var i = 0; i !== n; ++ i ) { + + r[ i ] = textures.allocateTextureUnit(); + + } + + return r; + + } + + // --- Setters --- + + // Note: Defining these methods externally, because they come in a bunch + // and this way their names minify. + + // Single scalar + + function setValueV1f( gl, v ) { + + var cache = this.cache; + + if ( cache[ 0 ] === v ) { return; } + + gl.uniform1f( this.addr, v ); + + cache[ 0 ] = v; + + } + + // Single float vector (from flat array or THREE.VectorN) + + function setValueV2f( gl, v ) { + + var cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) { + + gl.uniform2f( this.addr, v.x, v.y ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + + } + + } else { + + if ( arraysEqual( cache, v ) ) { return; } + + gl.uniform2fv( this.addr, v ); + + copyArray( cache, v ); + + } + + } + + function setValueV3f( gl, v ) { + + var cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) { + + gl.uniform3f( this.addr, v.x, v.y, v.z ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + cache[ 2 ] = v.z; + + } + + } else if ( v.r !== undefined ) { + + if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) { + + gl.uniform3f( this.addr, v.r, v.g, v.b ); + + cache[ 0 ] = v.r; + cache[ 1 ] = v.g; + cache[ 2 ] = v.b; + + } + + } else { + + if ( arraysEqual( cache, v ) ) { return; } + + gl.uniform3fv( this.addr, v ); + + copyArray( cache, v ); + + } + + } + + function setValueV4f( gl, v ) { + + var cache = this.cache; + + if ( v.x !== undefined ) { + + if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) { + + gl.uniform4f( this.addr, v.x, v.y, v.z, v.w ); + + cache[ 0 ] = v.x; + cache[ 1 ] = v.y; + cache[ 2 ] = v.z; + cache[ 3 ] = v.w; + + } + + } else { + + if ( arraysEqual( cache, v ) ) { return; } + + gl.uniform4fv( this.addr, v ); + + copyArray( cache, v ); + + } + + } + + // Single matrix (from flat array or MatrixN) + + function setValueM2( gl, v ) { + + var cache = this.cache; + var elements = v.elements; + + if ( elements === undefined ) { + + if ( arraysEqual( cache, v ) ) { return; } + + gl.uniformMatrix2fv( this.addr, false, v ); + + copyArray( cache, v ); + + } else { + + if ( arraysEqual( cache, elements ) ) { return; } + + mat2array.set( elements ); + + gl.uniformMatrix2fv( this.addr, false, mat2array ); + + copyArray( cache, elements ); + + } + + } + + function setValueM3( gl, v ) { + + var cache = this.cache; + var elements = v.elements; + + if ( elements === undefined ) { + + if ( arraysEqual( cache, v ) ) { return; } + + gl.uniformMatrix3fv( this.addr, false, v ); + + copyArray( cache, v ); + + } else { + + if ( arraysEqual( cache, elements ) ) { return; } + + mat3array.set( elements ); + + gl.uniformMatrix3fv( this.addr, false, mat3array ); + + copyArray( cache, elements ); + + } + + } + + function setValueM4( gl, v ) { + + var cache = this.cache; + var elements = v.elements; + + if ( elements === undefined ) { + + if ( arraysEqual( cache, v ) ) { return; } + + gl.uniformMatrix4fv( this.addr, false, v ); + + copyArray( cache, v ); + + } else { + + if ( arraysEqual( cache, elements ) ) { return; } + + mat4array.set( elements ); + + gl.uniformMatrix4fv( this.addr, false, mat4array ); + + copyArray( cache, elements ); + + } + + } + + // Single texture (2D / Cube) + + function setValueT1( gl, v, textures ) { + + var cache = this.cache; + var unit = textures.allocateTextureUnit(); + + if ( cache[ 0 ] !== unit ) { + + gl.uniform1i( this.addr, unit ); + cache[ 0 ] = unit; + + } + + textures.safeSetTexture2D( v || emptyTexture, unit ); + + } + + function setValueT2DArray1( gl, v, textures ) { + + var cache = this.cache; + var unit = textures.allocateTextureUnit(); + + if ( cache[ 0 ] !== unit ) { + + gl.uniform1i( this.addr, unit ); + cache[ 0 ] = unit; + + } + + textures.setTexture2DArray( v || emptyTexture2dArray, unit ); + + } + + function setValueT3D1( gl, v, textures ) { + + var cache = this.cache; + var unit = textures.allocateTextureUnit(); + + if ( cache[ 0 ] !== unit ) { + + gl.uniform1i( this.addr, unit ); + cache[ 0 ] = unit; + + } + + textures.setTexture3D( v || emptyTexture3d, unit ); + + } + + function setValueT6( gl, v, textures ) { + + var cache = this.cache; + var unit = textures.allocateTextureUnit(); + + if ( cache[ 0 ] !== unit ) { + + gl.uniform1i( this.addr, unit ); + cache[ 0 ] = unit; + + } + + textures.safeSetTextureCube( v || emptyCubeTexture, unit ); + + } + + // Integer / Boolean vectors or arrays thereof (always flat arrays) + + function setValueV1i( gl, v ) { + + var cache = this.cache; + + if ( cache[ 0 ] === v ) { return; } + + gl.uniform1i( this.addr, v ); + + cache[ 0 ] = v; + + } + + function setValueV2i( gl, v ) { + + var cache = this.cache; + + if ( arraysEqual( cache, v ) ) { return; } + + gl.uniform2iv( this.addr, v ); + + copyArray( cache, v ); + + } + + function setValueV3i( gl, v ) { + + var cache = this.cache; + + if ( arraysEqual( cache, v ) ) { return; } + + gl.uniform3iv( this.addr, v ); + + copyArray( cache, v ); + + } + + function setValueV4i( gl, v ) { + + var cache = this.cache; + + if ( arraysEqual( cache, v ) ) { return; } + + gl.uniform4iv( this.addr, v ); + + copyArray( cache, v ); + + } + + // uint + + function setValueV1ui( gl, v ) { + + var cache = this.cache; + + if ( cache[ 0 ] === v ) { return; } + + gl.uniform1ui( this.addr, v ); + + cache[ 0 ] = v; + + } + + // Helper to pick the right setter for the singular case + + function getSingularSetter( type ) { + + switch ( type ) { + + case 0x1406: return setValueV1f; // FLOAT + case 0x8b50: return setValueV2f; // _VEC2 + case 0x8b51: return setValueV3f; // _VEC3 + case 0x8b52: return setValueV4f; // _VEC4 + + case 0x8b5a: return setValueM2; // _MAT2 + case 0x8b5b: return setValueM3; // _MAT3 + case 0x8b5c: return setValueM4; // _MAT4 + + case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL + case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2 + case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3 + case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4 + + case 0x1405: return setValueV1ui; // UINT + + case 0x8b5e: // SAMPLER_2D + case 0x8d66: // SAMPLER_EXTERNAL_OES + case 0x8dca: // INT_SAMPLER_2D + case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D + case 0x8b62: // SAMPLER_2D_SHADOW + return setValueT1; + + case 0x8b5f: // SAMPLER_3D + case 0x8dcb: // INT_SAMPLER_3D + case 0x8dd3: // UNSIGNED_INT_SAMPLER_3D + return setValueT3D1; + + case 0x8b60: // SAMPLER_CUBE + case 0x8dcc: // INT_SAMPLER_CUBE + case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE + case 0x8dc5: // SAMPLER_CUBE_SHADOW + return setValueT6; + + case 0x8dc1: // SAMPLER_2D_ARRAY + case 0x8dcf: // INT_SAMPLER_2D_ARRAY + case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY + case 0x8dc4: // SAMPLER_2D_ARRAY_SHADOW + return setValueT2DArray1; + + } + + } + + // Array of scalars + function setValueV1fArray( gl, v ) { + + gl.uniform1fv( this.addr, v ); + + } + + // Integer / Boolean vectors or arrays thereof (always flat arrays) + function setValueV1iArray( gl, v ) { + + gl.uniform1iv( this.addr, v ); + + } + + function setValueV2iArray( gl, v ) { + + gl.uniform2iv( this.addr, v ); + + } + + function setValueV3iArray( gl, v ) { + + gl.uniform3iv( this.addr, v ); + + } + + function setValueV4iArray( gl, v ) { + + gl.uniform4iv( this.addr, v ); + + } + + + // Array of vectors (flat or from THREE classes) + + function setValueV2fArray( gl, v ) { + + var data = flatten( v, this.size, 2 ); + + gl.uniform2fv( this.addr, data ); + + } + + function setValueV3fArray( gl, v ) { + + var data = flatten( v, this.size, 3 ); + + gl.uniform3fv( this.addr, data ); + + } + + function setValueV4fArray( gl, v ) { + + var data = flatten( v, this.size, 4 ); + + gl.uniform4fv( this.addr, data ); + + } + + // Array of matrices (flat or from THREE clases) + + function setValueM2Array( gl, v ) { + + var data = flatten( v, this.size, 4 ); + + gl.uniformMatrix2fv( this.addr, false, data ); + + } + + function setValueM3Array( gl, v ) { + + var data = flatten( v, this.size, 9 ); + + gl.uniformMatrix3fv( this.addr, false, data ); + + } + + function setValueM4Array( gl, v ) { + + var data = flatten( v, this.size, 16 ); + + gl.uniformMatrix4fv( this.addr, false, data ); + + } + + // Array of textures (2D / Cube) + + function setValueT1Array( gl, v, textures ) { + + var n = v.length; + + var units = allocTexUnits( textures, n ); + + gl.uniform1iv( this.addr, units ); + + for ( var i = 0; i !== n; ++ i ) { + + textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] ); + + } + + } + + function setValueT6Array( gl, v, textures ) { + + var n = v.length; + + var units = allocTexUnits( textures, n ); + + gl.uniform1iv( this.addr, units ); + + for ( var i = 0; i !== n; ++ i ) { + + textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] ); + + } + + } + + // Helper to pick the right setter for a pure (bottom-level) array + + function getPureArraySetter( type ) { + + switch ( type ) { + + case 0x1406: return setValueV1fArray; // FLOAT + case 0x8b50: return setValueV2fArray; // _VEC2 + case 0x8b51: return setValueV3fArray; // _VEC3 + case 0x8b52: return setValueV4fArray; // _VEC4 + + case 0x8b5a: return setValueM2Array; // _MAT2 + case 0x8b5b: return setValueM3Array; // _MAT3 + case 0x8b5c: return setValueM4Array; // _MAT4 + + case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL + case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2 + case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3 + case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4 + + case 0x8b5e: // SAMPLER_2D + case 0x8d66: // SAMPLER_EXTERNAL_OES + case 0x8dca: // INT_SAMPLER_2D + case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D + case 0x8b62: // SAMPLER_2D_SHADOW + return setValueT1Array; + + case 0x8b60: // SAMPLER_CUBE + case 0x8dcc: // INT_SAMPLER_CUBE + case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE + case 0x8dc5: // SAMPLER_CUBE_SHADOW + return setValueT6Array; + + } + + } + + // --- Uniform Classes --- + + function SingleUniform( id, activeInfo, addr ) { + + this.id = id; + this.addr = addr; + this.cache = []; + this.setValue = getSingularSetter( activeInfo.type ); + + // this.path = activeInfo.name; // DEBUG + + } + + function PureArrayUniform( id, activeInfo, addr ) { + + this.id = id; + this.addr = addr; + this.cache = []; + this.size = activeInfo.size; + this.setValue = getPureArraySetter( activeInfo.type ); + + // this.path = activeInfo.name; // DEBUG + + } + + PureArrayUniform.prototype.updateCache = function ( data ) { + + var cache = this.cache; + + if ( data instanceof Float32Array && cache.length !== data.length ) { + + this.cache = new Float32Array( data.length ); + + } + + copyArray( cache, data ); + + }; + + function StructuredUniform( id ) { + + this.id = id; + + this.seq = []; + this.map = {}; + + } + + StructuredUniform.prototype.setValue = function ( gl, value, textures ) { + + var seq = this.seq; + + for ( var i = 0, n = seq.length; i !== n; ++ i ) { + + var u = seq[ i ]; + u.setValue( gl, value[ u.id ], textures ); + + } + + }; + + // --- Top-level --- + + // Parser - builds up the property tree from the path strings + + var RePathPart = /([\w\d_]+)(\])?(\[|\.)?/g; + + // extracts + // - the identifier (member name or array index) + // - followed by an optional right bracket (found when array index) + // - followed by an optional left bracket or dot (type of subscript) + // + // Note: These portions can be read in a non-overlapping fashion and + // allow straightforward parsing of the hierarchy that WebGL encodes + // in the uniform names. + + function addUniform( container, uniformObject ) { + + container.seq.push( uniformObject ); + container.map[ uniformObject.id ] = uniformObject; + + } + + function parseUniform( activeInfo, addr, container ) { + + var path = activeInfo.name, + pathLength = path.length; + + // reset RegExp object, because of the early exit of a previous run + RePathPart.lastIndex = 0; + + while ( true ) { + + var match = RePathPart.exec( path ), + matchEnd = RePathPart.lastIndex; + + var id = match[ 1 ], + idIsIndex = match[ 2 ] === ']', + subscript = match[ 3 ]; + + if ( idIsIndex ) { id = id | 0; } // convert to integer + + if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) { + + // bare name or "pure" bottom-level array "[0]" suffix + + addUniform( container, subscript === undefined ? + new SingleUniform( id, activeInfo, addr ) : + new PureArrayUniform( id, activeInfo, addr ) ); + + break; + + } else { + + // step into inner node / create it in case it doesn't exist + + var map = container.map; + var next = map[ id ]; + + if ( next === undefined ) { + + next = new StructuredUniform( id ); + addUniform( container, next ); + + } + + container = next; + + } + + } + + } + + // Root Container + + function WebGLUniforms( gl, program ) { + + this.seq = []; + this.map = {}; + + var n = gl.getProgramParameter( program, 35718 ); + + for ( var i = 0; i < n; ++ i ) { + + var info = gl.getActiveUniform( program, i ), + addr = gl.getUniformLocation( program, info.name ); + + parseUniform( info, addr, this ); + + } + + } + + WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) { + + var u = this.map[ name ]; + + if ( u !== undefined ) { u.setValue( gl, value, textures ); } + + }; + + WebGLUniforms.prototype.setOptional = function ( gl, object, name ) { + + var v = object[ name ]; + + if ( v !== undefined ) { this.setValue( gl, name, v ); } + + }; + + + // Static interface + + WebGLUniforms.upload = function ( gl, seq, values, textures ) { + + for ( var i = 0, n = seq.length; i !== n; ++ i ) { + + var u = seq[ i ], + v = values[ u.id ]; + + if ( v.needsUpdate !== false ) { + + // note: always updating when .needsUpdate is undefined + u.setValue( gl, v.value, textures ); + + } + + } + + }; + + WebGLUniforms.seqWithValue = function ( seq, values ) { + + var r = []; + + for ( var i = 0, n = seq.length; i !== n; ++ i ) { + + var u = seq[ i ]; + if ( u.id in values ) { r.push( u ); } + + } + + return r; + + }; + + function WebGLShader( gl, type, string ) { + + var shader = gl.createShader( type ); + + gl.shaderSource( shader, string ); + gl.compileShader( shader ); + + return shader; + + } + + var programIdCount = 0; + + function addLineNumbers( string ) { + + var lines = string.split( '\n' ); + + for ( var i = 0; i < lines.length; i ++ ) { + + lines[ i ] = ( i + 1 ) + ': ' + lines[ i ]; + + } + + return lines.join( '\n' ); + + } + + function getEncodingComponents( encoding ) { + + switch ( encoding ) { + + case LinearEncoding: + return [ 'Linear', '( value )' ]; + case sRGBEncoding: + return [ 'sRGB', '( value )' ]; + case RGBEEncoding: + return [ 'RGBE', '( value )' ]; + case RGBM7Encoding: + return [ 'RGBM', '( value, 7.0 )' ]; + case RGBM16Encoding: + return [ 'RGBM', '( value, 16.0 )' ]; + case RGBDEncoding: + return [ 'RGBD', '( value, 256.0 )' ]; + case GammaEncoding: + return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ]; + case LogLuvEncoding: + return [ 'LogLuv', '( value )' ]; + default: + console.warn( 'THREE.WebGLProgram: Unsupported encoding:', encoding ); + return [ 'Linear', '( value )' ]; + + } + + } + + function getShaderErrors( gl, shader, type ) { + + var status = gl.getShaderParameter( shader, 35713 ); + var log = gl.getShaderInfoLog( shader ).trim(); + + if ( status && log === '' ) { return ''; } + + // --enable-privileged-webgl-extension + // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) ); + + var source = gl.getShaderSource( shader ); + + return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source ); + + } + + function getTexelDecodingFunction( functionName, encoding ) { + + var components = getEncodingComponents( encoding ); + return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }'; + + } + + function getTexelEncodingFunction( functionName, encoding ) { + + var components = getEncodingComponents( encoding ); + return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }'; + + } + + function getToneMappingFunction( functionName, toneMapping ) { + + var toneMappingName; + + switch ( toneMapping ) { + + case LinearToneMapping: + toneMappingName = 'Linear'; + break; + + case ReinhardToneMapping: + toneMappingName = 'Reinhard'; + break; + + case CineonToneMapping: + toneMappingName = 'OptimizedCineon'; + break; + + case ACESFilmicToneMapping: + toneMappingName = 'ACESFilmic'; + break; + + case CustomToneMapping: + toneMappingName = 'Custom'; + break; + + default: + console.warn( 'THREE.WebGLProgram: Unsupported toneMapping:', toneMapping ); + toneMappingName = 'Linear'; + + } + + return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }'; + + } + + function generateExtensions( parameters ) { + + 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' : '' + ]; + + return chunks.filter( filterEmptyLine ).join( '\n' ); + + } + + function generateDefines( defines ) { + + var chunks = []; + + for ( var name in defines ) { + + var value = defines[ name ]; + + if ( value === false ) { continue; } + + chunks.push( '#define ' + name + ' ' + value ); + + } + + return chunks.join( '\n' ); + + } + + function fetchAttributeLocations( gl, program ) { + + var attributes = {}; + + var n = gl.getProgramParameter( program, 35721 ); + + for ( var i = 0; i < n; i ++ ) { + + var info = gl.getActiveAttrib( program, i ); + var name = info.name; + + // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i ); + + attributes[ name ] = gl.getAttribLocation( program, name ); + + } + + return attributes; + + } + + function filterEmptyLine( string ) { + + return string !== ''; + + } + + function replaceLightNums( string, parameters ) { + + 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 ); + + } + + function replaceClippingPlaneNums( string, parameters ) { + + return string + .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes ) + .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) ); + + } + + // Resolve Includes + + var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm; + + function resolveIncludes( string ) { + + return string.replace( includePattern, includeReplacer ); + + } + + function includeReplacer( match, include ) { + + var string = ShaderChunk[ include ]; + + if ( string === undefined ) { + + throw new Error( 'Can not resolve #include <' + include + '>' ); + + } + + return resolveIncludes( string ); + + } + + // Unroll Loops + + var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g; + var unrollLoopPattern = /#pragma unroll_loop_start[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}[\s]+?#pragma unroll_loop_end/g; + + function unrollLoops( string ) { + + return string + .replace( unrollLoopPattern, loopReplacer ) + .replace( deprecatedUnrollLoopPattern, deprecatedLoopReplacer ); + + } + + function deprecatedLoopReplacer( match, start, end, snippet ) { + + console.warn( 'WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.' ); + return loopReplacer( match, start, end, snippet ); + + } + + function loopReplacer( match, start, end, snippet ) { + + var string = ''; + + for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) { + + string += snippet + .replace( /\[ i \]/g, '[ ' + i + ' ]' ) + .replace( /UNROLLED_LOOP_INDEX/g, i ); + + } + + return string; + + } + + // + + function generatePrecision( parameters ) { + + var precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;"; + + if ( parameters.precision === "highp" ) { + + precisionstring += "\n#define HIGH_PRECISION"; + + } else if ( parameters.precision === "mediump" ) { + + precisionstring += "\n#define MEDIUM_PRECISION"; + + } else if ( parameters.precision === "lowp" ) { + + precisionstring += "\n#define LOW_PRECISION"; + + } + + return precisionstring; + + } + + function generateShadowMapTypeDefine( parameters ) { + + var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC'; + + if ( parameters.shadowMapType === PCFShadowMap ) { + + shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF'; + + } else if ( parameters.shadowMapType === PCFSoftShadowMap ) { + + shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT'; + + } else if ( parameters.shadowMapType === VSMShadowMap ) { + + shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM'; + + } + + return shadowMapTypeDefine; + + } + + function generateEnvMapTypeDefine( parameters ) { + + var envMapTypeDefine = 'ENVMAP_TYPE_CUBE'; + + if ( parameters.envMap ) { + + switch ( parameters.envMapMode ) { + + case CubeReflectionMapping: + case CubeRefractionMapping: + envMapTypeDefine = 'ENVMAP_TYPE_CUBE'; + break; + + case CubeUVReflectionMapping: + case CubeUVRefractionMapping: + envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV'; + break; + + case EquirectangularReflectionMapping: + case EquirectangularRefractionMapping: + envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC'; + break; + + } + + } + + return envMapTypeDefine; + + } + + function generateEnvMapModeDefine( parameters ) { + + var envMapModeDefine = 'ENVMAP_MODE_REFLECTION'; + + if ( parameters.envMap ) { + + switch ( parameters.envMapMode ) { + + case CubeRefractionMapping: + case EquirectangularRefractionMapping: + case CubeUVRefractionMapping: + + envMapModeDefine = 'ENVMAP_MODE_REFRACTION'; + break; + + } + + } + + return envMapModeDefine; + + } + + function generateEnvMapBlendingDefine( parameters ) { + + var envMapBlendingDefine = 'ENVMAP_BLENDING_NONE'; + + if ( parameters.envMap ) { + + switch ( parameters.combine ) { + + case MultiplyOperation: + envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY'; + break; + + case MixOperation: + envMapBlendingDefine = 'ENVMAP_BLENDING_MIX'; + break; + + case AddOperation: + envMapBlendingDefine = 'ENVMAP_BLENDING_ADD'; + break; + + } + + } + + return envMapBlendingDefine; + + } + + function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) { + + var gl = renderer.getContext(); + + var defines = parameters.defines; + + var vertexShader = parameters.vertexShader; + var fragmentShader = parameters.fragmentShader; + + var shadowMapTypeDefine = generateShadowMapTypeDefine( parameters ); + var envMapTypeDefine = generateEnvMapTypeDefine( parameters ); + var envMapModeDefine = generateEnvMapModeDefine( parameters ); + var envMapBlendingDefine = generateEnvMapBlendingDefine( parameters ); + + + var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0; + + var customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters ); + + var customDefines = generateDefines( defines ); + + var program = gl.createProgram(); + + var prefixVertex, prefixFragment; + + if ( parameters.isRawShaderMaterial ) { + + prefixVertex = [ + + customDefines + + ].filter( filterEmptyLine ).join( '\n' ); + + if ( prefixVertex.length > 0 ) { + + prefixVertex += '\n'; + + } + + prefixFragment = [ + + customExtensions, + customDefines + + ].filter( filterEmptyLine ).join( '\n' ); + + if ( prefixFragment.length > 0 ) { + + prefixFragment += '\n'; + + } + + } else { + + prefixVertex = [ + + generatePrecision( parameters ), + + '#define SHADER_NAME ' + parameters.shaderName, + + customDefines, + + parameters.instancing ? '#define USE_INSTANCING' : '', + 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', + + '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' ); + + prefixFragment = [ + + customExtensions, + + generatePrecision( parameters ), + + '#define SHADER_NAME ' + parameters.shaderName, + + customDefines, + + parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer + + '#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 ? '#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 + ( 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 + 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' ); + + } + + vertexShader = resolveIncludes( vertexShader ); + vertexShader = replaceLightNums( vertexShader, parameters ); + vertexShader = replaceClippingPlaneNums( vertexShader, parameters ); + + fragmentShader = resolveIncludes( fragmentShader ); + fragmentShader = replaceLightNums( fragmentShader, parameters ); + fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters ); + + vertexShader = unrollLoops( vertexShader ); + fragmentShader = unrollLoops( fragmentShader ); + + if ( parameters.isWebGL2 && ! parameters.isRawShaderMaterial ) { + + // GLSL 3.0 conversion + + prefixVertex = [ + '#version 300 es\n', + '#define attribute in', + '#define varying out', + '#define texture2D texture' + ].join( '\n' ) + '\n' + prefixVertex; + + prefixFragment = [ + '#version 300 es\n', + '#define varying in', + 'out highp vec4 pc_fragColor;', + '#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; + + } + + var vertexGlsl = prefixVertex + vertexShader; + var fragmentGlsl = prefixFragment + fragmentShader; + + // console.log( '*VERTEX*', vertexGlsl ); + // console.log( '*FRAGMENT*', fragmentGlsl ); + + var glVertexShader = WebGLShader( gl, 35633, vertexGlsl ); + var glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl ); + + gl.attachShader( program, glVertexShader ); + gl.attachShader( program, glFragmentShader ); + + // Force a particular attribute to index 0. + + if ( parameters.index0AttributeName !== undefined ) { + + gl.bindAttribLocation( program, 0, parameters.index0AttributeName ); + + } else if ( parameters.morphTargets === true ) { + + // programs with morphTargets displace position out of attribute 0 + gl.bindAttribLocation( program, 0, 'position' ); + + } + + gl.linkProgram( program ); + + // check for link errors + if ( renderer.debug.checkShaderErrors ) { + + var programLog = gl.getProgramInfoLog( program ).trim(); + var vertexLog = gl.getShaderInfoLog( glVertexShader ).trim(); + var fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim(); + + var runnable = true; + var haveDiagnostics = true; + + if ( gl.getProgramParameter( program, 35714 ) === false ) { + + runnable = false; + + var vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' ); + var fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' ); + + console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors ); + + } else if ( programLog !== '' ) { + + console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog ); + + } else if ( vertexLog === '' || fragmentLog === '' ) { + + haveDiagnostics = false; + + } + + if ( haveDiagnostics ) { + + this.diagnostics = { + + runnable: runnable, + + programLog: programLog, + + vertexShader: { + + log: vertexLog, + prefix: prefixVertex + + }, + + fragmentShader: { + + log: fragmentLog, + prefix: prefixFragment + + } + + }; + + } + + } + + // Clean up + + // Crashes in iOS9 and iOS10. #18402 + // gl.detachShader( program, glVertexShader ); + // gl.detachShader( program, glFragmentShader ); + + gl.deleteShader( glVertexShader ); + gl.deleteShader( glFragmentShader ); + + // set up caching for uniform locations + + var cachedUniforms; + + this.getUniforms = function () { + + if ( cachedUniforms === undefined ) { + + cachedUniforms = new WebGLUniforms( gl, program ); + + } + + return cachedUniforms; + + }; + + // set up caching for attribute locations + + var cachedAttributes; + + this.getAttributes = function () { + + if ( cachedAttributes === undefined ) { + + cachedAttributes = fetchAttributeLocations( gl, program ); + + } + + return cachedAttributes; + + }; + + // free resource + + this.destroy = function () { + + bindingStates.releaseStatesOfProgram( this ); + + gl.deleteProgram( program ); + this.program = undefined; + + }; + + // + + this.name = parameters.shaderName; + this.id = programIdCount ++; + this.cacheKey = cacheKey; + this.usedTimes = 1; + this.program = program; + this.vertexShader = glVertexShader; + this.fragmentShader = glFragmentShader; + + return this; + + } + + function WebGLPrograms( renderer, extensions, capabilities, bindingStates ) { + + var programs = []; + + var isWebGL2 = capabilities.isWebGL2; + var logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer; + var floatVertexTextures = capabilities.floatVertexTextures; + var maxVertexUniforms = capabilities.maxVertexUniforms; + var vertexTextures = capabilities.vertexTextures; + + var precision = capabilities.precision; + + var shaderIDs = { + MeshDepthMaterial: 'depth', + MeshDistanceMaterial: 'distanceRGBA', + MeshNormalMaterial: 'normal', + MeshBasicMaterial: 'basic', + MeshLambertMaterial: 'lambert', + MeshPhongMaterial: 'phong', + MeshToonMaterial: 'toon', + MeshStandardMaterial: 'physical', + MeshPhysicalMaterial: 'physical', + MeshMatcapMaterial: 'matcap', + LineBasicMaterial: 'basic', + LineDashedMaterial: 'dashed', + PointsMaterial: 'points', + ShadowMaterial: 'shadow', + SpriteMaterial: 'sprite' + }; + + var parameterNames = [ + "precision", "isWebGL2", "supportsVertexTextures", "outputEncoding", "instancing", + "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" + ]; + + function allocateBones( object ) { + + var skeleton = object.skeleton; + var bones = skeleton.bones; + + if ( floatVertexTextures ) { + + return 1024; + + } else { + + // default for when object is not specified + // ( for example when prebuilding shader to be used with multiple objects ) + // + // - leave some extra space for other uniforms + // - limit here is ANGLE's 254 max uniform vectors + // (up to 54 should be safe) + + var nVertexUniforms = maxVertexUniforms; + var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 ); + + var maxBones = Math.min( nVertexMatrices, bones.length ); + + if ( maxBones < bones.length ) { + + console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' ); + return 0; + + } + + return maxBones; + + } + + } + + function getTextureEncodingFromMap( map ) { + + var encoding; + + if ( ! map ) { + + encoding = LinearEncoding; + + } else if ( map.isTexture ) { + + encoding = map.encoding; + + } else if ( map.isWebGLRenderTarget ) { + + console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." ); + encoding = map.texture.encoding; + + } + + return encoding; + + } + + function getParameters( material, lights, shadows, scene, nClipPlanes, nClipIntersection, object ) { + + var fog = scene.fog; + var environment = material.isMeshStandardMaterial ? scene.environment : null; + + var envMap = material.envMap || environment; + + var shaderID = shaderIDs[ material.type ]; + + // heuristics to create shader parameters according to lights in the scene + // (not to blow over maxLights budget) + + var maxBones = object.isSkinnedMesh ? allocateBones( object ) : 0; + + if ( material.precision !== null ) { + + precision = capabilities.getMaxPrecision( material.precision ); + + if ( precision !== material.precision ) { + + console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' ); + + } + + } + + var vertexShader, fragmentShader; + + if ( shaderID ) { + + var shader = ShaderLib[ shaderID ]; + + vertexShader = shader.vertexShader; + fragmentShader = shader.fragmentShader; + + } else { + + vertexShader = material.vertexShader; + fragmentShader = material.fragmentShader; + + } + + var currentRenderTarget = renderer.getRenderTarget(); + + var parameters = { + + isWebGL2: isWebGL2, + + shaderID: shaderID, + shaderName: material.type, + + vertexShader: vertexShader, + fragmentShader: fragmentShader, + defines: material.defines, + + isRawShaderMaterial: material.isRawShaderMaterial, + isShaderMaterial: material.isShaderMaterial, + + precision: precision, + + instancing: object.isInstancedMesh === true, + + supportsVertexTextures: vertexTextures, + outputEncoding: ( currentRenderTarget !== null ) ? getTextureEncodingFromMap( currentRenderTarget.texture ) : renderer.outputEncoding, + map: !! material.map, + mapEncoding: getTextureEncodingFromMap( material.map ), + matcap: !! material.matcap, + matcapEncoding: getTextureEncodingFromMap( material.matcap ), + envMap: !! envMap, + envMapMode: envMap && envMap.mapping, + envMapEncoding: getTextureEncodingFromMap( envMap ), + envMapCubeUV: ( !! envMap ) && ( ( envMap.mapping === CubeUVReflectionMapping ) || ( envMap.mapping === CubeUVRefractionMapping ) ), + lightMap: !! material.lightMap, + lightMapEncoding: getTextureEncodingFromMap( material.lightMap ), + aoMap: !! material.aoMap, + emissiveMap: !! material.emissiveMap, + emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap ), + bumpMap: !! material.bumpMap, + normalMap: !! material.normalMap, + objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap, + tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap, + clearcoatMap: !! material.clearcoatMap, + clearcoatRoughnessMap: !! material.clearcoatRoughnessMap, + clearcoatNormalMap: !! material.clearcoatNormalMap, + displacementMap: !! material.displacementMap, + roughnessMap: !! material.roughnessMap, + metalnessMap: !! material.metalnessMap, + specularMap: !! material.specularMap, + alphaMap: !! material.alphaMap, + + gradientMap: !! material.gradientMap, + + sheen: !! material.sheen, + + transmissionMap: !! material.transmissionMap, + + combine: material.combine, + + vertexTangents: ( material.normalMap && material.vertexTangents ), + vertexColors: material.vertexColors, + 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, + uvsVertexOnly: ! ( !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap || !! material.transmissionMap ) && !! material.displacementMap, + + fog: !! fog, + useFog: material.fog, + fogExp2: ( fog && fog.isFogExp2 ), + + flatShading: material.flatShading, + + sizeAttenuation: material.sizeAttenuation, + logarithmicDepthBuffer: logarithmicDepthBuffer, + + skinning: material.skinning && maxBones > 0, + maxBones: maxBones, + useVertexTexture: floatVertexTextures, + + morphTargets: material.morphTargets, + morphNormals: material.morphNormals, + maxMorphTargets: renderer.maxMorphTargets, + maxMorphNormals: renderer.maxMorphNormals, + + numDirLights: lights.directional.length, + numPointLights: lights.point.length, + numSpotLights: lights.spot.length, + numRectAreaLights: lights.rectArea.length, + numHemiLights: lights.hemi.length, + + numDirLightShadows: lights.directionalShadowMap.length, + numPointLightShadows: lights.pointShadowMap.length, + numSpotLightShadows: lights.spotShadowMap.length, + + numClippingPlanes: nClipPlanes, + numClipIntersection: nClipIntersection, + + dithering: material.dithering, + + shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0, + shadowMapType: renderer.shadowMap.type, + + toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping, + physicallyCorrectLights: renderer.physicallyCorrectLights, + + premultipliedAlpha: material.premultipliedAlpha, + + alphaTest: material.alphaTest, + doubleSided: material.side === DoubleSide, + flipSided: material.side === BackSide, + + depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false, + + index0AttributeName: material.index0AttributeName, + + extensionDerivatives: material.extensions && material.extensions.derivatives, + extensionFragDepth: material.extensions && material.extensions.fragDepth, + extensionDrawBuffers: material.extensions && material.extensions.drawBuffers, + extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD, + + rendererExtensionFragDepth: isWebGL2 || extensions.get( 'EXT_frag_depth' ) !== null, + rendererExtensionDrawBuffers: isWebGL2 || extensions.get( 'WEBGL_draw_buffers' ) !== null, + rendererExtensionShaderTextureLod: isWebGL2 || extensions.get( 'EXT_shader_texture_lod' ) !== null, + + customProgramCacheKey: material.customProgramCacheKey() + + }; + + return parameters; + + } + + function getProgramCacheKey( parameters ) { + + var array = []; + + if ( parameters.shaderID ) { + + array.push( parameters.shaderID ); + + } else { + + array.push( parameters.fragmentShader ); + array.push( parameters.vertexShader ); + + } + + if ( parameters.defines !== undefined ) { + + for ( var name in parameters.defines ) { + + array.push( name ); + array.push( parameters.defines[ name ] ); + + } + + } + + if ( parameters.isRawShaderMaterial === undefined ) { + + for ( var i = 0; i < parameterNames.length; i ++ ) { + + array.push( parameters[ parameterNames[ i ] ] ); + + } + + array.push( renderer.outputEncoding ); + array.push( renderer.gammaFactor ); + + } + + array.push( parameters.customProgramCacheKey ); + + return array.join(); + + } + + function getUniforms( material ) { + + var shaderID = shaderIDs[ material.type ]; + var uniforms; + + if ( shaderID ) { + + var shader = ShaderLib[ shaderID ]; + uniforms = UniformsUtils.clone( shader.uniforms ); + + } else { + + uniforms = material.uniforms; + + } + + return uniforms; + + } + + function acquireProgram( parameters, cacheKey ) { + + var program; + + // Check if code has been already compiled + for ( var p = 0, pl = programs.length; p < pl; p ++ ) { + + var preexistingProgram = programs[ p ]; + + if ( preexistingProgram.cacheKey === cacheKey ) { + + program = preexistingProgram; + ++ program.usedTimes; + + break; + + } + + } + + if ( program === undefined ) { + + program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates ); + programs.push( program ); + + } + + return program; + + } + + function releaseProgram( program ) { + + if ( -- program.usedTimes === 0 ) { + + // Remove from unordered set + var i = programs.indexOf( program ); + programs[ i ] = programs[ programs.length - 1 ]; + programs.pop(); + + // Free WebGL resources + program.destroy(); + + } + + } + + return { + getParameters: getParameters, + getProgramCacheKey: getProgramCacheKey, + getUniforms: getUniforms, + acquireProgram: acquireProgram, + releaseProgram: releaseProgram, + // Exposed for resource monitoring & error feedback via renderer.info: + programs: programs + }; + + } + + function WebGLProperties() { + + var properties = new WeakMap(); + + function get( object ) { + + var map = properties.get( object ); + + if ( map === undefined ) { + + map = {}; + properties.set( object, map ); + + } + + return map; + + } + + function remove( object ) { + + properties.delete( object ); + + } + + function update( object, key, value ) { + + properties.get( object )[ key ] = value; + + } + + function dispose() { + + properties = new WeakMap(); + + } + + return { + get: get, + remove: remove, + update: update, + dispose: dispose + }; + + } + + function painterSortStable( a, b ) { + + if ( a.groupOrder !== b.groupOrder ) { + + return a.groupOrder - b.groupOrder; + + } else if ( a.renderOrder !== b.renderOrder ) { + + return a.renderOrder - b.renderOrder; + + } else if ( a.program !== b.program ) { + + return a.program.id - b.program.id; + + } else if ( a.material.id !== b.material.id ) { + + return a.material.id - b.material.id; + + } else if ( a.z !== b.z ) { + + return a.z - b.z; + + } else { + + return a.id - b.id; + + } + + } + + function reversePainterSortStable( a, b ) { + + if ( a.groupOrder !== b.groupOrder ) { + + return a.groupOrder - b.groupOrder; + + } else if ( a.renderOrder !== b.renderOrder ) { + + return a.renderOrder - b.renderOrder; + + } else if ( a.z !== b.z ) { + + return b.z - a.z; + + } else { + + return a.id - b.id; + + } + + } + + + function WebGLRenderList( properties ) { + + var renderItems = []; + var renderItemsIndex = 0; + + var opaque = []; + var transparent = []; + + var defaultProgram = { id: - 1 }; + + function init() { + + renderItemsIndex = 0; + + opaque.length = 0; + transparent.length = 0; + + } + + function getNextRenderItem( object, geometry, material, groupOrder, z, group ) { + + var renderItem = renderItems[ renderItemsIndex ]; + var materialProperties = properties.get( material ); + + if ( renderItem === undefined ) { + + renderItem = { + id: object.id, + object: object, + geometry: geometry, + material: material, + program: materialProperties.program || defaultProgram, + groupOrder: groupOrder, + renderOrder: object.renderOrder, + z: z, + group: group + }; + + renderItems[ renderItemsIndex ] = renderItem; + + } else { + + renderItem.id = object.id; + renderItem.object = object; + renderItem.geometry = geometry; + renderItem.material = material; + renderItem.program = materialProperties.program || defaultProgram; + renderItem.groupOrder = groupOrder; + renderItem.renderOrder = object.renderOrder; + renderItem.z = z; + renderItem.group = group; + + } + + renderItemsIndex ++; + + return renderItem; + + } + + function push( object, geometry, material, groupOrder, z, group ) { + + var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group ); + + ( material.transparent === true ? transparent : opaque ).push( renderItem ); + + } + + function unshift( object, geometry, material, groupOrder, z, group ) { + + var renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group ); + + ( material.transparent === true ? transparent : opaque ).unshift( renderItem ); + + } + + function sort( customOpaqueSort, customTransparentSort ) { + + if ( opaque.length > 1 ) { opaque.sort( customOpaqueSort || painterSortStable ); } + if ( transparent.length > 1 ) { transparent.sort( customTransparentSort || reversePainterSortStable ); } + + } + + function finish() { + + // Clear references from inactive renderItems in the list + + for ( var i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) { + + var renderItem = renderItems[ i ]; + + if ( renderItem.id === null ) { break; } + + renderItem.id = null; + renderItem.object = null; + renderItem.geometry = null; + renderItem.material = null; + renderItem.program = null; + renderItem.group = null; + + } + + } + + return { + + opaque: opaque, + transparent: transparent, + + init: init, + push: push, + unshift: unshift, + finish: finish, + + sort: sort + }; + + } + + function WebGLRenderLists( properties ) { + + var lists = new WeakMap(); + + function onSceneDispose( event ) { + + var scene = event.target; + + scene.removeEventListener( 'dispose', onSceneDispose ); + + lists.delete( scene ); + + } + + function get( scene, camera ) { + + var cameras = lists.get( scene ); + var list; + + if ( cameras === undefined ) { + + list = new WebGLRenderList( properties ); + lists.set( scene, new WeakMap() ); + lists.get( scene ).set( camera, list ); + + scene.addEventListener( 'dispose', onSceneDispose ); + + } else { + + list = cameras.get( camera ); + if ( list === undefined ) { + + list = new WebGLRenderList( properties ); + cameras.set( camera, list ); + + } + + } + + return list; + + } + + function dispose() { + + lists = new WeakMap(); + + } + + return { + get: get, + dispose: dispose + }; + + } + + function UniformsCache() { + + var lights = {}; + + return { + + get: function ( light ) { + + if ( lights[ light.id ] !== undefined ) { + + return lights[ light.id ]; + + } + + var uniforms; + + switch ( light.type ) { + + case 'DirectionalLight': + uniforms = { + direction: new Vector3(), + color: new Color() + }; + break; + + case 'SpotLight': + uniforms = { + position: new Vector3(), + direction: new Vector3(), + color: new Color(), + distance: 0, + coneCos: 0, + penumbraCos: 0, + decay: 0 + }; + break; + + case 'PointLight': + uniforms = { + position: new Vector3(), + color: new Color(), + distance: 0, + decay: 0 + }; + break; + + case 'HemisphereLight': + uniforms = { + direction: new Vector3(), + skyColor: new Color(), + groundColor: new Color() + }; + break; + + case 'RectAreaLight': + uniforms = { + color: new Color(), + position: new Vector3(), + halfWidth: new Vector3(), + halfHeight: new Vector3() + }; + break; + + } + + lights[ light.id ] = uniforms; + + return uniforms; + + } + + }; + + } + + function ShadowUniformsCache() { + + var lights = {}; + + return { + + get: function ( light ) { + + if ( lights[ light.id ] !== undefined ) { + + return lights[ light.id ]; + + } + + var uniforms; + + switch ( light.type ) { + + case 'DirectionalLight': + uniforms = { + shadowBias: 0, + shadowNormalBias: 0, + shadowRadius: 1, + shadowMapSize: new Vector2() + }; + break; + + case 'SpotLight': + uniforms = { + shadowBias: 0, + shadowNormalBias: 0, + shadowRadius: 1, + shadowMapSize: new Vector2() + }; + break; + + case 'PointLight': + uniforms = { + shadowBias: 0, + shadowNormalBias: 0, + shadowRadius: 1, + shadowMapSize: new Vector2(), + shadowCameraNear: 1, + shadowCameraFar: 1000 + }; + break; + + // TODO (abelnation): set RectAreaLight shadow uniforms + + } + + lights[ light.id ] = uniforms; + + return uniforms; + + } + + }; + + } + + + + var nextVersion = 0; + + function shadowCastingLightsFirst( lightA, lightB ) { + + return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 ); + + } + + function WebGLLights() { + + var cache = new UniformsCache(); + + var shadowCache = ShadowUniformsCache(); + + var state = { + + version: 0, + + hash: { + directionalLength: - 1, + pointLength: - 1, + spotLength: - 1, + rectAreaLength: - 1, + hemiLength: - 1, + + numDirectionalShadows: - 1, + numPointShadows: - 1, + numSpotShadows: - 1 + }, + + ambient: [ 0, 0, 0 ], + probe: [], + directional: [], + directionalShadow: [], + directionalShadowMap: [], + directionalShadowMatrix: [], + spot: [], + spotShadow: [], + spotShadowMap: [], + spotShadowMatrix: [], + rectArea: [], + point: [], + pointShadow: [], + pointShadowMap: [], + pointShadowMatrix: [], + hemi: [] + + }; + + for ( var i = 0; i < 9; i ++ ) { state.probe.push( new Vector3() ); } + + var vector3 = new Vector3(); + var matrix4 = new Matrix4(); + var matrix42 = new Matrix4(); + + function setup( lights, shadows, camera ) { + + var r = 0, g = 0, b = 0; + + for ( var i = 0; i < 9; i ++ ) { state.probe[ i ].set( 0, 0, 0 ); } + + var directionalLength = 0; + var pointLength = 0; + var spotLength = 0; + var rectAreaLength = 0; + var hemiLength = 0; + + var numDirectionalShadows = 0; + var numPointShadows = 0; + var numSpotShadows = 0; + + var viewMatrix = camera.matrixWorldInverse; + + lights.sort( shadowCastingLightsFirst ); + + for ( var i$1 = 0, l = lights.length; i$1 < l; i$1 ++ ) { + + var light = lights[ i$1 ]; + + var color = light.color; + var intensity = light.intensity; + var distance = light.distance; + + var shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null; + + if ( light.isAmbientLight ) { + + r += color.r * intensity; + g += color.g * intensity; + b += color.b * intensity; + + } else if ( light.isLightProbe ) { + + for ( var j = 0; j < 9; j ++ ) { + + state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity ); + + } + + } else if ( light.isDirectionalLight ) { + + var uniforms = cache.get( light ); + + uniforms.color.copy( light.color ).multiplyScalar( light.intensity ); + uniforms.direction.setFromMatrixPosition( light.matrixWorld ); + vector3.setFromMatrixPosition( light.target.matrixWorld ); + uniforms.direction.sub( vector3 ); + uniforms.direction.transformDirection( viewMatrix ); + + if ( light.castShadow ) { + + var shadow = light.shadow; + + var shadowUniforms = shadowCache.get( light ); + + shadowUniforms.shadowBias = shadow.bias; + shadowUniforms.shadowNormalBias = shadow.normalBias; + shadowUniforms.shadowRadius = shadow.radius; + shadowUniforms.shadowMapSize = shadow.mapSize; + + state.directionalShadow[ directionalLength ] = shadowUniforms; + state.directionalShadowMap[ directionalLength ] = shadowMap; + state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix; + + numDirectionalShadows ++; + + } + + state.directional[ directionalLength ] = uniforms; + + directionalLength ++; + + } else if ( light.isSpotLight ) { + + var uniforms$1 = cache.get( light ); + + uniforms$1.position.setFromMatrixPosition( light.matrixWorld ); + uniforms$1.position.applyMatrix4( viewMatrix ); + + uniforms$1.color.copy( color ).multiplyScalar( intensity ); + uniforms$1.distance = distance; + + uniforms$1.direction.setFromMatrixPosition( light.matrixWorld ); + vector3.setFromMatrixPosition( light.target.matrixWorld ); + uniforms$1.direction.sub( vector3 ); + uniforms$1.direction.transformDirection( viewMatrix ); + + uniforms$1.coneCos = Math.cos( light.angle ); + uniforms$1.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) ); + uniforms$1.decay = light.decay; + + if ( light.castShadow ) { + + var shadow$1 = light.shadow; + + var shadowUniforms$1 = shadowCache.get( light ); + + shadowUniforms$1.shadowBias = shadow$1.bias; + shadowUniforms$1.shadowNormalBias = shadow$1.normalBias; + shadowUniforms$1.shadowRadius = shadow$1.radius; + shadowUniforms$1.shadowMapSize = shadow$1.mapSize; + + state.spotShadow[ spotLength ] = shadowUniforms$1; + state.spotShadowMap[ spotLength ] = shadowMap; + state.spotShadowMatrix[ spotLength ] = light.shadow.matrix; + + numSpotShadows ++; + + } + + state.spot[ spotLength ] = uniforms$1; + + spotLength ++; + + } else if ( light.isRectAreaLight ) { + + var uniforms$2 = cache.get( light ); + + // (a) intensity is the total visible light emitted + //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) ); + + // (b) intensity is the brightness of the light + uniforms$2.color.copy( color ).multiplyScalar( intensity ); + + uniforms$2.position.setFromMatrixPosition( light.matrixWorld ); + uniforms$2.position.applyMatrix4( viewMatrix ); + + // extract local rotation of light to derive width/height half vectors + matrix42.identity(); + matrix4.copy( light.matrixWorld ); + matrix4.premultiply( viewMatrix ); + matrix42.extractRotation( matrix4 ); + + uniforms$2.halfWidth.set( light.width * 0.5, 0.0, 0.0 ); + uniforms$2.halfHeight.set( 0.0, light.height * 0.5, 0.0 ); + + uniforms$2.halfWidth.applyMatrix4( matrix42 ); + uniforms$2.halfHeight.applyMatrix4( matrix42 ); + + // TODO (abelnation): RectAreaLight distance? + // uniforms.distance = distance; + + state.rectArea[ rectAreaLength ] = uniforms$2; + + rectAreaLength ++; + + } else if ( light.isPointLight ) { + + var uniforms$3 = cache.get( light ); + + uniforms$3.position.setFromMatrixPosition( light.matrixWorld ); + uniforms$3.position.applyMatrix4( viewMatrix ); + + uniforms$3.color.copy( light.color ).multiplyScalar( light.intensity ); + uniforms$3.distance = light.distance; + uniforms$3.decay = light.decay; + + if ( light.castShadow ) { + + var shadow$2 = light.shadow; + + var shadowUniforms$2 = shadowCache.get( light ); + + shadowUniforms$2.shadowBias = shadow$2.bias; + shadowUniforms$2.shadowNormalBias = shadow$2.normalBias; + shadowUniforms$2.shadowRadius = shadow$2.radius; + shadowUniforms$2.shadowMapSize = shadow$2.mapSize; + shadowUniforms$2.shadowCameraNear = shadow$2.camera.near; + shadowUniforms$2.shadowCameraFar = shadow$2.camera.far; + + state.pointShadow[ pointLength ] = shadowUniforms$2; + state.pointShadowMap[ pointLength ] = shadowMap; + state.pointShadowMatrix[ pointLength ] = light.shadow.matrix; + + numPointShadows ++; + + } + + state.point[ pointLength ] = uniforms$3; + + pointLength ++; + + } else if ( light.isHemisphereLight ) { + + var uniforms$4 = cache.get( light ); + + uniforms$4.direction.setFromMatrixPosition( light.matrixWorld ); + uniforms$4.direction.transformDirection( viewMatrix ); + uniforms$4.direction.normalize(); + + uniforms$4.skyColor.copy( light.color ).multiplyScalar( intensity ); + uniforms$4.groundColor.copy( light.groundColor ).multiplyScalar( intensity ); + + state.hemi[ hemiLength ] = uniforms$4; + + hemiLength ++; + + } + + } + + state.ambient[ 0 ] = r; + state.ambient[ 1 ] = g; + state.ambient[ 2 ] = b; + + var hash = state.hash; + + 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 ) { + + state.directional.length = directionalLength; + state.spot.length = spotLength; + state.rectArea.length = rectAreaLength; + state.point.length = pointLength; + state.hemi.length = hemiLength; + + state.directionalShadow.length = numDirectionalShadows; + state.directionalShadowMap.length = numDirectionalShadows; + state.pointShadow.length = numPointShadows; + state.pointShadowMap.length = numPointShadows; + state.spotShadow.length = numSpotShadows; + state.spotShadowMap.length = numSpotShadows; + state.directionalShadowMatrix.length = numDirectionalShadows; + state.pointShadowMatrix.length = numPointShadows; + state.spotShadowMatrix.length = numSpotShadows; + + hash.directionalLength = directionalLength; + hash.pointLength = pointLength; + hash.spotLength = spotLength; + hash.rectAreaLength = rectAreaLength; + hash.hemiLength = hemiLength; + + hash.numDirectionalShadows = numDirectionalShadows; + hash.numPointShadows = numPointShadows; + hash.numSpotShadows = numSpotShadows; + + state.version = nextVersion ++; + + } + + } + + return { + setup: setup, + state: state + }; + + } + + function WebGLRenderState() { + + var lights = new WebGLLights(); + + var lightsArray = []; + var shadowsArray = []; + + function init() { + + lightsArray.length = 0; + shadowsArray.length = 0; + + } + + function pushLight( light ) { + + lightsArray.push( light ); + + } + + function pushShadow( shadowLight ) { + + shadowsArray.push( shadowLight ); + + } + + function setupLights( camera ) { + + lights.setup( lightsArray, shadowsArray, camera ); + + } + + var state = { + lightsArray: lightsArray, + shadowsArray: shadowsArray, + + lights: lights + }; + + return { + init: init, + state: state, + setupLights: setupLights, + + pushLight: pushLight, + pushShadow: pushShadow + }; + + } + + function WebGLRenderStates() { + + var renderStates = new WeakMap(); + + function onSceneDispose( event ) { + + var scene = event.target; + + scene.removeEventListener( 'dispose', onSceneDispose ); + + renderStates.delete( scene ); + + } + + function get( scene, camera ) { + + var renderState; + + if ( renderStates.has( scene ) === false ) { + + renderState = new WebGLRenderState(); + renderStates.set( scene, new WeakMap() ); + renderStates.get( scene ).set( camera, renderState ); + + scene.addEventListener( 'dispose', onSceneDispose ); + + } else { + + if ( renderStates.get( scene ).has( camera ) === false ) { + + renderState = new WebGLRenderState(); + renderStates.get( scene ).set( camera, renderState ); + + } else { + + renderState = renderStates.get( scene ).get( camera ); + + } + + } + + return renderState; + + } + + function dispose() { + + renderStates = new WeakMap(); + + } + + return { + get: get, + dispose: dispose + }; + + } + + /** + * parameters = { + * + * opacity: , + * + * map: new THREE.Texture( ), + * + * alphaMap: new THREE.Texture( ), + * + * displacementMap: new THREE.Texture( ), + * displacementScale: , + * displacementBias: , + * + * wireframe: , + * wireframeLinewidth: + * } + */ + + function MeshDepthMaterial( parameters ) { + + Material.call( this ); + + this.type = 'MeshDepthMaterial'; + + this.depthPacking = BasicDepthPacking; + + this.skinning = false; + this.morphTargets = false; + + this.map = null; + + this.alphaMap = null; + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.wireframe = false; + this.wireframeLinewidth = 1; + + this.fog = false; + + this.setValues( parameters ); + + } + + MeshDepthMaterial.prototype = Object.create( Material.prototype ); + MeshDepthMaterial.prototype.constructor = MeshDepthMaterial; + + MeshDepthMaterial.prototype.isMeshDepthMaterial = true; + + MeshDepthMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.depthPacking = source.depthPacking; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + + this.map = source.map; + + this.alphaMap = source.alphaMap; + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + + return this; + + }; + + /** + * parameters = { + * + * referencePosition: , + * nearDistance: , + * farDistance: , + * + * skinning: , + * morphTargets: , + * + * map: new THREE.Texture( ), + * + * alphaMap: new THREE.Texture( ), + * + * displacementMap: new THREE.Texture( ), + * displacementScale: , + * displacementBias: + * + * } + */ + + function MeshDistanceMaterial( parameters ) { + + Material.call( this ); + + this.type = 'MeshDistanceMaterial'; + + this.referencePosition = new Vector3(); + this.nearDistance = 1; + this.farDistance = 1000; + + this.skinning = false; + this.morphTargets = false; + + this.map = null; + + this.alphaMap = null; + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.fog = false; + + this.setValues( parameters ); + + } + + MeshDistanceMaterial.prototype = Object.create( Material.prototype ); + MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial; + + MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true; + + MeshDistanceMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.referencePosition.copy( source.referencePosition ); + this.nearDistance = source.nearDistance; + this.farDistance = source.farDistance; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + + this.map = source.map; + + this.alphaMap = source.alphaMap; + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + return this; + + }; + + var vsm_frag = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include \nvoid main() {\n float mean = 0.0;\n float squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n for ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n #ifdef HORIZONAL_PASS\n vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n mean += distribution.x;\n squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n #else\n float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n mean += depth;\n squared_mean += depth * depth;\n #endif\n }\n mean = mean * HALF_SAMPLE_RATE;\n squared_mean = squared_mean * HALF_SAMPLE_RATE;\n float std_dev = sqrt( squared_mean - mean * mean );\n gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}"; + + var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}"; + + function WebGLShadowMap( _renderer, _objects, maxTextureSize ) { + + var _frustum = new Frustum(); + + var _shadowMapSize = new Vector2(), + _viewportSize = new Vector2(), + + _viewport = new Vector4(), + + _depthMaterials = [], + _distanceMaterials = [], + + _materialCache = {}; + + var shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide }; + + var shadowMaterialVertical = new ShaderMaterial( { + + defines: { + SAMPLE_RATE: 2.0 / 8.0, + HALF_SAMPLE_RATE: 1.0 / 8.0 + }, + + uniforms: { + shadow_pass: { value: null }, + resolution: { value: new Vector2() }, + radius: { value: 4.0 } + }, + + vertexShader: vsm_vert, + + fragmentShader: vsm_frag + + } ); + + var shadowMaterialHorizonal = shadowMaterialVertical.clone(); + shadowMaterialHorizonal.defines.HORIZONAL_PASS = 1; + + var fullScreenTri = new BufferGeometry(); + fullScreenTri.setAttribute( + "position", + new BufferAttribute( + new Float32Array( [ - 1, - 1, 0.5, 3, - 1, 0.5, - 1, 3, 0.5 ] ), + 3 + ) + ); + + var fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical ); + + var scope = this; + + this.enabled = false; + + this.autoUpdate = true; + this.needsUpdate = false; + + this.type = PCFShadowMap; + + this.render = function ( lights, scene, camera ) { + + if ( scope.enabled === false ) { return; } + if ( scope.autoUpdate === false && scope.needsUpdate === false ) { return; } + + if ( lights.length === 0 ) { return; } + + var currentRenderTarget = _renderer.getRenderTarget(); + var activeCubeFace = _renderer.getActiveCubeFace(); + var activeMipmapLevel = _renderer.getActiveMipmapLevel(); + + var _state = _renderer.state; + + // Set GL state for depth map. + _state.setBlending( NoBlending ); + _state.buffers.color.setClear( 1, 1, 1, 1 ); + _state.buffers.depth.setTest( true ); + _state.setScissorTest( false ); + + // render depth map + + for ( var i = 0, il = lights.length; i < il; i ++ ) { + + var light = lights[ i ]; + var shadow = light.shadow; + + if ( shadow.autoUpdate === false && shadow.needsUpdate === false ) { continue; } + + if ( shadow === undefined ) { + + console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' ); + continue; + + } + + _shadowMapSize.copy( shadow.mapSize ); + + var shadowFrameExtents = shadow.getFrameExtents(); + + _shadowMapSize.multiply( shadowFrameExtents ); + + _viewportSize.copy( shadow.mapSize ); + + if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) { + + if ( _shadowMapSize.x > maxTextureSize ) { + + _viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x ); + _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x; + shadow.mapSize.x = _viewportSize.x; + + } + + if ( _shadowMapSize.y > maxTextureSize ) { + + _viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y ); + _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y; + shadow.mapSize.y = _viewportSize.y; + + } + + } + + if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) { + + var pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat, stencilBuffer: false }; + + shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars ); + shadow.map.texture.name = light.name + ".shadowMap"; + + shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars ); + + shadow.camera.updateProjectionMatrix(); + + } + + if ( shadow.map === null ) { + + var pars$1 = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat, stencilBuffer: false }; + + shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars$1 ); + shadow.map.texture.name = light.name + ".shadowMap"; + + shadow.camera.updateProjectionMatrix(); + + } + + _renderer.setRenderTarget( shadow.map ); + _renderer.clear(); + + var viewportCount = shadow.getViewportCount(); + + for ( var vp = 0; vp < viewportCount; vp ++ ) { + + var viewport = shadow.getViewport( vp ); + + _viewport.set( + _viewportSize.x * viewport.x, + _viewportSize.y * viewport.y, + _viewportSize.x * viewport.z, + _viewportSize.y * viewport.w + ); + + _state.viewport( _viewport ); + + shadow.updateMatrices( light, vp ); + + _frustum = shadow.getFrustum(); + + renderObject( scene, camera, shadow.camera, light, this.type ); + + } + + // do blur pass for VSM + + if ( ! shadow.isPointLightShadow && this.type === VSMShadowMap ) { + + VSMPass( shadow, camera ); + + } + + shadow.needsUpdate = false; + + } + + scope.needsUpdate = false; + + _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel ); + + }; + + function VSMPass( shadow, camera ) { + + var geometry = _objects.update( fullScreenMesh ); + + // vertical pass + + shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture; + shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize; + shadowMaterialVertical.uniforms.radius.value = shadow.radius; + _renderer.setRenderTarget( shadow.mapPass ); + _renderer.clear(); + _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null ); + + // horizonal pass + + shadowMaterialHorizonal.uniforms.shadow_pass.value = shadow.mapPass.texture; + shadowMaterialHorizonal.uniforms.resolution.value = shadow.mapSize; + shadowMaterialHorizonal.uniforms.radius.value = shadow.radius; + _renderer.setRenderTarget( shadow.map ); + _renderer.clear(); + _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizonal, fullScreenMesh, null ); + + } + + function getDepthMaterialVariant( useMorphing, useSkinning, useInstancing ) { + + var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2; + + var material = _depthMaterials[ index ]; + + if ( material === undefined ) { + + material = new MeshDepthMaterial( { + + depthPacking: RGBADepthPacking, + + morphTargets: useMorphing, + skinning: useSkinning + + } ); + + _depthMaterials[ index ] = material; + + } + + return material; + + } + + function getDistanceMaterialVariant( useMorphing, useSkinning, useInstancing ) { + + var index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2; + + var material = _distanceMaterials[ index ]; + + if ( material === undefined ) { + + material = new MeshDistanceMaterial( { + + morphTargets: useMorphing, + skinning: useSkinning + + } ); + + _distanceMaterials[ index ] = material; + + } + + return material; + + } + + function getDepthMaterial( object, geometry, material, light, shadowCameraNear, shadowCameraFar, type ) { + + var result = null; + + var getMaterialVariant = getDepthMaterialVariant; + var customMaterial = object.customDepthMaterial; + + if ( light.isPointLight === true ) { + + getMaterialVariant = getDistanceMaterialVariant; + customMaterial = object.customDistanceMaterial; + + } + + if ( customMaterial === undefined ) { + + var useMorphing = false; + + if ( material.morphTargets === true ) { + + useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0; + + } + + var useSkinning = false; + + if ( object.isSkinnedMesh === true ) { + + if ( material.skinning === true ) { + + useSkinning = true; + + } else { + + console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object ); + + } + + } + + var useInstancing = object.isInstancedMesh === true; + + result = getMaterialVariant( useMorphing, useSkinning, useInstancing ); + + } else { + + result = customMaterial; + + } + + if ( _renderer.localClippingEnabled && + material.clipShadows === true && + material.clippingPlanes.length !== 0 ) { + + // in this case we need a unique material instance reflecting the + // appropriate state + + var keyA = result.uuid, keyB = material.uuid; + + var materialsForVariant = _materialCache[ keyA ]; + + if ( materialsForVariant === undefined ) { + + materialsForVariant = {}; + _materialCache[ keyA ] = materialsForVariant; + + } + + var cachedMaterial = materialsForVariant[ keyB ]; + + if ( cachedMaterial === undefined ) { + + cachedMaterial = result.clone(); + materialsForVariant[ keyB ] = cachedMaterial; + + } + + result = cachedMaterial; + + } + + result.visible = material.visible; + result.wireframe = material.wireframe; + + if ( type === VSMShadowMap ) { + + result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side; + + } else { + + result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ]; + + } + + result.clipShadows = material.clipShadows; + result.clippingPlanes = material.clippingPlanes; + result.clipIntersection = material.clipIntersection; + + result.wireframeLinewidth = material.wireframeLinewidth; + result.linewidth = material.linewidth; + + if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) { + + result.referencePosition.setFromMatrixPosition( light.matrixWorld ); + result.nearDistance = shadowCameraNear; + result.farDistance = shadowCameraFar; + + } + + return result; + + } + + function renderObject( object, camera, shadowCamera, light, type ) { + + if ( object.visible === false ) { return; } + + var visible = object.layers.test( camera.layers ); + + if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) { + + if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) { + + object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld ); + + var geometry = _objects.update( object ); + var material = object.material; + + if ( Array.isArray( material ) ) { + + var groups = geometry.groups; + + for ( var k = 0, kl = groups.length; k < kl; k ++ ) { + + var group = groups[ k ]; + var groupMaterial = material[ group.materialIndex ]; + + if ( groupMaterial && groupMaterial.visible ) { + + var depthMaterial = getDepthMaterial( object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type ); + + _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group ); + + } + + } + + } else if ( material.visible ) { + + var depthMaterial$1 = getDepthMaterial( object, geometry, material, light, shadowCamera.near, shadowCamera.far, type ); + + _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial$1, object, null ); + + } + + } + + } + + var children = object.children; + + for ( var i = 0, l = children.length; i < l; i ++ ) { + + renderObject( children[ i ], camera, shadowCamera, light, type ); + + } + + } + + } + + function WebGLState( gl, extensions, capabilities ) { + + var isWebGL2 = capabilities.isWebGL2; + + function ColorBuffer() { + + var locked = false; + + var color = new Vector4(); + var currentColorMask = null; + var currentColorClear = new Vector4( 0, 0, 0, 0 ); + + return { + + setMask: function ( colorMask ) { + + if ( currentColorMask !== colorMask && ! locked ) { + + gl.colorMask( colorMask, colorMask, colorMask, colorMask ); + currentColorMask = colorMask; + + } + + }, + + setLocked: function ( lock ) { + + locked = lock; + + }, + + setClear: function ( r, g, b, a, premultipliedAlpha ) { + + if ( premultipliedAlpha === true ) { + + r *= a; g *= a; b *= a; + + } + + color.set( r, g, b, a ); + + if ( currentColorClear.equals( color ) === false ) { + + gl.clearColor( r, g, b, a ); + currentColorClear.copy( color ); + + } + + }, + + reset: function () { + + locked = false; + + currentColorMask = null; + currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state + + } + + }; + + } + + function DepthBuffer() { + + var locked = false; + + var currentDepthMask = null; + var currentDepthFunc = null; + var currentDepthClear = null; + + return { + + setTest: function ( depthTest ) { + + if ( depthTest ) { + + enable( 2929 ); + + } else { + + disable( 2929 ); + + } + + }, + + setMask: function ( depthMask ) { + + if ( currentDepthMask !== depthMask && ! locked ) { + + gl.depthMask( depthMask ); + currentDepthMask = depthMask; + + } + + }, + + setFunc: function ( depthFunc ) { + + if ( currentDepthFunc !== depthFunc ) { + + if ( depthFunc ) { + + switch ( depthFunc ) { + + case NeverDepth: + + gl.depthFunc( 512 ); + break; + + case AlwaysDepth: + + gl.depthFunc( 519 ); + break; + + case LessDepth: + + gl.depthFunc( 513 ); + break; + + case LessEqualDepth: + + gl.depthFunc( 515 ); + break; + + case EqualDepth: + + gl.depthFunc( 514 ); + break; + + case GreaterEqualDepth: + + gl.depthFunc( 518 ); + break; + + case GreaterDepth: + + gl.depthFunc( 516 ); + break; + + case NotEqualDepth: + + gl.depthFunc( 517 ); + break; + + default: + + gl.depthFunc( 515 ); + + } + + } else { + + gl.depthFunc( 515 ); + + } + + currentDepthFunc = depthFunc; + + } + + }, + + setLocked: function ( lock ) { + + locked = lock; + + }, + + setClear: function ( depth ) { + + if ( currentDepthClear !== depth ) { + + gl.clearDepth( depth ); + currentDepthClear = depth; + + } + + }, + + reset: function () { + + locked = false; + + currentDepthMask = null; + currentDepthFunc = null; + currentDepthClear = null; + + } + + }; + + } + + function StencilBuffer() { + + var locked = false; + + var currentStencilMask = null; + var currentStencilFunc = null; + var currentStencilRef = null; + var currentStencilFuncMask = null; + var currentStencilFail = null; + var currentStencilZFail = null; + var currentStencilZPass = null; + var currentStencilClear = null; + + return { + + setTest: function ( stencilTest ) { + + if ( ! locked ) { + + if ( stencilTest ) { + + enable( 2960 ); + + } else { + + disable( 2960 ); + + } + + } + + }, + + setMask: function ( stencilMask ) { + + if ( currentStencilMask !== stencilMask && ! locked ) { + + gl.stencilMask( stencilMask ); + currentStencilMask = stencilMask; + + } + + }, + + setFunc: function ( stencilFunc, stencilRef, stencilMask ) { + + if ( currentStencilFunc !== stencilFunc || + currentStencilRef !== stencilRef || + currentStencilFuncMask !== stencilMask ) { + + gl.stencilFunc( stencilFunc, stencilRef, stencilMask ); + + currentStencilFunc = stencilFunc; + currentStencilRef = stencilRef; + currentStencilFuncMask = stencilMask; + + } + + }, + + setOp: function ( stencilFail, stencilZFail, stencilZPass ) { + + if ( currentStencilFail !== stencilFail || + currentStencilZFail !== stencilZFail || + currentStencilZPass !== stencilZPass ) { + + gl.stencilOp( stencilFail, stencilZFail, stencilZPass ); + + currentStencilFail = stencilFail; + currentStencilZFail = stencilZFail; + currentStencilZPass = stencilZPass; + + } + + }, + + setLocked: function ( lock ) { + + locked = lock; + + }, + + setClear: function ( stencil ) { + + if ( currentStencilClear !== stencil ) { + + gl.clearStencil( stencil ); + currentStencilClear = stencil; + + } + + }, + + reset: function () { + + locked = false; + + currentStencilMask = null; + currentStencilFunc = null; + currentStencilRef = null; + currentStencilFuncMask = null; + currentStencilFail = null; + currentStencilZFail = null; + currentStencilZPass = null; + currentStencilClear = null; + + } + + }; + + } + + // + + var colorBuffer = new ColorBuffer(); + var depthBuffer = new DepthBuffer(); + var stencilBuffer = new StencilBuffer(); + + var enabledCapabilities = {}; + + var currentProgram = null; + + var currentBlendingEnabled = null; + var currentBlending = null; + var currentBlendEquation = null; + var currentBlendSrc = null; + var currentBlendDst = null; + var currentBlendEquationAlpha = null; + var currentBlendSrcAlpha = null; + var currentBlendDstAlpha = null; + var currentPremultipledAlpha = false; + + var currentFlipSided = null; + var currentCullFace = null; + + var currentLineWidth = null; + + var currentPolygonOffsetFactor = null; + var currentPolygonOffsetUnits = null; + + var maxTextures = gl.getParameter( 35661 ); + + var lineWidthAvailable = false; + var version = 0; + var glVersion = gl.getParameter( 7938 ); + + if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) { + + version = parseFloat( /^WebGL\ ([0-9])/.exec( glVersion )[ 1 ] ); + lineWidthAvailable = ( version >= 1.0 ); + + } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) { + + version = parseFloat( /^OpenGL\ ES\ ([0-9])/.exec( glVersion )[ 1 ] ); + lineWidthAvailable = ( version >= 2.0 ); + + } + + var currentTextureSlot = null; + var currentBoundTextures = {}; + + var currentScissor = new Vector4(); + var currentViewport = new Vector4(); + + function createTexture( type, target, count ) { + + var data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4. + var texture = gl.createTexture(); + + gl.bindTexture( type, texture ); + gl.texParameteri( type, 10241, 9728 ); + gl.texParameteri( type, 10240, 9728 ); + + for ( var i = 0; i < count; i ++ ) { + + gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data ); + + } + + return texture; + + } + + var emptyTextures = {}; + emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 ); + emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 ); + + // init + + colorBuffer.setClear( 0, 0, 0, 1 ); + depthBuffer.setClear( 1 ); + stencilBuffer.setClear( 0 ); + + enable( 2929 ); + depthBuffer.setFunc( LessEqualDepth ); + + setFlipSided( false ); + setCullFace( CullFaceBack ); + enable( 2884 ); + + setBlending( NoBlending ); + + // + + function enable( id ) { + + if ( enabledCapabilities[ id ] !== true ) { + + gl.enable( id ); + enabledCapabilities[ id ] = true; + + } + + } + + function disable( id ) { + + if ( enabledCapabilities[ id ] !== false ) { + + gl.disable( id ); + enabledCapabilities[ id ] = false; + + } + + } + + function useProgram( program ) { + + if ( currentProgram !== program ) { + + gl.useProgram( program ); + + currentProgram = program; + + return true; + + } + + return false; + + } + + var equationToGL = {}; + equationToGL[ AddEquation ] = 32774; + equationToGL[ SubtractEquation ] = 32778; + equationToGL[ ReverseSubtractEquation ] = 32779; + + if ( isWebGL2 ) { + + equationToGL[ MinEquation ] = 32775; + equationToGL[ MaxEquation ] = 32776; + + } else { + + var extension = extensions.get( 'EXT_blend_minmax' ); + + if ( extension !== null ) { + + equationToGL[ MinEquation ] = extension.MIN_EXT; + equationToGL[ MaxEquation ] = extension.MAX_EXT; + + } + + } + + var 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; + + function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) { + + if ( blending === NoBlending ) { + + if ( currentBlendingEnabled ) { + + disable( 3042 ); + currentBlendingEnabled = false; + + } + + return; + + } + + if ( ! currentBlendingEnabled ) { + + enable( 3042 ); + currentBlendingEnabled = true; + + } + + if ( blending !== CustomBlending ) { + + if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) { + + if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) { + + gl.blendEquation( 32774 ); + + currentBlendEquation = AddEquation; + currentBlendEquationAlpha = AddEquation; + + } + + if ( premultipliedAlpha ) { + + switch ( blending ) { + + case NormalBlending: + gl.blendFuncSeparate( 1, 771, 1, 771 ); + break; + + case AdditiveBlending: + gl.blendFunc( 1, 1 ); + break; + + case SubtractiveBlending: + gl.blendFuncSeparate( 0, 0, 769, 771 ); + break; + + case MultiplyBlending: + gl.blendFuncSeparate( 0, 768, 0, 770 ); + break; + + default: + console.error( 'THREE.WebGLState: Invalid blending: ', blending ); + break; + + } + + } else { + + switch ( blending ) { + + case NormalBlending: + gl.blendFuncSeparate( 770, 771, 1, 771 ); + break; + + case AdditiveBlending: + gl.blendFunc( 770, 1 ); + break; + + case SubtractiveBlending: + gl.blendFunc( 0, 769 ); + break; + + case MultiplyBlending: + gl.blendFunc( 0, 768 ); + break; + + default: + console.error( 'THREE.WebGLState: Invalid blending: ', blending ); + break; + + } + + } + + currentBlendSrc = null; + currentBlendDst = null; + currentBlendSrcAlpha = null; + currentBlendDstAlpha = null; + + currentBlending = blending; + currentPremultipledAlpha = premultipliedAlpha; + + } + + return; + + } + + // custom blending + + blendEquationAlpha = blendEquationAlpha || blendEquation; + blendSrcAlpha = blendSrcAlpha || blendSrc; + blendDstAlpha = blendDstAlpha || blendDst; + + if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) { + + gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] ); + + currentBlendEquation = blendEquation; + currentBlendEquationAlpha = blendEquationAlpha; + + } + + if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) { + + gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] ); + + currentBlendSrc = blendSrc; + currentBlendDst = blendDst; + currentBlendSrcAlpha = blendSrcAlpha; + currentBlendDstAlpha = blendDstAlpha; + + } + + currentBlending = blending; + currentPremultipledAlpha = null; + + } + + function setMaterial( material, frontFaceCW ) { + + material.side === DoubleSide + ? disable( 2884 ) + : enable( 2884 ); + + var flipSided = ( material.side === BackSide ); + if ( frontFaceCW ) { flipSided = ! flipSided; } + + setFlipSided( flipSided ); + + ( 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 ); + + depthBuffer.setFunc( material.depthFunc ); + depthBuffer.setTest( material.depthTest ); + depthBuffer.setMask( material.depthWrite ); + colorBuffer.setMask( material.colorWrite ); + + var stencilWrite = material.stencilWrite; + stencilBuffer.setTest( stencilWrite ); + if ( stencilWrite ) { + + stencilBuffer.setMask( material.stencilWriteMask ); + stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask ); + stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass ); + + } + + setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits ); + + } + + // + + function setFlipSided( flipSided ) { + + if ( currentFlipSided !== flipSided ) { + + if ( flipSided ) { + + gl.frontFace( 2304 ); + + } else { + + gl.frontFace( 2305 ); + + } + + currentFlipSided = flipSided; + + } + + } + + function setCullFace( cullFace ) { + + if ( cullFace !== CullFaceNone ) { + + enable( 2884 ); + + if ( cullFace !== currentCullFace ) { + + if ( cullFace === CullFaceBack ) { + + gl.cullFace( 1029 ); + + } else if ( cullFace === CullFaceFront ) { + + gl.cullFace( 1028 ); + + } else { + + gl.cullFace( 1032 ); + + } + + } + + } else { + + disable( 2884 ); + + } + + currentCullFace = cullFace; + + } + + function setLineWidth( width ) { + + if ( width !== currentLineWidth ) { + + if ( lineWidthAvailable ) { gl.lineWidth( width ); } + + currentLineWidth = width; + + } + + } + + function setPolygonOffset( polygonOffset, factor, units ) { + + if ( polygonOffset ) { + + enable( 32823 ); + + if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) { + + gl.polygonOffset( factor, units ); + + currentPolygonOffsetFactor = factor; + currentPolygonOffsetUnits = units; + + } + + } else { + + disable( 32823 ); + + } + + } + + function setScissorTest( scissorTest ) { + + if ( scissorTest ) { + + enable( 3089 ); + + } else { + + disable( 3089 ); + + } + + } + + // texture + + function activeTexture( webglSlot ) { + + if ( webglSlot === undefined ) { webglSlot = 33984 + maxTextures - 1; } + + if ( currentTextureSlot !== webglSlot ) { + + gl.activeTexture( webglSlot ); + currentTextureSlot = webglSlot; + + } + + } + + function bindTexture( webglType, webglTexture ) { + + if ( currentTextureSlot === null ) { + + activeTexture(); + + } + + var boundTexture = currentBoundTextures[ currentTextureSlot ]; + + if ( boundTexture === undefined ) { + + boundTexture = { type: undefined, texture: undefined }; + currentBoundTextures[ currentTextureSlot ] = boundTexture; + + } + + if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) { + + gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] ); + + boundTexture.type = webglType; + boundTexture.texture = webglTexture; + + } + + } + + function unbindTexture() { + + var boundTexture = currentBoundTextures[ currentTextureSlot ]; + + if ( boundTexture !== undefined && boundTexture.type !== undefined ) { + + gl.bindTexture( boundTexture.type, null ); + + boundTexture.type = undefined; + boundTexture.texture = undefined; + + } + + } + + function compressedTexImage2D() { + + try { + + gl.compressedTexImage2D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function texImage2D() { + + try { + + gl.texImage2D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + function texImage3D() { + + try { + + gl.texImage3D.apply( gl, arguments ); + + } catch ( error ) { + + console.error( 'THREE.WebGLState:', error ); + + } + + } + + // + + function scissor( scissor ) { + + if ( currentScissor.equals( scissor ) === false ) { + + gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w ); + currentScissor.copy( scissor ); + + } + + } + + function viewport( viewport ) { + + if ( currentViewport.equals( viewport ) === false ) { + + gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w ); + currentViewport.copy( viewport ); + + } + + } + + // + + function reset() { + + enabledCapabilities = {}; + + currentTextureSlot = null; + currentBoundTextures = {}; + + currentProgram = null; + + currentBlending = null; + + currentFlipSided = null; + currentCullFace = null; + + colorBuffer.reset(); + depthBuffer.reset(); + stencilBuffer.reset(); + + } + + return { + + buffers: { + color: colorBuffer, + depth: depthBuffer, + stencil: stencilBuffer + }, + + enable: enable, + disable: disable, + + useProgram: useProgram, + + setBlending: setBlending, + setMaterial: setMaterial, + + setFlipSided: setFlipSided, + setCullFace: setCullFace, + + setLineWidth: setLineWidth, + setPolygonOffset: setPolygonOffset, + + setScissorTest: setScissorTest, + + activeTexture: activeTexture, + bindTexture: bindTexture, + unbindTexture: unbindTexture, + compressedTexImage2D: compressedTexImage2D, + texImage2D: texImage2D, + texImage3D: texImage3D, + + scissor: scissor, + viewport: viewport, + + reset: reset + + }; + + } + + function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) { + + var isWebGL2 = capabilities.isWebGL2; + var maxTextures = capabilities.maxTextures; + var maxCubemapSize = capabilities.maxCubemapSize; + var maxTextureSize = capabilities.maxTextureSize; + var maxSamples = capabilities.maxSamples; + + var _videoTextures = new WeakMap(); + var _canvas; + + // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas, + // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")! + // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d). + + var useOffscreenCanvas = false; + + try { + + useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined' + && ( new OffscreenCanvas( 1, 1 ).getContext( "2d" ) ) !== null; + + } catch ( err ) { + + // Ignore any errors + + } + + function createCanvas( width, height ) { + + // Use OffscreenCanvas when available. Specially needed in web workers + + return useOffscreenCanvas ? + new OffscreenCanvas( width, height ) : + document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ); + + } + + function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) { + + var scale = 1; + + // handle case if texture exceeds max size + + if ( image.width > maxSize || image.height > maxSize ) { + + scale = maxSize / Math.max( image.width, image.height ); + + } + + // only perform resize if necessary + + if ( scale < 1 || needsPowerOfTwo === true ) { + + // only perform resize for certain image types + + if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) || + ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) || + ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) { + + var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor; + + var width = floor( scale * image.width ); + var height = floor( scale * image.height ); + + if ( _canvas === undefined ) { _canvas = createCanvas( width, height ); } + + // cube textures can't reuse the same canvas + + var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas; + + canvas.width = width; + canvas.height = height; + + var context = canvas.getContext( '2d' ); + context.drawImage( image, 0, 0, width, height ); + + console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' ); + + return canvas; + + } else { + + if ( 'data' in image ) { + + console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' ); + + } + + return image; + + } + + } + + return image; + + } + + function isPowerOfTwo( image ) { + + return MathUtils.isPowerOfTwo( image.width ) && MathUtils.isPowerOfTwo( image.height ); + + } + + function textureNeedsPowerOfTwo( texture ) { + + if ( isWebGL2 ) { return false; } + + return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) || + ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ); + + } + + function textureNeedsGenerateMipmaps( texture, supportsMips ) { + + return texture.generateMipmaps && supportsMips && + texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter; + + } + + function generateMipmap( target, texture, width, height ) { + + _gl.generateMipmap( target ); + + var textureProperties = properties.get( texture ); + + // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11 + textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E; + + } + + function getInternalFormat( internalFormatName, glFormat, glType ) { + + if ( isWebGL2 === false ) { return glFormat; } + + if ( internalFormatName !== null ) { + + if ( _gl[ internalFormatName ] !== undefined ) { return _gl[ internalFormatName ]; } + + console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' ); + + } + + var internalFormat = glFormat; + + if ( glFormat === 6403 ) { + + if ( glType === 5126 ) { internalFormat = 33326; } + if ( glType === 5131 ) { internalFormat = 33325; } + if ( glType === 5121 ) { internalFormat = 33321; } + + } + + if ( glFormat === 6407 ) { + + if ( glType === 5126 ) { internalFormat = 34837; } + if ( glType === 5131 ) { internalFormat = 34843; } + if ( glType === 5121 ) { internalFormat = 32849; } + + } + + if ( glFormat === 6408 ) { + + if ( glType === 5126 ) { internalFormat = 34836; } + if ( glType === 5131 ) { internalFormat = 34842; } + if ( glType === 5121 ) { internalFormat = 32856; } + + } + + if ( internalFormat === 33325 || internalFormat === 33326 || + internalFormat === 34842 || internalFormat === 34836 ) { + + extensions.get( 'EXT_color_buffer_float' ); + + } + + return internalFormat; + + } + + // Fallback filters for non-power-of-2 textures + + function filterFallback( f ) { + + if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) { + + return 9728; + + } + + return 9729; + + } + + // + + function onTextureDispose( event ) { + + var texture = event.target; + + texture.removeEventListener( 'dispose', onTextureDispose ); + + deallocateTexture( texture ); + + if ( texture.isVideoTexture ) { + + _videoTextures.delete( texture ); + + } + + info.memory.textures --; + + } + + function onRenderTargetDispose( event ) { + + var renderTarget = event.target; + + renderTarget.removeEventListener( 'dispose', onRenderTargetDispose ); + + deallocateRenderTarget( renderTarget ); + + info.memory.textures --; + + } + + // + + function deallocateTexture( texture ) { + + var textureProperties = properties.get( texture ); + + if ( textureProperties.__webglInit === undefined ) { return; } + + _gl.deleteTexture( textureProperties.__webglTexture ); + + properties.remove( texture ); + + } + + function deallocateRenderTarget( renderTarget ) { + + var renderTargetProperties = properties.get( renderTarget ); + var textureProperties = properties.get( renderTarget.texture ); + + if ( ! renderTarget ) { return; } + + if ( textureProperties.__webglTexture !== undefined ) { + + _gl.deleteTexture( textureProperties.__webglTexture ); + + } + + if ( renderTarget.depthTexture ) { + + renderTarget.depthTexture.dispose(); + + } + + if ( renderTarget.isWebGLCubeRenderTarget ) { + + for ( var i = 0; i < 6; i ++ ) { + + _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] ); + if ( renderTargetProperties.__webglDepthbuffer ) { _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] ); } + + } + + } else { + + _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer ); + if ( renderTargetProperties.__webglDepthbuffer ) { _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer ); } + if ( renderTargetProperties.__webglMultisampledFramebuffer ) { _gl.deleteFramebuffer( renderTargetProperties.__webglMultisampledFramebuffer ); } + if ( renderTargetProperties.__webglColorRenderbuffer ) { _gl.deleteRenderbuffer( renderTargetProperties.__webglColorRenderbuffer ); } + if ( renderTargetProperties.__webglDepthRenderbuffer ) { _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthRenderbuffer ); } + + } + + properties.remove( renderTarget.texture ); + properties.remove( renderTarget ); + + } + + // + + var textureUnits = 0; + + function resetTextureUnits() { + + textureUnits = 0; + + } + + function allocateTextureUnit() { + + var textureUnit = textureUnits; + + if ( textureUnit >= maxTextures ) { + + console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures ); + + } + + textureUnits += 1; + + return textureUnit; + + } + + // + + function setTexture2D( texture, slot ) { + + var textureProperties = properties.get( texture ); + + if ( texture.isVideoTexture ) { updateVideoTexture( texture ); } + + if ( texture.version > 0 && textureProperties.__version !== texture.version ) { + + var image = texture.image; + + if ( image === undefined ) { + + console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' ); + + } else if ( image.complete === false ) { + + console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' ); + + } else { + + uploadTexture( textureProperties, texture, slot ); + return; + + } + + } + + state.activeTexture( 33984 + slot ); + state.bindTexture( 3553, textureProperties.__webglTexture ); + + } + + function setTexture2DArray( texture, slot ) { + + var textureProperties = properties.get( texture ); + + if ( texture.version > 0 && textureProperties.__version !== texture.version ) { + + uploadTexture( textureProperties, texture, slot ); + return; + + } + + state.activeTexture( 33984 + slot ); + state.bindTexture( 35866, textureProperties.__webglTexture ); + + } + + function setTexture3D( texture, slot ) { + + var textureProperties = properties.get( texture ); + + if ( texture.version > 0 && textureProperties.__version !== texture.version ) { + + uploadTexture( textureProperties, texture, slot ); + return; + + } + + state.activeTexture( 33984 + slot ); + state.bindTexture( 32879, textureProperties.__webglTexture ); + + } + + function setTextureCube( texture, slot ) { + + if ( texture.image.length !== 6 ) { return; } + + var textureProperties = properties.get( texture ); + + if ( texture.version > 0 && textureProperties.__version !== texture.version ) { + + initTexture( textureProperties, texture ); + + state.activeTexture( 33984 + slot ); + state.bindTexture( 34067, textureProperties.__webglTexture ); + + _gl.pixelStorei( 37440, texture.flipY ); + + var isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) ); + var isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture ); + + var cubeImage = []; + + for ( var i = 0; i < 6; i ++ ) { + + if ( ! isCompressed && ! isDataTexture ) { + + cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, maxCubemapSize ); + + } else { + + cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ]; + + } + + } + + var image = cubeImage[ 0 ], + supportsMips = isPowerOfTwo( image ) || isWebGL2, + glFormat = utils.convert( texture.format ), + glType = utils.convert( texture.type ), + glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType ); + + setTextureParameters( 34067, texture, supportsMips ); + + var mipmaps; + + if ( isCompressed ) { + + for ( var i$1 = 0; i$1 < 6; i$1 ++ ) { + + mipmaps = cubeImage[ i$1 ].mipmaps; + + for ( var j = 0; j < mipmaps.length; j ++ ) { + + var mipmap = mipmaps[ j ]; + + if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) { + + if ( glFormat !== null ) { + + state.compressedTexImage2D( 34069 + i$1, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data ); + + } else { + + console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' ); + + } + + } else { + + state.texImage2D( 34069 + i$1, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data ); + + } + + } + + } + + textureProperties.__maxMipLevel = mipmaps.length - 1; + + } else { + + mipmaps = texture.mipmaps; + + for ( var i$2 = 0; i$2 < 6; i$2 ++ ) { + + if ( isDataTexture ) { + + state.texImage2D( 34069 + i$2, 0, glInternalFormat, cubeImage[ i$2 ].width, cubeImage[ i$2 ].height, 0, glFormat, glType, cubeImage[ i$2 ].data ); + + for ( var j$1 = 0; j$1 < mipmaps.length; j$1 ++ ) { + + var mipmap$1 = mipmaps[ j$1 ]; + var mipmapImage = mipmap$1.image[ i$2 ].image; + + state.texImage2D( 34069 + i$2, j$1 + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data ); + + } + + } else { + + state.texImage2D( 34069 + i$2, 0, glInternalFormat, glFormat, glType, cubeImage[ i$2 ] ); + + for ( var j$2 = 0; j$2 < mipmaps.length; j$2 ++ ) { + + var mipmap$2 = mipmaps[ j$2 ]; + + state.texImage2D( 34069 + i$2, j$2 + 1, glInternalFormat, glFormat, glType, mipmap$2.image[ i$2 ] ); + + } + + } + + } + + textureProperties.__maxMipLevel = mipmaps.length; + + } + + if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) { + + // We assume images for cube map have the same size. + generateMipmap( 34067, texture, image.width, image.height ); + + } + + textureProperties.__version = texture.version; + + if ( texture.onUpdate ) { texture.onUpdate( texture ); } + + } else { + + state.activeTexture( 33984 + slot ); + state.bindTexture( 34067, textureProperties.__webglTexture ); + + } + + } + + function setTextureCubeDynamic( texture, slot ) { + + state.activeTexture( 33984 + slot ); + state.bindTexture( 34067, properties.get( texture ).__webglTexture ); + + } + + var wrappingToGL = {}; + wrappingToGL[ RepeatWrapping ] = 10497; + wrappingToGL[ ClampToEdgeWrapping ] = 33071; + wrappingToGL[ MirroredRepeatWrapping ] = 33648; + + var filterToGL = {}; + filterToGL[ NearestFilter ] = 9728; + filterToGL[ NearestMipmapNearestFilter ] = 9984; + filterToGL[ NearestMipmapLinearFilter ] = 9986; + filterToGL[ LinearFilter ] = 9729; + filterToGL[ LinearMipmapNearestFilter ] = 9985; + filterToGL[ LinearMipmapLinearFilter ] = 9987; + + function setTextureParameters( textureType, texture, supportsMips ) { + + if ( supportsMips ) { + + _gl.texParameteri( textureType, 10242, wrappingToGL[ texture.wrapS ] ); + _gl.texParameteri( textureType, 10243, wrappingToGL[ texture.wrapT ] ); + + if ( textureType === 32879 || textureType === 35866 ) { + + _gl.texParameteri( textureType, 32882, wrappingToGL[ texture.wrapR ] ); + + } + + _gl.texParameteri( textureType, 10240, filterToGL[ texture.magFilter ] ); + _gl.texParameteri( textureType, 10241, filterToGL[ texture.minFilter ] ); + + } else { + + _gl.texParameteri( textureType, 10242, 33071 ); + _gl.texParameteri( textureType, 10243, 33071 ); + + if ( textureType === 32879 || textureType === 35866 ) { + + _gl.texParameteri( textureType, 32882, 33071 ); + + } + + if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) { + + console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' ); + + } + + _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) ); + _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) ); + + if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) { + + console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' ); + + } + + } + + var extension = extensions.get( 'EXT_texture_filter_anisotropic' ); + + if ( extension ) { + + if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) { return; } + if ( texture.type === HalfFloatType && ( isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) { return; } + + if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) { + + _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) ); + properties.get( texture ).__currentAnisotropy = texture.anisotropy; + + } + + } + + } + + function initTexture( textureProperties, texture ) { + + if ( textureProperties.__webglInit === undefined ) { + + textureProperties.__webglInit = true; + + texture.addEventListener( 'dispose', onTextureDispose ); + + textureProperties.__webglTexture = _gl.createTexture(); + + info.memory.textures ++; + + } + + } + + function uploadTexture( textureProperties, texture, slot ) { + + var textureType = 3553; + + if ( texture.isDataTexture2DArray ) { textureType = 35866; } + if ( texture.isDataTexture3D ) { textureType = 32879; } + + initTexture( textureProperties, texture ); + + state.activeTexture( 33984 + slot ); + state.bindTexture( textureType, textureProperties.__webglTexture ); + + _gl.pixelStorei( 37440, texture.flipY ); + _gl.pixelStorei( 37441, texture.premultiplyAlpha ); + _gl.pixelStorei( 3317, texture.unpackAlignment ); + + var needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false; + var image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize ); + + var supportsMips = isPowerOfTwo( image ) || isWebGL2, + glFormat = utils.convert( texture.format ); + + var glType = utils.convert( texture.type ), + glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType ); + + setTextureParameters( textureType, texture, supportsMips ); + + var mipmap; + var mipmaps = texture.mipmaps; + + if ( texture.isDepthTexture ) { + + // populate depth texture with dummy data + + glInternalFormat = 6402; + + if ( isWebGL2 ) { + + if ( texture.type === FloatType ) { + + glInternalFormat = 36012; + + } else if ( texture.type === UnsignedIntType ) { + + glInternalFormat = 33190; + + } else if ( texture.type === UnsignedInt248Type ) { + + glInternalFormat = 35056; + + } else { + + glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D + + } + + } else { + + if ( texture.type === FloatType ) { + + console.error( 'WebGLRenderer: Floating point depth texture requires WebGL2.' ); + + } + + } + + // validation checks for WebGL 1 + + if ( texture.format === DepthFormat && glInternalFormat === 6402 ) { + + // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are + // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT + // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/) + if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) { + + console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' ); + + texture.type = UnsignedShortType; + glType = utils.convert( texture.type ); + + } + + } + + if ( texture.format === DepthStencilFormat && glInternalFormat === 6402 ) { + + // Depth stencil textures need the DEPTH_STENCIL internal format + // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/) + glInternalFormat = 34041; + + // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are + // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL. + // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/) + if ( texture.type !== UnsignedInt248Type ) { + + console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' ); + + texture.type = UnsignedInt248Type; + glType = utils.convert( texture.type ); + + } + + } + + // + + state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null ); + + } else if ( texture.isDataTexture ) { + + // use manually created mipmaps if available + // if there are no manual mipmaps + // set 0 level mipmap and then use GL to generate other mipmap levels + + if ( mipmaps.length > 0 && supportsMips ) { + + for ( var i = 0, il = mipmaps.length; i < il; i ++ ) { + + mipmap = mipmaps[ i ]; + state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data ); + + } + + texture.generateMipmaps = false; + textureProperties.__maxMipLevel = mipmaps.length - 1; + + } else { + + state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data ); + textureProperties.__maxMipLevel = 0; + + } + + } else if ( texture.isCompressedTexture ) { + + for ( var i$1 = 0, il$1 = mipmaps.length; i$1 < il$1; i$1 ++ ) { + + mipmap = mipmaps[ i$1 ]; + + if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) { + + if ( glFormat !== null ) { + + state.compressedTexImage2D( 3553, i$1, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data ); + + } else { + + console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' ); + + } + + } else { + + state.texImage2D( 3553, i$1, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data ); + + } + + } + + textureProperties.__maxMipLevel = mipmaps.length - 1; + + } else if ( texture.isDataTexture2DArray ) { + + state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data ); + textureProperties.__maxMipLevel = 0; + + } else if ( texture.isDataTexture3D ) { + + state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data ); + textureProperties.__maxMipLevel = 0; + + } else { + + // regular Texture (image, video, canvas) + + // use manually created mipmaps if available + // if there are no manual mipmaps + // set 0 level mipmap and then use GL to generate other mipmap levels + + if ( mipmaps.length > 0 && supportsMips ) { + + for ( var i$2 = 0, il$2 = mipmaps.length; i$2 < il$2; i$2 ++ ) { + + mipmap = mipmaps[ i$2 ]; + state.texImage2D( 3553, i$2, glInternalFormat, glFormat, glType, mipmap ); + + } + + texture.generateMipmaps = false; + textureProperties.__maxMipLevel = mipmaps.length - 1; + + } else { + + state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image ); + textureProperties.__maxMipLevel = 0; + + } + + } + + if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) { + + generateMipmap( textureType, texture, image.width, image.height ); + + } + + textureProperties.__version = texture.version; + + if ( texture.onUpdate ) { texture.onUpdate( texture ); } + + } + + // Render targets + + // Setup storage for target texture and bind it to correct framebuffer + function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) { + + var glFormat = utils.convert( renderTarget.texture.format ); + var glType = utils.convert( renderTarget.texture.type ); + var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType ); + state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null ); + _gl.bindFramebuffer( 36160, framebuffer ); + _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 ); + _gl.bindFramebuffer( 36160, null ); + + } + + // Setup storage for internal depth/stencil buffers and bind to correct framebuffer + function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) { + + _gl.bindRenderbuffer( 36161, renderbuffer ); + + if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) { + + var glInternalFormat = 33189; + + if ( isMultisample ) { + + var depthTexture = renderTarget.depthTexture; + + if ( depthTexture && depthTexture.isDepthTexture ) { + + if ( depthTexture.type === FloatType ) { + + glInternalFormat = 36012; + + } else if ( depthTexture.type === UnsignedIntType ) { + + glInternalFormat = 33190; + + } + + } + + var samples = getRenderTargetSamples( renderTarget ); + + _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height ); + + } else { + + _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height ); + + } + + _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer ); + + } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) { + + if ( isMultisample ) { + + var samples$1 = getRenderTargetSamples( renderTarget ); + + _gl.renderbufferStorageMultisample( 36161, samples$1, 35056, renderTarget.width, renderTarget.height ); + + } else { + + _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height ); + + } + + + _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer ); + + } else { + + var glFormat = utils.convert( renderTarget.texture.format ); + var glType = utils.convert( renderTarget.texture.type ); + var glInternalFormat$1 = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType ); + + if ( isMultisample ) { + + var samples$2 = getRenderTargetSamples( renderTarget ); + + _gl.renderbufferStorageMultisample( 36161, samples$2, glInternalFormat$1, renderTarget.width, renderTarget.height ); + + } else { + + _gl.renderbufferStorage( 36161, glInternalFormat$1, renderTarget.width, renderTarget.height ); + + } + + } + + _gl.bindRenderbuffer( 36161, null ); + + } + + // Setup resources for a Depth Texture for a FBO (needs an extension) + function setupDepthTexture( framebuffer, renderTarget ) { + + var isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget ); + if ( isCube ) { throw new Error( 'Depth Texture with cube render targets is not supported' ); } + + _gl.bindFramebuffer( 36160, framebuffer ); + + if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) { + + throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' ); + + } + + // upload an empty depth texture with framebuffer size + if ( ! properties.get( renderTarget.depthTexture ).__webglTexture || + renderTarget.depthTexture.image.width !== renderTarget.width || + renderTarget.depthTexture.image.height !== renderTarget.height ) { + + renderTarget.depthTexture.image.width = renderTarget.width; + renderTarget.depthTexture.image.height = renderTarget.height; + renderTarget.depthTexture.needsUpdate = true; + + } + + setTexture2D( renderTarget.depthTexture, 0 ); + + var webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture; + + if ( renderTarget.depthTexture.format === DepthFormat ) { + + _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 ); + + } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) { + + _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 ); + + } else { + + throw new Error( 'Unknown depthTexture format' ); + + } + + } + + // Setup GL resources for a non-texture depth buffer + function setupDepthRenderbuffer( renderTarget ) { + + var renderTargetProperties = properties.get( renderTarget ); + + var isCube = ( renderTarget.isWebGLCubeRenderTarget === true ); + + if ( renderTarget.depthTexture ) { + + if ( isCube ) { throw new Error( 'target.depthTexture not supported in Cube render targets' ); } + + setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget ); + + } else { + + if ( isCube ) { + + renderTargetProperties.__webglDepthbuffer = []; + + for ( var i = 0; i < 6; i ++ ) { + + _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] ); + renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer(); + setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false ); + + } + + } else { + + _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer ); + renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer(); + setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false ); + + } + + } + + _gl.bindFramebuffer( 36160, null ); + + } + + // Set up GL resources for the render target + function setupRenderTarget( renderTarget ) { + + var renderTargetProperties = properties.get( renderTarget ); + var textureProperties = properties.get( renderTarget.texture ); + + renderTarget.addEventListener( 'dispose', onRenderTargetDispose ); + + textureProperties.__webglTexture = _gl.createTexture(); + + info.memory.textures ++; + + var isCube = ( renderTarget.isWebGLCubeRenderTarget === true ); + var isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true ); + var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2; + + // Handles WebGL2 RGBFormat fallback - #18858 + + if ( isWebGL2 && renderTarget.texture.format === RGBFormat && ( renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType ) ) { + + renderTarget.texture.format = RGBAFormat; + + console.warn( 'THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.' ); + + } + + // Setup framebuffer + + if ( isCube ) { + + renderTargetProperties.__webglFramebuffer = []; + + for ( var i = 0; i < 6; i ++ ) { + + renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer(); + + } + + } else { + + renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer(); + + if ( isMultisample ) { + + if ( isWebGL2 ) { + + renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer(); + renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer(); + + _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer ); + + var glFormat = utils.convert( renderTarget.texture.format ); + var glType = utils.convert( renderTarget.texture.type ); + var glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType ); + var samples = getRenderTargetSamples( renderTarget ); + _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height ); + + _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer ); + _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer ); + _gl.bindRenderbuffer( 36161, null ); + + if ( renderTarget.depthBuffer ) { + + renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer(); + setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true ); + + } + + _gl.bindFramebuffer( 36160, null ); + + + } else { + + console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' ); + + } + + } + + } + + // Setup color buffer + + if ( isCube ) { + + state.bindTexture( 34067, textureProperties.__webglTexture ); + setTextureParameters( 34067, renderTarget.texture, supportsMips ); + + for ( var i$1 = 0; i$1 < 6; i$1 ++ ) { + + setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i$1 ], renderTarget, 36064, 34069 + i$1 ); + + } + + if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) { + + generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height ); + + } + + state.bindTexture( 34067, null ); + + } else { + + state.bindTexture( 3553, textureProperties.__webglTexture ); + setTextureParameters( 3553, renderTarget.texture, supportsMips ); + setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 ); + + if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) { + + generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height ); + + } + + state.bindTexture( 3553, null ); + + } + + // Setup depth and stencil buffers + + if ( renderTarget.depthBuffer ) { + + setupDepthRenderbuffer( renderTarget ); + + } + + } + + function updateRenderTargetMipmap( renderTarget ) { + + var texture = renderTarget.texture; + var supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2; + + if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) { + + var target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553; + var webglTexture = properties.get( texture ).__webglTexture; + + state.bindTexture( target, webglTexture ); + generateMipmap( target, texture, renderTarget.width, renderTarget.height ); + state.bindTexture( target, null ); + + } + + } + + function updateMultisampleRenderTarget( renderTarget ) { + + if ( renderTarget.isWebGLMultisampleRenderTarget ) { + + if ( isWebGL2 ) { + + var renderTargetProperties = properties.get( renderTarget ); + + _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer ); + _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer ); + + var width = renderTarget.width; + var height = renderTarget.height; + var mask = 16384; + + if ( renderTarget.depthBuffer ) { mask |= 256; } + if ( renderTarget.stencilBuffer ) { mask |= 1024; } + + _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 ); + + _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer ); // see #18905 + + } else { + + console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' ); + + } + + } + + } + + function getRenderTargetSamples( renderTarget ) { + + return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ? + Math.min( maxSamples, renderTarget.samples ) : 0; + + } + + function updateVideoTexture( texture ) { + + var frame = info.render.frame; + + // Check the last frame we updated the VideoTexture + + if ( _videoTextures.get( texture ) !== frame ) { + + _videoTextures.set( texture, frame ); + texture.update(); + + } + + } + + // backwards compatibility + + var warnedTexture2D = false; + var warnedTextureCube = false; + + function safeSetTexture2D( texture, slot ) { + + if ( texture && texture.isWebGLRenderTarget ) { + + if ( warnedTexture2D === false ) { + + console.warn( "THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead." ); + warnedTexture2D = true; + + } + + texture = texture.texture; + + } + + setTexture2D( texture, slot ); + + } + + function safeSetTextureCube( texture, slot ) { + + if ( texture && texture.isWebGLCubeRenderTarget ) { + + if ( warnedTextureCube === false ) { + + console.warn( "THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead." ); + warnedTextureCube = true; + + } + + texture = texture.texture; + + } + + // currently relying on the fact that WebGLCubeRenderTarget.texture is a Texture and NOT a CubeTexture + // TODO: unify these code paths + if ( ( texture && texture.isCubeTexture ) || + ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) { + + // CompressedTexture can have Array in image :/ + + // this function alone should take care of cube textures + setTextureCube( texture, slot ); + + } else { + + // assumed: texture property of THREE.WebGLCubeRenderTarget + setTextureCubeDynamic( texture, slot ); + + } + + } + + // + + this.allocateTextureUnit = allocateTextureUnit; + this.resetTextureUnits = resetTextureUnits; + + this.setTexture2D = setTexture2D; + this.setTexture2DArray = setTexture2DArray; + this.setTexture3D = setTexture3D; + this.setTextureCube = setTextureCube; + this.setTextureCubeDynamic = setTextureCubeDynamic; + this.setupRenderTarget = setupRenderTarget; + this.updateRenderTargetMipmap = updateRenderTargetMipmap; + this.updateMultisampleRenderTarget = updateMultisampleRenderTarget; + + this.safeSetTexture2D = safeSetTexture2D; + this.safeSetTextureCube = safeSetTextureCube; + + } + + function WebGLUtils( gl, extensions, capabilities ) { + + var isWebGL2 = capabilities.isWebGL2; + + function convert( p ) { + + var extension; + + if ( p === UnsignedByteType ) { return 5121; } + if ( p === UnsignedShort4444Type ) { return 32819; } + if ( p === UnsignedShort5551Type ) { return 32820; } + if ( p === UnsignedShort565Type ) { return 33635; } + + if ( p === ByteType ) { return 5120; } + if ( p === ShortType ) { return 5122; } + if ( p === UnsignedShortType ) { return 5123; } + if ( p === IntType ) { return 5124; } + if ( p === UnsignedIntType ) { return 5125; } + if ( p === FloatType ) { return 5126; } + + if ( p === HalfFloatType ) { + + if ( isWebGL2 ) { return 5131; } + + extension = extensions.get( 'OES_texture_half_float' ); + + if ( extension !== null ) { + + return extension.HALF_FLOAT_OES; + + } else { + + return null; + + } + + } + + if ( p === AlphaFormat ) { return 6406; } + if ( p === RGBFormat ) { return 6407; } + if ( p === RGBAFormat ) { return 6408; } + if ( p === LuminanceFormat ) { return 6409; } + if ( p === LuminanceAlphaFormat ) { return 6410; } + if ( p === DepthFormat ) { return 6402; } + if ( p === DepthStencilFormat ) { return 34041; } + if ( p === RedFormat ) { return 6403; } + + // WebGL2 formats. + + if ( p === RedIntegerFormat ) { return 36244; } + if ( p === RGFormat ) { return 33319; } + if ( p === RGIntegerFormat ) { return 33320; } + if ( p === RGBIntegerFormat ) { return 36248; } + if ( p === RGBAIntegerFormat ) { return 36249; } + + if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || + p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format ) { + + extension = extensions.get( 'WEBGL_compressed_texture_s3tc' ); + + if ( extension !== null ) { + + if ( p === RGB_S3TC_DXT1_Format ) { return extension.COMPRESSED_RGB_S3TC_DXT1_EXT; } + if ( p === RGBA_S3TC_DXT1_Format ) { return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT; } + if ( p === RGBA_S3TC_DXT3_Format ) { return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT; } + if ( p === RGBA_S3TC_DXT5_Format ) { return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT; } + + } else { + + return null; + + } + + } + + if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || + p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) { + + extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' ); + + if ( extension !== null ) { + + if ( p === RGB_PVRTC_4BPPV1_Format ) { return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG; } + if ( p === RGB_PVRTC_2BPPV1_Format ) { return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG; } + if ( p === RGBA_PVRTC_4BPPV1_Format ) { return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; } + if ( p === RGBA_PVRTC_2BPPV1_Format ) { return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; } + + } else { + + return null; + + } + + } + + if ( p === RGB_ETC1_Format ) { + + extension = extensions.get( 'WEBGL_compressed_texture_etc1' ); + + if ( extension !== null ) { + + return extension.COMPRESSED_RGB_ETC1_WEBGL; + + } else { + + return null; + + } + + } + + if ( p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) { + + extension = extensions.get( 'WEBGL_compressed_texture_etc' ); + + if ( extension !== null ) { + + if ( p === RGB_ETC2_Format ) { return extension.COMPRESSED_RGB8_ETC2; } + if ( p === RGBA_ETC2_EAC_Format ) { return extension.COMPRESSED_RGBA8_ETC2_EAC; } + + } + + } + + 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 ) { + + extension = extensions.get( 'WEBGL_compressed_texture_astc' ); + + if ( extension !== null ) { + + // TODO Complete? + + return p; + + } else { + + return null; + + } + + } + + if ( p === RGBA_BPTC_Format ) { + + extension = extensions.get( 'EXT_texture_compression_bptc' ); + + if ( extension !== null ) { + + // TODO Complete? + + return p; + + } else { + + return null; + + } + + } + + if ( p === UnsignedInt248Type ) { + + if ( isWebGL2 ) { return 34042; } + + extension = extensions.get( 'WEBGL_depth_texture' ); + + if ( extension !== null ) { + + return extension.UNSIGNED_INT_24_8_WEBGL; + + } else { + + return null; + + } + + } + + } + + return { convert: convert }; + + } + + function ArrayCamera( array ) { + + PerspectiveCamera.call( this ); + + this.cameras = array || []; + + } + + ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), { + + constructor: ArrayCamera, + + isArrayCamera: true + + } ); + + function Group() { + + Object3D.call( this ); + + this.type = 'Group'; + + } + + Group.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: Group, + + isGroup: true + + } ); + + function WebXRController() { + + this._targetRay = null; + this._grip = null; + this._hand = null; + + } + + Object.assign( WebXRController.prototype, { + + constructor: WebXRController, + + getHandSpace: function () { + + if ( this._hand === null ) { + + this._hand = new Group(); + this._hand.matrixAutoUpdate = false; + this._hand.visible = false; + + this._hand.joints = []; + this._hand.inputState = { pinching: false }; + + if ( window.XRHand ) { + + for ( var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) { + + // The transform of this joint will be updated with the joint pose on each frame + var joint = new Group(); + joint.matrixAutoUpdate = false; + joint.visible = false; + this._hand.joints.push( joint ); + // ?? + this._hand.add( joint ); + + } + + } + + } + + return this._hand; + + }, + + getTargetRaySpace: function () { + + if ( this._targetRay === null ) { + + this._targetRay = new Group(); + this._targetRay.matrixAutoUpdate = false; + this._targetRay.visible = false; + + } + + return this._targetRay; + + }, + + getGripSpace: function () { + + if ( this._grip === null ) { + + this._grip = new Group(); + this._grip.matrixAutoUpdate = false; + this._grip.visible = false; + + } + + return this._grip; + + }, + + dispatchEvent: function ( event ) { + + if ( this._targetRay !== null ) { + + this._targetRay.dispatchEvent( event ); + + } + + if ( this._grip !== null ) { + + this._grip.dispatchEvent( event ); + + } + + if ( this._hand !== null ) { + + this._hand.dispatchEvent( event ); + + } + + return this; + + }, + + disconnect: function ( inputSource ) { + + this.dispatchEvent( { type: 'disconnected', data: inputSource } ); + + if ( this._targetRay !== null ) { + + this._targetRay.visible = false; + + } + + if ( this._grip !== null ) { + + this._grip.visible = false; + + } + + if ( this._hand !== null ) { + + this._hand.visible = false; + + } + + return this; + + }, + + update: function ( inputSource, frame, referenceSpace ) { + + var inputPose = null; + var gripPose = null; + var handPose = null; + + var targetRay = this._targetRay; + var grip = this._grip; + var hand = this._hand; + + if ( inputSource ) { + + if ( inputSource.hand ) { + + handPose = true; + + for ( var i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) { + + if ( inputSource.hand[ i ] ) { + + // Update the joints groups with the XRJoint poses + var jointPose = frame.getJointPose( inputSource.hand[ i ], referenceSpace ); + var joint = hand.joints[ i ]; + + if ( jointPose !== null ) { + + joint.matrix.fromArray( jointPose.transform.matrix ); + joint.matrix.decompose( joint.position, joint.rotation, joint.scale ); + joint.jointRadius = jointPose.radius; + + } + + joint.visible = jointPose !== null; + + // Custom events + + // Check pinch + var indexTip = hand.joints[ window.XRHand.INDEX_PHALANX_TIP ]; + var thumbTip = hand.joints[ window.XRHand.THUMB_PHALANX_TIP ]; + var distance = indexTip.position.distanceTo( thumbTip.position ); + + var distanceToPinch = 0.02; + var threshold = 0.005; + + if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) { + + hand.inputState.pinching = false; + this.dispatchEvent( { + type: "pinchend", + handedness: inputSource.handedness, + target: this + } ); + + } else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) { + + hand.inputState.pinching = true; + this.dispatchEvent( { + type: "pinchstart", + handedness: inputSource.handedness, + target: this + } ); + + } + + } + + } + + } else { + + if ( targetRay !== null ) { + + inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace ); + + if ( inputPose !== null ) { + + targetRay.matrix.fromArray( inputPose.transform.matrix ); + targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale ); + + } + + } + + if ( grip !== null && inputSource.gripSpace ) { + + gripPose = frame.getPose( inputSource.gripSpace, referenceSpace ); + + if ( gripPose !== null ) { + + grip.matrix.fromArray( gripPose.transform.matrix ); + grip.matrix.decompose( grip.position, grip.rotation, grip.scale ); + + } + + } + + } + + } + + if ( targetRay !== null ) { + + targetRay.visible = ( inputPose !== null ); + + } + + if ( grip !== null ) { + + grip.visible = ( gripPose !== null ); + + } + + if ( hand !== null ) { + + hand.visible = ( handPose !== null ); + + } + + return this; + + } + + } ); + + function WebXRManager( renderer, gl ) { + + var scope = this; + + var session = null; + + var framebufferScaleFactor = 1.0; + + var referenceSpace = null; + var referenceSpaceType = 'local-floor'; + + var pose = null; + + var controllers = []; + var inputSourcesMap = new Map(); + + // + + var cameraL = new PerspectiveCamera(); + cameraL.layers.enable( 1 ); + cameraL.viewport = new Vector4(); + + var cameraR = new PerspectiveCamera(); + cameraR.layers.enable( 2 ); + cameraR.viewport = new Vector4(); + + var cameras = [ cameraL, cameraR ]; + + var cameraVR = new ArrayCamera(); + cameraVR.layers.enable( 1 ); + cameraVR.layers.enable( 2 ); + + var _currentDepthNear = null; + var _currentDepthFar = null; + + // + + this.enabled = false; + + this.isPresenting = false; + + this.getController = function ( index ) { + + var controller = controllers[ index ]; + + if ( controller === undefined ) { + + controller = new WebXRController(); + controllers[ index ] = controller; + + } + + return controller.getTargetRaySpace(); + + }; + + this.getControllerGrip = function ( index ) { + + var controller = controllers[ index ]; + + if ( controller === undefined ) { + + controller = new WebXRController(); + controllers[ index ] = controller; + + } + + return controller.getGripSpace(); + + }; + + this.getHand = function ( index ) { + + var controller = controllers[ index ]; + + if ( controller === undefined ) { + + controller = new WebXRController(); + controllers[ index ] = controller; + + } + + return controller.getHandSpace(); + + }; + + // + + function onSessionEvent( event ) { + + var controller = inputSourcesMap.get( event.inputSource ); + + if ( controller ) { + + controller.dispatchEvent( { type: event.type } ); + + } + + } + + function onSessionEnd() { + + inputSourcesMap.forEach( function ( controller, inputSource ) { + + controller.disconnect( inputSource ); + + } ); + + inputSourcesMap.clear(); + + // + + renderer.setFramebuffer( null ); + renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830 + animation.stop(); + + scope.isPresenting = false; + + scope.dispatchEvent( { type: 'sessionend' } ); + + } + + function onRequestReferenceSpace( value ) { + + referenceSpace = value; + + animation.setContext( session ); + animation.start(); + + scope.isPresenting = true; + + scope.dispatchEvent( { type: 'sessionstart' } ); + + } + + this.setFramebufferScaleFactor = function ( value ) { + + framebufferScaleFactor = value; + + if ( scope.isPresenting === true ) { + + console.warn( 'THREE.WebXRManager: Cannot change framebuffer scale while presenting.' ); + + } + + }; + + this.setReferenceSpaceType = function ( value ) { + + referenceSpaceType = value; + + if ( scope.isPresenting === true ) { + + console.warn( 'THREE.WebXRManager: Cannot change reference space type while presenting.' ); + + } + + }; + + this.getReferenceSpace = function () { + + return referenceSpace; + + }; + + this.getSession = function () { + + return session; + + }; + + this.setSession = function ( value ) { + + session = value; + + if ( session !== null ) { + + session.addEventListener( 'select', onSessionEvent ); + session.addEventListener( 'selectstart', onSessionEvent ); + session.addEventListener( 'selectend', onSessionEvent ); + session.addEventListener( 'squeeze', onSessionEvent ); + session.addEventListener( 'squeezestart', onSessionEvent ); + session.addEventListener( 'squeezeend', onSessionEvent ); + session.addEventListener( 'end', onSessionEnd ); + + var attributes = gl.getContextAttributes(); + + if ( attributes.xrCompatible !== true ) { + + gl.makeXRCompatible(); + + } + + var layerInit = { + antialias: attributes.antialias, + alpha: attributes.alpha, + depth: attributes.depth, + stencil: attributes.stencil, + framebufferScaleFactor: framebufferScaleFactor + }; + + // eslint-disable-next-line no-undef + var baseLayer = new XRWebGLLayer( session, gl, layerInit ); + + session.updateRenderState( { baseLayer: baseLayer } ); + + session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace ); + + // + + session.addEventListener( 'inputsourceschange', updateInputSources ); + + } + + }; + + function updateInputSources( event ) { + + var inputSources = session.inputSources; + + // Assign inputSources to available controllers + + for ( var i = 0; i < controllers.length; i ++ ) { + + inputSourcesMap.set( inputSources[ i ], controllers[ i ] ); + + } + + // Notify disconnected + + for ( var i$1 = 0; i$1 < event.removed.length; i$1 ++ ) { + + var inputSource = event.removed[ i$1 ]; + var controller = inputSourcesMap.get( inputSource ); + + if ( controller ) { + + controller.dispatchEvent( { type: 'disconnected', data: inputSource } ); + inputSourcesMap.delete( inputSource ); + + } + + } + + // Notify connected + + for ( var i$2 = 0; i$2 < event.added.length; i$2 ++ ) { + + var inputSource$1 = event.added[ i$2 ]; + var controller$1 = inputSourcesMap.get( inputSource$1 ); + + if ( controller$1 ) { + + controller$1.dispatchEvent( { type: 'connected', data: inputSource$1 } ); + + } + + } + + } + + // + + var cameraLPos = new Vector3(); + var cameraRPos = new Vector3(); + + /** + * Assumes 2 cameras that are parallel and share an X-axis, and that + * the cameras' projection and world matrices have already been set. + * And that near and far planes are identical for both cameras. + * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765 + */ + function setProjectionFromUnion( camera, cameraL, cameraR ) { + + cameraLPos.setFromMatrixPosition( cameraL.matrixWorld ); + cameraRPos.setFromMatrixPosition( cameraR.matrixWorld ); + + var ipd = cameraLPos.distanceTo( cameraRPos ); + + var projL = cameraL.projectionMatrix.elements; + var projR = cameraR.projectionMatrix.elements; + + // VR systems will have identical far and near planes, and + // most likely identical top and bottom frustum extents. + // Use the left camera for these values. + var near = projL[ 14 ] / ( projL[ 10 ] - 1 ); + var far = projL[ 14 ] / ( projL[ 10 ] + 1 ); + var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ]; + var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ]; + + var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ]; + var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ]; + var left = near * leftFov; + var right = near * rightFov; + + // Calculate the new camera's position offset from the + // left camera. xOffset should be roughly half `ipd`. + var zOffset = ipd / ( - leftFov + rightFov ); + var xOffset = zOffset * - leftFov; + + // TODO: Better way to apply this offset? + cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale ); + camera.translateX( xOffset ); + camera.translateZ( zOffset ); + camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale ); + camera.matrixWorldInverse.getInverse( camera.matrixWorld ); + + // Find the union of the frustum values of the cameras and scale + // the values so that the near plane's position does not change in world space, + // although must now be relative to the new union camera. + var near2 = near + zOffset; + var far2 = far + zOffset; + var left2 = left - xOffset; + var right2 = right + ( ipd - xOffset ); + var top2 = topFov * far / far2 * near2; + var bottom2 = bottomFov * far / far2 * near2; + + camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 ); + + } + + function updateCamera( camera, parent ) { + + if ( parent === null ) { + + camera.matrixWorld.copy( camera.matrix ); + + } else { + + camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix ); + + } + + camera.matrixWorldInverse.getInverse( camera.matrixWorld ); + + } + + this.getCamera = function ( camera ) { + + cameraVR.near = cameraR.near = cameraL.near = camera.near; + cameraVR.far = cameraR.far = cameraL.far = camera.far; + + if ( _currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far ) { + + // Note that the new renderState won't apply until the next frame. See #18320 + + session.updateRenderState( { + depthNear: cameraVR.near, + depthFar: cameraVR.far + } ); + + _currentDepthNear = cameraVR.near; + _currentDepthFar = cameraVR.far; + + } + + var parent = camera.parent; + var cameras = cameraVR.cameras; + + updateCamera( cameraVR, parent ); + + for ( var i = 0; i < cameras.length; i ++ ) { + + updateCamera( cameras[ i ], parent ); + + } + + // update camera and its children + + camera.matrixWorld.copy( cameraVR.matrixWorld ); + + var children = camera.children; + + for ( var i$1 = 0, l = children.length; i$1 < l; i$1 ++ ) { + + children[ i$1 ].updateMatrixWorld( true ); + + } + + // update projection matrix for proper view frustum culling + + if ( cameras.length === 2 ) { + + setProjectionFromUnion( cameraVR, cameraL, cameraR ); + + } else { + + // assume single camera setup (AR) + + cameraVR.projectionMatrix.copy( cameraL.projectionMatrix ); + + } + + return cameraVR; + + }; + + // Animation Loop + + var onAnimationFrameCallback = null; + + function onAnimationFrame( time, frame ) { + + pose = frame.getViewerPose( referenceSpace ); + + if ( pose !== null ) { + + var views = pose.views; + var baseLayer = session.renderState.baseLayer; + + renderer.setFramebuffer( baseLayer.framebuffer ); + + var cameraVRNeedsUpdate = false; + + // check if it's necessary to rebuild cameraVR's camera list + + if ( views.length !== cameraVR.cameras.length ) { + + cameraVR.cameras.length = 0; + cameraVRNeedsUpdate = true; + + } + + for ( var i = 0; i < views.length; i ++ ) { + + var view = views[ i ]; + var viewport = baseLayer.getViewport( view ); + + var camera = cameras[ i ]; + camera.matrix.fromArray( view.transform.matrix ); + camera.projectionMatrix.fromArray( view.projectionMatrix ); + camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height ); + + if ( i === 0 ) { + + cameraVR.matrix.copy( camera.matrix ); + + } + + if ( cameraVRNeedsUpdate === true ) { + + cameraVR.cameras.push( camera ); + + } + + } + + } + + // + + var inputSources = session.inputSources; + + for ( var i$1 = 0; i$1 < controllers.length; i$1 ++ ) { + + var controller = controllers[ i$1 ]; + var inputSource = inputSources[ i$1 ]; + + controller.update( inputSource, frame, referenceSpace ); + + } + + if ( onAnimationFrameCallback ) { onAnimationFrameCallback( time, frame ); } + + } + + var animation = new WebGLAnimation(); + animation.setAnimationLoop( onAnimationFrame ); + + this.setAnimationLoop = function ( callback ) { + + onAnimationFrameCallback = callback; + + }; + + this.dispose = function () {}; + + } + + Object.assign( WebXRManager.prototype, EventDispatcher.prototype ); + + function WebGLMaterials( properties ) { + + function refreshFogUniforms( uniforms, fog ) { + + uniforms.fogColor.value.copy( fog.color ); + + if ( fog.isFog ) { + + uniforms.fogNear.value = fog.near; + uniforms.fogFar.value = fog.far; + + } else if ( fog.isFogExp2 ) { + + uniforms.fogDensity.value = fog.density; + + } + + } + + function refreshMaterialUniforms( uniforms, material, environment, pixelRatio, height ) { + + if ( material.isMeshBasicMaterial ) { + + refreshUniformsCommon( uniforms, material ); + + } else if ( material.isMeshLambertMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsLambert( uniforms, material ); + + } else if ( material.isMeshToonMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsToon( uniforms, material ); + + } else if ( material.isMeshPhongMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsPhong( uniforms, material ); + + } else if ( material.isMeshStandardMaterial ) { + + refreshUniformsCommon( uniforms, material, environment ); + + if ( material.isMeshPhysicalMaterial ) { + + refreshUniformsPhysical( uniforms, material, environment ); + + } else { + + refreshUniformsStandard( uniforms, material, environment ); + + } + + } else if ( material.isMeshMatcapMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsMatcap( uniforms, material ); + + } else if ( material.isMeshDepthMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsDepth( uniforms, material ); + + } else if ( material.isMeshDistanceMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsDistance( uniforms, material ); + + } else if ( material.isMeshNormalMaterial ) { + + refreshUniformsCommon( uniforms, material ); + refreshUniformsNormal( uniforms, material ); + + } else if ( material.isLineBasicMaterial ) { + + refreshUniformsLine( uniforms, material ); + + if ( material.isLineDashedMaterial ) { + + refreshUniformsDash( uniforms, material ); + + } + + } else if ( material.isPointsMaterial ) { + + refreshUniformsPoints( uniforms, material, pixelRatio, height ); + + } else if ( material.isSpriteMaterial ) { + + refreshUniformsSprites( uniforms, material ); + + } else if ( material.isShadowMaterial ) { + + uniforms.color.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + + } else if ( material.isShaderMaterial ) { + + material.uniformsNeedUpdate = false; // #15581 + + } + + } + + function refreshUniformsCommon( uniforms, material, environment ) { + + uniforms.opacity.value = material.opacity; + + if ( material.color ) { + + uniforms.diffuse.value.copy( material.color ); + + } + + if ( material.emissive ) { + + uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity ); + + } + + if ( material.map ) { + + uniforms.map.value = material.map; + + } + + if ( material.alphaMap ) { + + uniforms.alphaMap.value = material.alphaMap; + + } + + if ( material.specularMap ) { + + uniforms.specularMap.value = material.specularMap; + + } + + var envMap = material.envMap || environment; + + if ( envMap ) { + + uniforms.envMap.value = envMap; + + uniforms.flipEnvMap.value = envMap.isCubeTexture ? - 1 : 1; + + uniforms.reflectivity.value = material.reflectivity; + uniforms.refractionRatio.value = material.refractionRatio; + + var maxMipLevel = properties.get( envMap ).__maxMipLevel; + + if ( maxMipLevel !== undefined ) { + + uniforms.maxMipLevel.value = maxMipLevel; + + } + + } + + if ( material.lightMap ) { + + uniforms.lightMap.value = material.lightMap; + uniforms.lightMapIntensity.value = material.lightMapIntensity; + + } + + if ( material.aoMap ) { + + uniforms.aoMap.value = material.aoMap; + uniforms.aoMapIntensity.value = material.aoMapIntensity; + + } + + // uv repeat and offset setting priorities + // 1. color map + // 2. specular map + // 3. normal map + // 4. bump map + // 5. alpha map + // 6. emissive map + + var uvScaleMap; + + if ( material.map ) { + + uvScaleMap = material.map; + + } else if ( material.specularMap ) { + + uvScaleMap = material.specularMap; + + } else if ( material.displacementMap ) { + + uvScaleMap = material.displacementMap; + + } else if ( material.normalMap ) { + + uvScaleMap = material.normalMap; + + } else if ( material.bumpMap ) { + + uvScaleMap = material.bumpMap; + + } else if ( material.roughnessMap ) { + + uvScaleMap = material.roughnessMap; + + } else if ( material.metalnessMap ) { + + uvScaleMap = material.metalnessMap; + + } else if ( material.alphaMap ) { + + uvScaleMap = material.alphaMap; + + } else if ( material.emissiveMap ) { + + uvScaleMap = material.emissiveMap; + + } + + if ( uvScaleMap !== undefined ) { + + // backwards compatibility + if ( uvScaleMap.isWebGLRenderTarget ) { + + uvScaleMap = uvScaleMap.texture; + + } + + if ( uvScaleMap.matrixAutoUpdate === true ) { + + uvScaleMap.updateMatrix(); + + } + + uniforms.uvTransform.value.copy( uvScaleMap.matrix ); + + } + + // uv repeat and offset setting priorities for uv2 + // 1. ao map + // 2. light map + + var uv2ScaleMap; + + if ( material.aoMap ) { + + uv2ScaleMap = material.aoMap; + + } else if ( material.lightMap ) { + + uv2ScaleMap = material.lightMap; + + } + + if ( uv2ScaleMap !== undefined ) { + + // backwards compatibility + if ( uv2ScaleMap.isWebGLRenderTarget ) { + + uv2ScaleMap = uv2ScaleMap.texture; + + } + + if ( uv2ScaleMap.matrixAutoUpdate === true ) { + + uv2ScaleMap.updateMatrix(); + + } + + uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix ); + + } + + } + + function refreshUniformsLine( uniforms, material ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + + } + + function refreshUniformsDash( uniforms, material ) { + + uniforms.dashSize.value = material.dashSize; + uniforms.totalSize.value = material.dashSize + material.gapSize; + uniforms.scale.value = material.scale; + + } + + function refreshUniformsPoints( uniforms, material, pixelRatio, height ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + uniforms.size.value = material.size * pixelRatio; + uniforms.scale.value = height * 0.5; + + if ( material.map ) { + + uniforms.map.value = material.map; + + } + + if ( material.alphaMap ) { + + uniforms.alphaMap.value = material.alphaMap; + + } + + // uv repeat and offset setting priorities + // 1. color map + // 2. alpha map + + var uvScaleMap; + + if ( material.map ) { + + uvScaleMap = material.map; + + } else if ( material.alphaMap ) { + + uvScaleMap = material.alphaMap; + + } + + if ( uvScaleMap !== undefined ) { + + if ( uvScaleMap.matrixAutoUpdate === true ) { + + uvScaleMap.updateMatrix(); + + } + + uniforms.uvTransform.value.copy( uvScaleMap.matrix ); + + } + + } + + function refreshUniformsSprites( uniforms, material ) { + + uniforms.diffuse.value.copy( material.color ); + uniforms.opacity.value = material.opacity; + uniforms.rotation.value = material.rotation; + + if ( material.map ) { + + uniforms.map.value = material.map; + + } + + if ( material.alphaMap ) { + + uniforms.alphaMap.value = material.alphaMap; + + } + + // uv repeat and offset setting priorities + // 1. color map + // 2. alpha map + + var uvScaleMap; + + if ( material.map ) { + + uvScaleMap = material.map; + + } else if ( material.alphaMap ) { + + uvScaleMap = material.alphaMap; + + } + + if ( uvScaleMap !== undefined ) { + + if ( uvScaleMap.matrixAutoUpdate === true ) { + + uvScaleMap.updateMatrix(); + + } + + uniforms.uvTransform.value.copy( uvScaleMap.matrix ); + + } + + } + + function refreshUniformsLambert( uniforms, material ) { + + if ( material.emissiveMap ) { + + uniforms.emissiveMap.value = material.emissiveMap; + + } + + } + + function refreshUniformsPhong( uniforms, material ) { + + uniforms.specular.value.copy( material.specular ); + uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 ) + + if ( material.emissiveMap ) { + + uniforms.emissiveMap.value = material.emissiveMap; + + } + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) { uniforms.bumpScale.value *= - 1; } + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) { uniforms.normalScale.value.negate(); } + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + + } + + function refreshUniformsToon( uniforms, material ) { + + if ( material.gradientMap ) { + + uniforms.gradientMap.value = material.gradientMap; + + } + + if ( material.emissiveMap ) { + + uniforms.emissiveMap.value = material.emissiveMap; + + } + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) { uniforms.bumpScale.value *= - 1; } + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) { uniforms.normalScale.value.negate(); } + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + + } + + function refreshUniformsStandard( uniforms, material, environment ) { + + uniforms.roughness.value = material.roughness; + uniforms.metalness.value = material.metalness; + + if ( material.roughnessMap ) { + + uniforms.roughnessMap.value = material.roughnessMap; + + } + + if ( material.metalnessMap ) { + + uniforms.metalnessMap.value = material.metalnessMap; + + } + + if ( material.emissiveMap ) { + + uniforms.emissiveMap.value = material.emissiveMap; + + } + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) { uniforms.bumpScale.value *= - 1; } + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) { uniforms.normalScale.value.negate(); } + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + + if ( material.envMap || environment ) { + + //uniforms.envMap.value = material.envMap; // part of uniforms common + uniforms.envMapIntensity.value = material.envMapIntensity; + + } + + } + + function refreshUniformsPhysical( uniforms, material, environment ) { + + refreshUniformsStandard( uniforms, material, environment ); + + uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common + + uniforms.clearcoat.value = material.clearcoat; + uniforms.clearcoatRoughness.value = material.clearcoatRoughness; + if ( material.sheen ) { uniforms.sheen.value.copy( material.sheen ); } + + if ( material.clearcoatMap ) { + + uniforms.clearcoatMap.value = material.clearcoatMap; + + } + + if ( material.clearcoatRoughnessMap ) { + + uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap; + + } + + if ( material.clearcoatNormalMap ) { + + uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale ); + uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap; + + if ( material.side === BackSide ) { + + uniforms.clearcoatNormalScale.value.negate(); + + } + + } + + uniforms.transmission.value = material.transmission; + + if ( material.transmissionMap ) { + + uniforms.transmissionMap.value = material.transmissionMap; + + } + + } + + function refreshUniformsMatcap( uniforms, material ) { + + if ( material.matcap ) { + + uniforms.matcap.value = material.matcap; + + } + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) { uniforms.bumpScale.value *= - 1; } + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) { uniforms.normalScale.value.negate(); } + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + + } + + function refreshUniformsDepth( uniforms, material ) { + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + + } + + function refreshUniformsDistance( uniforms, material ) { + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + + uniforms.referencePosition.value.copy( material.referencePosition ); + uniforms.nearDistance.value = material.nearDistance; + uniforms.farDistance.value = material.farDistance; + + } + + function refreshUniformsNormal( uniforms, material ) { + + if ( material.bumpMap ) { + + uniforms.bumpMap.value = material.bumpMap; + uniforms.bumpScale.value = material.bumpScale; + if ( material.side === BackSide ) { uniforms.bumpScale.value *= - 1; } + + } + + if ( material.normalMap ) { + + uniforms.normalMap.value = material.normalMap; + uniforms.normalScale.value.copy( material.normalScale ); + if ( material.side === BackSide ) { uniforms.normalScale.value.negate(); } + + } + + if ( material.displacementMap ) { + + uniforms.displacementMap.value = material.displacementMap; + uniforms.displacementScale.value = material.displacementScale; + uniforms.displacementBias.value = material.displacementBias; + + } + + } + + return { + refreshFogUniforms: refreshFogUniforms, + refreshMaterialUniforms: refreshMaterialUniforms + }; + + } + + function WebGLRenderer( parameters ) { + + parameters = parameters || {}; + + var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' ), + _context = parameters.context !== undefined ? parameters.context : null, + + _alpha = parameters.alpha !== undefined ? parameters.alpha : false, + _depth = parameters.depth !== undefined ? parameters.depth : true, + _stencil = parameters.stencil !== undefined ? parameters.stencil : true, + _antialias = parameters.antialias !== undefined ? parameters.antialias : false, + _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true, + _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false, + _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default', + _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false; + + var currentRenderList = null; + var currentRenderState = null; + + // public properties + + this.domElement = _canvas; + + // Debug configuration container + this.debug = { + + /** + * Enables error checking and reporting when shader programs are being compiled + * @type {boolean} + */ + checkShaderErrors: true + }; + + // clearing + + this.autoClear = true; + this.autoClearColor = true; + this.autoClearDepth = true; + this.autoClearStencil = true; + + // scene graph + + this.sortObjects = true; + + // user-defined clipping + + this.clippingPlanes = []; + this.localClippingEnabled = false; + + // physically based shading + + this.gammaFactor = 2.0; // for backwards compatibility + this.outputEncoding = LinearEncoding; + + // physical lights + + this.physicallyCorrectLights = false; + + // tone mapping + + this.toneMapping = NoToneMapping; + this.toneMappingExposure = 1.0; + + // morphs + + this.maxMorphTargets = 8; + this.maxMorphNormals = 4; + + // internal properties + + var _this = this; + + var _isContextLost = false; + + // internal state cache + + var _framebuffer = null; + + var _currentActiveCubeFace = 0; + var _currentActiveMipmapLevel = 0; + var _currentRenderTarget = null; + var _currentFramebuffer = null; + var _currentMaterialId = - 1; + + var _currentCamera = null; + var _currentArrayCamera = null; + + var _currentViewport = new Vector4(); + var _currentScissor = new Vector4(); + var _currentScissorTest = null; + + // + + var _width = _canvas.width; + var _height = _canvas.height; + + var _pixelRatio = 1; + var _opaqueSort = null; + var _transparentSort = null; + + var _viewport = new Vector4( 0, 0, _width, _height ); + var _scissor = new Vector4( 0, 0, _width, _height ); + var _scissorTest = false; + + // frustum + + var _frustum = new Frustum(); + + // clipping + + var _clipping = new WebGLClipping(); + var _clippingEnabled = false; + var _localClippingEnabled = false; + + // camera matrices cache + + var _projScreenMatrix = new Matrix4(); + + var _vector3 = new Vector3(); + + var _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true }; + + function getTargetPixelRatio() { + + return _currentRenderTarget === null ? _pixelRatio : 1; + + } + + // initialize + + var _gl = _context; + + function getContext( contextNames, contextAttributes ) { + + for ( var i = 0; i < contextNames.length; i ++ ) { + + var contextName = contextNames[ i ]; + var context = _canvas.getContext( contextName, contextAttributes ); + if ( context !== null ) { return context; } + + } + + return null; + + } + + try { + + var contextAttributes = { + alpha: _alpha, + depth: _depth, + stencil: _stencil, + antialias: _antialias, + premultipliedAlpha: _premultipliedAlpha, + preserveDrawingBuffer: _preserveDrawingBuffer, + powerPreference: _powerPreference, + failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat + }; + + // event listeners must be registered before WebGL context is created, see #12753 + + _canvas.addEventListener( 'webglcontextlost', onContextLost, false ); + _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false ); + + if ( _gl === null ) { + + var contextNames = [ 'webgl2', 'webgl', 'experimental-webgl' ]; + + if ( _this.isWebGL1Renderer === true ) { + + contextNames.shift(); + + } + + _gl = getContext( contextNames, contextAttributes ); + + if ( _gl === null ) { + + if ( getContext( contextNames ) ) { + + throw new Error( 'Error creating WebGL context with your selected attributes.' ); + + } else { + + throw new Error( 'Error creating WebGL context.' ); + + } + + } + + } + + // Some experimental-webgl implementations do not have getShaderPrecisionFormat + + if ( _gl.getShaderPrecisionFormat === undefined ) { + + _gl.getShaderPrecisionFormat = function () { + + return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 }; + + }; + + } + + } catch ( error ) { + + console.error( 'THREE.WebGLRenderer: ' + error.message ); + throw error; + + } + + var extensions, capabilities, state, info; + var properties, textures, attributes, geometries, objects; + var programCache, materials, renderLists, renderStates; + + var background, morphtargets, bufferRenderer, indexedBufferRenderer; + + var utils, bindingStates; + + function initGLContext() { + + extensions = new WebGLExtensions( _gl ); + + capabilities = new WebGLCapabilities( _gl, extensions, parameters ); + + if ( capabilities.isWebGL2 === false ) { + + extensions.get( 'WEBGL_depth_texture' ); + extensions.get( 'OES_texture_float' ); + extensions.get( 'OES_texture_half_float' ); + extensions.get( 'OES_texture_half_float_linear' ); + extensions.get( 'OES_standard_derivatives' ); + extensions.get( 'OES_element_index_uint' ); + extensions.get( 'OES_vertex_array_object' ); + extensions.get( 'ANGLE_instanced_arrays' ); + + } + + extensions.get( 'OES_texture_float_linear' ); + + utils = new WebGLUtils( _gl, extensions, capabilities ); + + state = new WebGLState( _gl, extensions, capabilities ); + state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() ); + state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() ); + + info = new WebGLInfo( _gl ); + properties = new WebGLProperties(); + textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ); + attributes = new WebGLAttributes( _gl, capabilities ); + bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities ); + geometries = new WebGLGeometries( _gl, attributes, info, bindingStates ); + objects = new WebGLObjects( _gl, geometries, attributes, info ); + morphtargets = new WebGLMorphtargets( _gl ); + programCache = new WebGLPrograms( _this, extensions, capabilities, bindingStates ); + materials = new WebGLMaterials( properties ); + renderLists = new WebGLRenderLists( properties ); + renderStates = new WebGLRenderStates(); + + background = new WebGLBackground( _this, state, objects, _premultipliedAlpha ); + + bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities ); + indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities ); + + info.programs = programCache.programs; + + _this.capabilities = capabilities; + _this.extensions = extensions; + _this.properties = properties; + _this.renderLists = renderLists; + _this.state = state; + _this.info = info; + + } + + initGLContext(); + + // xr + + var xr = new WebXRManager( _this, _gl ); + + this.xr = xr; + + // shadow map + + var shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize ); + + this.shadowMap = shadowMap; + + // API + + this.getContext = function () { + + return _gl; + + }; + + this.getContextAttributes = function () { + + return _gl.getContextAttributes(); + + }; + + this.forceContextLoss = function () { + + var extension = extensions.get( 'WEBGL_lose_context' ); + if ( extension ) { extension.loseContext(); } + + }; + + this.forceContextRestore = function () { + + var extension = extensions.get( 'WEBGL_lose_context' ); + if ( extension ) { extension.restoreContext(); } + + }; + + this.getPixelRatio = function () { + + return _pixelRatio; + + }; + + this.setPixelRatio = function ( value ) { + + if ( value === undefined ) { return; } + + _pixelRatio = value; + + this.setSize( _width, _height, false ); + + }; + + this.getSize = function ( target ) { + + if ( target === undefined ) { + + console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' ); + + target = new Vector2(); + + } + + return target.set( _width, _height ); + + }; + + this.setSize = function ( width, height, updateStyle ) { + + if ( xr.isPresenting ) { + + console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' ); + return; + + } + + _width = width; + _height = height; + + _canvas.width = Math.floor( width * _pixelRatio ); + _canvas.height = Math.floor( height * _pixelRatio ); + + if ( updateStyle !== false ) { + + _canvas.style.width = width + 'px'; + _canvas.style.height = height + 'px'; + + } + + this.setViewport( 0, 0, width, height ); + + }; + + this.getDrawingBufferSize = function ( target ) { + + if ( target === undefined ) { + + console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' ); + + target = new Vector2(); + + } + + return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor(); + + }; + + this.setDrawingBufferSize = function ( width, height, pixelRatio ) { + + _width = width; + _height = height; + + _pixelRatio = pixelRatio; + + _canvas.width = Math.floor( width * pixelRatio ); + _canvas.height = Math.floor( height * pixelRatio ); + + this.setViewport( 0, 0, width, height ); + + }; + + this.getCurrentViewport = function ( target ) { + + if ( target === undefined ) { + + console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' ); + + target = new Vector4(); + + } + + return target.copy( _currentViewport ); + + }; + + this.getViewport = function ( target ) { + + return target.copy( _viewport ); + + }; + + this.setViewport = function ( x, y, width, height ) { + + if ( x.isVector4 ) { + + _viewport.set( x.x, x.y, x.z, x.w ); + + } else { + + _viewport.set( x, y, width, height ); + + } + + state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() ); + + }; + + this.getScissor = function ( target ) { + + return target.copy( _scissor ); + + }; + + this.setScissor = function ( x, y, width, height ) { + + if ( x.isVector4 ) { + + _scissor.set( x.x, x.y, x.z, x.w ); + + } else { + + _scissor.set( x, y, width, height ); + + } + + state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() ); + + }; + + this.getScissorTest = function () { + + return _scissorTest; + + }; + + this.setScissorTest = function ( boolean ) { + + state.setScissorTest( _scissorTest = boolean ); + + }; + + this.setOpaqueSort = function ( method ) { + + _opaqueSort = method; + + }; + + this.setTransparentSort = function ( method ) { + + _transparentSort = method; + + }; + + // Clearing + + this.getClearColor = function () { + + return background.getClearColor(); + + }; + + this.setClearColor = function () { + + background.setClearColor.apply( background, arguments ); + + }; + + this.getClearAlpha = function () { + + return background.getClearAlpha(); + + }; + + this.setClearAlpha = function () { + + background.setClearAlpha.apply( background, arguments ); + + }; + + this.clear = function ( color, depth, stencil ) { + + var bits = 0; + + if ( color === undefined || color ) { bits |= 16384; } + if ( depth === undefined || depth ) { bits |= 256; } + if ( stencil === undefined || stencil ) { bits |= 1024; } + + _gl.clear( bits ); + + }; + + this.clearColor = function () { + + this.clear( true, false, false ); + + }; + + this.clearDepth = function () { + + this.clear( false, true, false ); + + }; + + this.clearStencil = function () { + + this.clear( false, false, true ); + + }; + + // + + this.dispose = function () { + + _canvas.removeEventListener( 'webglcontextlost', onContextLost, false ); + _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false ); + + renderLists.dispose(); + renderStates.dispose(); + properties.dispose(); + objects.dispose(); + bindingStates.dispose(); + + xr.dispose(); + + animation.stop(); + + }; + + // Events + + function onContextLost( event ) { + + event.preventDefault(); + + console.log( 'THREE.WebGLRenderer: Context Lost.' ); + + _isContextLost = true; + + } + + function onContextRestore( /* event */ ) { + + console.log( 'THREE.WebGLRenderer: Context Restored.' ); + + _isContextLost = false; + + initGLContext(); + + } + + function onMaterialDispose( event ) { + + var material = event.target; + + material.removeEventListener( 'dispose', onMaterialDispose ); + + deallocateMaterial( material ); + + } + + // Buffer deallocation + + function deallocateMaterial( material ) { + + releaseMaterialProgramReference( material ); + + properties.remove( material ); + + } + + + function releaseMaterialProgramReference( material ) { + + var programInfo = properties.get( material ).program; + + if ( programInfo !== undefined ) { + + programCache.releaseProgram( programInfo ); + + } + + } + + // Buffer rendering + + function renderObjectImmediate( object, program ) { + + object.render( function ( object ) { + + _this.renderBufferImmediate( object, program ); + + } ); + + } + + this.renderBufferImmediate = function ( object, program ) { + + bindingStates.initAttributes(); + + var buffers = properties.get( object ); + + if ( object.hasPositions && ! buffers.position ) { buffers.position = _gl.createBuffer(); } + if ( object.hasNormals && ! buffers.normal ) { buffers.normal = _gl.createBuffer(); } + if ( object.hasUvs && ! buffers.uv ) { buffers.uv = _gl.createBuffer(); } + if ( object.hasColors && ! buffers.color ) { buffers.color = _gl.createBuffer(); } + + var programAttributes = program.getAttributes(); + + if ( object.hasPositions ) { + + _gl.bindBuffer( 34962, buffers.position ); + _gl.bufferData( 34962, object.positionArray, 35048 ); + + bindingStates.enableAttribute( programAttributes.position ); + _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 ); + + } + + if ( object.hasNormals ) { + + _gl.bindBuffer( 34962, buffers.normal ); + _gl.bufferData( 34962, object.normalArray, 35048 ); + + bindingStates.enableAttribute( programAttributes.normal ); + _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 ); + + } + + if ( object.hasUvs ) { + + _gl.bindBuffer( 34962, buffers.uv ); + _gl.bufferData( 34962, object.uvArray, 35048 ); + + bindingStates.enableAttribute( programAttributes.uv ); + _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 ); + + } + + if ( object.hasColors ) { + + _gl.bindBuffer( 34962, buffers.color ); + _gl.bufferData( 34962, object.colorArray, 35048 ); + + bindingStates.enableAttribute( programAttributes.color ); + _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 ); + + } + + bindingStates.disableUnusedAttributes(); + + _gl.drawArrays( 4, 0, object.count ); + + object.count = 0; + + }; + + this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) { + + if ( scene === null ) { scene = _emptyScene; } // renderBufferDirect second parameter used to be fog (could be null) + + var frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 ); + + var program = setProgram( camera, scene, material, object ); + + state.setMaterial( material, frontFaceCW ); + + // + + var index = geometry.index; + var position = geometry.attributes.position; + + // + + if ( index === null ) { + + if ( position === undefined || position.count === 0 ) { return; } + + } else if ( index.count === 0 ) { + + return; + + } + + // + + var rangeFactor = 1; + + if ( material.wireframe === true ) { + + index = geometries.getWireframeAttribute( geometry ); + rangeFactor = 2; + + } + + if ( material.morphTargets || material.morphNormals ) { + + morphtargets.update( object, geometry, material, program ); + + } + + bindingStates.setup( object, material, program, geometry, index ); + + var attribute; + var renderer = bufferRenderer; + + if ( index !== null ) { + + attribute = attributes.get( index ); + + renderer = indexedBufferRenderer; + renderer.setIndex( attribute ); + + } + + // + + var dataCount = ( index !== null ) ? index.count : position.count; + + var rangeStart = geometry.drawRange.start * rangeFactor; + var rangeCount = geometry.drawRange.count * rangeFactor; + + var groupStart = group !== null ? group.start * rangeFactor : 0; + var groupCount = group !== null ? group.count * rangeFactor : Infinity; + + var drawStart = Math.max( rangeStart, groupStart ); + var drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1; + + var drawCount = Math.max( 0, drawEnd - drawStart + 1 ); + + if ( drawCount === 0 ) { return; } + + // + + if ( object.isMesh ) { + + if ( material.wireframe === true ) { + + state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() ); + renderer.setMode( 1 ); + + } else { + + renderer.setMode( 4 ); + + } + + } else if ( object.isLine ) { + + var lineWidth = material.linewidth; + + if ( lineWidth === undefined ) { lineWidth = 1; } // Not using Line*Material + + state.setLineWidth( lineWidth * getTargetPixelRatio() ); + + if ( object.isLineSegments ) { + + renderer.setMode( 1 ); + + } else if ( object.isLineLoop ) { + + renderer.setMode( 2 ); + + } else { + + renderer.setMode( 3 ); + + } + + } else if ( object.isPoints ) { + + renderer.setMode( 0 ); + + } else if ( object.isSprite ) { + + renderer.setMode( 4 ); + + } + + if ( object.isInstancedMesh ) { + + renderer.renderInstances( drawStart, drawCount, object.count ); + + } else if ( geometry.isInstancedBufferGeometry ) { + + var instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount ); + + renderer.renderInstances( drawStart, drawCount, instanceCount ); + + } else { + + renderer.render( drawStart, drawCount ); + + } + + }; + + // Compile + + this.compile = function ( scene, camera ) { + + currentRenderState = renderStates.get( scene, camera ); + currentRenderState.init(); + + scene.traverse( function ( object ) { + + if ( object.isLight ) { + + currentRenderState.pushLight( object ); + + if ( object.castShadow ) { + + currentRenderState.pushShadow( object ); + + } + + } + + } ); + + currentRenderState.setupLights( camera ); + + var compiled = new WeakMap(); + + scene.traverse( function ( object ) { + + var material = object.material; + + if ( material ) { + + if ( Array.isArray( material ) ) { + + for ( var i = 0; i < material.length; i ++ ) { + + var material2 = material[ i ]; + + if ( compiled.has( material2 ) === false ) { + + initMaterial( material2, scene, object ); + compiled.set( material2 ); + + } + + } + + } else if ( compiled.has( material ) === false ) { + + initMaterial( material, scene, object ); + compiled.set( material ); + + } + + } + + } ); + + }; + + // Animation Loop + + var onAnimationFrameCallback = null; + + function onAnimationFrame( time ) { + + if ( xr.isPresenting ) { return; } + if ( onAnimationFrameCallback ) { onAnimationFrameCallback( time ); } + + } + + var animation = new WebGLAnimation(); + animation.setAnimationLoop( onAnimationFrame ); + + if ( typeof window !== 'undefined' ) { animation.setContext( window ); } + + this.setAnimationLoop = function ( callback ) { + + onAnimationFrameCallback = callback; + xr.setAnimationLoop( callback ); + + ( callback === null ) ? animation.stop() : animation.start(); + + }; + + // Rendering + + this.render = function ( scene, camera ) { + + var renderTarget, forceClear; + + if ( arguments[ 2 ] !== undefined ) { + + console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' ); + renderTarget = arguments[ 2 ]; + + } + + if ( arguments[ 3 ] !== undefined ) { + + console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' ); + forceClear = arguments[ 3 ]; + + } + + if ( camera !== undefined && camera.isCamera !== true ) { + + console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' ); + return; + + } + + if ( _isContextLost === true ) { return; } + + // reset caching for this frame + + bindingStates.resetDefaultState(); + _currentMaterialId = - 1; + _currentCamera = null; + + // update scene graph + + if ( scene.autoUpdate === true ) { scene.updateMatrixWorld(); } + + // update camera matrices and frustum + + if ( camera.parent === null ) { camera.updateMatrixWorld(); } + + if ( xr.enabled === true && xr.isPresenting === true ) { + + camera = xr.getCamera( camera ); + + } + + // + if ( scene.isScene === true ) { scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget ); } + + currentRenderState = renderStates.get( scene, camera ); + currentRenderState.init(); + + _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ); + _frustum.setFromProjectionMatrix( _projScreenMatrix ); + + _localClippingEnabled = this.localClippingEnabled; + _clippingEnabled = _clipping.init( this.clippingPlanes, _localClippingEnabled, camera ); + + currentRenderList = renderLists.get( scene, camera ); + currentRenderList.init(); + + projectObject( scene, camera, 0, _this.sortObjects ); + + currentRenderList.finish(); + + if ( _this.sortObjects === true ) { + + currentRenderList.sort( _opaqueSort, _transparentSort ); + + } + + // + + if ( _clippingEnabled === true ) { _clipping.beginShadows(); } + + var shadowsArray = currentRenderState.state.shadowsArray; + + shadowMap.render( shadowsArray, scene, camera ); + + currentRenderState.setupLights( camera ); + + if ( _clippingEnabled === true ) { _clipping.endShadows(); } + + // + + if ( this.info.autoReset === true ) { this.info.reset(); } + + if ( renderTarget !== undefined ) { + + this.setRenderTarget( renderTarget ); + + } + + // + + background.render( currentRenderList, scene, camera, forceClear ); + + // render scene + + var opaqueObjects = currentRenderList.opaque; + var transparentObjects = currentRenderList.transparent; + + if ( opaqueObjects.length > 0 ) { renderObjects( opaqueObjects, scene, camera ); } + if ( transparentObjects.length > 0 ) { renderObjects( transparentObjects, scene, camera ); } + + // + + if ( scene.isScene === true ) { scene.onAfterRender( _this, scene, camera ); } + + // + + if ( _currentRenderTarget !== null ) { + + // Generate mipmap if we're using any kind of mipmap filtering + + textures.updateRenderTargetMipmap( _currentRenderTarget ); + + // resolve multisample renderbuffers to a single-sample texture if necessary + + textures.updateMultisampleRenderTarget( _currentRenderTarget ); + + } + + // Ensure depth buffer writing is enabled so it can be cleared on next render + + state.buffers.depth.setTest( true ); + state.buffers.depth.setMask( true ); + state.buffers.color.setMask( true ); + + state.setPolygonOffset( false ); + + // _gl.finish(); + + currentRenderList = null; + currentRenderState = null; + + }; + + function projectObject( object, camera, groupOrder, sortObjects ) { + + if ( object.visible === false ) { return; } + + var visible = object.layers.test( camera.layers ); + + if ( visible ) { + + if ( object.isGroup ) { + + groupOrder = object.renderOrder; + + } else if ( object.isLOD ) { + + if ( object.autoUpdate === true ) { object.update( camera ); } + + } else if ( object.isLight ) { + + currentRenderState.pushLight( object ); + + if ( object.castShadow ) { + + currentRenderState.pushShadow( object ); + + } + + } else if ( object.isSprite ) { + + if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) { + + if ( sortObjects ) { + + _vector3.setFromMatrixPosition( object.matrixWorld ) + .applyMatrix4( _projScreenMatrix ); + + } + + var geometry = objects.update( object ); + var material = object.material; + + if ( material.visible ) { + + currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null ); + + } + + } + + } else if ( object.isImmediateRenderObject ) { + + if ( sortObjects ) { + + _vector3.setFromMatrixPosition( object.matrixWorld ) + .applyMatrix4( _projScreenMatrix ); + + } + + currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null ); + + } else if ( object.isMesh || object.isLine || object.isPoints ) { + + if ( object.isSkinnedMesh ) { + + // update skeleton only once in a frame + + if ( object.skeleton.frame !== info.render.frame ) { + + object.skeleton.update(); + object.skeleton.frame = info.render.frame; + + } + + } + + if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) { + + if ( sortObjects ) { + + _vector3.setFromMatrixPosition( object.matrixWorld ) + .applyMatrix4( _projScreenMatrix ); + + } + + var geometry$1 = objects.update( object ); + var material$1 = object.material; + + if ( Array.isArray( material$1 ) ) { + + var groups = geometry$1.groups; + + for ( var i = 0, l = groups.length; i < l; i ++ ) { + + var group = groups[ i ]; + var groupMaterial = material$1[ group.materialIndex ]; + + if ( groupMaterial && groupMaterial.visible ) { + + currentRenderList.push( object, geometry$1, groupMaterial, groupOrder, _vector3.z, group ); + + } + + } + + } else if ( material$1.visible ) { + + currentRenderList.push( object, geometry$1, material$1, groupOrder, _vector3.z, null ); + + } + + } + + } + + } + + var children = object.children; + + for ( var i$1 = 0, l$1 = children.length; i$1 < l$1; i$1 ++ ) { + + projectObject( children[ i$1 ], camera, groupOrder, sortObjects ); + + } + + } + + function renderObjects( renderList, scene, camera ) { + + var overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null; + + for ( var i = 0, l = renderList.length; i < l; i ++ ) { + + var renderItem = renderList[ i ]; + + var object = renderItem.object; + var geometry = renderItem.geometry; + var material = overrideMaterial === null ? renderItem.material : overrideMaterial; + var group = renderItem.group; + + if ( camera.isArrayCamera ) { + + _currentArrayCamera = camera; + + var cameras = camera.cameras; + + for ( var j = 0, jl = cameras.length; j < jl; j ++ ) { + + var camera2 = cameras[ j ]; + + if ( object.layers.test( camera2.layers ) ) { + + state.viewport( _currentViewport.copy( camera2.viewport ) ); + + currentRenderState.setupLights( camera2 ); + + renderObject( object, scene, camera2, geometry, material, group ); + + } + + } + + } else { + + _currentArrayCamera = null; + + renderObject( object, scene, camera, geometry, material, group ); + + } + + } + + } + + function renderObject( object, scene, camera, geometry, material, group ) { + + object.onBeforeRender( _this, scene, camera, geometry, material, group ); + currentRenderState = renderStates.get( scene, _currentArrayCamera || camera ); + + object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld ); + object.normalMatrix.getNormalMatrix( object.modelViewMatrix ); + + if ( object.isImmediateRenderObject ) { + + var program = setProgram( camera, scene, material, object ); + + state.setMaterial( material ); + + bindingStates.reset(); + + renderObjectImmediate( object, program ); + + } else { + + _this.renderBufferDirect( camera, scene, geometry, material, object, group ); + + } + + object.onAfterRender( _this, scene, camera, geometry, material, group ); + currentRenderState = renderStates.get( scene, _currentArrayCamera || camera ); + + } + + function initMaterial( material, scene, object ) { + + if ( scene.isScene !== true ) { scene = _emptyScene; } // scene could be a Mesh, Line, Points, ... + + var materialProperties = properties.get( material ); + + var lights = currentRenderState.state.lights; + var shadowsArray = currentRenderState.state.shadowsArray; + + var lightsStateVersion = lights.state.version; + + var parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, _clipping.numPlanes, _clipping.numIntersection, object ); + var programCacheKey = programCache.getProgramCacheKey( parameters ); + + var program = materialProperties.program; + var programChange = true; + + if ( program === undefined ) { + + // new material + material.addEventListener( 'dispose', onMaterialDispose ); + + } else if ( program.cacheKey !== programCacheKey ) { + + // changed glsl or parameters + releaseMaterialProgramReference( material ); + + } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) { + + materialProperties.lightsStateVersion = lightsStateVersion; + + programChange = false; + + } else if ( parameters.shaderID !== undefined ) { + + // same glsl and uniform list + return; + + } else { + + // only rebuild uniform list + programChange = false; + + } + + if ( programChange ) { + + parameters.uniforms = programCache.getUniforms( material, parameters ); + + material.onBeforeCompile( parameters, _this ); + + program = programCache.acquireProgram( parameters, programCacheKey ); + + materialProperties.program = program; + materialProperties.uniforms = parameters.uniforms; + materialProperties.outputEncoding = parameters.outputEncoding; + + } + + var programAttributes = program.getAttributes(); + + if ( material.morphTargets ) { + + material.numSupportedMorphTargets = 0; + + for ( var i = 0; i < _this.maxMorphTargets; i ++ ) { + + if ( programAttributes[ 'morphTarget' + i ] >= 0 ) { + + material.numSupportedMorphTargets ++; + + } + + } + + } + + if ( material.morphNormals ) { + + material.numSupportedMorphNormals = 0; + + for ( var i$1 = 0; i$1 < _this.maxMorphNormals; i$1 ++ ) { + + if ( programAttributes[ 'morphNormal' + i$1 ] >= 0 ) { + + material.numSupportedMorphNormals ++; + + } + + } + + } + + var uniforms = materialProperties.uniforms; + + if ( ! material.isShaderMaterial && + ! material.isRawShaderMaterial || + material.clipping === true ) { + + materialProperties.numClippingPlanes = _clipping.numPlanes; + materialProperties.numIntersection = _clipping.numIntersection; + uniforms.clippingPlanes = _clipping.uniform; + + } + + materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null; + materialProperties.fog = scene.fog; + + // store the light setup it was created for + + materialProperties.needsLights = materialNeedsLights( material ); + materialProperties.lightsStateVersion = lightsStateVersion; + + if ( materialProperties.needsLights ) { + + // wire up the material to this renderer's lighting state + + uniforms.ambientLightColor.value = lights.state.ambient; + uniforms.lightProbe.value = lights.state.probe; + uniforms.directionalLights.value = lights.state.directional; + uniforms.directionalLightShadows.value = lights.state.directionalShadow; + uniforms.spotLights.value = lights.state.spot; + uniforms.spotLightShadows.value = lights.state.spotShadow; + uniforms.rectAreaLights.value = lights.state.rectArea; + uniforms.pointLights.value = lights.state.point; + uniforms.pointLightShadows.value = lights.state.pointShadow; + uniforms.hemisphereLights.value = lights.state.hemi; + + uniforms.directionalShadowMap.value = lights.state.directionalShadowMap; + uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix; + uniforms.spotShadowMap.value = lights.state.spotShadowMap; + uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix; + uniforms.pointShadowMap.value = lights.state.pointShadowMap; + uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; + // TODO (abelnation): add area lights shadow info to uniforms + + } + + var progUniforms = materialProperties.program.getUniforms(), + uniformsList = + WebGLUniforms.seqWithValue( progUniforms.seq, uniforms ); + + materialProperties.uniformsList = uniformsList; + + } + + function setProgram( camera, scene, material, object ) { + + if ( scene.isScene !== true ) { scene = _emptyScene; } // scene could be a Mesh, Line, Points, ... + + textures.resetTextureUnits(); + + var fog = scene.fog; + var environment = material.isMeshStandardMaterial ? scene.environment : null; + var encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding; + + var materialProperties = properties.get( material ); + var lights = currentRenderState.state.lights; + + if ( _clippingEnabled === true ) { + + if ( _localClippingEnabled === true || camera !== _currentCamera ) { + + var useCache = + camera === _currentCamera && + material.id === _currentMaterialId; + + // we might want to call this function with some ClippingGroup + // object instead of the material, once it becomes feasible + // (#8465, #8379) + _clipping.setState( + material.clippingPlanes, material.clipIntersection, material.clipShadows, + camera, materialProperties, useCache ); + + } + + } + + if ( material.version === materialProperties.__version ) { + + if ( materialProperties.program === undefined ) { + + initMaterial( material, scene, object ); + + } else if ( material.fog && materialProperties.fog !== fog ) { + + initMaterial( material, scene, object ); + + } else if ( materialProperties.environment !== environment ) { + + initMaterial( material, scene, object ); + + } else if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) { + + initMaterial( material, scene, object ); + + } else if ( materialProperties.numClippingPlanes !== undefined && + ( materialProperties.numClippingPlanes !== _clipping.numPlanes || + materialProperties.numIntersection !== _clipping.numIntersection ) ) { + + initMaterial( material, scene, object ); + + } else if ( materialProperties.outputEncoding !== encoding ) { + + initMaterial( material, scene, object ); + + } + + } else { + + initMaterial( material, scene, object ); + materialProperties.__version = material.version; + + } + + var refreshProgram = false; + var refreshMaterial = false; + var refreshLights = false; + + var program = materialProperties.program, + p_uniforms = program.getUniforms(), + m_uniforms = materialProperties.uniforms; + + if ( state.useProgram( program.program ) ) { + + refreshProgram = true; + refreshMaterial = true; + refreshLights = true; + + } + + if ( material.id !== _currentMaterialId ) { + + _currentMaterialId = material.id; + + refreshMaterial = true; + + } + + if ( refreshProgram || _currentCamera !== camera ) { + + p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix ); + + if ( capabilities.logarithmicDepthBuffer ) { + + p_uniforms.setValue( _gl, 'logDepthBufFC', + 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) ); + + } + + if ( _currentCamera !== camera ) { + + _currentCamera = camera; + + // lighting uniforms depend on the camera so enforce an update + // now, in case this material supports lights - or later, when + // the next material that does gets activated: + + refreshMaterial = true; // set to true on material change + refreshLights = true; // remains set until update done + + } + + // load material specific uniforms + // (shader material also gets them for the sake of genericity) + + if ( material.isShaderMaterial || + material.isMeshPhongMaterial || + material.isMeshToonMaterial || + material.isMeshStandardMaterial || + material.envMap ) { + + var uCamPos = p_uniforms.map.cameraPosition; + + if ( uCamPos !== undefined ) { + + uCamPos.setValue( _gl, + _vector3.setFromMatrixPosition( camera.matrixWorld ) ); + + } + + } + + if ( material.isMeshPhongMaterial || + material.isMeshToonMaterial || + material.isMeshLambertMaterial || + material.isMeshBasicMaterial || + material.isMeshStandardMaterial || + material.isShaderMaterial ) { + + p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true ); + + } + + if ( material.isMeshPhongMaterial || + material.isMeshToonMaterial || + material.isMeshLambertMaterial || + material.isMeshBasicMaterial || + material.isMeshStandardMaterial || + material.isShaderMaterial || + material.isShadowMaterial || + material.skinning ) { + + p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse ); + + } + + } + + // skinning uniforms must be set even if material didn't change + // auto-setting of texture unit for bone texture must go before other textures + // otherwise textures used for skinning can take over texture units reserved for other material textures + + if ( material.skinning ) { + + p_uniforms.setOptional( _gl, object, 'bindMatrix' ); + p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' ); + + var skeleton = object.skeleton; + + if ( skeleton ) { + + var bones = skeleton.bones; + + if ( capabilities.floatVertexTextures ) { + + if ( skeleton.boneTexture === undefined ) { + + // layout (1 matrix = 4 pixels) + // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4) + // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8) + // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16) + // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32) + // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64) + + + var size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix + size = MathUtils.ceilPowerOfTwo( size ); + size = Math.max( size, 4 ); + + var boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel + boneMatrices.set( skeleton.boneMatrices ); // copy current values + + var boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType ); + + skeleton.boneMatrices = boneMatrices; + skeleton.boneTexture = boneTexture; + skeleton.boneTextureSize = size; + + } + + p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures ); + p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize ); + + } else { + + p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' ); + + } + + } + + } + + if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) { + + materialProperties.receiveShadow = object.receiveShadow; + p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow ); + + } + + if ( refreshMaterial ) { + + p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure ); + + if ( materialProperties.needsLights ) { + + // the current material requires lighting info + + // note: all lighting uniforms are always set correctly + // they simply reference the renderer's state for their + // values + // + // use the current material's .needsUpdate flags to set + // the GL state when required + + markUniformsLightsNeedsUpdate( m_uniforms, refreshLights ); + + } + + // refresh uniforms common to several materials + + if ( fog && material.fog ) { + + materials.refreshFogUniforms( m_uniforms, fog ); + + } + + materials.refreshMaterialUniforms( m_uniforms, material, environment, _pixelRatio, _height ); + + // RectAreaLight Texture + // TODO (mrdoob): Find a nicer implementation + + if ( m_uniforms.ltc_1 !== undefined ) { m_uniforms.ltc_1.value = UniformsLib.LTC_1; } + if ( m_uniforms.ltc_2 !== undefined ) { m_uniforms.ltc_2.value = UniformsLib.LTC_2; } + + WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures ); + + } + + if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) { + + WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures ); + material.uniformsNeedUpdate = false; + + } + + if ( material.isSpriteMaterial ) { + + p_uniforms.setValue( _gl, 'center', object.center ); + + } + + // common matrices + + p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix ); + p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix ); + p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld ); + + return program; + + } + + // If uniforms are marked as clean, they don't need to be loaded to the GPU. + + function markUniformsLightsNeedsUpdate( uniforms, value ) { + + uniforms.ambientLightColor.needsUpdate = value; + uniforms.lightProbe.needsUpdate = value; + + uniforms.directionalLights.needsUpdate = value; + uniforms.directionalLightShadows.needsUpdate = value; + uniforms.pointLights.needsUpdate = value; + uniforms.pointLightShadows.needsUpdate = value; + uniforms.spotLights.needsUpdate = value; + uniforms.spotLightShadows.needsUpdate = value; + uniforms.rectAreaLights.needsUpdate = value; + uniforms.hemisphereLights.needsUpdate = value; + + } + + function materialNeedsLights( material ) { + + return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || + material.isMeshStandardMaterial || material.isShadowMaterial || + ( material.isShaderMaterial && material.lights === true ); + + } + + // + this.setFramebuffer = function ( value ) { + + if ( _framebuffer !== value && _currentRenderTarget === null ) { _gl.bindFramebuffer( 36160, value ); } + + _framebuffer = value; + + }; + + this.getActiveCubeFace = function () { + + return _currentActiveCubeFace; + + }; + + this.getActiveMipmapLevel = function () { + + return _currentActiveMipmapLevel; + + }; + + this.getRenderTarget = function () { + + return _currentRenderTarget; + + }; + + this.setRenderTarget = function ( renderTarget, activeCubeFace, activeMipmapLevel ) { + + _currentRenderTarget = renderTarget; + _currentActiveCubeFace = activeCubeFace; + _currentActiveMipmapLevel = activeMipmapLevel; + + if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) { + + textures.setupRenderTarget( renderTarget ); + + } + + var framebuffer = _framebuffer; + var isCube = false; + + if ( renderTarget ) { + + var _webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer; + + if ( renderTarget.isWebGLCubeRenderTarget ) { + + framebuffer = _webglFramebuffer[ activeCubeFace || 0 ]; + isCube = true; + + } else if ( renderTarget.isWebGLMultisampleRenderTarget ) { + + framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer; + + } else { + + framebuffer = _webglFramebuffer; + + } + + _currentViewport.copy( renderTarget.viewport ); + _currentScissor.copy( renderTarget.scissor ); + _currentScissorTest = renderTarget.scissorTest; + + } else { + + _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor(); + _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor(); + _currentScissorTest = _scissorTest; + + } + + if ( _currentFramebuffer !== framebuffer ) { + + _gl.bindFramebuffer( 36160, framebuffer ); + _currentFramebuffer = framebuffer; + + } + + state.viewport( _currentViewport ); + state.scissor( _currentScissor ); + state.setScissorTest( _currentScissorTest ); + + if ( isCube ) { + + var textureProperties = properties.get( renderTarget.texture ); + _gl.framebufferTexture2D( 36160, 36064, 34069 + ( activeCubeFace || 0 ), textureProperties.__webglTexture, activeMipmapLevel || 0 ); + + } + + }; + + this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) { + + if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) { + + console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' ); + return; + + } + + var framebuffer = properties.get( renderTarget ).__webglFramebuffer; + + if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) { + + framebuffer = framebuffer[ activeCubeFaceIndex ]; + + } + + if ( framebuffer ) { + + var restore = false; + + if ( framebuffer !== _currentFramebuffer ) { + + _gl.bindFramebuffer( 36160, framebuffer ); + + restore = true; + + } + + try { + + var texture = renderTarget.texture; + var textureFormat = texture.format; + var textureType = texture.type; + + if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) { + + console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' ); + return; + + } + + if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513) + ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox + ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) { + + console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' ); + return; + + } + + if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) { + + // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604) + + if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) { + + _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer ); + + } + + } else { + + console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' ); + + } + + } finally { + + if ( restore ) { + + _gl.bindFramebuffer( 36160, _currentFramebuffer ); + + } + + } + + } + + }; + + this.copyFramebufferToTexture = function ( position, texture, level ) { + + if ( level === undefined ) { level = 0; } + + var levelScale = Math.pow( 2, - level ); + var width = Math.floor( texture.image.width * levelScale ); + var height = Math.floor( texture.image.height * levelScale ); + var glFormat = utils.convert( texture.format ); + + textures.setTexture2D( texture, 0 ); + + _gl.copyTexImage2D( 3553, level, glFormat, position.x, position.y, width, height, 0 ); + + state.unbindTexture(); + + }; + + this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level ) { + + if ( level === undefined ) { level = 0; } + + var width = srcTexture.image.width; + var height = srcTexture.image.height; + var glFormat = utils.convert( dstTexture.format ); + var glType = utils.convert( dstTexture.type ); + + textures.setTexture2D( dstTexture, 0 ); + + // As another texture upload may have changed pixelStorei + // parameters, make sure they are correct for the dstTexture + _gl.pixelStorei( 37440, dstTexture.flipY ); + _gl.pixelStorei( 37441, dstTexture.premultiplyAlpha ); + _gl.pixelStorei( 3317, dstTexture.unpackAlignment ); + + if ( srcTexture.isDataTexture ) { + + _gl.texSubImage2D( 3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data ); + + } else { + + if ( srcTexture.isCompressedTexture ) { + + _gl.compressedTexSubImage2D( 3553, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data ); + + } else { + + _gl.texSubImage2D( 3553, level, position.x, position.y, glFormat, glType, srcTexture.image ); + + } + + } + + // Generate mipmaps only when copying level 0 + if ( level === 0 && dstTexture.generateMipmaps ) { _gl.generateMipmap( 3553 ); } + + state.unbindTexture(); + + }; + + this.initTexture = function ( texture ) { + + textures.setTexture2D( texture, 0 ); + + state.unbindTexture(); + + }; + + if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) { + + __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef + + } + + } + + function WebGL1Renderer( parameters ) { + + WebGLRenderer.call( this, parameters ); + + } + + WebGL1Renderer.prototype = Object.assign( Object.create( WebGLRenderer.prototype ), { + + constructor: WebGL1Renderer, + + isWebGL1Renderer: true + + } ); + + function FogExp2( color, density ) { + + this.name = ''; + + this.color = new Color( color ); + this.density = ( density !== undefined ) ? density : 0.00025; + + } + + Object.assign( FogExp2.prototype, { + + isFogExp2: true, + + clone: function () { + + return new FogExp2( this.color, this.density ); + + }, + + toJSON: function ( /* meta */ ) { + + return { + type: 'FogExp2', + color: this.color.getHex(), + density: this.density + }; + + } + + } ); + + function Fog( color, near, far ) { + + this.name = ''; + + this.color = new Color( color ); + + this.near = ( near !== undefined ) ? near : 1; + this.far = ( far !== undefined ) ? far : 1000; + + } + + Object.assign( Fog.prototype, { + + isFog: true, + + clone: function () { + + return new Fog( this.color, this.near, this.far ); + + }, + + toJSON: function ( /* meta */ ) { + + return { + type: 'Fog', + color: this.color.getHex(), + near: this.near, + far: this.far + }; + + } + + } ); + + function InterleavedBuffer( array, stride ) { + + this.array = array; + this.stride = stride; + this.count = array !== undefined ? array.length / stride : 0; + + this.usage = StaticDrawUsage; + this.updateRange = { offset: 0, count: - 1 }; + + this.version = 0; + + this.uuid = MathUtils.generateUUID(); + + } + + Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', { + + set: function ( value ) { + + if ( value === true ) { this.version ++; } + + } + + } ); + + Object.assign( InterleavedBuffer.prototype, { + + isInterleavedBuffer: true, + + onUploadCallback: function () {}, + + setUsage: function ( value ) { + + this.usage = value; + + return this; + + }, + + copy: function ( source ) { + + this.array = new source.array.constructor( source.array ); + this.count = source.count; + this.stride = source.stride; + this.usage = source.usage; + + return this; + + }, + + copyAt: function ( index1, attribute, index2 ) { + + index1 *= this.stride; + index2 *= attribute.stride; + + for ( var i = 0, l = this.stride; i < l; i ++ ) { + + this.array[ index1 + i ] = attribute.array[ index2 + i ]; + + } + + return this; + + }, + + set: function ( value, offset ) { + + if ( offset === undefined ) { offset = 0; } + + this.array.set( value, offset ); + + return this; + + }, + + clone: function ( data ) { + + if ( data.arrayBuffers === undefined ) { + + data.arrayBuffers = {}; + + } + + if ( this.array.buffer._uuid === undefined ) { + + this.array.buffer._uuid = MathUtils.generateUUID(); + + } + + if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) { + + data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer; + + } + + var array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] ); + + var ib = new InterleavedBuffer( array, this.stride ); + ib.setUsage( this.usage ); + + return ib; + + }, + + onUpload: function ( callback ) { + + this.onUploadCallback = callback; + + return this; + + }, + + toJSON: function ( data ) { + + if ( data.arrayBuffers === undefined ) { + + data.arrayBuffers = {}; + + } + + // generate UUID for array buffer if necessary + + if ( this.array.buffer._uuid === undefined ) { + + this.array.buffer._uuid = MathUtils.generateUUID(); + + } + + if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) { + + data.arrayBuffers[ this.array.buffer._uuid ] = Array.prototype.slice.call( new Uint32Array( this.array.buffer ) ); + + } + + // + + return { + uuid: this.uuid, + buffer: this.array.buffer._uuid, + type: this.array.constructor.name, + stride: this.stride + }; + + } + + } ); + + var _vector$6 = new Vector3(); + + function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) { + + this.name = ''; + + this.data = interleavedBuffer; + this.itemSize = itemSize; + this.offset = offset; + + this.normalized = normalized === true; + + } + + Object.defineProperties( InterleavedBufferAttribute.prototype, { + + count: { + + get: function () { + + return this.data.count; + + } + + }, + + array: { + + get: function () { + + return this.data.array; + + } + + }, + + needsUpdate: { + + set: function ( value ) { + + this.data.needsUpdate = value; + + } + + } + + } ); + + Object.assign( InterleavedBufferAttribute.prototype, { + + isInterleavedBufferAttribute: true, + + applyMatrix4: function ( m ) { + + for ( var i = 0, l = this.data.count; i < l; i ++ ) { + + _vector$6.x = this.getX( i ); + _vector$6.y = this.getY( i ); + _vector$6.z = this.getZ( i ); + + _vector$6.applyMatrix4( m ); + + this.setXYZ( i, _vector$6.x, _vector$6.y, _vector$6.z ); + + } + + return this; + + }, + + setX: function ( index, x ) { + + this.data.array[ index * this.data.stride + this.offset ] = x; + + return this; + + }, + + setY: function ( index, y ) { + + this.data.array[ index * this.data.stride + this.offset + 1 ] = y; + + return this; + + }, + + setZ: function ( index, z ) { + + this.data.array[ index * this.data.stride + this.offset + 2 ] = z; + + return this; + + }, + + setW: function ( index, w ) { + + this.data.array[ index * this.data.stride + this.offset + 3 ] = w; + + return this; + + }, + + getX: function ( index ) { + + return this.data.array[ index * this.data.stride + this.offset ]; + + }, + + getY: function ( index ) { + + return this.data.array[ index * this.data.stride + this.offset + 1 ]; + + }, + + getZ: function ( index ) { + + return this.data.array[ index * this.data.stride + this.offset + 2 ]; + + }, + + getW: function ( index ) { + + return this.data.array[ index * this.data.stride + this.offset + 3 ]; + + }, + + setXY: function ( index, x, y ) { + + index = index * this.data.stride + this.offset; + + this.data.array[ index + 0 ] = x; + this.data.array[ index + 1 ] = y; + + return this; + + }, + + setXYZ: function ( index, x, y, z ) { + + index = index * this.data.stride + this.offset; + + this.data.array[ index + 0 ] = x; + this.data.array[ index + 1 ] = y; + this.data.array[ index + 2 ] = z; + + return this; + + }, + + setXYZW: function ( index, x, y, z, w ) { + + index = index * this.data.stride + this.offset; + + this.data.array[ index + 0 ] = x; + this.data.array[ index + 1 ] = y; + this.data.array[ index + 2 ] = z; + this.data.array[ index + 3 ] = w; + + return this; + + }, + + clone: function ( data ) { + + if ( data === undefined ) { + + console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.' ); + + var array = []; + + for ( var i = 0; i < this.count; i ++ ) { + + var index = i * this.data.stride + this.offset; + + for ( var j = 0; j < this.itemSize; j ++ ) { + + array.push( this.data.array[ index + j ] ); + + } + + } + + return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized ); + + } else { + + if ( data.interleavedBuffers === undefined ) { + + data.interleavedBuffers = {}; + + } + + if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) { + + data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data ); + + } + + return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized ); + + } + + }, + + toJSON: function ( data ) { + + if ( data === undefined ) { + + console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.' ); + + var array = []; + + for ( var i = 0; i < this.count; i ++ ) { + + var index = i * this.data.stride + this.offset; + + for ( var j = 0; j < this.itemSize; j ++ ) { + + array.push( this.data.array[ index + j ] ); + + } + + } + + // deinterleave data and save it as an ordinary buffer attribute for now + + return { + itemSize: this.itemSize, + type: this.array.constructor.name, + array: array, + normalized: this.normalized + }; + + } else { + + // save as true interlaved attribtue + + if ( data.interleavedBuffers === undefined ) { + + data.interleavedBuffers = {}; + + } + + if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) { + + data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data ); + + } + + return { + isInterleavedBufferAttribute: true, + itemSize: this.itemSize, + data: this.data.uuid, + offset: this.offset, + normalized: this.normalized + }; + + } + + } + + } ); + + /** + * parameters = { + * color: , + * map: new THREE.Texture( ), + * alphaMap: new THREE.Texture( ), + * rotation: , + * sizeAttenuation: + * } + */ + + function SpriteMaterial( parameters ) { + + Material.call( this ); + + this.type = 'SpriteMaterial'; + + this.color = new Color( 0xffffff ); + + this.map = null; + + this.alphaMap = null; + + this.rotation = 0; + + this.sizeAttenuation = true; + + this.transparent = true; + + this.setValues( parameters ); + + } + + SpriteMaterial.prototype = Object.create( Material.prototype ); + SpriteMaterial.prototype.constructor = SpriteMaterial; + SpriteMaterial.prototype.isSpriteMaterial = true; + + SpriteMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.color.copy( source.color ); + + this.map = source.map; + + this.alphaMap = source.alphaMap; + + this.rotation = source.rotation; + + this.sizeAttenuation = source.sizeAttenuation; + + return this; + + }; + + var _geometry; + + var _intersectPoint = new Vector3(); + var _worldScale = new Vector3(); + var _mvPosition = new Vector3(); + + var _alignedPosition = new Vector2(); + var _rotatedPosition = new Vector2(); + var _viewWorldMatrix = new Matrix4(); + + var _vA$1 = new Vector3(); + var _vB$1 = new Vector3(); + var _vC$1 = new Vector3(); + + var _uvA$1 = new Vector2(); + var _uvB$1 = new Vector2(); + var _uvC$1 = new Vector2(); + + function Sprite( material ) { + + Object3D.call( this ); + + this.type = 'Sprite'; + + if ( _geometry === undefined ) { + + _geometry = new BufferGeometry(); + + 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 + ] ); + + var interleavedBuffer = new InterleavedBuffer( float32Array, 5 ); + + _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] ); + _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) ); + _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) ); + + } + + this.geometry = _geometry; + this.material = ( material !== undefined ) ? material : new SpriteMaterial(); + + this.center = new Vector2( 0.5, 0.5 ); + + } + + Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: Sprite, + + isSprite: true, + + raycast: function ( raycaster, intersects ) { + + if ( raycaster.camera === null ) { + + console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' ); + + } + + _worldScale.setFromMatrixScale( this.matrixWorld ); + + _viewWorldMatrix.copy( raycaster.camera.matrixWorld ); + this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld ); + + _mvPosition.setFromMatrixPosition( this.modelViewMatrix ); + + if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) { + + _worldScale.multiplyScalar( - _mvPosition.z ); + + } + + var rotation = this.material.rotation; + var sin, cos; + + if ( rotation !== 0 ) { + + cos = Math.cos( rotation ); + sin = Math.sin( rotation ); + + } + + var center = this.center; + + transformVertex( _vA$1.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos ); + transformVertex( _vB$1.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos ); + transformVertex( _vC$1.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos ); + + _uvA$1.set( 0, 0 ); + _uvB$1.set( 1, 0 ); + _uvC$1.set( 1, 1 ); + + // check first triangle + var intersect = raycaster.ray.intersectTriangle( _vA$1, _vB$1, _vC$1, false, _intersectPoint ); + + if ( intersect === null ) { + + // check second triangle + transformVertex( _vB$1.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos ); + _uvB$1.set( 0, 1 ); + + intersect = raycaster.ray.intersectTriangle( _vA$1, _vC$1, _vB$1, false, _intersectPoint ); + if ( intersect === null ) { + + return; + + } + + } + + var distance = raycaster.ray.origin.distanceTo( _intersectPoint ); + + if ( distance < raycaster.near || distance > raycaster.far ) { return; } + + intersects.push( { + + distance: distance, + point: _intersectPoint.clone(), + uv: Triangle.getUV( _intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() ), + face: null, + object: this + + } ); + + }, + + copy: function ( source ) { + + Object3D.prototype.copy.call( this, source ); + + if ( source.center !== undefined ) { this.center.copy( source.center ); } + + this.material = source.material; + + return this; + + } + + } ); + + function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) { + + // compute position in camera space + _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale ); + + // to check if rotation is not zero + if ( sin !== undefined ) { + + _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y ); + _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y ); + + } else { + + _rotatedPosition.copy( _alignedPosition ); + + } + + + vertexPosition.copy( mvPosition ); + vertexPosition.x += _rotatedPosition.x; + vertexPosition.y += _rotatedPosition.y; + + // transform to world space + vertexPosition.applyMatrix4( _viewWorldMatrix ); + + } + + var _v1$4 = new Vector3(); + var _v2$2 = new Vector3(); + + function LOD() { + + Object3D.call( this ); + + this._currentLevel = 0; + + this.type = 'LOD'; + + Object.defineProperties( this, { + levels: { + enumerable: true, + value: [] + } + } ); + + this.autoUpdate = true; + + } + + LOD.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: LOD, + + isLOD: true, + + copy: function ( source ) { + + Object3D.prototype.copy.call( this, source, false ); + + var levels = source.levels; + + for ( var i = 0, l = levels.length; i < l; i ++ ) { + + var level = levels[ i ]; + + this.addLevel( level.object.clone(), level.distance ); + + } + + this.autoUpdate = source.autoUpdate; + + return this; + + }, + + addLevel: function ( object, distance ) { + + if ( distance === undefined ) { distance = 0; } + + distance = Math.abs( distance ); + + var levels = this.levels; + + var l; + + for ( l = 0; l < levels.length; l ++ ) { + + if ( distance < levels[ l ].distance ) { + + break; + + } + + } + + levels.splice( l, 0, { distance: distance, object: object } ); + + this.add( object ); + + return this; + + }, + + getCurrentLevel: function () { + + return this._currentLevel; + + }, + + getObjectForDistance: function ( distance ) { + + var levels = this.levels; + + if ( levels.length > 0 ) { + + var i, l; + + for ( i = 1, l = levels.length; i < l; i ++ ) { + + if ( distance < levels[ i ].distance ) { + + break; + + } + + } + + return levels[ i - 1 ].object; + + } + + return null; + + }, + + raycast: function ( raycaster, intersects ) { + + var levels = this.levels; + + if ( levels.length > 0 ) { + + _v1$4.setFromMatrixPosition( this.matrixWorld ); + + var distance = raycaster.ray.origin.distanceTo( _v1$4 ); + + this.getObjectForDistance( distance ).raycast( raycaster, intersects ); + + } + + }, + + update: function ( camera ) { + + var levels = this.levels; + + if ( levels.length > 1 ) { + + _v1$4.setFromMatrixPosition( camera.matrixWorld ); + _v2$2.setFromMatrixPosition( this.matrixWorld ); + + var distance = _v1$4.distanceTo( _v2$2 ) / camera.zoom; + + levels[ 0 ].object.visible = true; + + var i, l; + + for ( i = 1, l = levels.length; i < l; i ++ ) { + + if ( distance >= levels[ i ].distance ) { + + levels[ i - 1 ].object.visible = false; + levels[ i ].object.visible = true; + + } else { + + break; + + } + + } + + this._currentLevel = i - 1; + + for ( ; i < l; i ++ ) { + + levels[ i ].object.visible = false; + + } + + } + + }, + + toJSON: function ( meta ) { + + var data = Object3D.prototype.toJSON.call( this, meta ); + + if ( this.autoUpdate === false ) { data.object.autoUpdate = false; } + + data.object.levels = []; + + var levels = this.levels; + + for ( var i = 0, l = levels.length; i < l; i ++ ) { + + var level = levels[ i ]; + + data.object.levels.push( { + object: level.object.uuid, + distance: level.distance + } ); + + } + + return data; + + } + + } ); + + function SkinnedMesh( geometry, material ) { + + if ( geometry && geometry.isGeometry ) { + + console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' ); + + } + + Mesh.call( this, geometry, material ); + + this.type = 'SkinnedMesh'; + + this.bindMode = 'attached'; + this.bindMatrix = new Matrix4(); + this.bindMatrixInverse = new Matrix4(); + + } + + SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), { + + constructor: SkinnedMesh, + + isSkinnedMesh: true, + + copy: function ( source ) { + + Mesh.prototype.copy.call( this, source ); + + this.bindMode = source.bindMode; + this.bindMatrix.copy( source.bindMatrix ); + this.bindMatrixInverse.copy( source.bindMatrixInverse ); + + this.skeleton = source.skeleton; + + return this; + + }, + + bind: function ( skeleton, bindMatrix ) { + + this.skeleton = skeleton; + + if ( bindMatrix === undefined ) { + + this.updateMatrixWorld( true ); + + this.skeleton.calculateInverses(); + + bindMatrix = this.matrixWorld; + + } + + this.bindMatrix.copy( bindMatrix ); + this.bindMatrixInverse.getInverse( bindMatrix ); + + }, + + pose: function () { + + this.skeleton.pose(); + + }, + + normalizeSkinWeights: function () { + + var vector = new Vector4(); + + var skinWeight = this.geometry.attributes.skinWeight; + + for ( var i = 0, l = skinWeight.count; i < l; i ++ ) { + + vector.x = skinWeight.getX( i ); + vector.y = skinWeight.getY( i ); + vector.z = skinWeight.getZ( i ); + vector.w = skinWeight.getW( i ); + + var scale = 1.0 / vector.manhattanLength(); + + if ( scale !== Infinity ) { + + vector.multiplyScalar( scale ); + + } else { + + vector.set( 1, 0, 0, 0 ); // do something reasonable + + } + + skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w ); + + } + + }, + + updateMatrixWorld: function ( force ) { + + Mesh.prototype.updateMatrixWorld.call( this, force ); + + if ( this.bindMode === 'attached' ) { + + this.bindMatrixInverse.getInverse( this.matrixWorld ); + + } else if ( this.bindMode === 'detached' ) { + + this.bindMatrixInverse.getInverse( this.bindMatrix ); + + } else { + + console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode ); + + } + + }, + + boneTransform: ( function () { + + var basePosition = new Vector3(); + + var skinIndex = new Vector4(); + var skinWeight = new Vector4(); + + var vector = new Vector3(); + var matrix = new Matrix4(); + + return function ( index, target ) { + + var skeleton = this.skeleton; + var geometry = this.geometry; + + skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index ); + skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index ); + + basePosition.fromBufferAttribute( geometry.attributes.position, index ).applyMatrix4( this.bindMatrix ); + + target.set( 0, 0, 0 ); + + for ( var i = 0; i < 4; i ++ ) { + + var weight = skinWeight.getComponent( i ); + + if ( weight !== 0 ) { + + var boneIndex = skinIndex.getComponent( i ); + + matrix.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] ); + + target.addScaledVector( vector.copy( basePosition ).applyMatrix4( matrix ), weight ); + + } + + } + + return target.applyMatrix4( this.bindMatrixInverse ); + + }; + + }() ) + + } ); + + var _offsetMatrix = new Matrix4(); + var _identityMatrix = new Matrix4(); + + function Skeleton( bones, boneInverses ) { + + // copy the bone array + + bones = bones || []; + + this.bones = bones.slice( 0 ); + this.boneMatrices = new Float32Array( this.bones.length * 16 ); + + this.frame = - 1; + + // use the supplied bone inverses or calculate the inverses + + if ( boneInverses === undefined ) { + + this.calculateInverses(); + + } else { + + if ( this.bones.length === boneInverses.length ) { + + this.boneInverses = boneInverses.slice( 0 ); + + } else { + + console.warn( 'THREE.Skeleton boneInverses is the wrong length.' ); + + this.boneInverses = []; + + for ( var i = 0, il = this.bones.length; i < il; i ++ ) { + + this.boneInverses.push( new Matrix4() ); + + } + + } + + } + + } + + Object.assign( Skeleton.prototype, { + + calculateInverses: function () { + + this.boneInverses = []; + + for ( var i = 0, il = this.bones.length; i < il; i ++ ) { + + var inverse = new Matrix4(); + + if ( this.bones[ i ] ) { + + inverse.getInverse( this.bones[ i ].matrixWorld ); + + } + + this.boneInverses.push( inverse ); + + } + + }, + + pose: function () { + + // recover the bind-time world matrices + + for ( var i = 0, il = this.bones.length; i < il; i ++ ) { + + var bone = this.bones[ i ]; + + if ( bone ) { + + bone.matrixWorld.getInverse( this.boneInverses[ i ] ); + + } + + } + + // compute the local matrices, positions, rotations and scales + + for ( var i$1 = 0, il$1 = this.bones.length; i$1 < il$1; i$1 ++ ) { + + var bone$1 = this.bones[ i$1 ]; + + if ( bone$1 ) { + + if ( bone$1.parent && bone$1.parent.isBone ) { + + bone$1.matrix.getInverse( bone$1.parent.matrixWorld ); + bone$1.matrix.multiply( bone$1.matrixWorld ); + + } else { + + bone$1.matrix.copy( bone$1.matrixWorld ); + + } + + bone$1.matrix.decompose( bone$1.position, bone$1.quaternion, bone$1.scale ); + + } + + } + + }, + + update: function () { + + var bones = this.bones; + var boneInverses = this.boneInverses; + var boneMatrices = this.boneMatrices; + var boneTexture = this.boneTexture; + + // flatten bone matrices to array + + for ( var i = 0, il = bones.length; i < il; i ++ ) { + + // compute the offset between the current and the original transform + + var matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix; + + _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] ); + _offsetMatrix.toArray( boneMatrices, i * 16 ); + + } + + if ( boneTexture !== undefined ) { + + boneTexture.needsUpdate = true; + + } + + }, + + clone: function () { + + return new Skeleton( this.bones, this.boneInverses ); + + }, + + getBoneByName: function ( name ) { + + for ( var i = 0, il = this.bones.length; i < il; i ++ ) { + + var bone = this.bones[ i ]; + + if ( bone.name === name ) { + + return bone; + + } + + } + + return undefined; + + }, + + dispose: function ( ) { + + if ( this.boneTexture ) { + + this.boneTexture.dispose(); + + this.boneTexture = undefined; + + } + + } + + } ); + + function Bone() { + + Object3D.call( this ); + + this.type = 'Bone'; + + } + + Bone.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: Bone, + + isBone: true + + } ); + + var _instanceLocalMatrix = new Matrix4(); + var _instanceWorldMatrix = new Matrix4(); + + var _instanceIntersects = []; + + var _mesh = new Mesh(); + + function InstancedMesh( geometry, material, count ) { + + Mesh.call( this, geometry, material ); + + this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 ); + + this.count = count; + + this.frustumCulled = false; + + } + + InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), { + + constructor: InstancedMesh, + + isInstancedMesh: true, + + copy: function ( source ) { + + Mesh.prototype.copy.call( this, source ); + + this.instanceMatrix.copy( source.instanceMatrix ); + this.count = source.count; + + return this; + + }, + + getMatrixAt: function ( index, matrix ) { + + matrix.fromArray( this.instanceMatrix.array, index * 16 ); + + }, + + raycast: function ( raycaster, intersects ) { + + var matrixWorld = this.matrixWorld; + var raycastTimes = this.count; + + _mesh.geometry = this.geometry; + _mesh.material = this.material; + + if ( _mesh.material === undefined ) { return; } + + for ( var instanceId = 0; instanceId < raycastTimes; instanceId ++ ) { + + // calculate the world matrix for each instance + + this.getMatrixAt( instanceId, _instanceLocalMatrix ); + + _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix ); + + // the mesh represents this single instance + + _mesh.matrixWorld = _instanceWorldMatrix; + + _mesh.raycast( raycaster, _instanceIntersects ); + + // process the result of raycast + + for ( var i = 0, l = _instanceIntersects.length; i < l; i ++ ) { + + var intersect = _instanceIntersects[ i ]; + intersect.instanceId = instanceId; + intersect.object = this; + intersects.push( intersect ); + + } + + _instanceIntersects.length = 0; + + } + + }, + + setMatrixAt: function ( index, matrix ) { + + matrix.toArray( this.instanceMatrix.array, index * 16 ); + + }, + + updateMorphTargets: function () { + + } + + } ); + + /** + * parameters = { + * color: , + * opacity: , + * + * linewidth: , + * linecap: "round", + * linejoin: "round" + * } + */ + + function LineBasicMaterial( parameters ) { + + Material.call( this ); + + this.type = 'LineBasicMaterial'; + + this.color = new Color( 0xffffff ); + + this.linewidth = 1; + this.linecap = 'round'; + this.linejoin = 'round'; + + this.morphTargets = false; + + this.setValues( parameters ); + + } + + LineBasicMaterial.prototype = Object.create( Material.prototype ); + LineBasicMaterial.prototype.constructor = LineBasicMaterial; + + LineBasicMaterial.prototype.isLineBasicMaterial = true; + + LineBasicMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.color.copy( source.color ); + + this.linewidth = source.linewidth; + this.linecap = source.linecap; + this.linejoin = source.linejoin; + + this.morphTargets = source.morphTargets; + + return this; + + }; + + var _start = new Vector3(); + var _end = new Vector3(); + var _inverseMatrix$1 = new Matrix4(); + var _ray$1 = new Ray(); + var _sphere$2 = new Sphere(); + + function Line( geometry, material, mode ) { + + if ( mode === 1 ) { + + console.error( 'THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.' ); + + } + + Object3D.call( this ); + + this.type = 'Line'; + + this.geometry = geometry !== undefined ? geometry : new BufferGeometry(); + this.material = material !== undefined ? material : new LineBasicMaterial(); + + this.updateMorphTargets(); + + } + + Line.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: Line, + + isLine: true, + + copy: function ( source ) { + + Object3D.prototype.copy.call( this, source ); + + this.material = source.material; + this.geometry = source.geometry; + + return this; + + }, + + computeLineDistances: function () { + + var geometry = this.geometry; + + if ( geometry.isBufferGeometry ) { + + // we assume non-indexed geometry + + if ( geometry.index === null ) { + + var positionAttribute = geometry.attributes.position; + var lineDistances = [ 0 ]; + + for ( var i = 1, l = positionAttribute.count; i < l; i ++ ) { + + _start.fromBufferAttribute( positionAttribute, i - 1 ); + _end.fromBufferAttribute( positionAttribute, i ); + + lineDistances[ i ] = lineDistances[ i - 1 ]; + lineDistances[ i ] += _start.distanceTo( _end ); + + } + + geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) ); + + } else { + + console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' ); + + } + + } else if ( geometry.isGeometry ) { + + var vertices = geometry.vertices; + var lineDistances$1 = geometry.lineDistances; + + lineDistances$1[ 0 ] = 0; + + for ( var i$1 = 1, l$1 = vertices.length; i$1 < l$1; i$1 ++ ) { + + lineDistances$1[ i$1 ] = lineDistances$1[ i$1 - 1 ]; + lineDistances$1[ i$1 ] += vertices[ i$1 - 1 ].distanceTo( vertices[ i$1 ] ); + + } + + } + + return this; + + }, + + raycast: function ( raycaster, intersects ) { + + var geometry = this.geometry; + var matrixWorld = this.matrixWorld; + var threshold = raycaster.params.Line.threshold; + + // Checking boundingSphere distance to ray + + if ( geometry.boundingSphere === null ) { geometry.computeBoundingSphere(); } + + _sphere$2.copy( geometry.boundingSphere ); + _sphere$2.applyMatrix4( matrixWorld ); + _sphere$2.radius += threshold; + + if ( raycaster.ray.intersectsSphere( _sphere$2 ) === false ) { return; } + + // + + _inverseMatrix$1.getInverse( matrixWorld ); + _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 ); + + var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 ); + var localThresholdSq = localThreshold * localThreshold; + + var vStart = new Vector3(); + var vEnd = new Vector3(); + var interSegment = new Vector3(); + var interRay = new Vector3(); + var step = ( this && this.isLineSegments ) ? 2 : 1; + + if ( geometry.isBufferGeometry ) { + + var index = geometry.index; + var attributes = geometry.attributes; + var positions = attributes.position.array; + + if ( index !== null ) { + + var indices = index.array; + + for ( var i = 0, l = indices.length - 1; i < l; i += step ) { + + var a = indices[ i ]; + var b = indices[ i + 1 ]; + + vStart.fromArray( positions, a * 3 ); + vEnd.fromArray( positions, b * 3 ); + + var distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment ); + + if ( distSq > localThresholdSq ) { continue; } + + interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation + + var distance = raycaster.ray.origin.distanceTo( interRay ); + + if ( distance < raycaster.near || distance > raycaster.far ) { continue; } + + intersects.push( { + + distance: distance, + // What do we want? intersection point on the ray or on the segment?? + // point: raycaster.ray.at( distance ), + point: interSegment.clone().applyMatrix4( this.matrixWorld ), + index: i, + face: null, + faceIndex: null, + object: this + + } ); + + } + + } else { + + for ( var i$1 = 0, l$1 = positions.length / 3 - 1; i$1 < l$1; i$1 += step ) { + + vStart.fromArray( positions, 3 * i$1 ); + vEnd.fromArray( positions, 3 * i$1 + 3 ); + + var distSq$1 = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment ); + + if ( distSq$1 > localThresholdSq ) { continue; } + + interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation + + var distance$1 = raycaster.ray.origin.distanceTo( interRay ); + + if ( distance$1 < raycaster.near || distance$1 > raycaster.far ) { continue; } + + intersects.push( { + + distance: distance$1, + // What do we want? intersection point on the ray or on the segment?? + // point: raycaster.ray.at( distance ), + point: interSegment.clone().applyMatrix4( this.matrixWorld ), + index: i$1, + face: null, + faceIndex: null, + object: this + + } ); + + } + + } + + } else if ( geometry.isGeometry ) { + + var vertices = geometry.vertices; + var nbVertices = vertices.length; + + for ( var i$2 = 0; i$2 < nbVertices - 1; i$2 += step ) { + + var distSq$2 = _ray$1.distanceSqToSegment( vertices[ i$2 ], vertices[ i$2 + 1 ], interRay, interSegment ); + + if ( distSq$2 > localThresholdSq ) { continue; } + + interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation + + var distance$2 = raycaster.ray.origin.distanceTo( interRay ); + + if ( distance$2 < raycaster.near || distance$2 > raycaster.far ) { continue; } + + intersects.push( { + + distance: distance$2, + // What do we want? intersection point on the ray or on the segment?? + // point: raycaster.ray.at( distance ), + point: interSegment.clone().applyMatrix4( this.matrixWorld ), + index: i$2, + face: null, + faceIndex: null, + object: this + + } ); + + } + + } + + }, + + updateMorphTargets: function () { + + var geometry = this.geometry; + + if ( geometry.isBufferGeometry ) { + + var morphAttributes = geometry.morphAttributes; + var keys = Object.keys( morphAttributes ); + + if ( keys.length > 0 ) { + + var morphAttribute = morphAttributes[ keys[ 0 ] ]; + + if ( morphAttribute !== undefined ) { + + this.morphTargetInfluences = []; + this.morphTargetDictionary = {}; + + for ( var m = 0, ml = morphAttribute.length; m < ml; m ++ ) { + + var name = morphAttribute[ m ].name || String( m ); + + this.morphTargetInfluences.push( 0 ); + this.morphTargetDictionary[ name ] = m; + + } + + } + + } + + } else { + + var morphTargets = geometry.morphTargets; + + if ( morphTargets !== undefined && morphTargets.length > 0 ) { + + console.error( 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' ); + + } + + } + + } + + } ); + + var _start$1 = new Vector3(); + var _end$1 = new Vector3(); + + function LineSegments( geometry, material ) { + + Line.call( this, geometry, material ); + + this.type = 'LineSegments'; + + } + + LineSegments.prototype = Object.assign( Object.create( Line.prototype ), { + + constructor: LineSegments, + + isLineSegments: true, + + computeLineDistances: function () { + + var geometry = this.geometry; + + if ( geometry.isBufferGeometry ) { + + // we assume non-indexed geometry + + if ( geometry.index === null ) { + + var positionAttribute = geometry.attributes.position; + var lineDistances = []; + + for ( var i = 0, l = positionAttribute.count; i < l; i += 2 ) { + + _start$1.fromBufferAttribute( positionAttribute, i ); + _end$1.fromBufferAttribute( positionAttribute, i + 1 ); + + lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ]; + lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 ); + + } + + geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) ); + + } else { + + console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' ); + + } + + } else if ( geometry.isGeometry ) { + + var vertices = geometry.vertices; + var lineDistances$1 = geometry.lineDistances; + + for ( var i$1 = 0, l$1 = vertices.length; i$1 < l$1; i$1 += 2 ) { + + _start$1.copy( vertices[ i$1 ] ); + _end$1.copy( vertices[ i$1 + 1 ] ); + + lineDistances$1[ i$1 ] = ( i$1 === 0 ) ? 0 : lineDistances$1[ i$1 - 1 ]; + lineDistances$1[ i$1 + 1 ] = lineDistances$1[ i$1 ] + _start$1.distanceTo( _end$1 ); + + } + + } + + return this; + + } + + } ); + + function LineLoop( geometry, material ) { + + Line.call( this, geometry, material ); + + this.type = 'LineLoop'; + + } + + LineLoop.prototype = Object.assign( Object.create( Line.prototype ), { + + constructor: LineLoop, + + isLineLoop: true, + + } ); + + /** + * parameters = { + * color: , + * opacity: , + * map: new THREE.Texture( ), + * alphaMap: new THREE.Texture( ), + * + * size: , + * sizeAttenuation: + * + * morphTargets: + * } + */ + + function PointsMaterial( parameters ) { + + Material.call( this ); + + this.type = 'PointsMaterial'; + + this.color = new Color( 0xffffff ); + + this.map = null; + + this.alphaMap = null; + + this.size = 1; + this.sizeAttenuation = true; + + this.morphTargets = false; + + this.setValues( parameters ); + + } + + PointsMaterial.prototype = Object.create( Material.prototype ); + PointsMaterial.prototype.constructor = PointsMaterial; + + PointsMaterial.prototype.isPointsMaterial = true; + + PointsMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.color.copy( source.color ); + + this.map = source.map; + + this.alphaMap = source.alphaMap; + + this.size = source.size; + this.sizeAttenuation = source.sizeAttenuation; + + this.morphTargets = source.morphTargets; + + return this; + + }; + + var _inverseMatrix$2 = new Matrix4(); + var _ray$2 = new Ray(); + var _sphere$3 = new Sphere(); + var _position$1 = new Vector3(); + + function Points( geometry, material ) { + + Object3D.call( this ); + + this.type = 'Points'; + + this.geometry = geometry !== undefined ? geometry : new BufferGeometry(); + this.material = material !== undefined ? material : new PointsMaterial(); + + this.updateMorphTargets(); + + } + + Points.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: Points, + + isPoints: true, + + copy: function ( source ) { + + Object3D.prototype.copy.call( this, source ); + + this.material = source.material; + this.geometry = source.geometry; + + return this; + + }, + + raycast: function ( raycaster, intersects ) { + + var geometry = this.geometry; + var matrixWorld = this.matrixWorld; + var threshold = raycaster.params.Points.threshold; + + // Checking boundingSphere distance to ray + + if ( geometry.boundingSphere === null ) { geometry.computeBoundingSphere(); } + + _sphere$3.copy( geometry.boundingSphere ); + _sphere$3.applyMatrix4( matrixWorld ); + _sphere$3.radius += threshold; + + if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) { return; } + + // + + _inverseMatrix$2.getInverse( matrixWorld ); + _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 ); + + var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 ); + var localThresholdSq = localThreshold * localThreshold; + + if ( geometry.isBufferGeometry ) { + + var index = geometry.index; + var attributes = geometry.attributes; + var positions = attributes.position.array; + + if ( index !== null ) { + + var indices = index.array; + + for ( var i = 0, il = indices.length; i < il; i ++ ) { + + var a = indices[ i ]; + + _position$1.fromArray( positions, a * 3 ); + + testPoint( _position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this ); + + } + + } else { + + for ( var i$1 = 0, l = positions.length / 3; i$1 < l; i$1 ++ ) { + + _position$1.fromArray( positions, i$1 * 3 ); + + testPoint( _position$1, i$1, localThresholdSq, matrixWorld, raycaster, intersects, this ); + + } + + } + + } else { + + var vertices = geometry.vertices; + + for ( var i$2 = 0, l$1 = vertices.length; i$2 < l$1; i$2 ++ ) { + + testPoint( vertices[ i$2 ], i$2, localThresholdSq, matrixWorld, raycaster, intersects, this ); + + } + + } + + }, + + updateMorphTargets: function () { + + var geometry = this.geometry; + + if ( geometry.isBufferGeometry ) { + + var morphAttributes = geometry.morphAttributes; + var keys = Object.keys( morphAttributes ); + + if ( keys.length > 0 ) { + + var morphAttribute = morphAttributes[ keys[ 0 ] ]; + + if ( morphAttribute !== undefined ) { + + this.morphTargetInfluences = []; + this.morphTargetDictionary = {}; + + for ( var m = 0, ml = morphAttribute.length; m < ml; m ++ ) { + + var name = morphAttribute[ m ].name || String( m ); + + this.morphTargetInfluences.push( 0 ); + this.morphTargetDictionary[ name ] = m; + + } + + } + + } + + } else { + + var morphTargets = geometry.morphTargets; + + if ( morphTargets !== undefined && morphTargets.length > 0 ) { + + console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' ); + + } + + } + + } + + } ); + + function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) { + + var rayPointDistanceSq = _ray$2.distanceSqToPoint( point ); + + if ( rayPointDistanceSq < localThresholdSq ) { + + var intersectPoint = new Vector3(); + + _ray$2.closestPointToPoint( point, intersectPoint ); + intersectPoint.applyMatrix4( matrixWorld ); + + var distance = raycaster.ray.origin.distanceTo( intersectPoint ); + + if ( distance < raycaster.near || distance > raycaster.far ) { return; } + + intersects.push( { + + distance: distance, + distanceToRay: Math.sqrt( rayPointDistanceSq ), + point: intersectPoint, + index: index, + face: null, + object: object + + } ); + + } + + } + + function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) { + + Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ); + + this.format = format !== undefined ? format : RGBFormat; + + this.minFilter = minFilter !== undefined ? minFilter : LinearFilter; + this.magFilter = magFilter !== undefined ? magFilter : LinearFilter; + + this.generateMipmaps = false; + + var scope = this; + + function updateVideo() { + + scope.needsUpdate = true; + video.requestVideoFrameCallback( updateVideo ); + + } + + if ( 'requestVideoFrameCallback' in video ) { + + video.requestVideoFrameCallback( updateVideo ); + + } + + } + + VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), { + + constructor: VideoTexture, + + isVideoTexture: true, + + update: function () { + + var video = this.image; + var hasVideoFrameCallback = 'requestVideoFrameCallback' in video; + + if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) { + + this.needsUpdate = true; + + } + + } + + } ); + + function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) { + + Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ); + + this.image = { width: width, height: height }; + this.mipmaps = mipmaps; + + // no flipping for cube textures + // (also flipping doesn't work for compressed textures ) + + this.flipY = false; + + // can't generate mipmaps for compressed textures + // mips must be embedded in DDS files + + this.generateMipmaps = false; + + } + + CompressedTexture.prototype = Object.create( Texture.prototype ); + CompressedTexture.prototype.constructor = CompressedTexture; + + CompressedTexture.prototype.isCompressedTexture = true; + + function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) { + + Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ); + + this.needsUpdate = true; + + } + + CanvasTexture.prototype = Object.create( Texture.prototype ); + CanvasTexture.prototype.constructor = CanvasTexture; + CanvasTexture.prototype.isCanvasTexture = true; + + function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) { + + format = format !== undefined ? format : DepthFormat; + + if ( format !== DepthFormat && format !== DepthStencilFormat ) { + + throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' ); + + } + + if ( type === undefined && format === DepthFormat ) { type = UnsignedShortType; } + if ( type === undefined && format === DepthStencilFormat ) { type = UnsignedInt248Type; } + + Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ); + + this.image = { width: width, height: height }; + + this.magFilter = magFilter !== undefined ? magFilter : NearestFilter; + this.minFilter = minFilter !== undefined ? minFilter : NearestFilter; + + this.flipY = false; + this.generateMipmaps = false; + + } + + DepthTexture.prototype = Object.create( Texture.prototype ); + DepthTexture.prototype.constructor = DepthTexture; + DepthTexture.prototype.isDepthTexture = true; + + function WireframeGeometry( geometry ) { + + BufferGeometry.call( this ); + + this.type = 'WireframeGeometry'; + + // buffer + + var vertices = []; + + // helper variables + + var edge = [ 0, 0 ], edges = {}; + var keys = [ 'a', 'b', 'c' ]; + + // different logic for Geometry and BufferGeometry + + if ( geometry && geometry.isGeometry ) { + + // create a data structure that contains all edges without duplicates + + var faces = geometry.faces; + + for ( var i = 0, l = faces.length; i < l; i ++ ) { + + var face = faces[ i ]; + + for ( var j = 0; j < 3; j ++ ) { + + var edge1 = face[ keys[ j ] ]; + var edge2 = face[ keys[ ( j + 1 ) % 3 ] ]; + edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates + edge[ 1 ] = Math.max( edge1, edge2 ); + + var key = edge[ 0 ] + ',' + edge[ 1 ]; + + if ( edges[ key ] === undefined ) { + + edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] }; + + } + + } + + } + + // generate vertices + + for ( var key$1 in edges ) { + + var e = edges[ key$1 ]; + + var vertex = geometry.vertices[ e.index1 ]; + vertices.push( vertex.x, vertex.y, vertex.z ); + + vertex = geometry.vertices[ e.index2 ]; + vertices.push( vertex.x, vertex.y, vertex.z ); + + } + + } else if ( geometry && geometry.isBufferGeometry ) { + + var vertex$1 = new Vector3(); + + if ( geometry.index !== null ) { + + // indexed BufferGeometry + + var position = geometry.attributes.position; + var indices = geometry.index; + var groups = geometry.groups; + + if ( groups.length === 0 ) { + + groups = [ { start: 0, count: indices.count, materialIndex: 0 } ]; + + } + + // create a data structure that contains all eges without duplicates + + for ( var o = 0, ol = groups.length; o < ol; ++ o ) { + + var group = groups[ o ]; + + var start = group.start; + var count = group.count; + + for ( var i$1 = start, l$1 = ( start + count ); i$1 < l$1; i$1 += 3 ) { + + for ( var j$1 = 0; j$1 < 3; j$1 ++ ) { + + var edge1$1 = indices.getX( i$1 + j$1 ); + var edge2$1 = indices.getX( i$1 + ( j$1 + 1 ) % 3 ); + edge[ 0 ] = Math.min( edge1$1, edge2$1 ); // sorting prevents duplicates + edge[ 1 ] = Math.max( edge1$1, edge2$1 ); + + var key$2 = edge[ 0 ] + ',' + edge[ 1 ]; + + if ( edges[ key$2 ] === undefined ) { + + edges[ key$2 ] = { index1: edge[ 0 ], index2: edge[ 1 ] }; + + } + + } + + } + + } + + // generate vertices + + for ( var key$3 in edges ) { + + var e$1 = edges[ key$3 ]; + + vertex$1.fromBufferAttribute( position, e$1.index1 ); + vertices.push( vertex$1.x, vertex$1.y, vertex$1.z ); + + vertex$1.fromBufferAttribute( position, e$1.index2 ); + vertices.push( vertex$1.x, vertex$1.y, vertex$1.z ); + + } + + } else { + + // non-indexed BufferGeometry + + var position$1 = geometry.attributes.position; + + for ( var i$2 = 0, l$2 = ( position$1.count / 3 ); i$2 < l$2; i$2 ++ ) { + + for ( var j$2 = 0; j$2 < 3; j$2 ++ ) { + + // three edges per triangle, an edge is represented as (index1, index2) + // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0) + + var index1 = 3 * i$2 + j$2; + vertex$1.fromBufferAttribute( position$1, index1 ); + vertices.push( vertex$1.x, vertex$1.y, vertex$1.z ); + + var index2 = 3 * i$2 + ( ( j$2 + 1 ) % 3 ); + vertex$1.fromBufferAttribute( position$1, index2 ); + vertices.push( vertex$1.x, vertex$1.y, vertex$1.z ); + + } + + } + + } + + } + + // build geometry + + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + + } + + WireframeGeometry.prototype = Object.create( BufferGeometry.prototype ); + WireframeGeometry.prototype.constructor = WireframeGeometry; + + /** + * Parametric Surfaces Geometry + * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html + */ + + // ParametricGeometry + + function ParametricGeometry( func, slices, stacks ) { + + Geometry.call( this ); + + this.type = 'ParametricGeometry'; + + this.parameters = { + func: func, + slices: slices, + stacks: stacks + }; + + this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) ); + this.mergeVertices(); + + } + + ParametricGeometry.prototype = Object.create( Geometry.prototype ); + ParametricGeometry.prototype.constructor = ParametricGeometry; + + // ParametricBufferGeometry + + function ParametricBufferGeometry( func, slices, stacks ) { + + BufferGeometry.call( this ); + + this.type = 'ParametricBufferGeometry'; + + this.parameters = { + func: func, + slices: slices, + stacks: stacks + }; + + // buffers + + var indices = []; + var vertices = []; + var normals = []; + var uvs = []; + + var EPS = 0.00001; + + var normal = new Vector3(); + + var p0 = new Vector3(), p1 = new Vector3(); + var pu = new Vector3(), pv = new Vector3(); + + if ( func.length < 3 ) { + + console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' ); + + } + + // generate vertices, normals and uvs + + var sliceCount = slices + 1; + + for ( var i = 0; i <= stacks; i ++ ) { + + var v = i / stacks; + + for ( var j = 0; j <= slices; j ++ ) { + + var u = j / slices; + + // vertex + + func( u, v, p0 ); + vertices.push( p0.x, p0.y, p0.z ); + + // normal + + // approximate tangent vectors via finite differences + + if ( u - EPS >= 0 ) { + + func( u - EPS, v, p1 ); + pu.subVectors( p0, p1 ); + + } else { + + func( u + EPS, v, p1 ); + pu.subVectors( p1, p0 ); + + } + + if ( v - EPS >= 0 ) { + + func( u, v - EPS, p1 ); + pv.subVectors( p0, p1 ); + + } else { + + func( u, v + EPS, p1 ); + pv.subVectors( p1, p0 ); + + } + + // cross product of tangent vectors returns surface normal + + normal.crossVectors( pu, pv ).normalize(); + normals.push( normal.x, normal.y, normal.z ); + + // uv + + uvs.push( u, v ); + + } + + } + + // generate indices + + for ( var i$1 = 0; i$1 < stacks; i$1 ++ ) { + + for ( var j$1 = 0; j$1 < slices; j$1 ++ ) { + + var a = i$1 * sliceCount + j$1; + var b = i$1 * sliceCount + j$1 + 1; + var c = ( i$1 + 1 ) * sliceCount + j$1 + 1; + var d = ( i$1 + 1 ) * sliceCount + j$1; + + // faces one and two + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry; + + // PolyhedronGeometry + + function PolyhedronGeometry( vertices, indices, radius, detail ) { + + Geometry.call( this ); + + this.type = 'PolyhedronGeometry'; + + this.parameters = { + vertices: vertices, + indices: indices, + radius: radius, + detail: detail + }; + + this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) ); + this.mergeVertices(); + + } + + PolyhedronGeometry.prototype = Object.create( Geometry.prototype ); + PolyhedronGeometry.prototype.constructor = PolyhedronGeometry; + + // PolyhedronBufferGeometry + + function PolyhedronBufferGeometry( vertices, indices, radius, detail ) { + + BufferGeometry.call( this ); + + this.type = 'PolyhedronBufferGeometry'; + + this.parameters = { + vertices: vertices, + indices: indices, + radius: radius, + detail: detail + }; + + radius = radius || 1; + detail = detail || 0; + + // default buffer data + + var vertexBuffer = []; + var uvBuffer = []; + + // the subdivision creates the vertex buffer data + + subdivide( detail ); + + // all vertices should lie on a conceptual sphere with a given radius + + applyRadius( radius ); + + // finally, create the uv data + + generateUVs(); + + // build non-indexed geometry + + this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) ); + + if ( detail === 0 ) { + + this.computeVertexNormals(); // flat normals + + } else { + + this.normalizeNormals(); // smooth normals + + } + + // helper functions + + function subdivide( detail ) { + + var a = new Vector3(); + var b = new Vector3(); + var c = new Vector3(); + + // iterate over all faces and apply a subdivison with the given detail value + + for ( var i = 0; i < indices.length; i += 3 ) { + + // get the vertices of the face + + getVertexByIndex( indices[ i + 0 ], a ); + getVertexByIndex( indices[ i + 1 ], b ); + getVertexByIndex( indices[ i + 2 ], c ); + + // perform subdivision + + subdivideFace( a, b, c, detail ); + + } + + } + + function subdivideFace( a, b, c, detail ) { + + var cols = Math.pow( 2, detail ); + + // we use this multidimensional array as a data structure for creating the subdivision + + var v = []; + + // construct all of the vertices for this subdivision + + for ( var i = 0; i <= cols; i ++ ) { + + v[ i ] = []; + + var aj = a.clone().lerp( c, i / cols ); + var bj = b.clone().lerp( c, i / cols ); + + var rows = cols - i; + + for ( var j = 0; j <= rows; j ++ ) { + + if ( j === 0 && i === cols ) { + + v[ i ][ j ] = aj; + + } else { + + v[ i ][ j ] = aj.clone().lerp( bj, j / rows ); + + } + + } + + } + + // construct all of the faces + + for ( var i$1 = 0; i$1 < cols; i$1 ++ ) { + + for ( var j$1 = 0; j$1 < 2 * ( cols - i$1 ) - 1; j$1 ++ ) { + + var k = Math.floor( j$1 / 2 ); + + if ( j$1 % 2 === 0 ) { + + pushVertex( v[ i$1 ][ k + 1 ] ); + pushVertex( v[ i$1 + 1 ][ k ] ); + pushVertex( v[ i$1 ][ k ] ); + + } else { + + pushVertex( v[ i$1 ][ k + 1 ] ); + pushVertex( v[ i$1 + 1 ][ k + 1 ] ); + pushVertex( v[ i$1 + 1 ][ k ] ); + + } + + } + + } + + } + + function applyRadius( radius ) { + + var vertex = new Vector3(); + + // iterate over the entire buffer and apply the radius to each vertex + + for ( var i = 0; i < vertexBuffer.length; i += 3 ) { + + vertex.x = vertexBuffer[ i + 0 ]; + vertex.y = vertexBuffer[ i + 1 ]; + vertex.z = vertexBuffer[ i + 2 ]; + + vertex.normalize().multiplyScalar( radius ); + + vertexBuffer[ i + 0 ] = vertex.x; + vertexBuffer[ i + 1 ] = vertex.y; + vertexBuffer[ i + 2 ] = vertex.z; + + } + + } + + function generateUVs() { + + var vertex = new Vector3(); + + for ( var i = 0; i < vertexBuffer.length; i += 3 ) { + + vertex.x = vertexBuffer[ i + 0 ]; + vertex.y = vertexBuffer[ i + 1 ]; + vertex.z = vertexBuffer[ i + 2 ]; + + var u = azimuth( vertex ) / 2 / Math.PI + 0.5; + var v = inclination( vertex ) / Math.PI + 0.5; + uvBuffer.push( u, 1 - v ); + + } + + correctUVs(); + + correctSeam(); + + } + + function correctSeam() { + + // handle case when face straddles the seam, see #3269 + + for ( var i = 0; i < uvBuffer.length; i += 6 ) { + + // uv data of a single face + + var x0 = uvBuffer[ i + 0 ]; + var x1 = uvBuffer[ i + 2 ]; + var x2 = uvBuffer[ i + 4 ]; + + var max = Math.max( x0, x1, x2 ); + var min = Math.min( x0, x1, x2 ); + + // 0.9 is somewhat arbitrary + + if ( max > 0.9 && min < 0.1 ) { + + if ( x0 < 0.2 ) { uvBuffer[ i + 0 ] += 1; } + if ( x1 < 0.2 ) { uvBuffer[ i + 2 ] += 1; } + if ( x2 < 0.2 ) { uvBuffer[ i + 4 ] += 1; } + + } + + } + + } + + function pushVertex( vertex ) { + + vertexBuffer.push( vertex.x, vertex.y, vertex.z ); + + } + + function getVertexByIndex( index, vertex ) { + + var stride = index * 3; + + vertex.x = vertices[ stride + 0 ]; + vertex.y = vertices[ stride + 1 ]; + vertex.z = vertices[ stride + 2 ]; + + } + + function correctUVs() { + + var a = new Vector3(); + var b = new Vector3(); + var c = new Vector3(); + + var centroid = new Vector3(); + + var uvA = new Vector2(); + var uvB = new Vector2(); + var uvC = new Vector2(); + + for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) { + + a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] ); + b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] ); + c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] ); + + uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] ); + uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] ); + uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] ); + + centroid.copy( a ).add( b ).add( c ).divideScalar( 3 ); + + var azi = azimuth( centroid ); + + correctUV( uvA, j + 0, a, azi ); + correctUV( uvB, j + 2, b, azi ); + correctUV( uvC, j + 4, c, azi ); + + } + + } + + function correctUV( uv, stride, vector, azimuth ) { + + if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) { + + uvBuffer[ stride ] = uv.x - 1; + + } + + if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) { + + uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5; + + } + + } + + // Angle around the Y axis, counter-clockwise when looking from above. + + function azimuth( vector ) { + + return Math.atan2( vector.z, - vector.x ); + + } + + + // Angle above the XZ plane. + + function inclination( vector ) { + + return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) ); + + } + + } + + PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry; + + // TetrahedronGeometry + + function TetrahedronGeometry( radius, detail ) { + + Geometry.call( this ); + + this.type = 'TetrahedronGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) ); + this.mergeVertices(); + + } + + TetrahedronGeometry.prototype = Object.create( Geometry.prototype ); + TetrahedronGeometry.prototype.constructor = TetrahedronGeometry; + + // TetrahedronBufferGeometry + + function TetrahedronBufferGeometry( radius, detail ) { + + var vertices = [ + 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1 + ]; + + var indices = [ + 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1 + ]; + + PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail ); + + this.type = 'TetrahedronBufferGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + } + + TetrahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype ); + TetrahedronBufferGeometry.prototype.constructor = TetrahedronBufferGeometry; + + // OctahedronGeometry + + function OctahedronGeometry( radius, detail ) { + + Geometry.call( this ); + + this.type = 'OctahedronGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) ); + this.mergeVertices(); + + } + + OctahedronGeometry.prototype = Object.create( Geometry.prototype ); + OctahedronGeometry.prototype.constructor = OctahedronGeometry; + + // OctahedronBufferGeometry + + function OctahedronBufferGeometry( radius, detail ) { + + var vertices = [ + 1, 0, 0, - 1, 0, 0, 0, 1, 0, + 0, - 1, 0, 0, 0, 1, 0, 0, - 1 + ]; + + 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 + ]; + + PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail ); + + this.type = 'OctahedronBufferGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + } + + OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype ); + OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry; + + // IcosahedronGeometry + + function IcosahedronGeometry( radius, detail ) { + + Geometry.call( this ); + + this.type = 'IcosahedronGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) ); + this.mergeVertices(); + + } + + IcosahedronGeometry.prototype = Object.create( Geometry.prototype ); + IcosahedronGeometry.prototype.constructor = IcosahedronGeometry; + + // IcosahedronBufferGeometry + + function IcosahedronBufferGeometry( radius, detail ) { + + var t = ( 1 + Math.sqrt( 5 ) ) / 2; + + 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 + ]; + + 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 + ]; + + PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail ); + + this.type = 'IcosahedronBufferGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + } + + IcosahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype ); + IcosahedronBufferGeometry.prototype.constructor = IcosahedronBufferGeometry; + + // DodecahedronGeometry + + function DodecahedronGeometry( radius, detail ) { + + Geometry.call( this ); + + this.type = 'DodecahedronGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) ); + this.mergeVertices(); + + } + + DodecahedronGeometry.prototype = Object.create( Geometry.prototype ); + DodecahedronGeometry.prototype.constructor = DodecahedronGeometry; + + // DodecahedronBufferGeometry + + function DodecahedronBufferGeometry( radius, detail ) { + + var t = ( 1 + Math.sqrt( 5 ) ) / 2; + var r = 1 / t; + + var vertices = [ + + // (±1, ±1, ±1) + - 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/φ, ±φ) + 0, - r, - t, 0, - r, t, + 0, r, - t, 0, r, t, + + // (±1/φ, ±φ, 0) + - r, - t, 0, - r, t, 0, + r, - t, 0, r, t, 0, + + // (±φ, 0, ±1/φ) + - t, 0, - r, t, 0, - r, + - t, 0, r, t, 0, r + ]; + + 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 + ]; + + PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail ); + + this.type = 'DodecahedronBufferGeometry'; + + this.parameters = { + radius: radius, + detail: detail + }; + + } + + DodecahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype ); + DodecahedronBufferGeometry.prototype.constructor = DodecahedronBufferGeometry; + + // TubeGeometry + + function TubeGeometry( path, tubularSegments, radius, radialSegments, closed, taper ) { + + Geometry.call( this ); + + this.type = 'TubeGeometry'; + + this.parameters = { + path: path, + tubularSegments: tubularSegments, + radius: radius, + radialSegments: radialSegments, + closed: closed + }; + + if ( taper !== undefined ) { console.warn( 'THREE.TubeGeometry: taper has been removed.' ); } + + var bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ); + + // expose internals + + this.tangents = bufferGeometry.tangents; + this.normals = bufferGeometry.normals; + this.binormals = bufferGeometry.binormals; + + // create geometry + + this.fromBufferGeometry( bufferGeometry ); + this.mergeVertices(); + + } + + TubeGeometry.prototype = Object.create( Geometry.prototype ); + TubeGeometry.prototype.constructor = TubeGeometry; + + // TubeBufferGeometry + + function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed ) { + + BufferGeometry.call( this ); + + this.type = 'TubeBufferGeometry'; + + this.parameters = { + path: path, + tubularSegments: tubularSegments, + radius: radius, + radialSegments: radialSegments, + closed: closed + }; + + tubularSegments = tubularSegments || 64; + radius = radius || 1; + radialSegments = radialSegments || 8; + closed = closed || false; + + var frames = path.computeFrenetFrames( tubularSegments, closed ); + + // expose internals + + this.tangents = frames.tangents; + this.normals = frames.normals; + this.binormals = frames.binormals; + + // helper variables + + var vertex = new Vector3(); + var normal = new Vector3(); + var uv = new Vector2(); + var P = new Vector3(); + + // buffer + + var vertices = []; + var normals = []; + var uvs = []; + var indices = []; + + // create buffer data + + generateBufferData(); + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + // functions + + function generateBufferData() { + + for ( var i = 0; i < tubularSegments; i ++ ) { + + generateSegment( i ); + + } + + // if the geometry is not closed, generate the last row of vertices and normals + // at the regular position on the given path + // + // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ) + + generateSegment( ( closed === false ) ? tubularSegments : 0 ); + + // uvs are generated in a separate function. + // this makes it easy compute correct values for closed geometries + + generateUVs(); + + // finally create faces + + generateIndices(); + + } + + function generateSegment( i ) { + + // we use getPointAt to sample evenly distributed points from the given path + + P = path.getPointAt( i / tubularSegments, P ); + + // retrieve corresponding normal and binormal + + var N = frames.normals[ i ]; + var B = frames.binormals[ i ]; + + // generate normals and vertices for the current segment + + for ( var j = 0; j <= radialSegments; j ++ ) { + + var v = j / radialSegments * Math.PI * 2; + + var sin = Math.sin( v ); + var cos = - Math.cos( v ); + + // normal + + normal.x = ( cos * N.x + sin * B.x ); + normal.y = ( cos * N.y + sin * B.y ); + normal.z = ( cos * N.z + sin * B.z ); + normal.normalize(); + + normals.push( normal.x, normal.y, normal.z ); + + // vertex + + vertex.x = P.x + radius * normal.x; + vertex.y = P.y + radius * normal.y; + vertex.z = P.z + radius * normal.z; + + vertices.push( vertex.x, vertex.y, vertex.z ); + + } + + } + + function generateIndices() { + + for ( var j = 1; j <= tubularSegments; j ++ ) { + + for ( var i = 1; i <= radialSegments; i ++ ) { + + var a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 ); + var b = ( radialSegments + 1 ) * j + ( i - 1 ); + var c = ( radialSegments + 1 ) * j + i; + var d = ( radialSegments + 1 ) * ( j - 1 ) + i; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + } + + function generateUVs() { + + for ( var i = 0; i <= tubularSegments; i ++ ) { + + for ( var j = 0; j <= radialSegments; j ++ ) { + + uv.x = i / tubularSegments; + uv.y = j / radialSegments; + + uvs.push( uv.x, uv.y ); + + } + + } + + } + + } + + TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + TubeBufferGeometry.prototype.constructor = TubeBufferGeometry; + + TubeBufferGeometry.prototype.toJSON = function () { + + var data = BufferGeometry.prototype.toJSON.call( this ); + + data.path = this.parameters.path.toJSON(); + + return data; + + }; + + // TorusKnotGeometry + + function TorusKnotGeometry( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) { + + Geometry.call( this ); + + this.type = 'TorusKnotGeometry'; + + this.parameters = { + radius: radius, + tube: tube, + tubularSegments: tubularSegments, + radialSegments: radialSegments, + p: p, + q: q + }; + + if ( heightScale !== undefined ) { console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' ); } + + this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) ); + this.mergeVertices(); + + } + + TorusKnotGeometry.prototype = Object.create( Geometry.prototype ); + TorusKnotGeometry.prototype.constructor = TorusKnotGeometry; + + // TorusKnotBufferGeometry + + function TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) { + + BufferGeometry.call( this ); + + this.type = 'TorusKnotBufferGeometry'; + + this.parameters = { + radius: radius, + tube: tube, + tubularSegments: tubularSegments, + radialSegments: radialSegments, + p: p, + q: q + }; + + radius = radius || 1; + tube = tube || 0.4; + tubularSegments = Math.floor( tubularSegments ) || 64; + radialSegments = Math.floor( radialSegments ) || 8; + p = p || 2; + q = q || 3; + + // buffers + + var indices = []; + var vertices = []; + var normals = []; + var uvs = []; + + // helper variables + + var vertex = new Vector3(); + var normal = new Vector3(); + + var P1 = new Vector3(); + var P2 = new Vector3(); + + var B = new Vector3(); + var T = new Vector3(); + var N = new Vector3(); + + // generate vertices, normals and uvs + + for ( var i = 0; i <= tubularSegments; ++ i ) { + + // the radian "u" is used to calculate the position on the torus curve of the current tubular segement + + 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. + // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions + + calculatePositionOnCurve( u, p, q, radius, P1 ); + calculatePositionOnCurve( u + 0.01, p, q, radius, P2 ); + + // calculate orthonormal basis + + T.subVectors( P2, P1 ); + N.addVectors( P2, P1 ); + B.crossVectors( T, N ); + N.crossVectors( B, T ); + + // normalize B, N. T can be ignored, we don't use it + + B.normalize(); + N.normalize(); + + for ( var j = 0; j <= radialSegments; ++ j ) { + + // now calculate the vertices. they are nothing more than an extrusion of the torus curve. + // because we extrude a shape in the xy-plane, there is no need to calculate a z-value. + + var v = j / radialSegments * Math.PI * 2; + var cx = - tube * Math.cos( v ); + var cy = tube * Math.sin( v ); + + // now calculate the final vertex position. + // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve + + vertex.x = P1.x + ( cx * N.x + cy * B.x ); + vertex.y = P1.y + ( cx * N.y + cy * B.y ); + vertex.z = P1.z + ( cx * N.z + cy * B.z ); + + 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) + + normal.subVectors( vertex, P1 ).normalize(); + + normals.push( normal.x, normal.y, normal.z ); + + // uv + + uvs.push( i / tubularSegments ); + uvs.push( j / radialSegments ); + + } + + } + + // generate indices + + for ( var j$1 = 1; j$1 <= tubularSegments; j$1 ++ ) { + + for ( var i$1 = 1; i$1 <= radialSegments; i$1 ++ ) { + + // indices + + var a = ( radialSegments + 1 ) * ( j$1 - 1 ) + ( i$1 - 1 ); + var b = ( radialSegments + 1 ) * j$1 + ( i$1 - 1 ); + var c = ( radialSegments + 1 ) * j$1 + i$1; + var d = ( radialSegments + 1 ) * ( j$1 - 1 ) + i$1; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + // this function calculates the current position on the torus curve + + function calculatePositionOnCurve( u, p, q, radius, position ) { + + var cu = Math.cos( u ); + var su = Math.sin( u ); + var quOverP = q / p * u; + var cs = Math.cos( quOverP ); + + position.x = radius * ( 2 + cs ) * 0.5 * cu; + position.y = radius * ( 2 + cs ) * su * 0.5; + position.z = radius * Math.sin( quOverP ) * 0.5; + + } + + } + + TorusKnotBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + TorusKnotBufferGeometry.prototype.constructor = TorusKnotBufferGeometry; + + // TorusGeometry + + function TorusGeometry( radius, tube, radialSegments, tubularSegments, arc ) { + + Geometry.call( this ); + + this.type = 'TorusGeometry'; + + this.parameters = { + radius: radius, + tube: tube, + radialSegments: radialSegments, + tubularSegments: tubularSegments, + arc: arc + }; + + this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) ); + this.mergeVertices(); + + } + + TorusGeometry.prototype = Object.create( Geometry.prototype ); + TorusGeometry.prototype.constructor = TorusGeometry; + + // TorusBufferGeometry + + function TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) { + + BufferGeometry.call( this ); + + this.type = 'TorusBufferGeometry'; + + this.parameters = { + radius: radius, + tube: tube, + radialSegments: radialSegments, + tubularSegments: tubularSegments, + arc: arc + }; + + radius = radius || 1; + tube = tube || 0.4; + radialSegments = Math.floor( radialSegments ) || 8; + tubularSegments = Math.floor( tubularSegments ) || 6; + arc = arc || Math.PI * 2; + + // buffers + + var indices = []; + var vertices = []; + var normals = []; + var uvs = []; + + // helper variables + + var center = new Vector3(); + var vertex = new Vector3(); + var normal = new Vector3(); + + // generate vertices, normals and uvs + + for ( var j = 0; j <= radialSegments; j ++ ) { + + for ( var i = 0; i <= tubularSegments; i ++ ) { + + var u = i / tubularSegments * arc; + var v = j / radialSegments * Math.PI * 2; + + // vertex + + vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u ); + vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u ); + vertex.z = tube * Math.sin( v ); + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + center.x = radius * Math.cos( u ); + center.y = radius * Math.sin( u ); + normal.subVectors( vertex, center ).normalize(); + + normals.push( normal.x, normal.y, normal.z ); + + // uv + + uvs.push( i / tubularSegments ); + uvs.push( j / radialSegments ); + + } + + } + + // generate indices + + for ( var j$1 = 1; j$1 <= radialSegments; j$1 ++ ) { + + for ( var i$1 = 1; i$1 <= tubularSegments; i$1 ++ ) { + + // indices + + var a = ( tubularSegments + 1 ) * j$1 + i$1 - 1; + var b = ( tubularSegments + 1 ) * ( j$1 - 1 ) + i$1 - 1; + var c = ( tubularSegments + 1 ) * ( j$1 - 1 ) + i$1; + var d = ( tubularSegments + 1 ) * j$1 + i$1; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + TorusBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + TorusBufferGeometry.prototype.constructor = TorusBufferGeometry; + + /** + * Port from https://github.com/mapbox/earcut (v2.2.2) + */ + + var Earcut = { + + triangulate: function ( data, holeIndices, dim ) { + + dim = dim || 2; + + var hasHoles = holeIndices && holeIndices.length, + outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length, + outerNode = linkedList( data, 0, outerLen, dim, true ), + triangles = []; + + if ( ! outerNode || outerNode.next === outerNode.prev ) { return triangles; } + + var minX, minY, maxX, maxY, x, y, invSize; + + 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 + if ( data.length > 80 * dim ) { + + minX = maxX = data[ 0 ]; + minY = maxY = data[ 1 ]; + + for ( var i = dim; i < outerLen; i += dim ) { + + x = data[ i ]; + y = data[ i + 1 ]; + if ( x < minX ) { minX = x; } + if ( y < minY ) { minY = y; } + if ( x > maxX ) { maxX = x; } + if ( y > maxY ) { maxY = y; } + + } + + // minX, minY and invSize are later used to transform coords into integers for z-order calculation + invSize = Math.max( maxX - minX, maxY - minY ); + invSize = invSize !== 0 ? 1 / invSize : 0; + + } + + earcutLinked( outerNode, triangles, dim, minX, minY, invSize ); + + return triangles; + + } + + }; + + // create a circular doubly linked list from polygon points in the specified winding order + function linkedList( data, start, end, dim, clockwise ) { + + var i, last; + + if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) { + + for ( i = start; i < end; i += dim ) { last = insertNode( i, data[ i ], data[ i + 1 ], last ); } + + } else { + + for ( i = end - dim; i >= start; i -= dim ) { last = insertNode( i, data[ i ], data[ i + 1 ], last ); } + + } + + if ( last && equals( last, last.next ) ) { + + removeNode( last ); + last = last.next; + + } + + return last; + + } + + // eliminate colinear or duplicate points + function filterPoints( start, end ) { + + if ( ! start ) { return start; } + if ( ! end ) { end = start; } + + var p = start, + again; + do { + + again = false; + + if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) { + + removeNode( p ); + p = end = p.prev; + if ( p === p.next ) { break; } + again = true; + + } else { + + p = p.next; + + } + + } while ( again || p !== end ); + + return end; + + } + + // main ear slicing loop which triangulates a polygon (given as a linked list) + function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) { + + if ( ! ear ) { return; } + + // interlink polygon nodes in z-order + if ( ! pass && invSize ) { indexCurve( ear, minX, minY, invSize ); } + + var stop = ear, + prev, next; + + // iterate through ears, slicing them one by one + while ( ear.prev !== ear.next ) { + + prev = ear.prev; + next = ear.next; + + if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) { + + // cut off the triangle + triangles.push( prev.i / dim ); + triangles.push( ear.i / dim ); + triangles.push( next.i / dim ); + + removeNode( ear ); + + // skipping the next vertex leads to less sliver triangles + ear = next.next; + stop = next.next; + + continue; + + } + + ear = next; + + // if we looped through the whole remaining polygon and can't find any more ears + if ( ear === stop ) { + + // try filtering points and slicing again + if ( ! pass ) { + + earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 ); + + // if this didn't work, try curing all small self-intersections locally + + } else if ( pass === 1 ) { + + ear = cureLocalIntersections( filterPoints( ear ), triangles, dim ); + earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 ); + + // as a last resort, try splitting the remaining polygon into two + + } else if ( pass === 2 ) { + + splitEarcut( ear, triangles, dim, minX, minY, invSize ); + + } + + break; + + } + + } + + } + + // check whether a polygon node forms a valid ear with adjacent nodes + function isEar( ear ) { + + var a = ear.prev, + b = ear, + c = ear.next; + + if ( area( a, b, c ) >= 0 ) { return false; } // reflex, can't be an ear + + // now make sure we don't have other points inside the potential ear + var p = ear.next.next; + + while ( p !== ear.prev ) { + + 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; } + p = p.next; + + } + + return true; + + } + + function isEarHashed( ear, minX, minY, invSize ) { + + var a = ear.prev, + b = ear, + c = ear.next; + + if ( area( a, b, c ) >= 0 ) { return false; } // reflex, can't be an ear + + // triangle bbox; min & max are calculated like this for speed + var minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ), + minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ), + maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ), + 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; + var minZ = zOrder( minTX, minTY, minX, minY, invSize ), + maxZ = zOrder( maxTX, maxTY, minX, minY, invSize ); + + var p = ear.prevZ, + n = ear.nextZ; + + // look for points inside the triangle in both directions + while ( p && p.z >= minZ && n && n.z <= maxZ ) { + + 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; } + p = p.prevZ; + + 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; } + n = n.nextZ; + + } + + // look for remaining points in decreasing z-order + while ( p && p.z >= minZ ) { + + 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; } + p = p.prevZ; + + } + + // look for remaining points in increasing z-order + while ( n && n.z <= maxZ ) { + + 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; } + n = n.nextZ; + + } + + return true; + + } + + // go through all polygon nodes and cure small local self-intersections + function cureLocalIntersections( start, triangles, dim ) { + + var p = start; + do { + + var a = p.prev, + b = p.next.next; + + if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) { + + triangles.push( a.i / dim ); + triangles.push( p.i / dim ); + triangles.push( b.i / dim ); + + // remove two nodes involved + removeNode( p ); + removeNode( p.next ); + + p = start = b; + + } + + p = p.next; + + } while ( p !== start ); + + return filterPoints( p ); + + } + + // try splitting polygon into two and triangulate them independently + function splitEarcut( start, triangles, dim, minX, minY, invSize ) { + + // look for a valid diagonal that divides the polygon into two + var a = start; + do { + + var b = a.next.next; + while ( b !== a.prev ) { + + if ( a.i !== b.i && isValidDiagonal( a, b ) ) { + + // split the polygon in two by the diagonal + var c = splitPolygon( a, b ); + + // filter colinear points around the cuts + a = filterPoints( a, a.next ); + c = filterPoints( c, c.next ); + + // run earcut on each half + earcutLinked( a, triangles, dim, minX, minY, invSize ); + earcutLinked( c, triangles, dim, minX, minY, invSize ); + return; + + } + + b = b.next; + + } + + a = a.next; + + } while ( a !== start ); + + } + + // link every hole into the outer loop, producing a single-ring polygon without holes + function eliminateHoles( data, holeIndices, outerNode, dim ) { + + var queue = [], + i, len, start, end, list; + + for ( i = 0, len = holeIndices.length; i < len; i ++ ) { + + start = holeIndices[ i ] * dim; + end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length; + list = linkedList( data, start, end, dim, false ); + if ( list === list.next ) { list.steiner = true; } + queue.push( getLeftmost( list ) ); + + } + + queue.sort( compareX ); + + // process holes from left to right + for ( i = 0; i < queue.length; i ++ ) { + + eliminateHole( queue[ i ], outerNode ); + outerNode = filterPoints( outerNode, outerNode.next ); + + } + + return outerNode; + + } + + function compareX( a, b ) { + + return a.x - b.x; + + } + + // find a bridge between vertices that connects hole with an outer ring and and link it + function eliminateHole( hole, outerNode ) { + + outerNode = findHoleBridge( hole, outerNode ); + if ( outerNode ) { + + var b = splitPolygon( outerNode, hole ); + + // filter collinear points around the cuts + filterPoints( outerNode, outerNode.next ); + filterPoints( b, b.next ); + + } + + } + + // David Eberly's algorithm for finding a bridge between hole and outer polygon + function findHoleBridge( hole, outerNode ) { + + var p = outerNode, + hx = hole.x, + hy = hole.y, + qx = - Infinity, + m; + + // find a segment intersected by a ray from the hole's leftmost point to the left; + // segment's endpoint with lesser x will be potential connection point + do { + + if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) { + + var x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y ); + if ( x <= hx && x > qx ) { + + qx = x; + if ( x === hx ) { + + if ( hy === p.y ) { return p; } + if ( hy === p.next.y ) { return p.next; } + + } + + m = p.x < p.next.x ? p : p.next; + + } + + } + + p = p.next; + + } while ( p !== outerNode ); + + if ( ! m ) { return null; } + + if ( hx === qx ) { return m; } // hole touches outer segment; pick leftmost endpoint + + // look for points inside the triangle of hole point, segment intersection and endpoint; + // if there are no points found, we have a valid connection; + // otherwise choose the point of the minimum angle with the ray as connection point + + var stop = m, + mx = m.x, + my = m.y, + tanMin = Infinity, + tan; + + p = m; + + do { + + 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 ) ) { + + tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential + + if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) { + + m = p; + tanMin = tan; + + } + + } + + p = p.next; + + } while ( p !== stop ); + + return m; + + } + + // whether sector in vertex m contains sector in vertex p in the same coordinates + function sectorContainsSector( m, p ) { + + return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0; + + } + + // interlink polygon nodes in z-order + function indexCurve( start, minX, minY, invSize ) { + + var p = start; + do { + + if ( p.z === null ) { p.z = zOrder( p.x, p.y, minX, minY, invSize ); } + p.prevZ = p.prev; + p.nextZ = p.next; + p = p.next; + + } while ( p !== start ); + + p.prevZ.nextZ = null; + p.prevZ = null; + + sortLinked( p ); + + } + + // Simon Tatham's linked list merge sort algorithm + // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html + function sortLinked( list ) { + + var i, p, q, e, tail, numMerges, pSize, qSize, + inSize = 1; + + do { + + p = list; + list = null; + tail = null; + numMerges = 0; + + while ( p ) { + + numMerges ++; + q = p; + pSize = 0; + for ( i = 0; i < inSize; i ++ ) { + + pSize ++; + q = q.nextZ; + if ( ! q ) { break; } + + } + + qSize = inSize; + + while ( pSize > 0 || ( qSize > 0 && q ) ) { + + if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) { + + e = p; + p = p.nextZ; + pSize --; + + } else { + + e = q; + q = q.nextZ; + qSize --; + + } + + if ( tail ) { tail.nextZ = e; } + else { list = e; } + + e.prevZ = tail; + tail = e; + + } + + p = q; + + } + + tail.nextZ = null; + inSize *= 2; + + } while ( numMerges > 1 ); + + return list; + + } + + // z-order of a point given coords and inverse of the longer side of data bbox + function zOrder( x, y, minX, minY, invSize ) { + + // coords are transformed into non-negative 15-bit integer range + x = 32767 * ( x - minX ) * invSize; + y = 32767 * ( y - minY ) * invSize; + + x = ( x | ( x << 8 ) ) & 0x00FF00FF; + x = ( x | ( x << 4 ) ) & 0x0F0F0F0F; + x = ( x | ( x << 2 ) ) & 0x33333333; + x = ( x | ( x << 1 ) ) & 0x55555555; + + y = ( y | ( y << 8 ) ) & 0x00FF00FF; + y = ( y | ( y << 4 ) ) & 0x0F0F0F0F; + y = ( y | ( y << 2 ) ) & 0x33333333; + y = ( y | ( y << 1 ) ) & 0x55555555; + + return x | ( y << 1 ); + + } + + // find the leftmost node of a polygon ring + function getLeftmost( start ) { + + var p = start, + leftmost = start; + do { + + if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) { leftmost = p; } + p = p.next; + + } while ( p !== start ); + + return leftmost; + + } + + // check if a point lies within a convex triangle + function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) { + + 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; + + } + + // check if a diagonal between two polygon nodes is valid (lies in polygon interior) + function isValidDiagonal( a, b ) { + + return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges + ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible + ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors + equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case + + } + + // signed area of a triangle + function area( p, q, r ) { + + return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y ); + + } + + // check if two points are equal + function equals( p1, p2 ) { + + return p1.x === p2.x && p1.y === p2.y; + + } + + // check if two segments intersect + function intersects( p1, q1, p2, q2 ) { + + var o1 = sign( area( p1, q1, p2 ) ); + var o2 = sign( area( p1, q1, q2 ) ); + var o3 = sign( area( p2, q2, p1 ) ); + var o4 = sign( area( p2, q2, q1 ) ); + + if ( o1 !== o2 && o3 !== o4 ) { return true; } // general case + + if ( o1 === 0 && onSegment( p1, p2, q1 ) ) { return true; } // p1, q1 and p2 are collinear and p2 lies on p1q1 + if ( o2 === 0 && onSegment( p1, q2, q1 ) ) { return true; } // p1, q1 and q2 are collinear and q2 lies on p1q1 + if ( o3 === 0 && onSegment( p2, p1, q2 ) ) { return true; } // p2, q2 and p1 are collinear and p1 lies on p2q2 + if ( o4 === 0 && onSegment( p2, q1, q2 ) ) { return true; } // p2, q2 and q1 are collinear and q1 lies on p2q2 + + return false; + + } + + // for collinear points p, q, r, check if point q lies on segment pr + function onSegment( p, q, r ) { + + 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 ); + + } + + function sign( num ) { + + return num > 0 ? 1 : num < 0 ? - 1 : 0; + + } + + // check if a polygon diagonal intersects any polygon segments + function intersectsPolygon( a, b ) { + + var p = a; + do { + + 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; } + p = p.next; + + } while ( p !== a ); + + return false; + + } + + // check if a polygon diagonal is locally inside the polygon + function locallyInside( a, b ) { + + 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; + + } + + // check if the middle point of a polygon diagonal is inside the polygon + function middleInside( a, b ) { + + var p = a, + inside = false, + px = ( a.x + b.x ) / 2, + py = ( a.y + b.y ) / 2; + do { + + 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; } + p = p.next; + + } while ( p !== a ); + + return inside; + + } + + // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two; + // if one belongs to the outer ring and another to a hole, it merges it into a single ring + function splitPolygon( a, b ) { + + var a2 = new Node( a.i, a.x, a.y ), + b2 = new Node( b.i, b.x, b.y ), + an = a.next, + bp = b.prev; + + a.next = b; + b.prev = a; + + a2.next = an; + an.prev = a2; + + b2.next = a2; + a2.prev = b2; + + bp.next = b2; + b2.prev = bp; + + return b2; + + } + + // create a node and optionally link it with previous one (in a circular doubly linked list) + function insertNode( i, x, y, last ) { + + var p = new Node( i, x, y ); + + if ( ! last ) { + + p.prev = p; + p.next = p; + + } else { + + p.next = last.next; + p.prev = last; + last.next.prev = p; + last.next = p; + + } + + return p; + + } + + function removeNode( p ) { + + p.next.prev = p.prev; + p.prev.next = p.next; + + if ( p.prevZ ) { p.prevZ.nextZ = p.nextZ; } + if ( p.nextZ ) { p.nextZ.prevZ = p.prevZ; } + + } + + function Node( i, x, y ) { + + // vertex index in coordinates array + this.i = i; + + // vertex coordinates + this.x = x; + this.y = y; + + // previous and next vertex nodes in a polygon ring + this.prev = null; + this.next = null; + + // z-order curve value + this.z = null; + + // previous and next nodes in z-order + this.prevZ = null; + this.nextZ = null; + + // indicates whether this is a steiner point + this.steiner = false; + + } + + function signedArea( data, start, end, dim ) { + + var sum = 0; + for ( var i = start, j = end - dim; i < end; i += dim ) { + + sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] ); + j = i; + + } + + return sum; + + } + + var ShapeUtils = { + + // calculate area of the contour polygon + + area: function ( contour ) { + + var n = contour.length; + var a = 0.0; + + for ( var p = n - 1, q = 0; q < n; p = q ++ ) { + + a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y; + + } + + return a * 0.5; + + }, + + isClockWise: function ( pts ) { + + return ShapeUtils.area( pts ) < 0; + + }, + + triangulateShape: function ( contour, holes ) { + + var vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ] + var holeIndices = []; // array of hole indices + var faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ] + + removeDupEndPts( contour ); + addContour( vertices, contour ); + + // + + var holeIndex = contour.length; + + holes.forEach( removeDupEndPts ); + + for ( var i = 0; i < holes.length; i ++ ) { + + holeIndices.push( holeIndex ); + holeIndex += holes[ i ].length; + addContour( vertices, holes[ i ] ); + + } + + // + + var triangles = Earcut.triangulate( vertices, holeIndices ); + + // + + for ( var i$1 = 0; i$1 < triangles.length; i$1 += 3 ) { + + faces.push( triangles.slice( i$1, i$1 + 3 ) ); + + } + + return faces; + + } + + }; + + function removeDupEndPts( points ) { + + var l = points.length; + + if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) { + + points.pop(); + + } + + } + + function addContour( vertices, contour ) { + + for ( var i = 0; i < contour.length; i ++ ) { + + vertices.push( contour[ i ].x ); + vertices.push( contour[ i ].y ); + + } + + } + + /** + * Creates extruded geometry from a path shape. + * + * parameters = { + * + * curveSegments: , // number of points on the curves + * steps: , // number of points for z-side extrusions / used for subdividing segments of extrude spline too + * depth: , // Depth to extrude the shape + * + * bevelEnabled: , // turn on bevel + * bevelThickness: , // how deep into the original shape bevel goes + * bevelSize: , // how far from shape outline (including bevelOffset) is bevel + * bevelOffset: , // how far from shape outline does bevel start + * bevelSegments: , // number of bevel layers + * + * extrudePath: // curve to extrude shape along + * + * UVGenerator: // object that provides UV generator functions + * + * } + */ + + // ExtrudeGeometry + + function ExtrudeGeometry( shapes, options ) { + + Geometry.call( this ); + + this.type = 'ExtrudeGeometry'; + + this.parameters = { + shapes: shapes, + options: options + }; + + this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) ); + this.mergeVertices(); + + } + + ExtrudeGeometry.prototype = Object.create( Geometry.prototype ); + ExtrudeGeometry.prototype.constructor = ExtrudeGeometry; + + ExtrudeGeometry.prototype.toJSON = function () { + + var data = Geometry.prototype.toJSON.call( this ); + + var shapes = this.parameters.shapes; + var options = this.parameters.options; + + return toJSON( shapes, options, data ); + + }; + + // ExtrudeBufferGeometry + + function ExtrudeBufferGeometry( shapes, options ) { + + BufferGeometry.call( this ); + + this.type = 'ExtrudeBufferGeometry'; + + this.parameters = { + shapes: shapes, + options: options + }; + + shapes = Array.isArray( shapes ) ? shapes : [ shapes ]; + + var scope = this; + + var verticesArray = []; + var uvArray = []; + + for ( var i = 0, l = shapes.length; i < l; i ++ ) { + + var shape = shapes[ i ]; + addShape( shape ); + + } + + // build geometry + + this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) ); + + this.computeVertexNormals(); + + // functions + + function addShape( shape ) { + + var placeholder = []; + + // options + + var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12; + var steps = options.steps !== undefined ? options.steps : 1; + var depth = options.depth !== undefined ? options.depth : 100; + + var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; + var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; + var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; + var bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0; + var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3; + + var extrudePath = options.extrudePath; + + var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator; + + // deprecated options + + if ( options.amount !== undefined ) { + + console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' ); + depth = options.amount; + + } + + // + + var extrudePts, extrudeByPath = false; + var splineTube, binormal, normal, position2; + + if ( extrudePath ) { + + extrudePts = extrudePath.getSpacedPoints( steps ); + + extrudeByPath = true; + bevelEnabled = false; // bevels not supported for path extrusion + + // SETUP TNB variables + + // TODO1 - have a .isClosed in spline? + + splineTube = extrudePath.computeFrenetFrames( steps, false ); + + // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length); + + binormal = new Vector3(); + normal = new Vector3(); + position2 = new Vector3(); + + } + + // Safeguards if bevels are not enabled + + if ( ! bevelEnabled ) { + + bevelSegments = 0; + bevelThickness = 0; + bevelSize = 0; + bevelOffset = 0; + + } + + // Variables initialization + + var shapePoints = shape.extractPoints( curveSegments ); + + var vertices = shapePoints.shape; + var holes = shapePoints.holes; + + var reverse = ! ShapeUtils.isClockWise( vertices ); + + if ( reverse ) { + + vertices = vertices.reverse(); + + // Maybe we should also check if holes are in the opposite direction, just to be safe ... + + for ( var h = 0, hl = holes.length; h < hl; h ++ ) { + + var ahole = holes[ h ]; + + if ( ShapeUtils.isClockWise( ahole ) ) { + + holes[ h ] = ahole.reverse(); + + } + + } + + } + + + var faces = ShapeUtils.triangulateShape( vertices, holes ); + + /* Vertices */ + + var contour = vertices; // vertices has all points but contour has only points of circumference + + for ( var h$1 = 0, hl$1 = holes.length; h$1 < hl$1; h$1 ++ ) { + + var ahole$1 = holes[ h$1 ]; + + vertices = vertices.concat( ahole$1 ); + + } + + + function scalePt2( pt, vec, size ) { + + if ( ! vec ) { console.error( "THREE.ExtrudeGeometry: vec does not exist" ); } + + return vec.clone().multiplyScalar( size ).add( pt ); + + } + + var vlen = vertices.length, flen = faces.length; + + + // Find directions for point movement + + + function getBevelVec( inPt, inPrev, inNext ) { + + // computes for inPt the corresponding point inPt' on a new contour + // shifted by 1 unit (length of normalized vector) to the left + // if we walk along contour clockwise, this new contour is outside the old one + // + // inPt' is the intersection of the two lines parallel to the two + // adjacent edges of inPt at a distance of 1 unit on the left side. + + var v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt + + // good reading for geometry algorithms (here: line-line intersection) + // http://geomalgorithms.com/a05-_intersect-1.html + + var v_prev_x = inPt.x - inPrev.x, + v_prev_y = inPt.y - inPrev.y; + var v_next_x = inNext.x - inPt.x, + v_next_y = inNext.y - inPt.y; + + var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y ); + + // check for collinear edges + var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x ); + + if ( Math.abs( collinear0 ) > Number.EPSILON ) { + + // not collinear + + // length of vectors for normalizing + + var v_prev_len = Math.sqrt( v_prev_lensq ); + 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 + + var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len ); + var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len ); + + var ptNextShift_x = ( inNext.x - v_next_y / v_next_len ); + var ptNextShift_y = ( inNext.y + v_next_x / v_next_len ); + + // scaling factor for v_prev to intersection point + + 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 + + v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x ); + v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y ); + + // Don't normalize!, otherwise sharp corners become ugly + // but prevent crazy spikes + var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y ); + if ( v_trans_lensq <= 2 ) { + + return new Vector2( v_trans_x, v_trans_y ); + + } else { + + shrink_by = Math.sqrt( v_trans_lensq / 2 ); + + } + + } else { + + // handle special case of collinear edges + + var direction_eq = false; // assumes: opposite + + if ( v_prev_x > Number.EPSILON ) { + + if ( v_next_x > Number.EPSILON ) { + + direction_eq = true; + + } + + } else { + + if ( v_prev_x < - Number.EPSILON ) { + + if ( v_next_x < - Number.EPSILON ) { + + direction_eq = true; + + } + + } else { + + if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) { + + direction_eq = true; + + } + + } + + } + + if ( direction_eq ) { + + // console.log("Warning: lines are a straight sequence"); + v_trans_x = - v_prev_y; + v_trans_y = v_prev_x; + shrink_by = Math.sqrt( v_prev_lensq ); + + } else { + + // console.log("Warning: lines are a straight spike"); + v_trans_x = v_prev_x; + v_trans_y = v_prev_y; + shrink_by = Math.sqrt( v_prev_lensq / 2 ); + + } + + } + + return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by ); + + } + + + var contourMovements = []; + + for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) { + + if ( j === il ) { j = 0; } + if ( k === il ) { k = 0; } + + // (j)---(i)---(k) + // console.log('i,j,k', i, j , k) + + contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] ); + + } + + var holesMovements = []; + var oneHoleMovements, verticesMovements = contourMovements.concat(); + + for ( var h$2 = 0, hl$2 = holes.length; h$2 < hl$2; h$2 ++ ) { + + var ahole$2 = holes[ h$2 ]; + + oneHoleMovements = []; + + for ( var i$1 = 0, il$1 = ahole$2.length, j$1 = il$1 - 1, k$1 = i$1 + 1; i$1 < il$1; i$1 ++, j$1 ++, k$1 ++ ) { + + if ( j$1 === il$1 ) { j$1 = 0; } + if ( k$1 === il$1 ) { k$1 = 0; } + + // (j)---(i)---(k) + oneHoleMovements[ i$1 ] = getBevelVec( ahole$2[ i$1 ], ahole$2[ j$1 ], ahole$2[ k$1 ] ); + + } + + holesMovements.push( oneHoleMovements ); + verticesMovements = verticesMovements.concat( oneHoleMovements ); + + } + + + // Loop bevelSegments, 1 for the front, 1 for the back + + for ( var b = 0; b < bevelSegments; b ++ ) { + + //for ( b = bevelSegments; b > 0; b -- ) { + + var t = b / bevelSegments; + var z = bevelThickness * Math.cos( t * Math.PI / 2 ); + var bs$1 = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset; + + // contract shape + + for ( var i$2 = 0, il$2 = contour.length; i$2 < il$2; i$2 ++ ) { + + var vert = scalePt2( contour[ i$2 ], contourMovements[ i$2 ], bs$1 ); + + v( vert.x, vert.y, - z ); + + } + + // expand holes + + for ( var h$3 = 0, hl$3 = holes.length; h$3 < hl$3; h$3 ++ ) { + + var ahole$3 = holes[ h$3 ]; + oneHoleMovements = holesMovements[ h$3 ]; + + for ( var i$3 = 0, il$3 = ahole$3.length; i$3 < il$3; i$3 ++ ) { + + var vert$1 = scalePt2( ahole$3[ i$3 ], oneHoleMovements[ i$3 ], bs$1 ); + + v( vert$1.x, vert$1.y, - z ); + + } + + } + + } + + var bs = bevelSize + bevelOffset; + + // Back facing vertices + + for ( var i$4 = 0; i$4 < vlen; i$4 ++ ) { + + var vert$2 = bevelEnabled ? scalePt2( vertices[ i$4 ], verticesMovements[ i$4 ], bs ) : vertices[ i$4 ]; + + if ( ! extrudeByPath ) { + + v( vert$2.x, vert$2.y, 0 ); + + } else { + + // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x ); + + normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert$2.x ); + binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert$2.y ); + + position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal ); + + v( position2.x, position2.y, position2.z ); + + } + + } + + // Add stepped vertices... + // Including front facing vertices + + for ( var s = 1; s <= steps; s ++ ) { + + for ( var i$5 = 0; i$5 < vlen; i$5 ++ ) { + + var vert$3 = bevelEnabled ? scalePt2( vertices[ i$5 ], verticesMovements[ i$5 ], bs ) : vertices[ i$5 ]; + + if ( ! extrudeByPath ) { + + v( vert$3.x, vert$3.y, depth / steps * s ); + + } else { + + // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x ); + + normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert$3.x ); + binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert$3.y ); + + position2.copy( extrudePts[ s ] ).add( normal ).add( binormal ); + + v( position2.x, position2.y, position2.z ); + + } + + } + + } + + + // Add bevel segments planes + + //for ( b = 1; b <= bevelSegments; b ++ ) { + for ( var b$1 = bevelSegments - 1; b$1 >= 0; b$1 -- ) { + + var t$1 = b$1 / bevelSegments; + var z$1 = bevelThickness * Math.cos( t$1 * Math.PI / 2 ); + var bs$2 = bevelSize * Math.sin( t$1 * Math.PI / 2 ) + bevelOffset; + + // contract shape + + for ( var i$6 = 0, il$4 = contour.length; i$6 < il$4; i$6 ++ ) { + + var vert$4 = scalePt2( contour[ i$6 ], contourMovements[ i$6 ], bs$2 ); + v( vert$4.x, vert$4.y, depth + z$1 ); + + } + + // expand holes + + for ( var h$4 = 0, hl$4 = holes.length; h$4 < hl$4; h$4 ++ ) { + + var ahole$4 = holes[ h$4 ]; + oneHoleMovements = holesMovements[ h$4 ]; + + for ( var i$7 = 0, il$5 = ahole$4.length; i$7 < il$5; i$7 ++ ) { + + var vert$5 = scalePt2( ahole$4[ i$7 ], oneHoleMovements[ i$7 ], bs$2 ); + + if ( ! extrudeByPath ) { + + v( vert$5.x, vert$5.y, depth + z$1 ); + + } else { + + v( vert$5.x, vert$5.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z$1 ); + + } + + } + + } + + } + + /* Faces */ + + // Top and bottom faces + + buildLidFaces(); + + // Sides faces + + buildSideFaces(); + + + ///// Internal functions + + function buildLidFaces() { + + var start = verticesArray.length / 3; + + if ( bevelEnabled ) { + + var layer = 0; // steps + 1 + var offset = vlen * layer; + + // Bottom faces + + for ( var i = 0; i < flen; i ++ ) { + + var face = faces[ i ]; + f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset ); + + } + + layer = steps + bevelSegments * 2; + offset = vlen * layer; + + // Top faces + + for ( var i$1 = 0; i$1 < flen; i$1 ++ ) { + + var face$1 = faces[ i$1 ]; + f3( face$1[ 0 ] + offset, face$1[ 1 ] + offset, face$1[ 2 ] + offset ); + + } + + } else { + + // Bottom faces + + for ( var i$2 = 0; i$2 < flen; i$2 ++ ) { + + var face$2 = faces[ i$2 ]; + f3( face$2[ 2 ], face$2[ 1 ], face$2[ 0 ] ); + + } + + // Top faces + + for ( var i$3 = 0; i$3 < flen; i$3 ++ ) { + + var face$3 = faces[ i$3 ]; + f3( face$3[ 0 ] + vlen * steps, face$3[ 1 ] + vlen * steps, face$3[ 2 ] + vlen * steps ); + + } + + } + + scope.addGroup( start, verticesArray.length / 3 - start, 0 ); + + } + + // Create faces for the z-sides of the shape + + function buildSideFaces() { + + var start = verticesArray.length / 3; + var layeroffset = 0; + sidewalls( contour, layeroffset ); + layeroffset += contour.length; + + for ( var h = 0, hl = holes.length; h < hl; h ++ ) { + + var ahole = holes[ h ]; + sidewalls( ahole, layeroffset ); + + //, true + layeroffset += ahole.length; + + } + + + scope.addGroup( start, verticesArray.length / 3 - start, 1 ); + + + } + + function sidewalls( contour, layeroffset ) { + + var i = contour.length; + + while ( -- i >= 0 ) { + + var j = i; + var k = i - 1; + if ( k < 0 ) { k = contour.length - 1; } + + //console.log('b', i,j, i-1, k,vertices.length); + + for ( var s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) { + + var slen1 = vlen * s; + var slen2 = vlen * ( s + 1 ); + + var a = layeroffset + j + slen1, + b = layeroffset + k + slen1, + c = layeroffset + k + slen2, + d = layeroffset + j + slen2; + + f4( a, b, c, d ); + + } + + } + + } + + function v( x, y, z ) { + + placeholder.push( x ); + placeholder.push( y ); + placeholder.push( z ); + + } + + + function f3( a, b, c ) { + + addVertex( a ); + addVertex( b ); + addVertex( c ); + + var nextIndex = verticesArray.length / 3; + var uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 ); + + addUV( uvs[ 0 ] ); + addUV( uvs[ 1 ] ); + addUV( uvs[ 2 ] ); + + } + + function f4( a, b, c, d ) { + + addVertex( a ); + addVertex( b ); + addVertex( d ); + + addVertex( b ); + addVertex( c ); + addVertex( d ); + + + var nextIndex = verticesArray.length / 3; + var uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 ); + + addUV( uvs[ 0 ] ); + addUV( uvs[ 1 ] ); + addUV( uvs[ 3 ] ); + + addUV( uvs[ 1 ] ); + addUV( uvs[ 2 ] ); + addUV( uvs[ 3 ] ); + + } + + function addVertex( index ) { + + verticesArray.push( placeholder[ index * 3 + 0 ] ); + verticesArray.push( placeholder[ index * 3 + 1 ] ); + verticesArray.push( placeholder[ index * 3 + 2 ] ); + + } + + + function addUV( vector2 ) { + + uvArray.push( vector2.x ); + uvArray.push( vector2.y ); + + } + + } + + } + + ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry; + + ExtrudeBufferGeometry.prototype.toJSON = function () { + + var data = BufferGeometry.prototype.toJSON.call( this ); + + var shapes = this.parameters.shapes; + var options = this.parameters.options; + + return toJSON( shapes, options, data ); + + }; + + // + + var WorldUVGenerator = { + + generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) { + + var a_x = vertices[ indexA * 3 ]; + var a_y = vertices[ indexA * 3 + 1 ]; + var b_x = vertices[ indexB * 3 ]; + var b_y = vertices[ indexB * 3 + 1 ]; + var c_x = vertices[ indexC * 3 ]; + var c_y = vertices[ indexC * 3 + 1 ]; + + return [ + new Vector2( a_x, a_y ), + new Vector2( b_x, b_y ), + new Vector2( c_x, c_y ) + ]; + + }, + + generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) { + + var a_x = vertices[ indexA * 3 ]; + var a_y = vertices[ indexA * 3 + 1 ]; + var a_z = vertices[ indexA * 3 + 2 ]; + var b_x = vertices[ indexB * 3 ]; + var b_y = vertices[ indexB * 3 + 1 ]; + var b_z = vertices[ indexB * 3 + 2 ]; + var c_x = vertices[ indexC * 3 ]; + var c_y = vertices[ indexC * 3 + 1 ]; + var c_z = vertices[ indexC * 3 + 2 ]; + var d_x = vertices[ indexD * 3 ]; + var d_y = vertices[ indexD * 3 + 1 ]; + var d_z = vertices[ indexD * 3 + 2 ]; + + if ( Math.abs( a_y - b_y ) < 0.01 ) { + + 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 ) + ]; + + } else { + + 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 ) + ]; + + } + + } + }; + + function toJSON( shapes, options, data ) { + + // + + data.shapes = []; + + if ( Array.isArray( shapes ) ) { + + for ( var i = 0, l = shapes.length; i < l; i ++ ) { + + var shape = shapes[ i ]; + + data.shapes.push( shape.uuid ); + + } + + } else { + + data.shapes.push( shapes.uuid ); + + } + + // + + if ( options.extrudePath !== undefined ) { data.options.extrudePath = options.extrudePath.toJSON(); } + + return data; + + } + + /** + * Text = 3D Text + * + * parameters = { + * font: , // font + * + * size: , // size of the text + * height: , // thickness to extrude text + * curveSegments: , // number of points on the curves + * + * bevelEnabled: , // turn on bevel + * bevelThickness: , // how deep into text bevel goes + * bevelSize: , // how far from text outline (including bevelOffset) is bevel + * bevelOffset: // how far from text outline does bevel start + * } + */ + + // TextGeometry + + function TextGeometry( text, parameters ) { + + Geometry.call( this ); + + this.type = 'TextGeometry'; + + this.parameters = { + text: text, + parameters: parameters + }; + + this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) ); + this.mergeVertices(); + + } + + TextGeometry.prototype = Object.create( Geometry.prototype ); + TextGeometry.prototype.constructor = TextGeometry; + + // TextBufferGeometry + + function TextBufferGeometry( text, parameters ) { + + parameters = parameters || {}; + + var font = parameters.font; + + if ( ! ( font && font.isFont ) ) { + + console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' ); + return new Geometry(); + + } + + var shapes = font.generateShapes( text, parameters.size ); + + // translate parameters to ExtrudeGeometry API + + parameters.depth = parameters.height !== undefined ? parameters.height : 50; + + // defaults + + if ( parameters.bevelThickness === undefined ) { parameters.bevelThickness = 10; } + if ( parameters.bevelSize === undefined ) { parameters.bevelSize = 8; } + if ( parameters.bevelEnabled === undefined ) { parameters.bevelEnabled = false; } + + ExtrudeBufferGeometry.call( this, shapes, parameters ); + + this.type = 'TextBufferGeometry'; + + } + + TextBufferGeometry.prototype = Object.create( ExtrudeBufferGeometry.prototype ); + TextBufferGeometry.prototype.constructor = TextBufferGeometry; + + // SphereGeometry + + function SphereGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) { + + Geometry.call( this ); + + this.type = 'SphereGeometry'; + + this.parameters = { + radius: radius, + widthSegments: widthSegments, + heightSegments: heightSegments, + phiStart: phiStart, + phiLength: phiLength, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) ); + this.mergeVertices(); + + } + + SphereGeometry.prototype = Object.create( Geometry.prototype ); + SphereGeometry.prototype.constructor = SphereGeometry; + + // SphereBufferGeometry + + function SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) { + + BufferGeometry.call( this ); + + this.type = 'SphereBufferGeometry'; + + this.parameters = { + radius: radius, + widthSegments: widthSegments, + heightSegments: heightSegments, + phiStart: phiStart, + phiLength: phiLength, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + radius = radius || 1; + + widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 ); + heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 ); + + phiStart = phiStart !== undefined ? phiStart : 0; + phiLength = phiLength !== undefined ? phiLength : Math.PI * 2; + + thetaStart = thetaStart !== undefined ? thetaStart : 0; + thetaLength = thetaLength !== undefined ? thetaLength : Math.PI; + + var thetaEnd = Math.min( thetaStart + thetaLength, Math.PI ); + + var index = 0; + var grid = []; + + var vertex = new Vector3(); + var normal = new Vector3(); + + // buffers + + var indices = []; + var vertices = []; + var normals = []; + var uvs = []; + + // generate vertices, normals and uvs + + for ( var iy = 0; iy <= heightSegments; iy ++ ) { + + var verticesRow = []; + + var v = iy / heightSegments; + + // special case for the poles + + var uOffset = 0; + + if ( iy == 0 && thetaStart == 0 ) { + + uOffset = 0.5 / widthSegments; + + } else if ( iy == heightSegments && thetaEnd == Math.PI ) { + + uOffset = - 0.5 / widthSegments; + + } + + for ( var ix = 0; ix <= widthSegments; ix ++ ) { + + var u = ix / widthSegments; + + // vertex + + vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength ); + vertex.y = radius * Math.cos( thetaStart + v * thetaLength ); + vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength ); + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + normal.copy( vertex ).normalize(); + normals.push( normal.x, normal.y, normal.z ); + + // uv + + uvs.push( u + uOffset, 1 - v ); + + verticesRow.push( index ++ ); + + } + + grid.push( verticesRow ); + + } + + // indices + + for ( var iy$1 = 0; iy$1 < heightSegments; iy$1 ++ ) { + + for ( var ix$1 = 0; ix$1 < widthSegments; ix$1 ++ ) { + + var a = grid[ iy$1 ][ ix$1 + 1 ]; + var b = grid[ iy$1 ][ ix$1 ]; + var c = grid[ iy$1 + 1 ][ ix$1 ]; + var d = grid[ iy$1 + 1 ][ ix$1 + 1 ]; + + if ( iy$1 !== 0 || thetaStart > 0 ) { indices.push( a, b, d ); } + if ( iy$1 !== heightSegments - 1 || thetaEnd < Math.PI ) { indices.push( b, c, d ); } + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + SphereBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + SphereBufferGeometry.prototype.constructor = SphereBufferGeometry; + + // RingGeometry + + function RingGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) { + + Geometry.call( this ); + + this.type = 'RingGeometry'; + + this.parameters = { + innerRadius: innerRadius, + outerRadius: outerRadius, + thetaSegments: thetaSegments, + phiSegments: phiSegments, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) ); + this.mergeVertices(); + + } + + RingGeometry.prototype = Object.create( Geometry.prototype ); + RingGeometry.prototype.constructor = RingGeometry; + + // RingBufferGeometry + + function RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) { + + BufferGeometry.call( this ); + + this.type = 'RingBufferGeometry'; + + this.parameters = { + innerRadius: innerRadius, + outerRadius: outerRadius, + thetaSegments: thetaSegments, + phiSegments: phiSegments, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + innerRadius = innerRadius || 0.5; + outerRadius = outerRadius || 1; + + thetaStart = thetaStart !== undefined ? thetaStart : 0; + thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; + + thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8; + phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 1; + + // buffers + + var indices = []; + var vertices = []; + var normals = []; + var uvs = []; + + // some helper variables + + var radius = innerRadius; + var radiusStep = ( ( outerRadius - innerRadius ) / phiSegments ); + var vertex = new Vector3(); + var uv = new Vector2(); + + // generate vertices, normals and uvs + + for ( var j = 0; j <= phiSegments; j ++ ) { + + for ( var i = 0; i <= thetaSegments; i ++ ) { + + // values are generate from the inside of the ring to the outside + + var segment = thetaStart + i / thetaSegments * thetaLength; + + // vertex + + vertex.x = radius * Math.cos( segment ); + vertex.y = radius * Math.sin( segment ); + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + normals.push( 0, 0, 1 ); + + // uv + + uv.x = ( vertex.x / outerRadius + 1 ) / 2; + uv.y = ( vertex.y / outerRadius + 1 ) / 2; + + uvs.push( uv.x, uv.y ); + + } + + // increase the radius for next row of vertices + + radius += radiusStep; + + } + + // indices + + for ( var j$1 = 0; j$1 < phiSegments; j$1 ++ ) { + + var thetaSegmentLevel = j$1 * ( thetaSegments + 1 ); + + for ( var i$1 = 0; i$1 < thetaSegments; i$1 ++ ) { + + var segment$1 = i$1 + thetaSegmentLevel; + + var a = segment$1; + var b = segment$1 + thetaSegments + 1; + var c = segment$1 + thetaSegments + 2; + var d = segment$1 + 1; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + RingBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + RingBufferGeometry.prototype.constructor = RingBufferGeometry; + + // LatheGeometry + + function LatheGeometry( points, segments, phiStart, phiLength ) { + + Geometry.call( this ); + + this.type = 'LatheGeometry'; + + this.parameters = { + points: points, + segments: segments, + phiStart: phiStart, + phiLength: phiLength + }; + + this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) ); + this.mergeVertices(); + + } + + LatheGeometry.prototype = Object.create( Geometry.prototype ); + LatheGeometry.prototype.constructor = LatheGeometry; + + // LatheBufferGeometry + + function LatheBufferGeometry( points, segments, phiStart, phiLength ) { + + BufferGeometry.call( this ); + + this.type = 'LatheBufferGeometry'; + + this.parameters = { + points: points, + segments: segments, + phiStart: phiStart, + phiLength: phiLength + }; + + segments = Math.floor( segments ) || 12; + phiStart = phiStart || 0; + phiLength = phiLength || Math.PI * 2; + + // clamp phiLength so it's in range of [ 0, 2PI ] + + phiLength = MathUtils.clamp( phiLength, 0, Math.PI * 2 ); + + + // buffers + + var indices = []; + var vertices = []; + var uvs = []; + + // helper variables + + var inverseSegments = 1.0 / segments; + var vertex = new Vector3(); + var uv = new Vector2(); + + // generate vertices and uvs + + for ( var i = 0; i <= segments; i ++ ) { + + var phi = phiStart + i * inverseSegments * phiLength; + + var sin = Math.sin( phi ); + var cos = Math.cos( phi ); + + for ( var j = 0; j <= ( points.length - 1 ); j ++ ) { + + // vertex + + vertex.x = points[ j ].x * sin; + vertex.y = points[ j ].y; + vertex.z = points[ j ].x * cos; + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // uv + + uv.x = i / segments; + uv.y = j / ( points.length - 1 ); + + uvs.push( uv.x, uv.y ); + + + } + + } + + // indices + + for ( var i$1 = 0; i$1 < segments; i$1 ++ ) { + + for ( var j$1 = 0; j$1 < ( points.length - 1 ); j$1 ++ ) { + + var base = j$1 + i$1 * points.length; + + var a = base; + var b = base + points.length; + var c = base + points.length + 1; + var d = base + 1; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + // generate normals + + this.computeVertexNormals(); + + // if the geometry is closed, we need to average the normals along the seam. + // because the corresponding vertices are identical (but still have different UVs). + + if ( phiLength === Math.PI * 2 ) { + + var normals = this.attributes.normal.array; + var n1 = new Vector3(); + var n2 = new Vector3(); + var n = new Vector3(); + + // this is the buffer offset for the last line of vertices + + var base$1 = segments * points.length * 3; + + for ( var i$2 = 0, j$2 = 0; i$2 < points.length; i$2 ++, j$2 += 3 ) { + + // select the normal of the vertex in the first line + + n1.x = normals[ j$2 + 0 ]; + n1.y = normals[ j$2 + 1 ]; + n1.z = normals[ j$2 + 2 ]; + + // select the normal of the vertex in the last line + + n2.x = normals[ base$1 + j$2 + 0 ]; + n2.y = normals[ base$1 + j$2 + 1 ]; + n2.z = normals[ base$1 + j$2 + 2 ]; + + // average normals + + n.addVectors( n1, n2 ).normalize(); + + // assign the new values to both normals + + normals[ j$2 + 0 ] = normals[ base$1 + j$2 + 0 ] = n.x; + normals[ j$2 + 1 ] = normals[ base$1 + j$2 + 1 ] = n.y; + normals[ j$2 + 2 ] = normals[ base$1 + j$2 + 2 ] = n.z; + + } + + } + + } + + LatheBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + LatheBufferGeometry.prototype.constructor = LatheBufferGeometry; + + // ShapeGeometry + + function ShapeGeometry( shapes, curveSegments ) { + + Geometry.call( this ); + + this.type = 'ShapeGeometry'; + + if ( typeof curveSegments === 'object' ) { + + console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' ); + + curveSegments = curveSegments.curveSegments; + + } + + this.parameters = { + shapes: shapes, + curveSegments: curveSegments + }; + + this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) ); + this.mergeVertices(); + + } + + ShapeGeometry.prototype = Object.create( Geometry.prototype ); + ShapeGeometry.prototype.constructor = ShapeGeometry; + + ShapeGeometry.prototype.toJSON = function () { + + var data = Geometry.prototype.toJSON.call( this ); + + var shapes = this.parameters.shapes; + + return toJSON$1( shapes, data ); + + }; + + // ShapeBufferGeometry + + function ShapeBufferGeometry( shapes, curveSegments ) { + + BufferGeometry.call( this ); + + this.type = 'ShapeBufferGeometry'; + + this.parameters = { + shapes: shapes, + curveSegments: curveSegments + }; + + curveSegments = curveSegments || 12; + + // buffers + + var indices = []; + var vertices = []; + var normals = []; + var uvs = []; + + // helper variables + + var groupStart = 0; + var groupCount = 0; + + // allow single and array values for "shapes" parameter + + if ( Array.isArray( shapes ) === false ) { + + addShape( shapes ); + + } else { + + for ( var i = 0; i < shapes.length; i ++ ) { + + addShape( shapes[ i ] ); + + this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support + + groupStart += groupCount; + groupCount = 0; + + } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + + // helper functions + + function addShape( shape ) { + + var indexOffset = vertices.length / 3; + var points = shape.extractPoints( curveSegments ); + + var shapeVertices = points.shape; + var shapeHoles = points.holes; + + // check direction of vertices + + if ( ShapeUtils.isClockWise( shapeVertices ) === false ) { + + shapeVertices = shapeVertices.reverse(); + + } + + for ( var i = 0, l = shapeHoles.length; i < l; i ++ ) { + + var shapeHole = shapeHoles[ i ]; + + if ( ShapeUtils.isClockWise( shapeHole ) === true ) { + + shapeHoles[ i ] = shapeHole.reverse(); + + } + + } + + var faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles ); + + // join vertices of inner and outer paths to a single array + + for ( var i$1 = 0, l$1 = shapeHoles.length; i$1 < l$1; i$1 ++ ) { + + var shapeHole$1 = shapeHoles[ i$1 ]; + shapeVertices = shapeVertices.concat( shapeHole$1 ); + + } + + // vertices, normals, uvs + + for ( var i$2 = 0, l$2 = shapeVertices.length; i$2 < l$2; i$2 ++ ) { + + var vertex = shapeVertices[ i$2 ]; + + vertices.push( vertex.x, vertex.y, 0 ); + normals.push( 0, 0, 1 ); + uvs.push( vertex.x, vertex.y ); // world uvs + + } + + // incides + + for ( var i$3 = 0, l$3 = faces.length; i$3 < l$3; i$3 ++ ) { + + var face = faces[ i$3 ]; + + var a = face[ 0 ] + indexOffset; + var b = face[ 1 ] + indexOffset; + var c = face[ 2 ] + indexOffset; + + indices.push( a, b, c ); + groupCount += 3; + + } + + } + + } + + ShapeBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + ShapeBufferGeometry.prototype.constructor = ShapeBufferGeometry; + + ShapeBufferGeometry.prototype.toJSON = function () { + + var data = BufferGeometry.prototype.toJSON.call( this ); + + var shapes = this.parameters.shapes; + + return toJSON$1( shapes, data ); + + }; + + // + + function toJSON$1( shapes, data ) { + + data.shapes = []; + + if ( Array.isArray( shapes ) ) { + + for ( var i = 0, l = shapes.length; i < l; i ++ ) { + + var shape = shapes[ i ]; + + data.shapes.push( shape.uuid ); + + } + + } else { + + data.shapes.push( shapes.uuid ); + + } + + return data; + + } + + function EdgesGeometry( geometry, thresholdAngle ) { + + BufferGeometry.call( this ); + + this.type = 'EdgesGeometry'; + + this.parameters = { + thresholdAngle: thresholdAngle + }; + + thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1; + + // buffer + + var vertices = []; + + // helper variables + + var thresholdDot = Math.cos( MathUtils.DEG2RAD * thresholdAngle ); + var edge = [ 0, 0 ], edges = {}; + var edge1, edge2, key; + var keys = [ 'a', 'b', 'c' ]; + + // prepare source geometry + + var geometry2; + + if ( geometry.isBufferGeometry ) { + + geometry2 = new Geometry(); + geometry2.fromBufferGeometry( geometry ); + + } else { + + geometry2 = geometry.clone(); + + } + + geometry2.mergeVertices(); + geometry2.computeFaceNormals(); + + var sourceVertices = geometry2.vertices; + var faces = geometry2.faces; + + // now create a data structure where each entry represents an edge with its adjoining faces + + for ( var i = 0, l = faces.length; i < l; i ++ ) { + + var face = faces[ i ]; + + for ( var j = 0; j < 3; j ++ ) { + + edge1 = face[ keys[ j ] ]; + edge2 = face[ keys[ ( j + 1 ) % 3 ] ]; + edge[ 0 ] = Math.min( edge1, edge2 ); + edge[ 1 ] = Math.max( edge1, edge2 ); + + key = edge[ 0 ] + ',' + edge[ 1 ]; + + if ( edges[ key ] === undefined ) { + + edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ], face1: i, face2: undefined }; + + } else { + + edges[ key ].face2 = i; + + } + + } + + } + + // generate vertices + + for ( key in edges ) { + + var e = edges[ key ]; + + // an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree. + + if ( e.face2 === undefined || faces[ e.face1 ].normal.dot( faces[ e.face2 ].normal ) <= thresholdDot ) { + + var vertex = sourceVertices[ e.index1 ]; + vertices.push( vertex.x, vertex.y, vertex.z ); + + vertex = sourceVertices[ e.index2 ]; + vertices.push( vertex.x, vertex.y, vertex.z ); + + } + + } + + // build geometry + + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + + } + + EdgesGeometry.prototype = Object.create( BufferGeometry.prototype ); + EdgesGeometry.prototype.constructor = EdgesGeometry; + + // CylinderGeometry + + function CylinderGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) { + + Geometry.call( this ); + + this.type = 'CylinderGeometry'; + + this.parameters = { + radiusTop: radiusTop, + radiusBottom: radiusBottom, + height: height, + radialSegments: radialSegments, + heightSegments: heightSegments, + openEnded: openEnded, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) ); + this.mergeVertices(); + + } + + CylinderGeometry.prototype = Object.create( Geometry.prototype ); + CylinderGeometry.prototype.constructor = CylinderGeometry; + + // CylinderBufferGeometry + + function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) { + + BufferGeometry.call( this ); + + this.type = 'CylinderBufferGeometry'; + + this.parameters = { + radiusTop: radiusTop, + radiusBottom: radiusBottom, + height: height, + radialSegments: radialSegments, + heightSegments: heightSegments, + openEnded: openEnded, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + var scope = this; + + radiusTop = radiusTop !== undefined ? radiusTop : 1; + radiusBottom = radiusBottom !== undefined ? radiusBottom : 1; + height = height || 1; + + radialSegments = Math.floor( radialSegments ) || 8; + heightSegments = Math.floor( heightSegments ) || 1; + + openEnded = openEnded !== undefined ? openEnded : false; + thetaStart = thetaStart !== undefined ? thetaStart : 0.0; + thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; + + // buffers + + var indices = []; + var vertices = []; + var normals = []; + var uvs = []; + + // helper variables + + var index = 0; + var indexArray = []; + var halfHeight = height / 2; + var groupStart = 0; + + // generate geometry + + generateTorso(); + + if ( openEnded === false ) { + + if ( radiusTop > 0 ) { generateCap( true ); } + if ( radiusBottom > 0 ) { generateCap( false ); } + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + function generateTorso() { + + var normal = new Vector3(); + var vertex = new Vector3(); + + var groupCount = 0; + + // this will be used to calculate the normal + var slope = ( radiusBottom - radiusTop ) / height; + + // generate vertices, normals and uvs + + for ( var y = 0; y <= heightSegments; y ++ ) { + + var indexRow = []; + + var v = y / heightSegments; + + // calculate the radius of the current row + + var radius = v * ( radiusBottom - radiusTop ) + radiusTop; + + for ( var x = 0; x <= radialSegments; x ++ ) { + + var u = x / radialSegments; + + var theta = u * thetaLength + thetaStart; + + var sinTheta = Math.sin( theta ); + var cosTheta = Math.cos( theta ); + + // vertex + + vertex.x = radius * sinTheta; + vertex.y = - v * height + halfHeight; + vertex.z = radius * cosTheta; + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + normal.set( sinTheta, slope, cosTheta ).normalize(); + normals.push( normal.x, normal.y, normal.z ); + + // uv + + uvs.push( u, 1 - v ); + + // save index of vertex in respective row + + indexRow.push( index ++ ); + + } + + // now save vertices of the row in our index array + + indexArray.push( indexRow ); + + } + + // generate indices + + for ( var x$1 = 0; x$1 < radialSegments; x$1 ++ ) { + + for ( var y$1 = 0; y$1 < heightSegments; y$1 ++ ) { + + // we use the index array to access the correct indices + + var a = indexArray[ y$1 ][ x$1 ]; + var b = indexArray[ y$1 + 1 ][ x$1 ]; + var c = indexArray[ y$1 + 1 ][ x$1 + 1 ]; + var d = indexArray[ y$1 ][ x$1 + 1 ]; + + // faces + + indices.push( a, b, d ); + indices.push( b, c, d ); + + // update group counter + + groupCount += 6; + + } + + } + + // add a group to the geometry. this will ensure multi material support + + scope.addGroup( groupStart, groupCount, 0 ); + + // calculate new start value for groups + + groupStart += groupCount; + + } + + function generateCap( top ) { + + var centerIndexStart, centerIndexEnd; + + var uv = new Vector2(); + var vertex = new Vector3(); + + var groupCount = 0; + + var radius = ( top === true ) ? radiusTop : radiusBottom; + var sign = ( top === true ) ? 1 : - 1; + + // save the index of the first center vertex + centerIndexStart = index; + + // first we generate the center vertex data of the cap. + // because the geometry needs one set of uvs per face, + // we must generate a center vertex per face/segment + + for ( var x = 1; x <= radialSegments; x ++ ) { + + // vertex + + vertices.push( 0, halfHeight * sign, 0 ); + + // normal + + normals.push( 0, sign, 0 ); + + // uv + + uvs.push( 0.5, 0.5 ); + + // increase index + + index ++; + + } + + // save the index of the last center vertex + + centerIndexEnd = index; + + // now we generate the surrounding vertices, normals and uvs + + for ( var x$1 = 0; x$1 <= radialSegments; x$1 ++ ) { + + var u = x$1 / radialSegments; + var theta = u * thetaLength + thetaStart; + + var cosTheta = Math.cos( theta ); + var sinTheta = Math.sin( theta ); + + // vertex + + vertex.x = radius * sinTheta; + vertex.y = halfHeight * sign; + vertex.z = radius * cosTheta; + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + normals.push( 0, sign, 0 ); + + // uv + + uv.x = ( cosTheta * 0.5 ) + 0.5; + uv.y = ( sinTheta * 0.5 * sign ) + 0.5; + uvs.push( uv.x, uv.y ); + + // increase index + + index ++; + + } + + // generate indices + + for ( var x$2 = 0; x$2 < radialSegments; x$2 ++ ) { + + var c = centerIndexStart + x$2; + var i = centerIndexEnd + x$2; + + if ( top === true ) { + + // face top + + indices.push( i, i + 1, c ); + + } else { + + // face bottom + + indices.push( i + 1, i, c ); + + } + + groupCount += 3; + + } + + // add a group to the geometry. this will ensure multi material support + + scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 ); + + // calculate new start value for groups + + groupStart += groupCount; + + } + + } + + CylinderBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + CylinderBufferGeometry.prototype.constructor = CylinderBufferGeometry; + + // ConeGeometry + + function ConeGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) { + + CylinderGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ); + + this.type = 'ConeGeometry'; + + this.parameters = { + radius: radius, + height: height, + radialSegments: radialSegments, + heightSegments: heightSegments, + openEnded: openEnded, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + } + + ConeGeometry.prototype = Object.create( CylinderGeometry.prototype ); + ConeGeometry.prototype.constructor = ConeGeometry; + + // ConeBufferGeometry + + function ConeBufferGeometry( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) { + + CylinderBufferGeometry.call( this, 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ); + + this.type = 'ConeBufferGeometry'; + + this.parameters = { + radius: radius, + height: height, + radialSegments: radialSegments, + heightSegments: heightSegments, + openEnded: openEnded, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + } + + ConeBufferGeometry.prototype = Object.create( CylinderBufferGeometry.prototype ); + ConeBufferGeometry.prototype.constructor = ConeBufferGeometry; + + // CircleGeometry + + function CircleGeometry( radius, segments, thetaStart, thetaLength ) { + + Geometry.call( this ); + + this.type = 'CircleGeometry'; + + this.parameters = { + radius: radius, + segments: segments, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) ); + this.mergeVertices(); + + } + + CircleGeometry.prototype = Object.create( Geometry.prototype ); + CircleGeometry.prototype.constructor = CircleGeometry; + + // CircleBufferGeometry + + function CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) { + + BufferGeometry.call( this ); + + this.type = 'CircleBufferGeometry'; + + this.parameters = { + radius: radius, + segments: segments, + thetaStart: thetaStart, + thetaLength: thetaLength + }; + + radius = radius || 1; + segments = segments !== undefined ? Math.max( 3, segments ) : 8; + + thetaStart = thetaStart !== undefined ? thetaStart : 0; + thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; + + // buffers + + var indices = []; + var vertices = []; + var normals = []; + var uvs = []; + + // helper variables + + var vertex = new Vector3(); + var uv = new Vector2(); + + // center point + + vertices.push( 0, 0, 0 ); + normals.push( 0, 0, 1 ); + uvs.push( 0.5, 0.5 ); + + for ( var s = 0, i = 3; s <= segments; s ++, i += 3 ) { + + var segment = thetaStart + s / segments * thetaLength; + + // vertex + + vertex.x = radius * Math.cos( segment ); + vertex.y = radius * Math.sin( segment ); + + vertices.push( vertex.x, vertex.y, vertex.z ); + + // normal + + normals.push( 0, 0, 1 ); + + // uvs + + uv.x = ( vertices[ i ] / radius + 1 ) / 2; + uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2; + + uvs.push( uv.x, uv.y ); + + } + + // indices + + for ( var i$1 = 1; i$1 <= segments; i$1 ++ ) { + + indices.push( i$1, i$1 + 1, 0 ); + + } + + // build geometry + + this.setIndex( indices ); + this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) ); + this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) ); + + } + + CircleBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); + CircleBufferGeometry.prototype.constructor = CircleBufferGeometry; + + var Geometries = /*#__PURE__*/Object.freeze({ + __proto__: null, + WireframeGeometry: WireframeGeometry, + ParametricGeometry: ParametricGeometry, + ParametricBufferGeometry: ParametricBufferGeometry, + TetrahedronGeometry: TetrahedronGeometry, + TetrahedronBufferGeometry: TetrahedronBufferGeometry, + OctahedronGeometry: OctahedronGeometry, + OctahedronBufferGeometry: OctahedronBufferGeometry, + IcosahedronGeometry: IcosahedronGeometry, + IcosahedronBufferGeometry: IcosahedronBufferGeometry, + DodecahedronGeometry: DodecahedronGeometry, + DodecahedronBufferGeometry: DodecahedronBufferGeometry, + PolyhedronGeometry: PolyhedronGeometry, + PolyhedronBufferGeometry: PolyhedronBufferGeometry, + TubeGeometry: TubeGeometry, + TubeBufferGeometry: TubeBufferGeometry, + TorusKnotGeometry: TorusKnotGeometry, + TorusKnotBufferGeometry: TorusKnotBufferGeometry, + TorusGeometry: TorusGeometry, + TorusBufferGeometry: TorusBufferGeometry, + TextGeometry: TextGeometry, + TextBufferGeometry: TextBufferGeometry, + SphereGeometry: SphereGeometry, + SphereBufferGeometry: SphereBufferGeometry, + RingGeometry: RingGeometry, + RingBufferGeometry: RingBufferGeometry, + PlaneGeometry: PlaneGeometry, + PlaneBufferGeometry: PlaneBufferGeometry, + LatheGeometry: LatheGeometry, + LatheBufferGeometry: LatheBufferGeometry, + ShapeGeometry: ShapeGeometry, + ShapeBufferGeometry: ShapeBufferGeometry, + ExtrudeGeometry: ExtrudeGeometry, + ExtrudeBufferGeometry: ExtrudeBufferGeometry, + EdgesGeometry: EdgesGeometry, + ConeGeometry: ConeGeometry, + ConeBufferGeometry: ConeBufferGeometry, + CylinderGeometry: CylinderGeometry, + CylinderBufferGeometry: CylinderBufferGeometry, + CircleGeometry: CircleGeometry, + CircleBufferGeometry: CircleBufferGeometry, + BoxGeometry: BoxGeometry, + BoxBufferGeometry: BoxBufferGeometry + }); + + /** + * parameters = { + * color: + * } + */ + + function ShadowMaterial( parameters ) { + + Material.call( this ); + + this.type = 'ShadowMaterial'; + + this.color = new Color( 0x000000 ); + this.transparent = true; + + this.setValues( parameters ); + + } + + ShadowMaterial.prototype = Object.create( Material.prototype ); + ShadowMaterial.prototype.constructor = ShadowMaterial; + + ShadowMaterial.prototype.isShadowMaterial = true; + + ShadowMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.color.copy( source.color ); + + return this; + + }; + + function RawShaderMaterial( parameters ) { + + ShaderMaterial.call( this, parameters ); + + this.type = 'RawShaderMaterial'; + + } + + RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype ); + RawShaderMaterial.prototype.constructor = RawShaderMaterial; + + RawShaderMaterial.prototype.isRawShaderMaterial = true; + + /** + * parameters = { + * color: , + * roughness: , + * metalness: , + * opacity: , + * + * map: new THREE.Texture( ), + * + * lightMap: new THREE.Texture( ), + * lightMapIntensity: + * + * aoMap: new THREE.Texture( ), + * aoMapIntensity: + * + * emissive: , + * emissiveIntensity: + * emissiveMap: new THREE.Texture( ), + * + * bumpMap: new THREE.Texture( ), + * bumpScale: , + * + * normalMap: new THREE.Texture( ), + * normalMapType: THREE.TangentSpaceNormalMap, + * normalScale: , + * + * displacementMap: new THREE.Texture( ), + * displacementScale: , + * displacementBias: , + * + * roughnessMap: new THREE.Texture( ), + * + * metalnessMap: new THREE.Texture( ), + * + * alphaMap: new THREE.Texture( ), + * + * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ), + * envMapIntensity: + * + * refractionRatio: , + * + * wireframe: , + * wireframeLinewidth: , + * + * skinning: , + * morphTargets: , + * morphNormals: + * } + */ + + function MeshStandardMaterial( parameters ) { + + Material.call( this ); + + this.defines = { 'STANDARD': '' }; + + this.type = 'MeshStandardMaterial'; + + this.color = new Color( 0xffffff ); // diffuse + this.roughness = 1.0; + this.metalness = 0.0; + + this.map = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.roughnessMap = null; + + this.metalnessMap = null; + + this.alphaMap = null; + + this.envMap = null; + this.envMapIntensity = 1.0; + + this.refractionRatio = 0.98; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; + + this.vertexTangents = false; + + this.setValues( parameters ); + + } + + MeshStandardMaterial.prototype = Object.create( Material.prototype ); + MeshStandardMaterial.prototype.constructor = MeshStandardMaterial; + + MeshStandardMaterial.prototype.isMeshStandardMaterial = true; + + MeshStandardMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.defines = { 'STANDARD': '' }; + + this.color.copy( source.color ); + this.roughness = source.roughness; + this.metalness = source.metalness; + + this.map = source.map; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.roughnessMap = source.roughnessMap; + + this.metalnessMap = source.metalnessMap; + + this.alphaMap = source.alphaMap; + + this.envMap = source.envMap; + this.envMapIntensity = source.envMapIntensity; + + this.refractionRatio = source.refractionRatio; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; + + this.vertexTangents = source.vertexTangents; + + return this; + + }; + + /** + * parameters = { + * clearcoat: , + * clearcoatMap: new THREE.Texture( ), + * clearcoatRoughness: , + * clearcoatRoughnessMap: new THREE.Texture( ), + * clearcoatNormalScale: , + * clearcoatNormalMap: new THREE.Texture( ), + * + * reflectivity: , + * + * sheen: , + * + * transmission: , + * transmissionMap: new THREE.Texture( ) + * } + */ + + function MeshPhysicalMaterial( parameters ) { + + MeshStandardMaterial.call( this ); + + this.defines = { + + 'STANDARD': '', + 'PHYSICAL': '' + + }; + + this.type = 'MeshPhysicalMaterial'; + + this.clearcoat = 0.0; + this.clearcoatMap = null; + this.clearcoatRoughness = 0.0; + this.clearcoatRoughnessMap = null; + this.clearcoatNormalScale = new Vector2( 1, 1 ); + this.clearcoatNormalMap = null; + + this.reflectivity = 0.5; // maps to F0 = 0.04 + + this.sheen = null; // null will disable sheen bsdf + + this.transmission = 0.0; + this.transmissionMap = null; + + this.setValues( parameters ); + + } + + MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype ); + MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial; + + MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true; + + MeshPhysicalMaterial.prototype.copy = function ( source ) { + + MeshStandardMaterial.prototype.copy.call( this, source ); + + this.defines = { + + 'STANDARD': '', + 'PHYSICAL': '' + + }; + + this.clearcoat = source.clearcoat; + this.clearcoatMap = source.clearcoatMap; + this.clearcoatRoughness = source.clearcoatRoughness; + this.clearcoatRoughnessMap = source.clearcoatRoughnessMap; + this.clearcoatNormalMap = source.clearcoatNormalMap; + this.clearcoatNormalScale.copy( source.clearcoatNormalScale ); + + this.reflectivity = source.reflectivity; + + if ( source.sheen ) { + + this.sheen = ( this.sheen || new Color() ).copy( source.sheen ); + + } else { + + this.sheen = null; + + } + + this.transmission = source.transmission; + this.transmissionMap = source.transmissionMap; + + return this; + + }; + + /** + * parameters = { + * color: , + * specular: , + * shininess: , + * opacity: , + * + * map: new THREE.Texture( ), + * + * lightMap: new THREE.Texture( ), + * lightMapIntensity: + * + * aoMap: new THREE.Texture( ), + * aoMapIntensity: + * + * emissive: , + * emissiveIntensity: + * emissiveMap: new THREE.Texture( ), + * + * bumpMap: new THREE.Texture( ), + * bumpScale: , + * + * normalMap: new THREE.Texture( ), + * normalMapType: THREE.TangentSpaceNormalMap, + * normalScale: , + * + * displacementMap: new THREE.Texture( ), + * displacementScale: , + * displacementBias: , + * + * specularMap: new THREE.Texture( ), + * + * alphaMap: new THREE.Texture( ), + * + * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ), + * combine: THREE.MultiplyOperation, + * reflectivity: , + * refractionRatio: , + * + * wireframe: , + * wireframeLinewidth: , + * + * skinning: , + * morphTargets: , + * morphNormals: + * } + */ + + function MeshPhongMaterial( parameters ) { + + Material.call( this ); + + this.type = 'MeshPhongMaterial'; + + this.color = new Color( 0xffffff ); // diffuse + this.specular = new Color( 0x111111 ); + this.shininess = 30; + + this.map = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.specularMap = null; + + this.alphaMap = null; + + this.envMap = null; + this.combine = MultiplyOperation; + this.reflectivity = 1; + this.refractionRatio = 0.98; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; + + this.setValues( parameters ); + + } + + MeshPhongMaterial.prototype = Object.create( Material.prototype ); + MeshPhongMaterial.prototype.constructor = MeshPhongMaterial; + + MeshPhongMaterial.prototype.isMeshPhongMaterial = true; + + MeshPhongMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.color.copy( source.color ); + this.specular.copy( source.specular ); + this.shininess = source.shininess; + + this.map = source.map; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.specularMap = source.specularMap; + + this.alphaMap = source.alphaMap; + + this.envMap = source.envMap; + this.combine = source.combine; + this.reflectivity = source.reflectivity; + this.refractionRatio = source.refractionRatio; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; + + return this; + + }; + + /** + * parameters = { + * color: , + * + * map: new THREE.Texture( ), + * gradientMap: new THREE.Texture( ), + * + * lightMap: new THREE.Texture( ), + * lightMapIntensity: + * + * aoMap: new THREE.Texture( ), + * aoMapIntensity: + * + * emissive: , + * emissiveIntensity: + * emissiveMap: new THREE.Texture( ), + * + * bumpMap: new THREE.Texture( ), + * bumpScale: , + * + * normalMap: new THREE.Texture( ), + * normalMapType: THREE.TangentSpaceNormalMap, + * normalScale: , + * + * displacementMap: new THREE.Texture( ), + * displacementScale: , + * displacementBias: , + * + * alphaMap: new THREE.Texture( ), + * + * wireframe: , + * wireframeLinewidth: , + * + * skinning: , + * morphTargets: , + * morphNormals: + * } + */ + + function MeshToonMaterial( parameters ) { + + Material.call( this ); + + this.defines = { 'TOON': '' }; + + this.type = 'MeshToonMaterial'; + + this.color = new Color( 0xffffff ); + + this.map = null; + this.gradientMap = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.alphaMap = null; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; + + this.setValues( parameters ); + + } + + MeshToonMaterial.prototype = Object.create( Material.prototype ); + MeshToonMaterial.prototype.constructor = MeshToonMaterial; + + MeshToonMaterial.prototype.isMeshToonMaterial = true; + + MeshToonMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.color.copy( source.color ); + + this.map = source.map; + this.gradientMap = source.gradientMap; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.alphaMap = source.alphaMap; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; + + return this; + + }; + + /** + * parameters = { + * opacity: , + * + * bumpMap: new THREE.Texture( ), + * bumpScale: , + * + * normalMap: new THREE.Texture( ), + * normalMapType: THREE.TangentSpaceNormalMap, + * normalScale: , + * + * displacementMap: new THREE.Texture( ), + * displacementScale: , + * displacementBias: , + * + * wireframe: , + * wireframeLinewidth: + * + * skinning: , + * morphTargets: , + * morphNormals: + * } + */ + + function MeshNormalMaterial( parameters ) { + + Material.call( this ); + + this.type = 'MeshNormalMaterial'; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.wireframe = false; + this.wireframeLinewidth = 1; + + this.fog = false; + + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; + + this.setValues( parameters ); + + } + + MeshNormalMaterial.prototype = Object.create( Material.prototype ); + MeshNormalMaterial.prototype.constructor = MeshNormalMaterial; + + MeshNormalMaterial.prototype.isMeshNormalMaterial = true; + + MeshNormalMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; + + return this; + + }; + + /** + * parameters = { + * color: , + * opacity: , + * + * map: new THREE.Texture( ), + * + * lightMap: new THREE.Texture( ), + * lightMapIntensity: + * + * aoMap: new THREE.Texture( ), + * aoMapIntensity: + * + * emissive: , + * emissiveIntensity: + * emissiveMap: new THREE.Texture( ), + * + * specularMap: new THREE.Texture( ), + * + * alphaMap: new THREE.Texture( ), + * + * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ), + * combine: THREE.Multiply, + * reflectivity: , + * refractionRatio: , + * + * wireframe: , + * wireframeLinewidth: , + * + * skinning: , + * morphTargets: , + * morphNormals: + * } + */ + + function MeshLambertMaterial( parameters ) { + + Material.call( this ); + + this.type = 'MeshLambertMaterial'; + + this.color = new Color( 0xffffff ); // diffuse + + this.map = null; + + this.lightMap = null; + this.lightMapIntensity = 1.0; + + this.aoMap = null; + this.aoMapIntensity = 1.0; + + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; + + this.specularMap = null; + + this.alphaMap = null; + + this.envMap = null; + this.combine = MultiplyOperation; + this.reflectivity = 1; + this.refractionRatio = 0.98; + + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; + + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; + + this.setValues( parameters ); + + } + + MeshLambertMaterial.prototype = Object.create( Material.prototype ); + MeshLambertMaterial.prototype.constructor = MeshLambertMaterial; + + MeshLambertMaterial.prototype.isMeshLambertMaterial = true; + + MeshLambertMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.color.copy( source.color ); + + this.map = source.map; + + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; + + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; + + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; + + this.specularMap = source.specularMap; + + this.alphaMap = source.alphaMap; + + this.envMap = source.envMap; + this.combine = source.combine; + this.reflectivity = source.reflectivity; + this.refractionRatio = source.refractionRatio; + + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; + + return this; + + }; + + /** + * parameters = { + * color: , + * opacity: , + * + * matcap: new THREE.Texture( ), + * + * map: new THREE.Texture( ), + * + * bumpMap: new THREE.Texture( ), + * bumpScale: , + * + * normalMap: new THREE.Texture( ), + * normalMapType: THREE.TangentSpaceNormalMap, + * normalScale: , + * + * displacementMap: new THREE.Texture( ), + * displacementScale: , + * displacementBias: , + * + * alphaMap: new THREE.Texture( ), + * + * skinning: , + * morphTargets: , + * morphNormals: + * } + */ + + function MeshMatcapMaterial( parameters ) { + + Material.call( this ); + + this.defines = { 'MATCAP': '' }; + + this.type = 'MeshMatcapMaterial'; + + this.color = new Color( 0xffffff ); // diffuse + + this.matcap = null; + + this.map = null; + + this.bumpMap = null; + this.bumpScale = 1; + + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); + + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; + + this.alphaMap = null; + + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; + + this.setValues( parameters ); + + } + + MeshMatcapMaterial.prototype = Object.create( Material.prototype ); + MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial; + + MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true; + + MeshMatcapMaterial.prototype.copy = function ( source ) { + + Material.prototype.copy.call( this, source ); + + this.defines = { 'MATCAP': '' }; + + this.color.copy( source.color ); + + this.matcap = source.matcap; + + this.map = source.map; + + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; + + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); + + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; + + this.alphaMap = source.alphaMap; + + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; + + return this; + + }; + + /** + * parameters = { + * color: , + * opacity: , + * + * linewidth: , + * + * scale: , + * dashSize: , + * gapSize: + * } + */ + + function LineDashedMaterial( parameters ) { + + LineBasicMaterial.call( this ); + + this.type = 'LineDashedMaterial'; + + this.scale = 1; + this.dashSize = 3; + this.gapSize = 1; + + this.setValues( parameters ); + + } + + LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype ); + LineDashedMaterial.prototype.constructor = LineDashedMaterial; + + LineDashedMaterial.prototype.isLineDashedMaterial = true; + + LineDashedMaterial.prototype.copy = function ( source ) { + + LineBasicMaterial.prototype.copy.call( this, source ); + + this.scale = source.scale; + this.dashSize = source.dashSize; + this.gapSize = source.gapSize; + + return this; + + }; + + var Materials = /*#__PURE__*/Object.freeze({ + __proto__: null, + ShadowMaterial: ShadowMaterial, + SpriteMaterial: SpriteMaterial, + RawShaderMaterial: RawShaderMaterial, + ShaderMaterial: ShaderMaterial, + PointsMaterial: PointsMaterial, + MeshPhysicalMaterial: MeshPhysicalMaterial, + MeshStandardMaterial: MeshStandardMaterial, + MeshPhongMaterial: MeshPhongMaterial, + MeshToonMaterial: MeshToonMaterial, + MeshNormalMaterial: MeshNormalMaterial, + MeshLambertMaterial: MeshLambertMaterial, + MeshDepthMaterial: MeshDepthMaterial, + MeshDistanceMaterial: MeshDistanceMaterial, + MeshBasicMaterial: MeshBasicMaterial, + MeshMatcapMaterial: MeshMatcapMaterial, + LineDashedMaterial: LineDashedMaterial, + LineBasicMaterial: LineBasicMaterial, + Material: Material + }); + + var AnimationUtils = { + + // same as Array.prototype.slice, but also works on typed arrays + arraySlice: function ( array, from, to ) { + + if ( AnimationUtils.isTypedArray( array ) ) { + + // in ios9 array.subarray(from, undefined) will return empty array + // but array.subarray(from) or array.subarray(from, len) is correct + return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) ); + + } + + return array.slice( from, to ); + + }, + + // converts an array to a specific type + convertArray: function ( array, type, forceClone ) { + + if ( ! array || // let 'undefined' and 'null' pass + ! forceClone && array.constructor === type ) { return array; } + + if ( typeof type.BYTES_PER_ELEMENT === 'number' ) { + + return new type( array ); // create typed array + + } + + return Array.prototype.slice.call( array ); // create Array + + }, + + isTypedArray: function ( object ) { + + return ArrayBuffer.isView( object ) && + ! ( object instanceof DataView ); + + }, + + // returns an array by which times and values can be sorted + getKeyframeOrder: function ( times ) { + + function compareTime( i, j ) { + + return times[ i ] - times[ j ]; + + } + + var n = times.length; + var result = new Array( n ); + for ( var i = 0; i !== n; ++ i ) { result[ i ] = i; } + + result.sort( compareTime ); + + return result; + + }, + + // uses the array previously returned by 'getKeyframeOrder' to sort data + sortedArray: function ( values, stride, order ) { + + var nValues = values.length; + var result = new values.constructor( nValues ); + + for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) { + + var srcOffset = order[ i ] * stride; + + for ( var j = 0; j !== stride; ++ j ) { + + result[ dstOffset ++ ] = values[ srcOffset + j ]; + + } + + } + + return result; + + }, + + // function for parsing AOS keyframe formats + flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) { + + var i = 1, key = jsonKeys[ 0 ]; + + while ( key !== undefined && key[ valuePropertyName ] === undefined ) { + + key = jsonKeys[ i ++ ]; + + } + + if ( key === undefined ) { return; } // no data + + var value = key[ valuePropertyName ]; + if ( value === undefined ) { return; } // no data + + if ( Array.isArray( value ) ) { + + do { + + value = key[ valuePropertyName ]; + + if ( value !== undefined ) { + + times.push( key.time ); + values.push.apply( values, value ); // push all elements + + } + + key = jsonKeys[ i ++ ]; + + } while ( key !== undefined ); + + } else if ( value.toArray !== undefined ) { + + // ...assume THREE.Math-ish + + do { + + value = key[ valuePropertyName ]; + + if ( value !== undefined ) { + + times.push( key.time ); + value.toArray( values, values.length ); + + } + + key = jsonKeys[ i ++ ]; + + } while ( key !== undefined ); + + } else { + + // otherwise push as-is + + do { + + value = key[ valuePropertyName ]; + + if ( value !== undefined ) { + + times.push( key.time ); + values.push( value ); + + } + + key = jsonKeys[ i ++ ]; + + } while ( key !== undefined ); + + } + + }, + + subclip: function ( sourceClip, name, startFrame, endFrame, fps ) { + + fps = fps || 30; + + var clip = sourceClip.clone(); + + clip.name = name; + + var tracks = []; + + for ( var i = 0; i < clip.tracks.length; ++ i ) { + + var track = clip.tracks[ i ]; + var valueSize = track.getValueSize(); + + var times = []; + var values = []; + + for ( var j = 0; j < track.times.length; ++ j ) { + + var frame = track.times[ j ] * fps; + + if ( frame < startFrame || frame >= endFrame ) { continue; } + + times.push( track.times[ j ] ); + + for ( var k = 0; k < valueSize; ++ k ) { + + values.push( track.values[ j * valueSize + k ] ); + + } + + } + + if ( times.length === 0 ) { continue; } + + track.times = AnimationUtils.convertArray( times, track.times.constructor ); + track.values = AnimationUtils.convertArray( values, track.values.constructor ); + + tracks.push( track ); + + } + + clip.tracks = tracks; + + // find minimum .times value across all tracks in the trimmed clip + + var minStartTime = Infinity; + + for ( var i$1 = 0; i$1 < clip.tracks.length; ++ i$1 ) { + + if ( minStartTime > clip.tracks[ i$1 ].times[ 0 ] ) { + + minStartTime = clip.tracks[ i$1 ].times[ 0 ]; + + } + + } + + // shift all tracks such that clip begins at t=0 + + for ( var i$2 = 0; i$2 < clip.tracks.length; ++ i$2 ) { + + clip.tracks[ i$2 ].shift( - 1 * minStartTime ); + + } + + clip.resetDuration(); + + return clip; + + }, + + makeClipAdditive: function ( targetClip, referenceFrame, referenceClip, fps ) { + + if ( referenceFrame === undefined ) { referenceFrame = 0; } + if ( referenceClip === undefined ) { referenceClip = targetClip; } + if ( fps === undefined || fps <= 0 ) { fps = 30; } + + var numTracks = targetClip.tracks.length; + var referenceTime = referenceFrame / fps; + + // Make each track's values relative to the values at the reference frame + var loop = function ( i ) { + + var referenceTrack = referenceClip.tracks[ i ]; + var referenceTrackType = referenceTrack.ValueTypeName; + + // Skip this track if it's non-numeric + if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) { return; } + + // Find the track in the target clip whose name and type matches the reference track + var targetTrack = targetClip.tracks.find( function ( track ) { + + return track.name === referenceTrack.name + && track.ValueTypeName === referenceTrackType; + + } ); + + if ( targetTrack === undefined ) { return; } + + var valueSize = referenceTrack.getValueSize(); + var lastIndex = referenceTrack.times.length - 1; + var referenceValue = (void 0); + + // Find the value to subtract out of the track + if ( referenceTime <= referenceTrack.times[ 0 ] ) { + + // Reference frame is earlier than the first keyframe, so just use the first keyframe + referenceValue = AnimationUtils.arraySlice( referenceTrack.values, 0, referenceTrack.valueSize ); + + } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) { + + // Reference frame is after the last keyframe, so just use the last keyframe + var startIndex = lastIndex * valueSize; + referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex ); + + } else { + + // Interpolate to the reference value + var interpolant = referenceTrack.createInterpolant(); + interpolant.evaluate( referenceTime ); + referenceValue = interpolant.resultBuffer; + + } + + // Conjugate the quaternion + if ( referenceTrackType === 'quaternion' ) { + + var referenceQuat = new Quaternion( + referenceValue[ 0 ], + referenceValue[ 1 ], + referenceValue[ 2 ], + referenceValue[ 3 ] + ).normalize().conjugate(); + referenceQuat.toArray( referenceValue ); + + } + + // Subtract the reference value from all of the track values + + var numTimes = targetTrack.times.length; + for ( var j = 0; j < numTimes; ++ j ) { + + var valueStart = j * valueSize; + + if ( referenceTrackType === 'quaternion' ) { + + // Multiply the conjugate for quaternion track types + Quaternion.multiplyQuaternionsFlat( + targetTrack.values, + valueStart, + referenceValue, + 0, + targetTrack.values, + valueStart + ); + + } else { + + // Subtract each value for all other numeric track types + for ( var k = 0; k < valueSize; ++ k ) { + + targetTrack.values[ valueStart + k ] -= referenceValue[ k ]; + + } + + } + + } + + }; + + for ( var i = 0; i < numTracks; ++ i ) loop( i ); + + targetClip.blendMode = AdditiveAnimationBlendMode; + + return targetClip; + + } + + }; + + /** + * Abstract base class of interpolants over parametric samples. + * + * The parameter domain is one dimensional, typically the time or a path + * along a curve defined by the data. + * + * The sample values can have any dimensionality and derived classes may + * apply special interpretations to the data. + * + * This class provides the interval seek in a Template Method, deferring + * the actual interpolation to derived classes. + * + * Time complexity is O(1) for linear access crossing at most two points + * and O(log N) for random access, where N is the number of positions. + * + * References: + * + * http://www.oodesign.com/template-method-pattern.html + * + */ + + function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + this.parameterPositions = parameterPositions; + this._cachedIndex = 0; + + this.resultBuffer = resultBuffer !== undefined ? + resultBuffer : new sampleValues.constructor( sampleSize ); + this.sampleValues = sampleValues; + this.valueSize = sampleSize; + + } + + Object.assign( Interpolant.prototype, { + + evaluate: function ( t ) { + + var pp = this.parameterPositions, + i1 = this._cachedIndex, + + t1 = pp[ i1 ], + t0 = pp[ i1 - 1 ]; + + validate_interval: { + + seek: { + + var right; + + linear_scan: { + + //- See http://jsperf.com/comparison-to-undefined/3 + //- slower code: + //- + //- if ( t >= t1 || t1 === undefined ) { + forward_scan: if ( ! ( t < t1 ) ) { + + for ( var giveUpAt = i1 + 2; ; ) { + + if ( t1 === undefined ) { + + if ( t < t0 ) { break forward_scan; } + + // after end + + i1 = pp.length; + this._cachedIndex = i1; + return this.afterEnd_( i1 - 1, t, t0 ); + + } + + if ( i1 === giveUpAt ) { break; } // this loop + + t0 = t1; + t1 = pp[ ++ i1 ]; + + if ( t < t1 ) { + + // we have arrived at the sought interval + break seek; + + } + + } + + // prepare binary search on the right side of the index + right = pp.length; + break linear_scan; + + } + + //- slower code: + //- if ( t < t0 || t0 === undefined ) { + if ( ! ( t >= t0 ) ) { + + // looping? + + var t1global = pp[ 1 ]; + + if ( t < t1global ) { + + i1 = 2; // + 1, using the scan for the details + t0 = t1global; + + } + + // linear reverse scan + + for ( var giveUpAt$1 = i1 - 2; ; ) { + + if ( t0 === undefined ) { + + // before start + + this._cachedIndex = 0; + return this.beforeStart_( 0, t, t1 ); + + } + + if ( i1 === giveUpAt$1 ) { break; } // this loop + + t1 = t0; + t0 = pp[ -- i1 - 1 ]; + + if ( t >= t0 ) { + + // we have arrived at the sought interval + break seek; + + } + + } + + // prepare binary search on the left side of the index + right = i1; + i1 = 0; + break linear_scan; + + } + + // the interval is valid + + break validate_interval; + + } // linear scan + + // binary search + + while ( i1 < right ) { + + var mid = ( i1 + right ) >>> 1; + + if ( t < pp[ mid ] ) { + + right = mid; + + } else { + + i1 = mid + 1; + + } + + } + + t1 = pp[ i1 ]; + t0 = pp[ i1 - 1 ]; + + // check boundary cases, again + + if ( t0 === undefined ) { + + this._cachedIndex = 0; + return this.beforeStart_( 0, t, t1 ); + + } + + if ( t1 === undefined ) { + + i1 = pp.length; + this._cachedIndex = i1; + return this.afterEnd_( i1 - 1, t0, t ); + + } + + } // seek + + this._cachedIndex = i1; + + this.intervalChanged_( i1, t0, t1 ); + + } // validate_interval + + return this.interpolate_( i1, t0, t, t1 ); + + }, + + settings: null, // optional, subclass-specific settings structure + // Note: The indirection allows central control of many interpolants. + + // --- Protected interface + + DefaultSettings_: {}, + + getSettings_: function () { + + return this.settings || this.DefaultSettings_; + + }, + + copySampleValue_: function ( index ) { + + // copies a sample value to the result buffer + + var result = this.resultBuffer, + values = this.sampleValues, + stride = this.valueSize, + offset = index * stride; + + for ( var i = 0; i !== stride; ++ i ) { + + result[ i ] = values[ offset + i ]; + + } + + return result; + + }, + + // Template methods for derived classes: + + interpolate_: function ( /* i1, t0, t, t1 */ ) { + + throw new Error( 'call to abstract method' ); + // implementations shall return this.resultBuffer + + }, + + intervalChanged_: function ( /* i1, t0, t1 */ ) { + + // empty + + } + + } ); + + // DECLARE ALIAS AFTER assign prototype + Object.assign( Interpolant.prototype, { + + //( 0, t, t0 ), returns this.resultBuffer + beforeStart_: Interpolant.prototype.copySampleValue_, + + //( N-1, tN-1, t ), returns this.resultBuffer + afterEnd_: Interpolant.prototype.copySampleValue_, + + } ); + + /** + * Fast and simple cubic spline interpolant. + * + * It was derived from a Hermitian construction setting the first derivative + * at each sample position to the linear slope between neighboring positions + * over their parameter interval. + */ + + function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer ); + + this._weightPrev = - 0; + this._offsetPrev = - 0; + this._weightNext = - 0; + this._offsetNext = - 0; + + } + + CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), { + + constructor: CubicInterpolant, + + DefaultSettings_: { + + endingStart: ZeroCurvatureEnding, + endingEnd: ZeroCurvatureEnding + + }, + + intervalChanged_: function ( i1, t0, t1 ) { + + var pp = this.parameterPositions, + iPrev = i1 - 2, + iNext = i1 + 1, + + tPrev = pp[ iPrev ], + tNext = pp[ iNext ]; + + if ( tPrev === undefined ) { + + switch ( this.getSettings_().endingStart ) { + + case ZeroSlopeEnding: + + // f'(t0) = 0 + iPrev = i1; + tPrev = 2 * t0 - t1; + + break; + + case WrapAroundEnding: + + // use the other end of the curve + iPrev = pp.length - 2; + tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ]; + + break; + + default: // ZeroCurvatureEnding + + // f''(t0) = 0 a.k.a. Natural Spline + iPrev = i1; + tPrev = t1; + + } + + } + + if ( tNext === undefined ) { + + switch ( this.getSettings_().endingEnd ) { + + case ZeroSlopeEnding: + + // f'(tN) = 0 + iNext = i1; + tNext = 2 * t1 - t0; + + break; + + case WrapAroundEnding: + + // use the other end of the curve + iNext = 1; + tNext = t1 + pp[ 1 ] - pp[ 0 ]; + + break; + + default: // ZeroCurvatureEnding + + // f''(tN) = 0, a.k.a. Natural Spline + iNext = i1 - 1; + tNext = t0; + + } + + } + + var halfDt = ( t1 - t0 ) * 0.5, + stride = this.valueSize; + + this._weightPrev = halfDt / ( t0 - tPrev ); + this._weightNext = halfDt / ( tNext - t1 ); + this._offsetPrev = iPrev * stride; + this._offsetNext = iNext * stride; + + }, + + interpolate_: function ( i1, t0, t, t1 ) { + + var result = this.resultBuffer, + values = this.sampleValues, + stride = this.valueSize, + + o1 = i1 * stride, o0 = o1 - stride, + oP = this._offsetPrev, oN = this._offsetNext, + wP = this._weightPrev, wN = this._weightNext, + + p = ( t - t0 ) / ( t1 - t0 ), + pp = p * p, + ppp = pp * p; + + // evaluate polynomials + + var sP = - wP * ppp + 2 * wP * pp - wP * p; + var s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1; + var s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p; + var sN = wN * ppp - wN * pp; + + // combine data linearly + + for ( var i = 0; i !== stride; ++ i ) { + + result[ i ] = + sP * values[ oP + i ] + + s0 * values[ o0 + i ] + + s1 * values[ o1 + i ] + + sN * values[ oN + i ]; + + } + + return result; + + } + + } ); + + function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer ); + + } + + LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), { + + constructor: LinearInterpolant, + + interpolate_: function ( i1, t0, t, t1 ) { + + var result = this.resultBuffer, + values = this.sampleValues, + stride = this.valueSize, + + offset1 = i1 * stride, + offset0 = offset1 - stride, + + weight1 = ( t - t0 ) / ( t1 - t0 ), + weight0 = 1 - weight1; + + for ( var i = 0; i !== stride; ++ i ) { + + result[ i ] = + values[ offset0 + i ] * weight0 + + values[ offset1 + i ] * weight1; + + } + + return result; + + } + + } ); + + /** + * + * Interpolant that evaluates to the sample value at the position preceeding + * the parameter. + */ + + function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer ); + + } + + DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), { + + constructor: DiscreteInterpolant, + + interpolate_: function ( i1 /*, t0, t, t1 */ ) { + + return this.copySampleValue_( i1 - 1 ); + + } + + } ); + + function KeyframeTrack( name, times, values, interpolation ) { + + if ( name === undefined ) { throw new Error( 'THREE.KeyframeTrack: track name is undefined' ); } + if ( times === undefined || times.length === 0 ) { throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name ); } + + this.name = name; + + this.times = AnimationUtils.convertArray( times, this.TimeBufferType ); + this.values = AnimationUtils.convertArray( values, this.ValueBufferType ); + + this.setInterpolation( interpolation || this.DefaultInterpolation ); + + } + + // Static methods + + Object.assign( KeyframeTrack, { + + // Serialization (in static context, because of constructor invocation + // and automatic invocation of .toJSON): + + toJSON: function ( track ) { + + var trackType = track.constructor; + + var json; + + // derived classes can define a static toJSON method + if ( trackType.toJSON !== undefined ) { + + json = trackType.toJSON( track ); + + } else { + + // by default, we assume the data can be serialized as-is + json = { + + 'name': track.name, + 'times': AnimationUtils.convertArray( track.times, Array ), + 'values': AnimationUtils.convertArray( track.values, Array ) + + }; + + var interpolation = track.getInterpolation(); + + if ( interpolation !== track.DefaultInterpolation ) { + + json.interpolation = interpolation; + + } + + } + + json.type = track.ValueTypeName; // mandatory + + return json; + + } + + } ); + + Object.assign( KeyframeTrack.prototype, { + + constructor: KeyframeTrack, + + TimeBufferType: Float32Array, + + ValueBufferType: Float32Array, + + DefaultInterpolation: InterpolateLinear, + + InterpolantFactoryMethodDiscrete: function ( result ) { + + return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result ); + + }, + + InterpolantFactoryMethodLinear: function ( result ) { + + return new LinearInterpolant( this.times, this.values, this.getValueSize(), result ); + + }, + + InterpolantFactoryMethodSmooth: function ( result ) { + + return new CubicInterpolant( this.times, this.values, this.getValueSize(), result ); + + }, + + setInterpolation: function ( interpolation ) { + + var factoryMethod; + + switch ( interpolation ) { + + case InterpolateDiscrete: + + factoryMethod = this.InterpolantFactoryMethodDiscrete; + + break; + + case InterpolateLinear: + + factoryMethod = this.InterpolantFactoryMethodLinear; + + break; + + case InterpolateSmooth: + + factoryMethod = this.InterpolantFactoryMethodSmooth; + + break; + + } + + if ( factoryMethod === undefined ) { + + var message = "unsupported interpolation for " + + this.ValueTypeName + " keyframe track named " + this.name; + + if ( this.createInterpolant === undefined ) { + + // fall back to default, unless the default itself is messed up + if ( interpolation !== this.DefaultInterpolation ) { + + this.setInterpolation( this.DefaultInterpolation ); + + } else { + + throw new Error( message ); // fatal, in this case + + } + + } + + console.warn( 'THREE.KeyframeTrack:', message ); + return this; + + } + + this.createInterpolant = factoryMethod; + + return this; + + }, + + getInterpolation: function () { + + switch ( this.createInterpolant ) { + + case this.InterpolantFactoryMethodDiscrete: + + return InterpolateDiscrete; + + case this.InterpolantFactoryMethodLinear: + + return InterpolateLinear; + + case this.InterpolantFactoryMethodSmooth: + + return InterpolateSmooth; + + } + + }, + + getValueSize: function () { + + return this.values.length / this.times.length; + + }, + + // move all keyframes either forwards or backwards in time + shift: function ( timeOffset ) { + + if ( timeOffset !== 0.0 ) { + + var times = this.times; + + for ( var i = 0, n = times.length; i !== n; ++ i ) { + + times[ i ] += timeOffset; + + } + + } + + return this; + + }, + + // scale all keyframe times by a factor (useful for frame <-> seconds conversions) + scale: function ( timeScale ) { + + if ( timeScale !== 1.0 ) { + + var times = this.times; + + for ( var i = 0, n = times.length; i !== n; ++ i ) { + + times[ i ] *= timeScale; + + } + + } + + return this; + + }, + + // removes keyframes before and after animation without changing any values within the range [startTime, endTime]. + // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values + trim: function ( startTime, endTime ) { + + var times = this.times, + nKeys = times.length; + + var from = 0, + to = nKeys - 1; + + while ( from !== nKeys && times[ from ] < startTime ) { + + ++ from; + + } + + while ( to !== - 1 && times[ to ] > endTime ) { + + -- to; + + } + + ++ to; // inclusive -> exclusive bound + + if ( from !== 0 || to !== nKeys ) { + + // empty tracks are forbidden, so keep at least one keyframe + if ( from >= to ) { + + to = Math.max( to, 1 ); + from = to - 1; + + } + + var stride = this.getValueSize(); + this.times = AnimationUtils.arraySlice( times, from, to ); + this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride ); + + } + + return this; + + }, + + // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable + validate: function () { + + var valid = true; + + var valueSize = this.getValueSize(); + if ( valueSize - Math.floor( valueSize ) !== 0 ) { + + console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this ); + valid = false; + + } + + var times = this.times, + values = this.values, + + nKeys = times.length; + + if ( nKeys === 0 ) { + + console.error( 'THREE.KeyframeTrack: Track is empty.', this ); + valid = false; + + } + + var prevTime = null; + + for ( var i = 0; i !== nKeys; i ++ ) { + + var currTime = times[ i ]; + + if ( typeof currTime === 'number' && isNaN( currTime ) ) { + + console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime ); + valid = false; + break; + + } + + if ( prevTime !== null && prevTime > currTime ) { + + console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime ); + valid = false; + break; + + } + + prevTime = currTime; + + } + + if ( values !== undefined ) { + + if ( AnimationUtils.isTypedArray( values ) ) { + + for ( var i$1 = 0, n = values.length; i$1 !== n; ++ i$1 ) { + + var value = values[ i$1 ]; + + if ( isNaN( value ) ) { + + console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i$1, value ); + valid = false; + break; + + } + + } + + } + + } + + return valid; + + }, + + // removes equivalent sequential keys as common in morph target sequences + // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0) + optimize: function () { + + // times or values may be shared with other tracks, so overwriting is unsafe + var times = AnimationUtils.arraySlice( this.times ), + values = AnimationUtils.arraySlice( this.values ), + stride = this.getValueSize(), + + smoothInterpolation = this.getInterpolation() === InterpolateSmooth, + + lastIndex = times.length - 1; + + var writeIndex = 1; + + for ( var i = 1; i < lastIndex; ++ i ) { + + var keep = false; + + var time = times[ i ]; + var timeNext = times[ i + 1 ]; + + // remove adjacent keyframes scheduled at the same time + + if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) { + + if ( ! smoothInterpolation ) { + + // remove unnecessary keyframes same as their neighbors + + var offset = i * stride, + offsetP = offset - stride, + offsetN = offset + stride; + + for ( var j = 0; j !== stride; ++ j ) { + + var value = values[ offset + j ]; + + if ( value !== values[ offsetP + j ] || + value !== values[ offsetN + j ] ) { + + keep = true; + break; + + } + + } + + } else { + + keep = true; + + } + + } + + // in-place compaction + + if ( keep ) { + + if ( i !== writeIndex ) { + + times[ writeIndex ] = times[ i ]; + + var readOffset = i * stride, + writeOffset = writeIndex * stride; + + for ( var j$1 = 0; j$1 !== stride; ++ j$1 ) { + + values[ writeOffset + j$1 ] = values[ readOffset + j$1 ]; + + } + + } + + ++ writeIndex; + + } + + } + + // flush last keyframe (compaction looks ahead) + + if ( lastIndex > 0 ) { + + times[ writeIndex ] = times[ lastIndex ]; + + for ( var readOffset$1 = lastIndex * stride, writeOffset$1 = writeIndex * stride, j$2 = 0; j$2 !== stride; ++ j$2 ) { + + values[ writeOffset$1 + j$2 ] = values[ readOffset$1 + j$2 ]; + + } + + ++ writeIndex; + + } + + if ( writeIndex !== times.length ) { + + this.times = AnimationUtils.arraySlice( times, 0, writeIndex ); + this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride ); + + } else { + + this.times = times; + this.values = values; + + } + + return this; + + }, + + clone: function () { + + var times = AnimationUtils.arraySlice( this.times, 0 ); + var values = AnimationUtils.arraySlice( this.values, 0 ); + + var TypedKeyframeTrack = this.constructor; + var track = new TypedKeyframeTrack( this.name, times, values ); + + // Interpolant argument to constructor is not saved, so copy the factory method directly. + track.createInterpolant = this.createInterpolant; + + return track; + + } + + } ); + + /** + * A Track of Boolean keyframe values. + */ + + function BooleanKeyframeTrack( name, times, values ) { + + KeyframeTrack.call( this, name, times, values ); + + } + + BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), { + + constructor: BooleanKeyframeTrack, + + ValueTypeName: 'bool', + ValueBufferType: Array, + + DefaultInterpolation: InterpolateDiscrete, + + InterpolantFactoryMethodLinear: undefined, + InterpolantFactoryMethodSmooth: undefined + + // Note: Actually this track could have a optimized / compressed + // representation of a single value and a custom interpolant that + // computes "firstValue ^ isOdd( index )". + + } ); + + /** + * A Track of keyframe values that represent color. + */ + + function ColorKeyframeTrack( name, times, values, interpolation ) { + + KeyframeTrack.call( this, name, times, values, interpolation ); + + } + + ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), { + + constructor: ColorKeyframeTrack, + + ValueTypeName: 'color' + + // ValueBufferType is inherited + + // DefaultInterpolation is inherited + + // Note: Very basic implementation and nothing special yet. + // However, this is the place for color space parameterization. + + } ); + + /** + * A Track of numeric keyframe values. + */ + + function NumberKeyframeTrack( name, times, values, interpolation ) { + + KeyframeTrack.call( this, name, times, values, interpolation ); + + } + + NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), { + + constructor: NumberKeyframeTrack, + + ValueTypeName: 'number' + + // ValueBufferType is inherited + + // DefaultInterpolation is inherited + + } ); + + /** + * Spherical linear unit quaternion interpolant. + */ + + function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) { + + Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer ); + + } + + QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), { + + constructor: QuaternionLinearInterpolant, + + interpolate_: function ( i1, t0, t, t1 ) { + + var result = this.resultBuffer, + values = this.sampleValues, + stride = this.valueSize, + + alpha = ( t - t0 ) / ( t1 - t0 ); + + var offset = i1 * stride; + + for ( var end = offset + stride; offset !== end; offset += 4 ) { + + Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha ); + + } + + return result; + + } + + } ); + + /** + * A Track of quaternion keyframe values. + */ + + function QuaternionKeyframeTrack( name, times, values, interpolation ) { + + KeyframeTrack.call( this, name, times, values, interpolation ); + + } + + QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), { + + constructor: QuaternionKeyframeTrack, + + ValueTypeName: 'quaternion', + + // ValueBufferType is inherited + + DefaultInterpolation: InterpolateLinear, + + InterpolantFactoryMethodLinear: function ( result ) { + + return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result ); + + }, + + InterpolantFactoryMethodSmooth: undefined // not yet implemented + + } ); + + /** + * A Track that interpolates Strings + */ + + function StringKeyframeTrack( name, times, values, interpolation ) { + + KeyframeTrack.call( this, name, times, values, interpolation ); + + } + + StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), { + + constructor: StringKeyframeTrack, + + ValueTypeName: 'string', + ValueBufferType: Array, + + DefaultInterpolation: InterpolateDiscrete, + + InterpolantFactoryMethodLinear: undefined, + + InterpolantFactoryMethodSmooth: undefined + + } ); + + /** + * A Track of vectored keyframe values. + */ + + function VectorKeyframeTrack( name, times, values, interpolation ) { + + KeyframeTrack.call( this, name, times, values, interpolation ); + + } + + VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), { + + constructor: VectorKeyframeTrack, + + ValueTypeName: 'vector' + + // ValueBufferType is inherited + + // DefaultInterpolation is inherited + + } ); + + function AnimationClip( name, duration, tracks, blendMode ) { + + this.name = name; + this.tracks = tracks; + this.duration = ( duration !== undefined ) ? duration : - 1; + this.blendMode = ( blendMode !== undefined ) ? blendMode : NormalAnimationBlendMode; + + this.uuid = MathUtils.generateUUID(); + + // this means it should figure out its duration by scanning the tracks + if ( this.duration < 0 ) { + + this.resetDuration(); + + } + + } + + function getTrackTypeForValueTypeName( typeName ) { + + switch ( typeName.toLowerCase() ) { + + case 'scalar': + case 'double': + case 'float': + case 'number': + case 'integer': + + return NumberKeyframeTrack; + + case 'vector': + case 'vector2': + case 'vector3': + case 'vector4': + + return VectorKeyframeTrack; + + case 'color': + + return ColorKeyframeTrack; + + case 'quaternion': + + return QuaternionKeyframeTrack; + + case 'bool': + case 'boolean': + + return BooleanKeyframeTrack; + + case 'string': + + return StringKeyframeTrack; + + } + + throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName ); + + } + + function parseKeyframeTrack( json ) { + + if ( json.type === undefined ) { + + throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' ); + + } + + var trackType = getTrackTypeForValueTypeName( json.type ); + + if ( json.times === undefined ) { + + var times = [], values = []; + + AnimationUtils.flattenJSON( json.keys, times, values, 'value' ); + + json.times = times; + json.values = values; + + } + + // derived classes can define a static parse method + if ( trackType.parse !== undefined ) { + + return trackType.parse( json ); + + } else { + + // by default, we assume a constructor compatible with the base + return new trackType( json.name, json.times, json.values, json.interpolation ); + + } + + } + + Object.assign( AnimationClip, { + + parse: function ( json ) { + + var tracks = [], + jsonTracks = json.tracks, + frameTime = 1.0 / ( json.fps || 1.0 ); + + for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) { + + tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) ); + + } + + return new AnimationClip( json.name, json.duration, tracks, json.blendMode ); + + }, + + toJSON: function ( clip ) { + + var tracks = [], + clipTracks = clip.tracks; + + var json = { + + 'name': clip.name, + 'duration': clip.duration, + 'tracks': tracks, + 'uuid': clip.uuid, + 'blendMode': clip.blendMode + + }; + + for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) { + + tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) ); + + } + + return json; + + }, + + CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) { + + var numMorphTargets = morphTargetSequence.length; + var tracks = []; + + for ( var i = 0; i < numMorphTargets; i ++ ) { + + var times = []; + var values = []; + + times.push( + ( i + numMorphTargets - 1 ) % numMorphTargets, + i, + ( i + 1 ) % numMorphTargets ); + + values.push( 0, 1, 0 ); + + var order = AnimationUtils.getKeyframeOrder( times ); + times = AnimationUtils.sortedArray( times, 1, order ); + values = AnimationUtils.sortedArray( values, 1, order ); + + // if there is a key at the first frame, duplicate it as the + // last frame as well for perfect loop. + if ( ! noLoop && times[ 0 ] === 0 ) { + + times.push( numMorphTargets ); + values.push( values[ 0 ] ); + + } + + tracks.push( + new NumberKeyframeTrack( + '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']', + times, values + ).scale( 1.0 / fps ) ); + + } + + return new AnimationClip( name, - 1, tracks ); + + }, + + findByName: function ( objectOrClipArray, name ) { + + var clipArray = objectOrClipArray; + + if ( ! Array.isArray( objectOrClipArray ) ) { + + var o = objectOrClipArray; + clipArray = o.geometry && o.geometry.animations || o.animations; + + } + + for ( var i = 0; i < clipArray.length; i ++ ) { + + if ( clipArray[ i ].name === name ) { + + return clipArray[ i ]; + + } + + } + + return null; + + }, + + CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) { + + var animationToMorphTargets = {}; + + // tested with https://regex101.com/ on trick sequences + // such flamingo_flyA_003, flamingo_run1_003, crdeath0059 + var pattern = /^([\w-]*?)([\d]+)$/; + + // sort morph target names into animation groups based + // patterns like Walk_001, Walk_002, Run_001, Run_002 + for ( var i = 0, il = morphTargets.length; i < il; i ++ ) { + + var morphTarget = morphTargets[ i ]; + var parts = morphTarget.name.match( pattern ); + + if ( parts && parts.length > 1 ) { + + var name = parts[ 1 ]; + + var animationMorphTargets = animationToMorphTargets[ name ]; + + if ( ! animationMorphTargets ) { + + animationToMorphTargets[ name ] = animationMorphTargets = []; + + } + + animationMorphTargets.push( morphTarget ); + + } + + } + + var clips = []; + + for ( var name$1 in animationToMorphTargets ) { + + clips.push( AnimationClip.CreateFromMorphTargetSequence( name$1, animationToMorphTargets[ name$1 ], fps, noLoop ) ); + + } + + return clips; + + }, + + // parse the animation.hierarchy format + parseAnimation: function ( animation, bones ) { + + if ( ! animation ) { + + console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' ); + return null; + + } + + var addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) { + + // only return track if there are actually keys. + if ( animationKeys.length !== 0 ) { + + var times = []; + var values = []; + + AnimationUtils.flattenJSON( animationKeys, times, values, propertyName ); + + // empty keys are filtered out, so check again + if ( times.length !== 0 ) { + + destTracks.push( new trackType( trackName, times, values ) ); + + } + + } + + }; + + var tracks = []; + + var clipName = animation.name || 'default'; + var fps = animation.fps || 30; + var blendMode = animation.blendMode; + + // automatic length determination in AnimationClip. + var duration = animation.length || - 1; + + var hierarchyTracks = animation.hierarchy || []; + + for ( var h = 0; h < hierarchyTracks.length; h ++ ) { + + var animationKeys = hierarchyTracks[ h ].keys; + + // skip empty tracks + if ( ! animationKeys || animationKeys.length === 0 ) { continue; } + + // process morph targets + if ( animationKeys[ 0 ].morphTargets ) { + + // figure out all morph targets used in this track + var morphTargetNames = {}; + + var k = (void 0); + + for ( k = 0; k < animationKeys.length; k ++ ) { + + if ( animationKeys[ k ].morphTargets ) { + + for ( var m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) { + + morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1; + + } + + } + + } + + // create a track for each morph target with all zero + // morphTargetInfluences except for the keys in which + // the morphTarget is named. + for ( var morphTargetName in morphTargetNames ) { + + var times = []; + var values = []; + + for ( var m$1 = 0; m$1 !== animationKeys[ k ].morphTargets.length; ++ m$1 ) { + + var animationKey = animationKeys[ k ]; + + times.push( animationKey.time ); + values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 ); + + } + + tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) ); + + } + + duration = morphTargetNames.length * ( fps || 1.0 ); + + } else { + + // ...assume skeletal animation + + var boneName = '.bones[' + bones[ h ].name + ']'; + + addNonemptyTrack( + VectorKeyframeTrack, boneName + '.position', + animationKeys, 'pos', tracks ); + + addNonemptyTrack( + QuaternionKeyframeTrack, boneName + '.quaternion', + animationKeys, 'rot', tracks ); + + addNonemptyTrack( + VectorKeyframeTrack, boneName + '.scale', + animationKeys, 'scl', tracks ); + + } + + } + + if ( tracks.length === 0 ) { + + return null; + + } + + var clip = new AnimationClip( clipName, duration, tracks, blendMode ); + + return clip; + + } + + } ); + + Object.assign( AnimationClip.prototype, { + + resetDuration: function () { + + var tracks = this.tracks; + var duration = 0; + + for ( var i = 0, n = tracks.length; i !== n; ++ i ) { + + var track = this.tracks[ i ]; + + duration = Math.max( duration, track.times[ track.times.length - 1 ] ); + + } + + this.duration = duration; + + return this; + + }, + + trim: function () { + + for ( var i = 0; i < this.tracks.length; i ++ ) { + + this.tracks[ i ].trim( 0, this.duration ); + + } + + return this; + + }, + + validate: function () { + + var valid = true; + + for ( var i = 0; i < this.tracks.length; i ++ ) { + + valid = valid && this.tracks[ i ].validate(); + + } + + return valid; + + }, + + optimize: function () { + + for ( var i = 0; i < this.tracks.length; i ++ ) { + + this.tracks[ i ].optimize(); + + } + + return this; + + }, + + clone: function () { + + var tracks = []; + + for ( var i = 0; i < this.tracks.length; i ++ ) { + + tracks.push( this.tracks[ i ].clone() ); + + } + + return new AnimationClip( this.name, this.duration, tracks, this.blendMode ); + + } + + } ); + + var Cache = { + + enabled: false, + + files: {}, + + add: function ( key, file ) { + + if ( this.enabled === false ) { return; } + + // console.log( 'THREE.Cache', 'Adding key:', key ); + + this.files[ key ] = file; + + }, + + get: function ( key ) { + + if ( this.enabled === false ) { return; } + + // console.log( 'THREE.Cache', 'Checking key:', key ); + + return this.files[ key ]; + + }, + + remove: function ( key ) { + + delete this.files[ key ]; + + }, + + clear: function () { + + this.files = {}; + + } + + }; + + function LoadingManager( onLoad, onProgress, onError ) { + + var scope = this; + + var isLoading = false; + var itemsLoaded = 0; + var itemsTotal = 0; + var urlModifier = undefined; + var handlers = []; + + // Refer to #5689 for the reason why we don't set .onStart + // in the constructor + + this.onStart = undefined; + this.onLoad = onLoad; + this.onProgress = onProgress; + this.onError = onError; + + this.itemStart = function ( url ) { + + itemsTotal ++; + + if ( isLoading === false ) { + + if ( scope.onStart !== undefined ) { + + scope.onStart( url, itemsLoaded, itemsTotal ); + + } + + } + + isLoading = true; + + }; + + this.itemEnd = function ( url ) { + + itemsLoaded ++; + + if ( scope.onProgress !== undefined ) { + + scope.onProgress( url, itemsLoaded, itemsTotal ); + + } + + if ( itemsLoaded === itemsTotal ) { + + isLoading = false; + + if ( scope.onLoad !== undefined ) { + + scope.onLoad(); + + } + + } + + }; + + this.itemError = function ( url ) { + + if ( scope.onError !== undefined ) { + + scope.onError( url ); + + } + + }; + + this.resolveURL = function ( url ) { + + if ( urlModifier ) { + + return urlModifier( url ); + + } + + return url; + + }; + + this.setURLModifier = function ( transform ) { + + urlModifier = transform; + + return this; + + }; + + this.addHandler = function ( regex, loader ) { + + handlers.push( regex, loader ); + + return this; + + }; + + this.removeHandler = function ( regex ) { + + var index = handlers.indexOf( regex ); + + if ( index !== - 1 ) { + + handlers.splice( index, 2 ); + + } + + return this; + + }; + + this.getHandler = function ( file ) { + + for ( var i = 0, l = handlers.length; i < l; i += 2 ) { + + var regex = handlers[ i ]; + var loader = handlers[ i + 1 ]; + + if ( regex.global ) { regex.lastIndex = 0; } // see #17920 + + if ( regex.test( file ) ) { + + return loader; + + } + + } + + return null; + + }; + + } + + var DefaultLoadingManager = new LoadingManager(); + + function Loader( manager ) { + + this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager; + + this.crossOrigin = 'anonymous'; + this.path = ''; + this.resourcePath = ''; + this.requestHeader = {}; + + } + + Object.assign( Loader.prototype, { + + load: function ( /* url, onLoad, onProgress, onError */ ) {}, + + loadAsync: function ( url, onProgress ) { + + var scope = this; + + return new Promise( function ( resolve, reject ) { + + scope.load( url, resolve, onProgress, reject ); + + } ); + + }, + + parse: function ( /* data */ ) {}, + + setCrossOrigin: function ( crossOrigin ) { + + this.crossOrigin = crossOrigin; + return this; + + }, + + setPath: function ( path ) { + + this.path = path; + return this; + + }, + + setResourcePath: function ( resourcePath ) { + + this.resourcePath = resourcePath; + return this; + + }, + + setRequestHeader: function ( requestHeader ) { + + this.requestHeader = requestHeader; + return this; + + } + + } ); + + var loading = {}; + + function FileLoader( manager ) { + + Loader.call( this, manager ); + + } + + FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: FileLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + if ( url === undefined ) { url = ''; } + + if ( this.path !== undefined ) { url = this.path + url; } + + url = this.manager.resolveURL( url ); + + var scope = this; + + var cached = Cache.get( url ); + + if ( cached !== undefined ) { + + scope.manager.itemStart( url ); + + setTimeout( function () { + + if ( onLoad ) { onLoad( cached ); } + + scope.manager.itemEnd( url ); + + }, 0 ); + + return cached; + + } + + // Check if request is duplicate + + if ( loading[ url ] !== undefined ) { + + loading[ url ].push( { + + onLoad: onLoad, + onProgress: onProgress, + onError: onError + + } ); + + return; + + } + + // Check for data: URI + var dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/; + var dataUriRegexResult = url.match( dataUriRegex ); + var request; + + // Safari can not handle Data URIs through XMLHttpRequest so process manually + if ( dataUriRegexResult ) { + + var mimeType = dataUriRegexResult[ 1 ]; + var isBase64 = !! dataUriRegexResult[ 2 ]; + + var data = dataUriRegexResult[ 3 ]; + data = decodeURIComponent( data ); + + if ( isBase64 ) { data = atob( data ); } + + try { + + var response; + var responseType = ( this.responseType || '' ).toLowerCase(); + + switch ( responseType ) { + + case 'arraybuffer': + case 'blob': + + var view = new Uint8Array( data.length ); + + for ( var i = 0; i < data.length; i ++ ) { + + view[ i ] = data.charCodeAt( i ); + + } + + if ( responseType === 'blob' ) { + + response = new Blob( [ view.buffer ], { type: mimeType } ); + + } else { + + response = view.buffer; + + } + + break; + + case 'document': + + var parser = new DOMParser(); + response = parser.parseFromString( data, mimeType ); + + break; + + case 'json': + + response = JSON.parse( data ); + + break; + + default: // 'text' or other + + response = data; + + break; + + } + + // Wait for next browser tick like standard XMLHttpRequest event dispatching does + setTimeout( function () { + + if ( onLoad ) { onLoad( response ); } + + scope.manager.itemEnd( url ); + + }, 0 ); + + } catch ( error ) { + + // Wait for next browser tick like standard XMLHttpRequest event dispatching does + setTimeout( function () { + + if ( onError ) { onError( error ); } + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + }, 0 ); + + } + + } else { + + // Initialise array for duplicate requests + + loading[ url ] = []; + + loading[ url ].push( { + + onLoad: onLoad, + onProgress: onProgress, + onError: onError + + } ); + + request = new XMLHttpRequest(); + + request.open( 'GET', url, true ); + + request.addEventListener( 'load', function ( event ) { + + var response = this.response; + + var callbacks = loading[ url ]; + + delete loading[ url ]; + + if ( this.status === 200 || this.status === 0 ) { + + // Some browsers return HTTP Status 0 when using non-http protocol + // e.g. 'file://' or 'data://'. Handle as success. + + 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 + // error response bodies as proper responses to requests. + Cache.add( url, response ); + + for ( var i = 0, il = callbacks.length; i < il; i ++ ) { + + var callback = callbacks[ i ]; + if ( callback.onLoad ) { callback.onLoad( response ); } + + } + + scope.manager.itemEnd( url ); + + } else { + + for ( var i$1 = 0, il$1 = callbacks.length; i$1 < il$1; i$1 ++ ) { + + var callback$1 = callbacks[ i$1 ]; + if ( callback$1.onError ) { callback$1.onError( event ); } + + } + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + } + + }, false ); + + request.addEventListener( 'progress', function ( event ) { + + var callbacks = loading[ url ]; + + for ( var i = 0, il = callbacks.length; i < il; i ++ ) { + + var callback = callbacks[ i ]; + if ( callback.onProgress ) { callback.onProgress( event ); } + + } + + }, false ); + + request.addEventListener( 'error', function ( event ) { + + var callbacks = loading[ url ]; + + delete loading[ url ]; + + for ( var i = 0, il = callbacks.length; i < il; i ++ ) { + + var callback = callbacks[ i ]; + if ( callback.onError ) { callback.onError( event ); } + + } + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + }, false ); + + request.addEventListener( 'abort', function ( event ) { + + var callbacks = loading[ url ]; + + delete loading[ url ]; + + for ( var i = 0, il = callbacks.length; i < il; i ++ ) { + + var callback = callbacks[ i ]; + if ( callback.onError ) { callback.onError( event ); } + + } + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + }, false ); + + if ( this.responseType !== undefined ) { request.responseType = this.responseType; } + if ( this.withCredentials !== undefined ) { request.withCredentials = this.withCredentials; } + + if ( request.overrideMimeType ) { request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' ); } + + for ( var header in this.requestHeader ) { + + request.setRequestHeader( header, this.requestHeader[ header ] ); + + } + + request.send( null ); + + } + + scope.manager.itemStart( url ); + + return request; + + }, + + setResponseType: function ( value ) { + + this.responseType = value; + return this; + + }, + + setWithCredentials: function ( value ) { + + this.withCredentials = value; + return this; + + }, + + setMimeType: function ( value ) { + + this.mimeType = value; + return this; + + } + + } ); + + function AnimationLoader( manager ) { + + Loader.call( this, manager ); + + } + + AnimationLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: AnimationLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + var scope = this; + + var loader = new FileLoader( scope.manager ); + loader.setPath( scope.path ); + loader.setRequestHeader( scope.requestHeader ); + loader.load( url, function ( text ) { + + try { + + onLoad( scope.parse( JSON.parse( text ) ) ); + + } catch ( e ) { + + if ( onError ) { + + onError( e ); + + } else { + + console.error( e ); + + } + + scope.manager.itemError( url ); + + } + + }, onProgress, onError ); + + }, + + parse: function ( json ) { + + var animations = []; + + for ( var i = 0; i < json.length; i ++ ) { + + var clip = AnimationClip.parse( json[ i ] ); + + animations.push( clip ); + + } + + return animations; + + } + + } ); + + /** + * Abstract Base class to block based textures loader (dds, pvr, ...) + * + * Sub classes have to implement the parse() method which will be used in load(). + */ + + function CompressedTextureLoader( manager ) { + + Loader.call( this, manager ); + + } + + CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: CompressedTextureLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + var scope = this; + + var images = []; + + var texture = new CompressedTexture(); + texture.image = images; + + var loader = new FileLoader( this.manager ); + loader.setPath( this.path ); + loader.setResponseType( 'arraybuffer' ); + loader.setRequestHeader( this.requestHeader ); + + var loaded = 0; + + function loadTexture( i ) { + + loader.load( url[ i ], function ( buffer ) { + + var texDatas = scope.parse( buffer, true ); + + images[ i ] = { + width: texDatas.width, + height: texDatas.height, + format: texDatas.format, + mipmaps: texDatas.mipmaps + }; + + loaded += 1; + + if ( loaded === 6 ) { + + if ( texDatas.mipmapCount === 1 ) + { texture.minFilter = LinearFilter; } + + texture.format = texDatas.format; + texture.needsUpdate = true; + + if ( onLoad ) { onLoad( texture ); } + + } + + }, onProgress, onError ); + + } + + if ( Array.isArray( url ) ) { + + for ( var i = 0, il = url.length; i < il; ++ i ) { + + loadTexture( i ); + + } + + } else { + + // compressed cubemap texture stored in a single DDS file + + loader.load( url, function ( buffer ) { + + var texDatas = scope.parse( buffer, true ); + + if ( texDatas.isCubemap ) { + + var faces = texDatas.mipmaps.length / texDatas.mipmapCount; + + for ( var f = 0; f < faces; f ++ ) { + + images[ f ] = { mipmaps: [] }; + + for ( var i = 0; i < texDatas.mipmapCount; i ++ ) { + + images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] ); + images[ f ].format = texDatas.format; + images[ f ].width = texDatas.width; + images[ f ].height = texDatas.height; + + } + + } + + } else { + + texture.image.width = texDatas.width; + texture.image.height = texDatas.height; + texture.mipmaps = texDatas.mipmaps; + + } + + if ( texDatas.mipmapCount === 1 ) { + + texture.minFilter = LinearFilter; + + } + + texture.format = texDatas.format; + texture.needsUpdate = true; + + if ( onLoad ) { onLoad( texture ); } + + }, onProgress, onError ); + + } + + return texture; + + } + + } ); + + /** + * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...) + * + * Sub classes have to implement the parse() method which will be used in load(). + */ + + function DataTextureLoader( manager ) { + + Loader.call( this, manager ); + + } + + DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: DataTextureLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + var scope = this; + + var texture = new DataTexture(); + + var loader = new FileLoader( this.manager ); + loader.setResponseType( 'arraybuffer' ); + loader.setRequestHeader( this.requestHeader ); + loader.setPath( this.path ); + loader.load( url, function ( buffer ) { + + var texData = scope.parse( buffer ); + + if ( ! texData ) { return; } + + if ( texData.image !== undefined ) { + + texture.image = texData.image; + + } else if ( texData.data !== undefined ) { + + texture.image.width = texData.width; + texture.image.height = texData.height; + texture.image.data = texData.data; + + } + + texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping; + texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping; + + texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter; + texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter; + + texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1; + + if ( texData.format !== undefined ) { + + texture.format = texData.format; + + } + + if ( texData.type !== undefined ) { + + texture.type = texData.type; + + } + + if ( texData.mipmaps !== undefined ) { + + texture.mipmaps = texData.mipmaps; + texture.minFilter = LinearMipmapLinearFilter; // presumably... + + } + + if ( texData.mipmapCount === 1 ) { + + texture.minFilter = LinearFilter; + + } + + texture.needsUpdate = true; + + if ( onLoad ) { onLoad( texture, texData ); } + + }, onProgress, onError ); + + + return texture; + + } + + } ); + + function ImageLoader( manager ) { + + Loader.call( this, manager ); + + } + + ImageLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: ImageLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + if ( this.path !== undefined ) { url = this.path + url; } + + url = this.manager.resolveURL( url ); + + var scope = this; + + var cached = Cache.get( url ); + + if ( cached !== undefined ) { + + scope.manager.itemStart( url ); + + setTimeout( function () { + + if ( onLoad ) { onLoad( cached ); } + + scope.manager.itemEnd( url ); + + }, 0 ); + + return cached; + + } + + var image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' ); + + function onImageLoad() { + + image.removeEventListener( 'load', onImageLoad, false ); + image.removeEventListener( 'error', onImageError, false ); + + Cache.add( url, this ); + + if ( onLoad ) { onLoad( this ); } + + scope.manager.itemEnd( url ); + + } + + function onImageError( event ) { + + image.removeEventListener( 'load', onImageLoad, false ); + image.removeEventListener( 'error', onImageError, false ); + + if ( onError ) { onError( event ); } + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + } + + image.addEventListener( 'load', onImageLoad, false ); + image.addEventListener( 'error', onImageError, false ); + + if ( url.substr( 0, 5 ) !== 'data:' ) { + + if ( this.crossOrigin !== undefined ) { image.crossOrigin = this.crossOrigin; } + + } + + scope.manager.itemStart( url ); + + image.src = url; + + return image; + + } + + } ); + + function CubeTextureLoader( manager ) { + + Loader.call( this, manager ); + + } + + CubeTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: CubeTextureLoader, + + load: function ( urls, onLoad, onProgress, onError ) { + + var texture = new CubeTexture(); + + var loader = new ImageLoader( this.manager ); + loader.setCrossOrigin( this.crossOrigin ); + loader.setPath( this.path ); + + var loaded = 0; + + function loadTexture( i ) { + + loader.load( urls[ i ], function ( image ) { + + texture.images[ i ] = image; + + loaded ++; + + if ( loaded === 6 ) { + + texture.needsUpdate = true; + + if ( onLoad ) { onLoad( texture ); } + + } + + }, undefined, onError ); + + } + + for ( var i = 0; i < urls.length; ++ i ) { + + loadTexture( i ); + + } + + return texture; + + } + + } ); + + function TextureLoader( manager ) { + + Loader.call( this, manager ); + + } + + TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: TextureLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + var texture = new Texture(); + + var loader = new ImageLoader( this.manager ); + loader.setCrossOrigin( this.crossOrigin ); + loader.setPath( this.path ); + + loader.load( url, function ( image ) { + + texture.image = image; + + // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB. + var isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0; + + texture.format = isJPEG ? RGBFormat : RGBAFormat; + texture.needsUpdate = true; + + if ( onLoad !== undefined ) { + + onLoad( texture ); + + } + + }, onProgress, onError ); + + return texture; + + } + + } ); + + /** + * Extensible curve object. + * + * Some common of curve methods: + * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget ) + * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget ) + * .getPoints(), .getSpacedPoints() + * .getLength() + * .updateArcLengths() + * + * This following curves inherit from THREE.Curve: + * + * -- 2D curves -- + * THREE.ArcCurve + * THREE.CubicBezierCurve + * THREE.EllipseCurve + * THREE.LineCurve + * THREE.QuadraticBezierCurve + * THREE.SplineCurve + * + * -- 3D curves -- + * THREE.CatmullRomCurve3 + * THREE.CubicBezierCurve3 + * THREE.LineCurve3 + * THREE.QuadraticBezierCurve3 + * + * A series of curves can be represented as a THREE.CurvePath. + * + **/ + + function Curve() { + + this.type = 'Curve'; + + this.arcLengthDivisions = 200; + + } + + Object.assign( Curve.prototype, { + + // Virtual base class method to overwrite and implement in subclasses + // - t [0 .. 1] + + getPoint: function ( /* t, optionalTarget */ ) { + + console.warn( 'THREE.Curve: .getPoint() not implemented.' ); + return null; + + }, + + // Get point at relative position in curve according to arc length + // - u [0 .. 1] + + getPointAt: function ( u, optionalTarget ) { + + var t = this.getUtoTmapping( u ); + return this.getPoint( t, optionalTarget ); + + }, + + // Get sequence of points using getPoint( t ) + + getPoints: function ( divisions ) { + + if ( divisions === undefined ) { divisions = 5; } + + var points = []; + + for ( var d = 0; d <= divisions; d ++ ) { + + points.push( this.getPoint( d / divisions ) ); + + } + + return points; + + }, + + // Get sequence of points using getPointAt( u ) + + getSpacedPoints: function ( divisions ) { + + if ( divisions === undefined ) { divisions = 5; } + + var points = []; + + for ( var d = 0; d <= divisions; d ++ ) { + + points.push( this.getPointAt( d / divisions ) ); + + } + + return points; + + }, + + // Get total curve arc length + + getLength: function () { + + var lengths = this.getLengths(); + return lengths[ lengths.length - 1 ]; + + }, + + // Get list of cumulative segment lengths + + getLengths: function ( divisions ) { + + if ( divisions === undefined ) { divisions = this.arcLengthDivisions; } + + if ( this.cacheArcLengths && + ( this.cacheArcLengths.length === divisions + 1 ) && + ! this.needsUpdate ) { + + return this.cacheArcLengths; + + } + + this.needsUpdate = false; + + var cache = []; + var current, last = this.getPoint( 0 ); + var sum = 0; + + cache.push( 0 ); + + for ( var p = 1; p <= divisions; p ++ ) { + + current = this.getPoint( p / divisions ); + sum += current.distanceTo( last ); + cache.push( sum ); + last = current; + + } + + this.cacheArcLengths = cache; + + return cache; // { sums: cache, sum: sum }; Sum is in the last element. + + }, + + updateArcLengths: function () { + + this.needsUpdate = true; + this.getLengths(); + + }, + + // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant + + getUtoTmapping: function ( u, distance ) { + + var arcLengths = this.getLengths(); + + var i = 0, il = arcLengths.length; + + var targetArcLength; // The targeted u distance value to get + + if ( distance ) { + + targetArcLength = distance; + + } else { + + targetArcLength = u * arcLengths[ il - 1 ]; + + } + + // binary search for the index with largest value smaller than target u distance + + var low = 0, high = il - 1, comparison; + + while ( low <= high ) { + + 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 + + comparison = arcLengths[ i ] - targetArcLength; + + if ( comparison < 0 ) { + + low = i + 1; + + } else if ( comparison > 0 ) { + + high = i - 1; + + } else { + + high = i; + break; + + // DONE + + } + + } + + i = high; + + if ( arcLengths[ i ] === targetArcLength ) { + + return i / ( il - 1 ); + + } + + // we could get finer grain at lengths, or use simple interpolation between two points + + var lengthBefore = arcLengths[ i ]; + var lengthAfter = arcLengths[ i + 1 ]; + + var segmentLength = lengthAfter - lengthBefore; + + // determine where we are between the 'before' and 'after' points + + var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength; + + // add that fractional amount to t + + var t = ( i + segmentFraction ) / ( il - 1 ); + + return t; + + }, + + // Returns a unit vector tangent at t + // In case any sub curve does not implement its tangent derivation, + // 2 points a small delta apart will be used to find its gradient + // which seems to give a reasonable approximation + + getTangent: function ( t, optionalTarget ) { + + var delta = 0.0001; + var t1 = t - delta; + var t2 = t + delta; + + // Capping in case of danger + + if ( t1 < 0 ) { t1 = 0; } + if ( t2 > 1 ) { t2 = 1; } + + var pt1 = this.getPoint( t1 ); + var pt2 = this.getPoint( t2 ); + + var tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() ); + + tangent.copy( pt2 ).sub( pt1 ).normalize(); + + return tangent; + + }, + + getTangentAt: function ( u, optionalTarget ) { + + var t = this.getUtoTmapping( u ); + return this.getTangent( t, optionalTarget ); + + }, + + computeFrenetFrames: function ( segments, closed ) { + + // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf + + var normal = new Vector3(); + + var tangents = []; + var normals = []; + var binormals = []; + + var vec = new Vector3(); + var mat = new Matrix4(); + + // compute the tangent vectors for each segment on the curve + + for ( var i = 0; i <= segments; i ++ ) { + + var u = i / segments; + + tangents[ i ] = this.getTangentAt( u, new Vector3() ); + tangents[ i ].normalize(); + + } + + // select an initial normal vector perpendicular to the first tangent vector, + // and in the direction of the minimum tangent xyz component + + normals[ 0 ] = new Vector3(); + binormals[ 0 ] = new Vector3(); + var min = Number.MAX_VALUE; + var tx = Math.abs( tangents[ 0 ].x ); + var ty = Math.abs( tangents[ 0 ].y ); + var tz = Math.abs( tangents[ 0 ].z ); + + if ( tx <= min ) { + + min = tx; + normal.set( 1, 0, 0 ); + + } + + if ( ty <= min ) { + + min = ty; + normal.set( 0, 1, 0 ); + + } + + if ( tz <= min ) { + + normal.set( 0, 0, 1 ); + + } + + vec.crossVectors( tangents[ 0 ], normal ).normalize(); + + normals[ 0 ].crossVectors( tangents[ 0 ], vec ); + binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ); + + + // compute the slowly-varying normal and binormal vectors for each segment on the curve + + for ( var i$1 = 1; i$1 <= segments; i$1 ++ ) { + + normals[ i$1 ] = normals[ i$1 - 1 ].clone(); + + binormals[ i$1 ] = binormals[ i$1 - 1 ].clone(); + + vec.crossVectors( tangents[ i$1 - 1 ], tangents[ i$1 ] ); + + if ( vec.length() > Number.EPSILON ) { + + vec.normalize(); + + var theta = Math.acos( MathUtils.clamp( tangents[ i$1 - 1 ].dot( tangents[ i$1 ] ), - 1, 1 ) ); // clamp for floating pt errors + + normals[ i$1 ].applyMatrix4( mat.makeRotationAxis( vec, theta ) ); + + } + + binormals[ i$1 ].crossVectors( tangents[ i$1 ], normals[ i$1 ] ); + + } + + // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same + + if ( closed === true ) { + + var theta$1 = Math.acos( MathUtils.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) ); + theta$1 /= segments; + + if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) { + + theta$1 = - theta$1; + + } + + for ( var i$2 = 1; i$2 <= segments; i$2 ++ ) { + + // twist a little... + normals[ i$2 ].applyMatrix4( mat.makeRotationAxis( tangents[ i$2 ], theta$1 * i$2 ) ); + binormals[ i$2 ].crossVectors( tangents[ i$2 ], normals[ i$2 ] ); + + } + + } + + return { + tangents: tangents, + normals: normals, + binormals: binormals + }; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( source ) { + + this.arcLengthDivisions = source.arcLengthDivisions; + + return this; + + }, + + toJSON: function () { + + var data = { + metadata: { + version: 4.5, + type: 'Curve', + generator: 'Curve.toJSON' + } + }; + + data.arcLengthDivisions = this.arcLengthDivisions; + data.type = this.type; + + return data; + + }, + + fromJSON: function ( json ) { + + this.arcLengthDivisions = json.arcLengthDivisions; + + return this; + + } + + } ); + + function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) { + + Curve.call( this ); + + this.type = 'EllipseCurve'; + + this.aX = aX || 0; + this.aY = aY || 0; + + this.xRadius = xRadius || 1; + this.yRadius = yRadius || 1; + + this.aStartAngle = aStartAngle || 0; + this.aEndAngle = aEndAngle || 2 * Math.PI; + + this.aClockwise = aClockwise || false; + + this.aRotation = aRotation || 0; + + } + + EllipseCurve.prototype = Object.create( Curve.prototype ); + EllipseCurve.prototype.constructor = EllipseCurve; + + EllipseCurve.prototype.isEllipseCurve = true; + + EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) { + + var point = optionalTarget || new Vector2(); + + var twoPi = Math.PI * 2; + var deltaAngle = this.aEndAngle - this.aStartAngle; + var samePoints = Math.abs( deltaAngle ) < Number.EPSILON; + + // ensures that deltaAngle is 0 .. 2 PI + while ( deltaAngle < 0 ) { deltaAngle += twoPi; } + while ( deltaAngle > twoPi ) { deltaAngle -= twoPi; } + + if ( deltaAngle < Number.EPSILON ) { + + if ( samePoints ) { + + deltaAngle = 0; + + } else { + + deltaAngle = twoPi; + + } + + } + + if ( this.aClockwise === true && ! samePoints ) { + + if ( deltaAngle === twoPi ) { + + deltaAngle = - twoPi; + + } else { + + deltaAngle = deltaAngle - twoPi; + + } + + } + + var angle = this.aStartAngle + t * deltaAngle; + var x = this.aX + this.xRadius * Math.cos( angle ); + var y = this.aY + this.yRadius * Math.sin( angle ); + + if ( this.aRotation !== 0 ) { + + var cos = Math.cos( this.aRotation ); + var sin = Math.sin( this.aRotation ); + + var tx = x - this.aX; + var ty = y - this.aY; + + // Rotate the point about the center of the ellipse. + x = tx * cos - ty * sin + this.aX; + y = tx * sin + ty * cos + this.aY; + + } + + return point.set( x, y ); + + }; + + EllipseCurve.prototype.copy = function ( source ) { + + Curve.prototype.copy.call( this, source ); + + this.aX = source.aX; + this.aY = source.aY; + + this.xRadius = source.xRadius; + this.yRadius = source.yRadius; + + this.aStartAngle = source.aStartAngle; + this.aEndAngle = source.aEndAngle; + + this.aClockwise = source.aClockwise; + + this.aRotation = source.aRotation; + + return this; + + }; + + + EllipseCurve.prototype.toJSON = function () { + + var data = Curve.prototype.toJSON.call( this ); + + data.aX = this.aX; + data.aY = this.aY; + + data.xRadius = this.xRadius; + data.yRadius = this.yRadius; + + data.aStartAngle = this.aStartAngle; + data.aEndAngle = this.aEndAngle; + + data.aClockwise = this.aClockwise; + + data.aRotation = this.aRotation; + + return data; + + }; + + EllipseCurve.prototype.fromJSON = function ( json ) { + + Curve.prototype.fromJSON.call( this, json ); + + this.aX = json.aX; + this.aY = json.aY; + + this.xRadius = json.xRadius; + this.yRadius = json.yRadius; + + this.aStartAngle = json.aStartAngle; + this.aEndAngle = json.aEndAngle; + + this.aClockwise = json.aClockwise; + + this.aRotation = json.aRotation; + + return this; + + }; + + function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) { + + EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise ); + + this.type = 'ArcCurve'; + + } + + ArcCurve.prototype = Object.create( EllipseCurve.prototype ); + ArcCurve.prototype.constructor = ArcCurve; + + ArcCurve.prototype.isArcCurve = true; + + /** + * Centripetal CatmullRom Curve - which is useful for avoiding + * cusps and self-intersections in non-uniform catmull rom curves. + * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf + * + * curve.type accepts centripetal(default), chordal and catmullrom + * curve.tension is used for catmullrom which defaults to 0.5 + */ + + + /* + Based on an optimized c++ solution in + - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/ + - http://ideone.com/NoEbVM + + This CubicPoly class could be used for reusing some variables and calculations, + but for three.js curve use, it could be possible inlined and flatten into a single function call + which can be placed in CurveUtils. + */ + + function CubicPoly() { + + var c0 = 0, c1 = 0, c2 = 0, c3 = 0; + + /* + * Compute coefficients for a cubic polynomial + * p(s) = c0 + c1*s + c2*s^2 + c3*s^3 + * such that + * p(0) = x0, p(1) = x1 + * and + * p'(0) = t0, p'(1) = t1. + */ + function init( x0, x1, t0, t1 ) { + + c0 = x0; + c1 = t0; + c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1; + c3 = 2 * x0 - 2 * x1 + t0 + t1; + + } + + return { + + initCatmullRom: function ( x0, x1, x2, x3, tension ) { + + init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) ); + + }, + + initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) { + + // compute tangents when parameterized in [t1,t2] + var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1; + var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2; + + // rescale tangents for parametrization in [0,1] + t1 *= dt1; + t2 *= dt1; + + init( x1, x2, t1, t2 ); + + }, + + calc: function ( t ) { + + var t2 = t * t; + var t3 = t2 * t; + return c0 + c1 * t + c2 * t2 + c3 * t3; + + } + + }; + + } + + // + + var tmp = new Vector3(); + var px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly(); + + function CatmullRomCurve3( points, closed, curveType, tension ) { + + Curve.call( this ); + + this.type = 'CatmullRomCurve3'; + + this.points = points || []; + this.closed = closed || false; + this.curveType = curveType || 'centripetal'; + this.tension = ( tension !== undefined ) ? tension : 0.5; + + } + + CatmullRomCurve3.prototype = Object.create( Curve.prototype ); + CatmullRomCurve3.prototype.constructor = CatmullRomCurve3; + + CatmullRomCurve3.prototype.isCatmullRomCurve3 = true; + + CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) { + + var point = optionalTarget || new Vector3(); + + var points = this.points; + var l = points.length; + + var p = ( l - ( this.closed ? 0 : 1 ) ) * t; + var intPoint = Math.floor( p ); + var weight = p - intPoint; + + if ( this.closed ) { + + intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l; + + } else if ( weight === 0 && intPoint === l - 1 ) { + + intPoint = l - 2; + weight = 1; + + } + + var p0, p1, p2, p3; // 4 points + + if ( this.closed || intPoint > 0 ) { + + p0 = points[ ( intPoint - 1 ) % l ]; + + } else { + + // extrapolate first point + tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] ); + p0 = tmp; + + } + + p1 = points[ intPoint % l ]; + p2 = points[ ( intPoint + 1 ) % l ]; + + if ( this.closed || intPoint + 2 < l ) { + + p3 = points[ ( intPoint + 2 ) % l ]; + + } else { + + // extrapolate last point + tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] ); + p3 = tmp; + + } + + if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) { + + // init Centripetal / Chordal Catmull-Rom + var pow = this.curveType === 'chordal' ? 0.5 : 0.25; + var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow ); + var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow ); + var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow ); + + // safety check for repeated points + if ( dt1 < 1e-4 ) { dt1 = 1.0; } + if ( dt0 < 1e-4 ) { dt0 = dt1; } + if ( dt2 < 1e-4 ) { dt2 = dt1; } + + px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 ); + py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 ); + pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 ); + + } else if ( this.curveType === 'catmullrom' ) { + + px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension ); + py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension ); + pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension ); + + } + + point.set( + px.calc( weight ), + py.calc( weight ), + pz.calc( weight ) + ); + + return point; + + }; + + CatmullRomCurve3.prototype.copy = function ( source ) { + + Curve.prototype.copy.call( this, source ); + + this.points = []; + + for ( var i = 0, l = source.points.length; i < l; i ++ ) { + + var point = source.points[ i ]; + + this.points.push( point.clone() ); + + } + + this.closed = source.closed; + this.curveType = source.curveType; + this.tension = source.tension; + + return this; + + }; + + CatmullRomCurve3.prototype.toJSON = function () { + + var data = Curve.prototype.toJSON.call( this ); + + data.points = []; + + for ( var i = 0, l = this.points.length; i < l; i ++ ) { + + var point = this.points[ i ]; + data.points.push( point.toArray() ); + + } + + data.closed = this.closed; + data.curveType = this.curveType; + data.tension = this.tension; + + return data; + + }; + + CatmullRomCurve3.prototype.fromJSON = function ( json ) { + + Curve.prototype.fromJSON.call( this, json ); + + this.points = []; + + for ( var i = 0, l = json.points.length; i < l; i ++ ) { + + var point = json.points[ i ]; + this.points.push( new Vector3().fromArray( point ) ); + + } + + this.closed = json.closed; + this.curveType = json.curveType; + this.tension = json.tension; + + return this; + + }; + + /** + * Bezier Curves formulas obtained from + * http://en.wikipedia.org/wiki/Bézier_curve + */ + + function CatmullRom( t, p0, p1, p2, p3 ) { + + var v0 = ( p2 - p0 ) * 0.5; + var v1 = ( p3 - p1 ) * 0.5; + var t2 = t * t; + var t3 = t * t2; + return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1; + + } + + // + + function QuadraticBezierP0( t, p ) { + + var k = 1 - t; + return k * k * p; + + } + + function QuadraticBezierP1( t, p ) { + + return 2 * ( 1 - t ) * t * p; + + } + + function QuadraticBezierP2( t, p ) { + + return t * t * p; + + } + + function QuadraticBezier( t, p0, p1, p2 ) { + + return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) + + QuadraticBezierP2( t, p2 ); + + } + + // + + function CubicBezierP0( t, p ) { + + var k = 1 - t; + return k * k * k * p; + + } + + function CubicBezierP1( t, p ) { + + var k = 1 - t; + return 3 * k * k * t * p; + + } + + function CubicBezierP2( t, p ) { + + return 3 * ( 1 - t ) * t * t * p; + + } + + function CubicBezierP3( t, p ) { + + return t * t * t * p; + + } + + function CubicBezier( t, p0, p1, p2, p3 ) { + + return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) + + CubicBezierP3( t, p3 ); + + } + + function CubicBezierCurve( v0, v1, v2, v3 ) { + + Curve.call( this ); + + this.type = 'CubicBezierCurve'; + + this.v0 = v0 || new Vector2(); + this.v1 = v1 || new Vector2(); + this.v2 = v2 || new Vector2(); + this.v3 = v3 || new Vector2(); + + } + + CubicBezierCurve.prototype = Object.create( Curve.prototype ); + CubicBezierCurve.prototype.constructor = CubicBezierCurve; + + CubicBezierCurve.prototype.isCubicBezierCurve = true; + + CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget ) { + + var point = optionalTarget || new Vector2(); + + var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3; + + point.set( + CubicBezier( t, v0.x, v1.x, v2.x, v3.x ), + CubicBezier( t, v0.y, v1.y, v2.y, v3.y ) + ); + + return point; + + }; + + CubicBezierCurve.prototype.copy = function ( source ) { + + Curve.prototype.copy.call( this, source ); + + this.v0.copy( source.v0 ); + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + this.v3.copy( source.v3 ); + + return this; + + }; + + CubicBezierCurve.prototype.toJSON = function () { + + var data = Curve.prototype.toJSON.call( this ); + + data.v0 = this.v0.toArray(); + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + data.v3 = this.v3.toArray(); + + return data; + + }; + + CubicBezierCurve.prototype.fromJSON = function ( json ) { + + Curve.prototype.fromJSON.call( this, json ); + + this.v0.fromArray( json.v0 ); + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + this.v3.fromArray( json.v3 ); + + return this; + + }; + + function CubicBezierCurve3( v0, v1, v2, v3 ) { + + Curve.call( this ); + + this.type = 'CubicBezierCurve3'; + + this.v0 = v0 || new Vector3(); + this.v1 = v1 || new Vector3(); + this.v2 = v2 || new Vector3(); + this.v3 = v3 || new Vector3(); + + } + + CubicBezierCurve3.prototype = Object.create( Curve.prototype ); + CubicBezierCurve3.prototype.constructor = CubicBezierCurve3; + + CubicBezierCurve3.prototype.isCubicBezierCurve3 = true; + + CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) { + + var point = optionalTarget || new Vector3(); + + var v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3; + + 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 ) + ); + + return point; + + }; + + CubicBezierCurve3.prototype.copy = function ( source ) { + + Curve.prototype.copy.call( this, source ); + + this.v0.copy( source.v0 ); + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + this.v3.copy( source.v3 ); + + return this; + + }; + + CubicBezierCurve3.prototype.toJSON = function () { + + var data = Curve.prototype.toJSON.call( this ); + + data.v0 = this.v0.toArray(); + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + data.v3 = this.v3.toArray(); + + return data; + + }; + + CubicBezierCurve3.prototype.fromJSON = function ( json ) { + + Curve.prototype.fromJSON.call( this, json ); + + this.v0.fromArray( json.v0 ); + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + this.v3.fromArray( json.v3 ); + + return this; + + }; + + function LineCurve( v1, v2 ) { + + Curve.call( this ); + + this.type = 'LineCurve'; + + this.v1 = v1 || new Vector2(); + this.v2 = v2 || new Vector2(); + + } + + LineCurve.prototype = Object.create( Curve.prototype ); + LineCurve.prototype.constructor = LineCurve; + + LineCurve.prototype.isLineCurve = true; + + LineCurve.prototype.getPoint = function ( t, optionalTarget ) { + + var point = optionalTarget || new Vector2(); + + if ( t === 1 ) { + + point.copy( this.v2 ); + + } else { + + point.copy( this.v2 ).sub( this.v1 ); + point.multiplyScalar( t ).add( this.v1 ); + + } + + return point; + + }; + + // Line curve is linear, so we can overwrite default getPointAt + + LineCurve.prototype.getPointAt = function ( u, optionalTarget ) { + + return this.getPoint( u, optionalTarget ); + + }; + + LineCurve.prototype.getTangent = function ( t, optionalTarget ) { + + var tangent = optionalTarget || new Vector2(); + + tangent.copy( this.v2 ).sub( this.v1 ).normalize(); + + return tangent; + + }; + + LineCurve.prototype.copy = function ( source ) { + + Curve.prototype.copy.call( this, source ); + + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + + return this; + + }; + + LineCurve.prototype.toJSON = function () { + + var data = Curve.prototype.toJSON.call( this ); + + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + + return data; + + }; + + LineCurve.prototype.fromJSON = function ( json ) { + + Curve.prototype.fromJSON.call( this, json ); + + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + + return this; + + }; + + function LineCurve3( v1, v2 ) { + + Curve.call( this ); + + this.type = 'LineCurve3'; + + this.v1 = v1 || new Vector3(); + this.v2 = v2 || new Vector3(); + + } + + LineCurve3.prototype = Object.create( Curve.prototype ); + LineCurve3.prototype.constructor = LineCurve3; + + LineCurve3.prototype.isLineCurve3 = true; + + LineCurve3.prototype.getPoint = function ( t, optionalTarget ) { + + var point = optionalTarget || new Vector3(); + + if ( t === 1 ) { + + point.copy( this.v2 ); + + } else { + + point.copy( this.v2 ).sub( this.v1 ); + point.multiplyScalar( t ).add( this.v1 ); + + } + + return point; + + }; + + // Line curve is linear, so we can overwrite default getPointAt + + LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) { + + return this.getPoint( u, optionalTarget ); + + }; + + LineCurve3.prototype.copy = function ( source ) { + + Curve.prototype.copy.call( this, source ); + + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + + return this; + + }; + + LineCurve3.prototype.toJSON = function () { + + var data = Curve.prototype.toJSON.call( this ); + + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + + return data; + + }; + + LineCurve3.prototype.fromJSON = function ( json ) { + + Curve.prototype.fromJSON.call( this, json ); + + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + + return this; + + }; + + function QuadraticBezierCurve( v0, v1, v2 ) { + + Curve.call( this ); + + this.type = 'QuadraticBezierCurve'; + + this.v0 = v0 || new Vector2(); + this.v1 = v1 || new Vector2(); + this.v2 = v2 || new Vector2(); + + } + + QuadraticBezierCurve.prototype = Object.create( Curve.prototype ); + QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve; + + QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true; + + QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget ) { + + var point = optionalTarget || new Vector2(); + + var v0 = this.v0, v1 = this.v1, v2 = this.v2; + + point.set( + QuadraticBezier( t, v0.x, v1.x, v2.x ), + QuadraticBezier( t, v0.y, v1.y, v2.y ) + ); + + return point; + + }; + + QuadraticBezierCurve.prototype.copy = function ( source ) { + + Curve.prototype.copy.call( this, source ); + + this.v0.copy( source.v0 ); + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + + return this; + + }; + + QuadraticBezierCurve.prototype.toJSON = function () { + + var data = Curve.prototype.toJSON.call( this ); + + data.v0 = this.v0.toArray(); + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + + return data; + + }; + + QuadraticBezierCurve.prototype.fromJSON = function ( json ) { + + Curve.prototype.fromJSON.call( this, json ); + + this.v0.fromArray( json.v0 ); + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + + return this; + + }; + + function QuadraticBezierCurve3( v0, v1, v2 ) { + + Curve.call( this ); + + this.type = 'QuadraticBezierCurve3'; + + this.v0 = v0 || new Vector3(); + this.v1 = v1 || new Vector3(); + this.v2 = v2 || new Vector3(); + + } + + QuadraticBezierCurve3.prototype = Object.create( Curve.prototype ); + QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3; + + QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true; + + QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget ) { + + var point = optionalTarget || new Vector3(); + + var v0 = this.v0, v1 = this.v1, v2 = this.v2; + + 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 ) + ); + + return point; + + }; + + QuadraticBezierCurve3.prototype.copy = function ( source ) { + + Curve.prototype.copy.call( this, source ); + + this.v0.copy( source.v0 ); + this.v1.copy( source.v1 ); + this.v2.copy( source.v2 ); + + return this; + + }; + + QuadraticBezierCurve3.prototype.toJSON = function () { + + var data = Curve.prototype.toJSON.call( this ); + + data.v0 = this.v0.toArray(); + data.v1 = this.v1.toArray(); + data.v2 = this.v2.toArray(); + + return data; + + }; + + QuadraticBezierCurve3.prototype.fromJSON = function ( json ) { + + Curve.prototype.fromJSON.call( this, json ); + + this.v0.fromArray( json.v0 ); + this.v1.fromArray( json.v1 ); + this.v2.fromArray( json.v2 ); + + return this; + + }; + + function SplineCurve( points ) { + + Curve.call( this ); + + this.type = 'SplineCurve'; + + this.points = points || []; + + } + + SplineCurve.prototype = Object.create( Curve.prototype ); + SplineCurve.prototype.constructor = SplineCurve; + + SplineCurve.prototype.isSplineCurve = true; + + SplineCurve.prototype.getPoint = function ( t, optionalTarget ) { + + var point = optionalTarget || new Vector2(); + + var points = this.points; + var p = ( points.length - 1 ) * t; + + var intPoint = Math.floor( p ); + var weight = p - intPoint; + + var p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ]; + var p1 = points[ intPoint ]; + var p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ]; + var p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ]; + + point.set( + CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ), + CatmullRom( weight, p0.y, p1.y, p2.y, p3.y ) + ); + + return point; + + }; + + SplineCurve.prototype.copy = function ( source ) { + + Curve.prototype.copy.call( this, source ); + + this.points = []; + + for ( var i = 0, l = source.points.length; i < l; i ++ ) { + + var point = source.points[ i ]; + + this.points.push( point.clone() ); + + } + + return this; + + }; + + SplineCurve.prototype.toJSON = function () { + + var data = Curve.prototype.toJSON.call( this ); + + data.points = []; + + for ( var i = 0, l = this.points.length; i < l; i ++ ) { + + var point = this.points[ i ]; + data.points.push( point.toArray() ); + + } + + return data; + + }; + + SplineCurve.prototype.fromJSON = function ( json ) { + + Curve.prototype.fromJSON.call( this, json ); + + this.points = []; + + for ( var i = 0, l = json.points.length; i < l; i ++ ) { + + var point = json.points[ i ]; + this.points.push( new Vector2().fromArray( point ) ); + + } + + return this; + + }; + + var Curves = /*#__PURE__*/Object.freeze({ + __proto__: null, + ArcCurve: ArcCurve, + CatmullRomCurve3: CatmullRomCurve3, + CubicBezierCurve: CubicBezierCurve, + CubicBezierCurve3: CubicBezierCurve3, + EllipseCurve: EllipseCurve, + LineCurve: LineCurve, + LineCurve3: LineCurve3, + QuadraticBezierCurve: QuadraticBezierCurve, + QuadraticBezierCurve3: QuadraticBezierCurve3, + SplineCurve: SplineCurve + }); + + /************************************************************** + * Curved Path - a curve path is simply a array of connected + * curves, but retains the api of a curve + **************************************************************/ + + function CurvePath() { + + Curve.call( this ); + + this.type = 'CurvePath'; + + this.curves = []; + this.autoClose = false; // Automatically closes the path + + } + + CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), { + + constructor: CurvePath, + + add: function ( curve ) { + + this.curves.push( curve ); + + }, + + closePath: function () { + + // Add a line curve if start and end of lines are not connected + var startPoint = this.curves[ 0 ].getPoint( 0 ); + var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 ); + + if ( ! startPoint.equals( endPoint ) ) { + + this.curves.push( new LineCurve( endPoint, startPoint ) ); + + } + + }, + + // To get accurate point with reference to + // entire path distance at time t, + // following has to be done: + + // 1. Length of each sub path have to be known + // 2. Locate and identify type of curve + // 3. Get t for the curve + // 4. Return curve.getPointAt(t') + + getPoint: function ( t ) { + + var d = t * this.getLength(); + var curveLengths = this.getCurveLengths(); + var i = 0; + + // To think about boundaries points. + + while ( i < curveLengths.length ) { + + if ( curveLengths[ i ] >= d ) { + + var diff = curveLengths[ i ] - d; + var curve = this.curves[ i ]; + + var segmentLength = curve.getLength(); + var u = segmentLength === 0 ? 0 : 1 - diff / segmentLength; + + return curve.getPointAt( u ); + + } + + i ++; + + } + + return null; + + // loop where sum != 0, sum > d , sum+1 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) { + + points.push( points[ 0 ] ); + + } + + return points; + + }, + + copy: function ( source ) { + + Curve.prototype.copy.call( this, source ); + + this.curves = []; + + for ( var i = 0, l = source.curves.length; i < l; i ++ ) { + + var curve = source.curves[ i ]; + + this.curves.push( curve.clone() ); + + } + + this.autoClose = source.autoClose; + + return this; + + }, + + toJSON: function () { + + var data = Curve.prototype.toJSON.call( this ); + + data.autoClose = this.autoClose; + data.curves = []; + + for ( var i = 0, l = this.curves.length; i < l; i ++ ) { + + var curve = this.curves[ i ]; + data.curves.push( curve.toJSON() ); + + } + + return data; + + }, + + fromJSON: function ( json ) { + + Curve.prototype.fromJSON.call( this, json ); + + this.autoClose = json.autoClose; + this.curves = []; + + for ( var i = 0, l = json.curves.length; i < l; i ++ ) { + + var curve = json.curves[ i ]; + this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) ); + + } + + return this; + + } + + } ); + + function Path( points ) { + + CurvePath.call( this ); + + this.type = 'Path'; + + this.currentPoint = new Vector2(); + + if ( points ) { + + this.setFromPoints( points ); + + } + + } + + Path.prototype = Object.assign( Object.create( CurvePath.prototype ), { + + constructor: Path, + + setFromPoints: function ( points ) { + + this.moveTo( points[ 0 ].x, points[ 0 ].y ); + + for ( var i = 1, l = points.length; i < l; i ++ ) { + + this.lineTo( points[ i ].x, points[ i ].y ); + + } + + return this; + + }, + + moveTo: function ( x, y ) { + + this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying? + + return this; + + }, + + lineTo: function ( x, y ) { + + var curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) ); + this.curves.push( curve ); + + this.currentPoint.set( x, y ); + + return this; + + }, + + quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) { + + var curve = new QuadraticBezierCurve( + this.currentPoint.clone(), + new Vector2( aCPx, aCPy ), + new Vector2( aX, aY ) + ); + + this.curves.push( curve ); + + this.currentPoint.set( aX, aY ); + + return this; + + }, + + bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) { + + var curve = new CubicBezierCurve( + this.currentPoint.clone(), + new Vector2( aCP1x, aCP1y ), + new Vector2( aCP2x, aCP2y ), + new Vector2( aX, aY ) + ); + + this.curves.push( curve ); + + this.currentPoint.set( aX, aY ); + + return this; + + }, + + splineThru: function ( pts /*Array of Vector*/ ) { + + var npts = [ this.currentPoint.clone() ].concat( pts ); + + var curve = new SplineCurve( npts ); + this.curves.push( curve ); + + this.currentPoint.copy( pts[ pts.length - 1 ] ); + + return this; + + }, + + arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) { + + var x0 = this.currentPoint.x; + var y0 = this.currentPoint.y; + + this.absarc( aX + x0, aY + y0, aRadius, + aStartAngle, aEndAngle, aClockwise ); + + return this; + + }, + + absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) { + + this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise ); + + return this; + + }, + + ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) { + + var x0 = this.currentPoint.x; + var y0 = this.currentPoint.y; + + this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ); + + return this; + + }, + + absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) { + + var curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ); + + if ( this.curves.length > 0 ) { + + // if a previous curve is present, attempt to join + var firstPoint = curve.getPoint( 0 ); + + if ( ! firstPoint.equals( this.currentPoint ) ) { + + this.lineTo( firstPoint.x, firstPoint.y ); + + } + + } + + this.curves.push( curve ); + + var lastPoint = curve.getPoint( 1 ); + this.currentPoint.copy( lastPoint ); + + return this; + + }, + + copy: function ( source ) { + + CurvePath.prototype.copy.call( this, source ); + + this.currentPoint.copy( source.currentPoint ); + + return this; + + }, + + toJSON: function () { + + var data = CurvePath.prototype.toJSON.call( this ); + + data.currentPoint = this.currentPoint.toArray(); + + return data; + + }, + + fromJSON: function ( json ) { + + CurvePath.prototype.fromJSON.call( this, json ); + + this.currentPoint.fromArray( json.currentPoint ); + + return this; + + } + + } ); + + function Shape( points ) { + + Path.call( this, points ); + + this.uuid = MathUtils.generateUUID(); + + this.type = 'Shape'; + + this.holes = []; + + } + + Shape.prototype = Object.assign( Object.create( Path.prototype ), { + + constructor: Shape, + + getPointsHoles: function ( divisions ) { + + var holesPts = []; + + for ( var i = 0, l = this.holes.length; i < l; i ++ ) { + + holesPts[ i ] = this.holes[ i ].getPoints( divisions ); + + } + + return holesPts; + + }, + + // get points of shape and holes (keypoints based on segments parameter) + + extractPoints: function ( divisions ) { + + return { + + shape: this.getPoints( divisions ), + holes: this.getPointsHoles( divisions ) + + }; + + }, + + copy: function ( source ) { + + Path.prototype.copy.call( this, source ); + + this.holes = []; + + for ( var i = 0, l = source.holes.length; i < l; i ++ ) { + + var hole = source.holes[ i ]; + + this.holes.push( hole.clone() ); + + } + + return this; + + }, + + toJSON: function () { + + var data = Path.prototype.toJSON.call( this ); + + data.uuid = this.uuid; + data.holes = []; + + for ( var i = 0, l = this.holes.length; i < l; i ++ ) { + + var hole = this.holes[ i ]; + data.holes.push( hole.toJSON() ); + + } + + return data; + + }, + + fromJSON: function ( json ) { + + Path.prototype.fromJSON.call( this, json ); + + this.uuid = json.uuid; + this.holes = []; + + for ( var i = 0, l = json.holes.length; i < l; i ++ ) { + + var hole = json.holes[ i ]; + this.holes.push( new Path().fromJSON( hole ) ); + + } + + return this; + + } + + } ); + + function Light( color, intensity ) { + + Object3D.call( this ); + + this.type = 'Light'; + + this.color = new Color( color ); + this.intensity = intensity !== undefined ? intensity : 1; + + this.receiveShadow = undefined; + + } + + Light.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: Light, + + isLight: true, + + copy: function ( source ) { + + Object3D.prototype.copy.call( this, source ); + + this.color.copy( source.color ); + this.intensity = source.intensity; + + return this; + + }, + + toJSON: function ( meta ) { + + var data = Object3D.prototype.toJSON.call( this, meta ); + + data.object.color = this.color.getHex(); + data.object.intensity = this.intensity; + + if ( this.groundColor !== undefined ) { data.object.groundColor = this.groundColor.getHex(); } + + if ( this.distance !== undefined ) { data.object.distance = this.distance; } + if ( this.angle !== undefined ) { data.object.angle = this.angle; } + if ( this.decay !== undefined ) { data.object.decay = this.decay; } + if ( this.penumbra !== undefined ) { data.object.penumbra = this.penumbra; } + + if ( this.shadow !== undefined ) { data.object.shadow = this.shadow.toJSON(); } + + return data; + + } + + } ); + + function HemisphereLight( skyColor, groundColor, intensity ) { + + Light.call( this, skyColor, intensity ); + + this.type = 'HemisphereLight'; + + this.castShadow = undefined; + + this.position.copy( Object3D.DefaultUp ); + this.updateMatrix(); + + this.groundColor = new Color( groundColor ); + + } + + HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), { + + constructor: HemisphereLight, + + isHemisphereLight: true, + + copy: function ( source ) { + + Light.prototype.copy.call( this, source ); + + this.groundColor.copy( source.groundColor ); + + return this; + + } + + } ); + + function LightShadow( camera ) { + + this.camera = camera; + + this.bias = 0; + this.normalBias = 0; + this.radius = 1; + + this.mapSize = new Vector2( 512, 512 ); + + this.map = null; + this.mapPass = null; + this.matrix = new Matrix4(); + + this.autoUpdate = true; + this.needsUpdate = false; + + this._frustum = new Frustum(); + this._frameExtents = new Vector2( 1, 1 ); + + this._viewportCount = 1; + + this._viewports = [ + + new Vector4( 0, 0, 1, 1 ) + + ]; + + } + + Object.assign( LightShadow.prototype, { + + _projScreenMatrix: new Matrix4(), + + _lightPositionWorld: new Vector3(), + + _lookTarget: new Vector3(), + + getViewportCount: function () { + + return this._viewportCount; + + }, + + getFrustum: function () { + + return this._frustum; + + }, + + updateMatrices: function ( light ) { + + var shadowCamera = this.camera, + shadowMatrix = this.matrix, + projScreenMatrix = this._projScreenMatrix, + lookTarget = this._lookTarget, + lightPositionWorld = this._lightPositionWorld; + + lightPositionWorld.setFromMatrixPosition( light.matrixWorld ); + shadowCamera.position.copy( lightPositionWorld ); + + lookTarget.setFromMatrixPosition( light.target.matrixWorld ); + shadowCamera.lookAt( lookTarget ); + shadowCamera.updateMatrixWorld(); + + projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse ); + this._frustum.setFromProjectionMatrix( projScreenMatrix ); + + 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 + ); + + shadowMatrix.multiply( shadowCamera.projectionMatrix ); + shadowMatrix.multiply( shadowCamera.matrixWorldInverse ); + + }, + + getViewport: function ( viewportIndex ) { + + return this._viewports[ viewportIndex ]; + + }, + + getFrameExtents: function () { + + return this._frameExtents; + + }, + + copy: function ( source ) { + + this.camera = source.camera.clone(); + + this.bias = source.bias; + this.radius = source.radius; + + this.mapSize.copy( source.mapSize ); + + return this; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + toJSON: function () { + + var object = {}; + + if ( this.bias !== 0 ) { object.bias = this.bias; } + if ( this.normalBias !== 0 ) { object.normalBias = this.normalBias; } + if ( this.radius !== 1 ) { object.radius = this.radius; } + if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) { object.mapSize = this.mapSize.toArray(); } + + object.camera = this.camera.toJSON( false ).object; + delete object.camera.matrix; + + return object; + + } + + } ); + + function SpotLightShadow() { + + LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) ); + + } + + SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), { + + constructor: SpotLightShadow, + + isSpotLightShadow: true, + + updateMatrices: function ( light ) { + + var camera = this.camera; + + var fov = MathUtils.RAD2DEG * 2 * light.angle; + var aspect = this.mapSize.width / this.mapSize.height; + var far = light.distance || camera.far; + + if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) { + + camera.fov = fov; + camera.aspect = aspect; + camera.far = far; + camera.updateProjectionMatrix(); + + } + + LightShadow.prototype.updateMatrices.call( this, light ); + + } + + } ); + + function SpotLight( color, intensity, distance, angle, penumbra, decay ) { + + Light.call( this, color, intensity ); + + this.type = 'SpotLight'; + + this.position.copy( Object3D.DefaultUp ); + this.updateMatrix(); + + this.target = new Object3D(); + + Object.defineProperty( this, 'power', { + get: function () { + + // intensity = power per solid angle. + // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf + return this.intensity * Math.PI; + + }, + set: function ( power ) { + + // intensity = power per solid angle. + // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf + this.intensity = power / Math.PI; + + } + } ); + + this.distance = ( distance !== undefined ) ? distance : 0; + this.angle = ( angle !== undefined ) ? angle : Math.PI / 3; + this.penumbra = ( penumbra !== undefined ) ? penumbra : 0; + this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2. + + this.shadow = new SpotLightShadow(); + + } + + SpotLight.prototype = Object.assign( Object.create( Light.prototype ), { + + constructor: SpotLight, + + isSpotLight: true, + + copy: function ( source ) { + + Light.prototype.copy.call( this, source ); + + this.distance = source.distance; + this.angle = source.angle; + this.penumbra = source.penumbra; + this.decay = source.decay; + + this.target = source.target.clone(); + + this.shadow = source.shadow.clone(); + + return this; + + } + + } ); + + function PointLightShadow() { + + LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) ); + + this._frameExtents = new Vector2( 4, 2 ); + + this._viewportCount = 6; + + this._viewports = [ + // These viewports map a cube-map onto a 2D texture with the + // following orientation: + // + // xzXZ + // y Y + // + // X - Positive x direction + // x - Negative x direction + // Y - Positive y direction + // y - Negative y direction + // Z - Positive z direction + // z - Negative z direction + + // positive X + new Vector4( 2, 1, 1, 1 ), + // negative X + new Vector4( 0, 1, 1, 1 ), + // positive Z + new Vector4( 3, 1, 1, 1 ), + // negative Z + new Vector4( 1, 1, 1, 1 ), + // positive Y + new Vector4( 3, 0, 1, 1 ), + // negative Y + new Vector4( 1, 0, 1, 1 ) + ]; + + 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 ) + ]; + + 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 ) + ]; + + } + + PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), { + + constructor: PointLightShadow, + + isPointLightShadow: true, + + updateMatrices: function ( light, viewportIndex ) { + + if ( viewportIndex === undefined ) { viewportIndex = 0; } + + var camera = this.camera, + shadowMatrix = this.matrix, + lightPositionWorld = this._lightPositionWorld, + lookTarget = this._lookTarget, + projScreenMatrix = this._projScreenMatrix; + + lightPositionWorld.setFromMatrixPosition( light.matrixWorld ); + camera.position.copy( lightPositionWorld ); + + lookTarget.copy( camera.position ); + lookTarget.add( this._cubeDirections[ viewportIndex ] ); + camera.up.copy( this._cubeUps[ viewportIndex ] ); + camera.lookAt( lookTarget ); + camera.updateMatrixWorld(); + + shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z ); + + projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse ); + this._frustum.setFromProjectionMatrix( projScreenMatrix ); + + } + + } ); + + function PointLight( color, intensity, distance, decay ) { + + Light.call( this, color, intensity ); + + this.type = 'PointLight'; + + Object.defineProperty( this, 'power', { + get: function () { + + // intensity = power per solid angle. + // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf + return this.intensity * 4 * Math.PI; + + }, + set: function ( power ) { + + // intensity = power per solid angle. + // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf + this.intensity = power / ( 4 * Math.PI ); + + } + } ); + + this.distance = ( distance !== undefined ) ? distance : 0; + this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2. + + this.shadow = new PointLightShadow(); + + } + + PointLight.prototype = Object.assign( Object.create( Light.prototype ), { + + constructor: PointLight, + + isPointLight: true, + + copy: function ( source ) { + + Light.prototype.copy.call( this, source ); + + this.distance = source.distance; + this.decay = source.decay; + + this.shadow = source.shadow.clone(); + + return this; + + } + + } ); + + function OrthographicCamera( left, right, top, bottom, near, far ) { + + Camera.call( this ); + + this.type = 'OrthographicCamera'; + + this.zoom = 1; + this.view = null; + + this.left = ( left !== undefined ) ? left : - 1; + this.right = ( right !== undefined ) ? right : 1; + this.top = ( top !== undefined ) ? top : 1; + this.bottom = ( bottom !== undefined ) ? bottom : - 1; + + this.near = ( near !== undefined ) ? near : 0.1; + this.far = ( far !== undefined ) ? far : 2000; + + this.updateProjectionMatrix(); + + } + + OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), { + + constructor: OrthographicCamera, + + isOrthographicCamera: true, + + copy: function ( source, recursive ) { + + Camera.prototype.copy.call( this, source, recursive ); + + this.left = source.left; + this.right = source.right; + this.top = source.top; + this.bottom = source.bottom; + this.near = source.near; + this.far = source.far; + + this.zoom = source.zoom; + this.view = source.view === null ? null : Object.assign( {}, source.view ); + + return this; + + }, + + setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) { + + if ( this.view === null ) { + + this.view = { + enabled: true, + fullWidth: 1, + fullHeight: 1, + offsetX: 0, + offsetY: 0, + width: 1, + height: 1 + }; + + } + + this.view.enabled = true; + this.view.fullWidth = fullWidth; + this.view.fullHeight = fullHeight; + this.view.offsetX = x; + this.view.offsetY = y; + this.view.width = width; + this.view.height = height; + + this.updateProjectionMatrix(); + + }, + + clearViewOffset: function () { + + if ( this.view !== null ) { + + this.view.enabled = false; + + } + + this.updateProjectionMatrix(); + + }, + + updateProjectionMatrix: function () { + + var dx = ( this.right - this.left ) / ( 2 * this.zoom ); + var dy = ( this.top - this.bottom ) / ( 2 * this.zoom ); + var cx = ( this.right + this.left ) / 2; + var cy = ( this.top + this.bottom ) / 2; + + var left = cx - dx; + var right = cx + dx; + var top = cy + dy; + var bottom = cy - dy; + + if ( this.view !== null && this.view.enabled ) { + + var scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom; + var scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom; + + left += scaleW * this.view.offsetX; + right = left + scaleW * this.view.width; + top -= scaleH * this.view.offsetY; + bottom = top - scaleH * this.view.height; + + } + + this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far ); + + this.projectionMatrixInverse.getInverse( this.projectionMatrix ); + + }, + + toJSON: function ( meta ) { + + var data = Object3D.prototype.toJSON.call( this, meta ); + + data.object.zoom = this.zoom; + data.object.left = this.left; + data.object.right = this.right; + data.object.top = this.top; + data.object.bottom = this.bottom; + data.object.near = this.near; + data.object.far = this.far; + + if ( this.view !== null ) { data.object.view = Object.assign( {}, this.view ); } + + return data; + + } + + } ); + + function DirectionalLightShadow() { + + LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) ); + + } + + DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), { + + constructor: DirectionalLightShadow, + + isDirectionalLightShadow: true, + + updateMatrices: function ( light ) { + + LightShadow.prototype.updateMatrices.call( this, light ); + + } + + } ); + + function DirectionalLight( color, intensity ) { + + Light.call( this, color, intensity ); + + this.type = 'DirectionalLight'; + + this.position.copy( Object3D.DefaultUp ); + this.updateMatrix(); + + this.target = new Object3D(); + + this.shadow = new DirectionalLightShadow(); + + } + + DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), { + + constructor: DirectionalLight, + + isDirectionalLight: true, + + copy: function ( source ) { + + Light.prototype.copy.call( this, source ); + + this.target = source.target.clone(); + + this.shadow = source.shadow.clone(); + + return this; + + } + + } ); + + function AmbientLight( color, intensity ) { + + Light.call( this, color, intensity ); + + this.type = 'AmbientLight'; + + this.castShadow = undefined; + + } + + AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), { + + constructor: AmbientLight, + + isAmbientLight: true + + } ); + + function RectAreaLight( color, intensity, width, height ) { + + Light.call( this, color, intensity ); + + this.type = 'RectAreaLight'; + + this.width = ( width !== undefined ) ? width : 10; + this.height = ( height !== undefined ) ? height : 10; + + } + + RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), { + + constructor: RectAreaLight, + + isRectAreaLight: true, + + copy: function ( source ) { + + Light.prototype.copy.call( this, source ); + + this.width = source.width; + this.height = source.height; + + return this; + + }, + + toJSON: function ( meta ) { + + var data = Light.prototype.toJSON.call( this, meta ); + + data.object.width = this.width; + data.object.height = this.height; + + return data; + + } + + } ); + + /** + * Primary reference: + * https://graphics.stanford.edu/papers/envmap/envmap.pdf + * + * Secondary reference: + * https://www.ppsloan.org/publications/StupidSH36.pdf + */ + + // 3-band SH defined by 9 coefficients + + function SphericalHarmonics3() { + + this.coefficients = []; + + for ( var i = 0; i < 9; i ++ ) { + + this.coefficients.push( new Vector3() ); + + } + + } + + Object.assign( SphericalHarmonics3.prototype, { + + isSphericalHarmonics3: true, + + set: function ( coefficients ) { + + for ( var i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].copy( coefficients[ i ] ); + + } + + return this; + + }, + + zero: function () { + + for ( var i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].set( 0, 0, 0 ); + + } + + return this; + + }, + + // get the radiance in the direction of the normal + // target is a Vector3 + getAt: function ( normal, target ) { + + // normal is assumed to be unit length + + var x = normal.x, y = normal.y, z = normal.z; + + var coeff = this.coefficients; + + // band 0 + target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 ); + + // band 1 + target.addScaledVector( coeff[ 1 ], 0.488603 * y ); + target.addScaledVector( coeff[ 2 ], 0.488603 * z ); + target.addScaledVector( coeff[ 3 ], 0.488603 * x ); + + // band 2 + target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) ); + target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) ); + target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) ); + target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) ); + target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) ); + + return target; + + }, + + // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal + // target is a Vector3 + // https://graphics.stanford.edu/papers/envmap/envmap.pdf + getIrradianceAt: function ( normal, target ) { + + // normal is assumed to be unit length + + var x = normal.x, y = normal.y, z = normal.z; + + var coeff = this.coefficients; + + // band 0 + target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095 + + // band 1 + target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603 + target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z ); + target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x ); + + // band 2 + target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548 + target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z ); + target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3 + target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z ); + target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274 + + return target; + + }, + + add: function ( sh ) { + + for ( var i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].add( sh.coefficients[ i ] ); + + } + + return this; + + }, + + addScaledSH: function ( sh, s ) { + + for ( var i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s ); + + } + + return this; + + }, + + scale: function ( s ) { + + for ( var i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].multiplyScalar( s ); + + } + + return this; + + }, + + lerp: function ( sh, alpha ) { + + for ( var i = 0; i < 9; i ++ ) { + + this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha ); + + } + + return this; + + }, + + equals: function ( sh ) { + + for ( var i = 0; i < 9; i ++ ) { + + if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) { + + return false; + + } + + } + + return true; + + }, + + copy: function ( sh ) { + + return this.set( sh.coefficients ); + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + fromArray: function ( array, offset ) { + + if ( offset === undefined ) { offset = 0; } + + var coefficients = this.coefficients; + + for ( var i = 0; i < 9; i ++ ) { + + coefficients[ i ].fromArray( array, offset + ( i * 3 ) ); + + } + + return this; + + }, + + toArray: function ( array, offset ) { + + if ( array === undefined ) { array = []; } + if ( offset === undefined ) { offset = 0; } + + var coefficients = this.coefficients; + + for ( var i = 0; i < 9; i ++ ) { + + coefficients[ i ].toArray( array, offset + ( i * 3 ) ); + + } + + return array; + + } + + } ); + + Object.assign( SphericalHarmonics3, { + + // evaluate the basis functions + // shBasis is an Array[ 9 ] + getBasisAt: function ( normal, shBasis ) { + + // normal is assumed to be unit length + + var x = normal.x, y = normal.y, z = normal.z; + + // band 0 + shBasis[ 0 ] = 0.282095; + + // band 1 + shBasis[ 1 ] = 0.488603 * y; + shBasis[ 2 ] = 0.488603 * z; + shBasis[ 3 ] = 0.488603 * x; + + // band 2 + shBasis[ 4 ] = 1.092548 * x * y; + shBasis[ 5 ] = 1.092548 * y * z; + shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 ); + shBasis[ 7 ] = 1.092548 * x * z; + shBasis[ 8 ] = 0.546274 * ( x * x - y * y ); + + } + + } ); + + function LightProbe( sh, intensity ) { + + Light.call( this, undefined, intensity ); + + this.type = 'LightProbe'; + + this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3(); + + } + + LightProbe.prototype = Object.assign( Object.create( Light.prototype ), { + + constructor: LightProbe, + + isLightProbe: true, + + copy: function ( source ) { + + Light.prototype.copy.call( this, source ); + + this.sh.copy( source.sh ); + + return this; + + }, + + fromJSON: function ( json ) { + + this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON(); + this.sh.fromArray( json.sh ); + + return this; + + }, + + toJSON: function ( meta ) { + + var data = Light.prototype.toJSON.call( this, meta ); + + data.object.sh = this.sh.toArray(); + + return data; + + } + + } ); + + function MaterialLoader( manager ) { + + Loader.call( this, manager ); + + this.textures = {}; + + } + + MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: MaterialLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + var scope = this; + + var loader = new FileLoader( scope.manager ); + loader.setPath( scope.path ); + loader.setRequestHeader( scope.requestHeader ); + loader.load( url, function ( text ) { + + try { + + onLoad( scope.parse( JSON.parse( text ) ) ); + + } catch ( e ) { + + if ( onError ) { + + onError( e ); + + } else { + + console.error( e ); + + } + + scope.manager.itemError( url ); + + } + + }, onProgress, onError ); + + }, + + parse: function ( json ) { + + var textures = this.textures; + + function getTexture( name ) { + + if ( textures[ name ] === undefined ) { + + console.warn( 'THREE.MaterialLoader: Undefined texture', name ); + + } + + return textures[ name ]; + + } + + var material = new Materials[ json.type ](); + + if ( json.uuid !== undefined ) { material.uuid = json.uuid; } + if ( json.name !== undefined ) { material.name = json.name; } + if ( json.color !== undefined ) { material.color.setHex( json.color ); } + if ( json.roughness !== undefined ) { material.roughness = json.roughness; } + if ( json.metalness !== undefined ) { material.metalness = json.metalness; } + if ( json.sheen !== undefined ) { material.sheen = new Color().setHex( json.sheen ); } + if ( json.emissive !== undefined ) { material.emissive.setHex( json.emissive ); } + if ( json.specular !== undefined ) { material.specular.setHex( json.specular ); } + if ( json.shininess !== undefined ) { material.shininess = json.shininess; } + if ( json.clearcoat !== undefined ) { material.clearcoat = json.clearcoat; } + if ( json.clearcoatRoughness !== undefined ) { material.clearcoatRoughness = json.clearcoatRoughness; } + if ( json.fog !== undefined ) { material.fog = json.fog; } + if ( json.flatShading !== undefined ) { material.flatShading = json.flatShading; } + if ( json.blending !== undefined ) { material.blending = json.blending; } + if ( json.combine !== undefined ) { material.combine = json.combine; } + if ( json.side !== undefined ) { material.side = json.side; } + if ( json.opacity !== undefined ) { material.opacity = json.opacity; } + if ( json.transparent !== undefined ) { material.transparent = json.transparent; } + if ( json.alphaTest !== undefined ) { material.alphaTest = json.alphaTest; } + if ( json.depthTest !== undefined ) { material.depthTest = json.depthTest; } + if ( json.depthWrite !== undefined ) { material.depthWrite = json.depthWrite; } + if ( json.colorWrite !== undefined ) { material.colorWrite = json.colorWrite; } + + if ( json.stencilWrite !== undefined ) { material.stencilWrite = json.stencilWrite; } + if ( json.stencilWriteMask !== undefined ) { material.stencilWriteMask = json.stencilWriteMask; } + if ( json.stencilFunc !== undefined ) { material.stencilFunc = json.stencilFunc; } + if ( json.stencilRef !== undefined ) { material.stencilRef = json.stencilRef; } + if ( json.stencilFuncMask !== undefined ) { material.stencilFuncMask = json.stencilFuncMask; } + if ( json.stencilFail !== undefined ) { material.stencilFail = json.stencilFail; } + if ( json.stencilZFail !== undefined ) { material.stencilZFail = json.stencilZFail; } + if ( json.stencilZPass !== undefined ) { material.stencilZPass = json.stencilZPass; } + + if ( json.wireframe !== undefined ) { material.wireframe = json.wireframe; } + if ( json.wireframeLinewidth !== undefined ) { material.wireframeLinewidth = json.wireframeLinewidth; } + if ( json.wireframeLinecap !== undefined ) { material.wireframeLinecap = json.wireframeLinecap; } + if ( json.wireframeLinejoin !== undefined ) { material.wireframeLinejoin = json.wireframeLinejoin; } + + if ( json.rotation !== undefined ) { material.rotation = json.rotation; } + + if ( json.linewidth !== 1 ) { material.linewidth = json.linewidth; } + if ( json.dashSize !== undefined ) { material.dashSize = json.dashSize; } + if ( json.gapSize !== undefined ) { material.gapSize = json.gapSize; } + if ( json.scale !== undefined ) { material.scale = json.scale; } + + if ( json.polygonOffset !== undefined ) { material.polygonOffset = json.polygonOffset; } + if ( json.polygonOffsetFactor !== undefined ) { material.polygonOffsetFactor = json.polygonOffsetFactor; } + if ( json.polygonOffsetUnits !== undefined ) { material.polygonOffsetUnits = json.polygonOffsetUnits; } + + if ( json.skinning !== undefined ) { material.skinning = json.skinning; } + if ( json.morphTargets !== undefined ) { material.morphTargets = json.morphTargets; } + if ( json.morphNormals !== undefined ) { material.morphNormals = json.morphNormals; } + if ( json.dithering !== undefined ) { material.dithering = json.dithering; } + + if ( json.vertexTangents !== undefined ) { material.vertexTangents = json.vertexTangents; } + + if ( json.visible !== undefined ) { material.visible = json.visible; } + + if ( json.toneMapped !== undefined ) { material.toneMapped = json.toneMapped; } + + if ( json.userData !== undefined ) { material.userData = json.userData; } + + if ( json.vertexColors !== undefined ) { + + if ( typeof json.vertexColors === 'number' ) { + + material.vertexColors = ( json.vertexColors > 0 ) ? true : false; + + } else { + + material.vertexColors = json.vertexColors; + + } + + } + + // Shader Material + + if ( json.uniforms !== undefined ) { + + for ( var name in json.uniforms ) { + + var uniform = json.uniforms[ name ]; + + material.uniforms[ name ] = {}; + + switch ( uniform.type ) { + + case 't': + material.uniforms[ name ].value = getTexture( uniform.value ); + break; + + case 'c': + material.uniforms[ name ].value = new Color().setHex( uniform.value ); + break; + + case 'v2': + material.uniforms[ name ].value = new Vector2().fromArray( uniform.value ); + break; + + case 'v3': + material.uniforms[ name ].value = new Vector3().fromArray( uniform.value ); + break; + + case 'v4': + material.uniforms[ name ].value = new Vector4().fromArray( uniform.value ); + break; + + case 'm3': + material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value ); + + case 'm4': + material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value ); + break; + + default: + material.uniforms[ name ].value = uniform.value; + + } + + } + + } + + if ( json.defines !== undefined ) { material.defines = json.defines; } + if ( json.vertexShader !== undefined ) { material.vertexShader = json.vertexShader; } + if ( json.fragmentShader !== undefined ) { material.fragmentShader = json.fragmentShader; } + + if ( json.extensions !== undefined ) { + + for ( var key in json.extensions ) { + + material.extensions[ key ] = json.extensions[ key ]; + + } + + } + + // Deprecated + + if ( json.shading !== undefined ) { material.flatShading = json.shading === 1; } // THREE.FlatShading + + // for PointsMaterial + + if ( json.size !== undefined ) { material.size = json.size; } + if ( json.sizeAttenuation !== undefined ) { material.sizeAttenuation = json.sizeAttenuation; } + + // maps + + if ( json.map !== undefined ) { material.map = getTexture( json.map ); } + if ( json.matcap !== undefined ) { material.matcap = getTexture( json.matcap ); } + + if ( json.alphaMap !== undefined ) { material.alphaMap = getTexture( json.alphaMap ); } + + if ( json.bumpMap !== undefined ) { material.bumpMap = getTexture( json.bumpMap ); } + if ( json.bumpScale !== undefined ) { material.bumpScale = json.bumpScale; } + + if ( json.normalMap !== undefined ) { material.normalMap = getTexture( json.normalMap ); } + if ( json.normalMapType !== undefined ) { material.normalMapType = json.normalMapType; } + if ( json.normalScale !== undefined ) { + + var normalScale = json.normalScale; + + if ( Array.isArray( normalScale ) === false ) { + + // Blender exporter used to export a scalar. See #7459 + + normalScale = [ normalScale, normalScale ]; + + } + + material.normalScale = new Vector2().fromArray( normalScale ); + + } + + if ( json.displacementMap !== undefined ) { material.displacementMap = getTexture( json.displacementMap ); } + if ( json.displacementScale !== undefined ) { material.displacementScale = json.displacementScale; } + if ( json.displacementBias !== undefined ) { material.displacementBias = json.displacementBias; } + + if ( json.roughnessMap !== undefined ) { material.roughnessMap = getTexture( json.roughnessMap ); } + if ( json.metalnessMap !== undefined ) { material.metalnessMap = getTexture( json.metalnessMap ); } + + if ( json.emissiveMap !== undefined ) { material.emissiveMap = getTexture( json.emissiveMap ); } + if ( json.emissiveIntensity !== undefined ) { material.emissiveIntensity = json.emissiveIntensity; } + + if ( json.specularMap !== undefined ) { material.specularMap = getTexture( json.specularMap ); } + + if ( json.envMap !== undefined ) { material.envMap = getTexture( json.envMap ); } + if ( json.envMapIntensity !== undefined ) { material.envMapIntensity = json.envMapIntensity; } + + if ( json.reflectivity !== undefined ) { material.reflectivity = json.reflectivity; } + if ( json.refractionRatio !== undefined ) { material.refractionRatio = json.refractionRatio; } + + if ( json.lightMap !== undefined ) { material.lightMap = getTexture( json.lightMap ); } + if ( json.lightMapIntensity !== undefined ) { material.lightMapIntensity = json.lightMapIntensity; } + + if ( json.aoMap !== undefined ) { material.aoMap = getTexture( json.aoMap ); } + if ( json.aoMapIntensity !== undefined ) { material.aoMapIntensity = json.aoMapIntensity; } + + if ( json.gradientMap !== undefined ) { material.gradientMap = getTexture( json.gradientMap ); } + + if ( json.clearcoatMap !== undefined ) { material.clearcoatMap = getTexture( json.clearcoatMap ); } + if ( json.clearcoatRoughnessMap !== undefined ) { material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap ); } + if ( json.clearcoatNormalMap !== undefined ) { material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap ); } + if ( json.clearcoatNormalScale !== undefined ) { material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale ); } + + if ( json.transmission !== undefined ) { material.transmission = json.transmission; } + if ( json.transmissionMap !== undefined ) { material.transmissionMap = getTexture( json.transmissionMap ); } + + return material; + + }, + + setTextures: function ( value ) { + + this.textures = value; + return this; + + } + + } ); + + var LoaderUtils = { + + decodeText: function ( array ) { + + if ( typeof TextDecoder !== 'undefined' ) { + + return new TextDecoder().decode( array ); + + } + + // Avoid the String.fromCharCode.apply(null, array) shortcut, which + // throws a "maximum call stack size exceeded" error for large arrays. + + var s = ''; + + for ( var i = 0, il = array.length; i < il; i ++ ) { + + // Implicitly assumes little-endian. + s += String.fromCharCode( array[ i ] ); + + } + + try { + + // merges multi-byte utf-8 characters. + + return decodeURIComponent( escape( s ) ); + + } catch ( e ) { // see #16358 + + return s; + + } + + }, + + extractUrlBase: function ( url ) { + + var index = url.lastIndexOf( '/' ); + + if ( index === - 1 ) { return './'; } + + return url.substr( 0, index + 1 ); + + } + + }; + + function InstancedBufferGeometry() { + + BufferGeometry.call( this ); + + this.type = 'InstancedBufferGeometry'; + this.instanceCount = Infinity; + + } + + InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), { + + constructor: InstancedBufferGeometry, + + isInstancedBufferGeometry: true, + + copy: function ( source ) { + + BufferGeometry.prototype.copy.call( this, source ); + + this.instanceCount = source.instanceCount; + + return this; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + toJSON: function () { + + var data = BufferGeometry.prototype.toJSON.call( this ); + + data.instanceCount = this.instanceCount; + + data.isInstancedBufferGeometry = true; + + return data; + + } + + } ); + + function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) { + + if ( typeof ( normalized ) === 'number' ) { + + meshPerAttribute = normalized; + + normalized = false; + + console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' ); + + } + + BufferAttribute.call( this, array, itemSize, normalized ); + + this.meshPerAttribute = meshPerAttribute || 1; + + } + + InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), { + + constructor: InstancedBufferAttribute, + + isInstancedBufferAttribute: true, + + copy: function ( source ) { + + BufferAttribute.prototype.copy.call( this, source ); + + this.meshPerAttribute = source.meshPerAttribute; + + return this; + + }, + + toJSON: function () { + + var data = BufferAttribute.prototype.toJSON.call( this ); + + data.meshPerAttribute = this.meshPerAttribute; + + data.isInstancedBufferAttribute = true; + + return data; + + } + + } ); + + function BufferGeometryLoader( manager ) { + + Loader.call( this, manager ); + + } + + BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: BufferGeometryLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + var scope = this; + + var loader = new FileLoader( scope.manager ); + loader.setPath( scope.path ); + loader.setRequestHeader( scope.requestHeader ); + loader.load( url, function ( text ) { + + try { + + onLoad( scope.parse( JSON.parse( text ) ) ); + + } catch ( e ) { + + if ( onError ) { + + onError( e ); + + } else { + + console.error( e ); + + } + + scope.manager.itemError( url ); + + } + + }, onProgress, onError ); + + }, + + parse: function ( json ) { + + var interleavedBufferMap = {}; + var arrayBufferMap = {}; + + function getInterleavedBuffer( json, uuid ) { + + if ( interleavedBufferMap[ uuid ] !== undefined ) { return interleavedBufferMap[ uuid ]; } + + var interleavedBuffers = json.interleavedBuffers; + var interleavedBuffer = interleavedBuffers[ uuid ]; + + var buffer = getArrayBuffer( json, interleavedBuffer.buffer ); + + var array = new TYPED_ARRAYS[ interleavedBuffer.type ]( buffer ); + var ib = new InterleavedBuffer( array, interleavedBuffer.stride ); + ib.uuid = interleavedBuffer.uuid; + + interleavedBufferMap[ uuid ] = ib; + + return ib; + + } + + function getArrayBuffer( json, uuid ) { + + if ( arrayBufferMap[ uuid ] !== undefined ) { return arrayBufferMap[ uuid ]; } + + var arrayBuffers = json.arrayBuffers; + var arrayBuffer = arrayBuffers[ uuid ]; + + var ab = new Uint32Array( arrayBuffer ).buffer; + + arrayBufferMap[ uuid ] = ab; + + return ab; + + } + + var geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry(); + + var index = json.data.index; + + if ( index !== undefined ) { + + var typedArray = new TYPED_ARRAYS[ index.type ]( index.array ); + geometry.setIndex( new BufferAttribute( typedArray, 1 ) ); + + } + + var attributes = json.data.attributes; + + for ( var key in attributes ) { + + var attribute = attributes[ key ]; + var bufferAttribute = (void 0); + + if ( attribute.isInterleavedBufferAttribute ) { + + var interleavedBuffer = getInterleavedBuffer( json.data, attribute.data ); + bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized ); + + } else { + + var typedArray$1 = new TYPED_ARRAYS[ attribute.type ]( attribute.array ); + var bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute; + bufferAttribute = new bufferAttributeConstr( typedArray$1, attribute.itemSize, attribute.normalized ); + + } + + if ( attribute.name !== undefined ) { bufferAttribute.name = attribute.name; } + geometry.setAttribute( key, bufferAttribute ); + + } + + var morphAttributes = json.data.morphAttributes; + + if ( morphAttributes ) { + + for ( var key$1 in morphAttributes ) { + + var attributeArray = morphAttributes[ key$1 ]; + + var array = []; + + for ( var i = 0, il = attributeArray.length; i < il; i ++ ) { + + var attribute$1 = attributeArray[ i ]; + var bufferAttribute$1 = (void 0); + + if ( attribute$1.isInterleavedBufferAttribute ) { + + var interleavedBuffer$1 = getInterleavedBuffer( json.data, attribute$1.data ); + bufferAttribute$1 = new InterleavedBufferAttribute( interleavedBuffer$1, attribute$1.itemSize, attribute$1.offset, attribute$1.normalized ); + + } else { + + var typedArray$2 = new TYPED_ARRAYS[ attribute$1.type ]( attribute$1.array ); + bufferAttribute$1 = new BufferAttribute( typedArray$2, attribute$1.itemSize, attribute$1.normalized ); + + } + + if ( attribute$1.name !== undefined ) { bufferAttribute$1.name = attribute$1.name; } + array.push( bufferAttribute$1 ); + + } + + geometry.morphAttributes[ key$1 ] = array; + + } + + } + + var morphTargetsRelative = json.data.morphTargetsRelative; + + if ( morphTargetsRelative ) { + + geometry.morphTargetsRelative = true; + + } + + var groups = json.data.groups || json.data.drawcalls || json.data.offsets; + + if ( groups !== undefined ) { + + for ( var i$1 = 0, n = groups.length; i$1 !== n; ++ i$1 ) { + + var group = groups[ i$1 ]; + + geometry.addGroup( group.start, group.count, group.materialIndex ); + + } + + } + + var boundingSphere = json.data.boundingSphere; + + if ( boundingSphere !== undefined ) { + + var center = new Vector3(); + + if ( boundingSphere.center !== undefined ) { + + center.fromArray( boundingSphere.center ); + + } + + geometry.boundingSphere = new Sphere( center, boundingSphere.radius ); + + } + + if ( json.name ) { geometry.name = json.name; } + if ( json.userData ) { geometry.userData = json.userData; } + + return geometry; + + } + + } ); + + var TYPED_ARRAYS = { + Int8Array: Int8Array, + Uint8Array: Uint8Array, + // Workaround for IE11 pre KB2929437. See #11440 + Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array, + Int16Array: Int16Array, + Uint16Array: Uint16Array, + Int32Array: Int32Array, + Uint32Array: Uint32Array, + Float32Array: Float32Array, + Float64Array: Float64Array + }; + + function ObjectLoader( manager ) { + + Loader.call( this, manager ); + + } + + ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: ObjectLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + var scope = this; + + var path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path; + this.resourcePath = this.resourcePath || path; + + var loader = new FileLoader( scope.manager ); + loader.setPath( this.path ); + loader.setRequestHeader( this.requestHeader ); + loader.load( url, function ( text ) { + + var json = null; + + try { + + json = JSON.parse( text ); + + } catch ( error ) { + + if ( onError !== undefined ) { onError( error ); } + + console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message ); + + return; + + } + + var metadata = json.metadata; + + if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) { + + console.error( 'THREE.ObjectLoader: Can\'t load ' + url ); + return; + + } + + scope.parse( json, onLoad ); + + }, onProgress, onError ); + + }, + + parse: function ( json, onLoad ) { + + var shapes = this.parseShape( json.shapes ); + var geometries = this.parseGeometries( json.geometries, shapes ); + + var images = this.parseImages( json.images, function () { + + if ( onLoad !== undefined ) { onLoad( object ); } + + } ); + + var textures = this.parseTextures( json.textures, images ); + var materials = this.parseMaterials( json.materials, textures ); + + var object = this.parseObject( json.object, geometries, materials ); + + if ( json.animations ) { + + object.animations = this.parseAnimations( json.animations ); + + } + + if ( json.images === undefined || json.images.length === 0 ) { + + if ( onLoad !== undefined ) { onLoad( object ); } + + } + + return object; + + }, + + parseShape: function ( json ) { + + var shapes = {}; + + if ( json !== undefined ) { + + for ( var i = 0, l = json.length; i < l; i ++ ) { + + var shape = new Shape().fromJSON( json[ i ] ); + + shapes[ shape.uuid ] = shape; + + } + + } + + return shapes; + + }, + + parseGeometries: function ( json, shapes ) { + + var geometries = {}; + var geometryShapes; + + if ( json !== undefined ) { + + var bufferGeometryLoader = new BufferGeometryLoader(); + + for ( var i = 0, l = json.length; i < l; i ++ ) { + + var geometry = (void 0); + var data = json[ i ]; + + switch ( data.type ) { + + case 'PlaneGeometry': + case 'PlaneBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.width, + data.height, + data.widthSegments, + data.heightSegments + ); + + break; + + case 'BoxGeometry': + case 'BoxBufferGeometry': + case 'CubeGeometry': // backwards compatible + + geometry = new Geometries[ data.type ]( + data.width, + data.height, + data.depth, + data.widthSegments, + data.heightSegments, + data.depthSegments + ); + + break; + + case 'CircleGeometry': + case 'CircleBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.radius, + data.segments, + data.thetaStart, + data.thetaLength + ); + + break; + + case 'CylinderGeometry': + case 'CylinderBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.radiusTop, + data.radiusBottom, + data.height, + data.radialSegments, + data.heightSegments, + data.openEnded, + data.thetaStart, + data.thetaLength + ); + + break; + + case 'ConeGeometry': + case 'ConeBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.radius, + data.height, + data.radialSegments, + data.heightSegments, + data.openEnded, + data.thetaStart, + data.thetaLength + ); + + break; + + case 'SphereGeometry': + case 'SphereBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.radius, + data.widthSegments, + data.heightSegments, + data.phiStart, + data.phiLength, + data.thetaStart, + data.thetaLength + ); + + break; + + case 'DodecahedronGeometry': + case 'DodecahedronBufferGeometry': + case 'IcosahedronGeometry': + case 'IcosahedronBufferGeometry': + case 'OctahedronGeometry': + case 'OctahedronBufferGeometry': + case 'TetrahedronGeometry': + case 'TetrahedronBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.radius, + data.detail + ); + + break; + + case 'RingGeometry': + case 'RingBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.innerRadius, + data.outerRadius, + data.thetaSegments, + data.phiSegments, + data.thetaStart, + data.thetaLength + ); + + break; + + case 'TorusGeometry': + case 'TorusBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.radius, + data.tube, + data.radialSegments, + data.tubularSegments, + data.arc + ); + + break; + + case 'TorusKnotGeometry': + case 'TorusKnotBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.radius, + data.tube, + data.tubularSegments, + data.radialSegments, + data.p, + data.q + ); + + break; + + case 'TubeGeometry': + case 'TubeBufferGeometry': + + // This only works for built-in curves (e.g. CatmullRomCurve3). + // User defined curves or instances of CurvePath will not be deserialized. + geometry = new Geometries[ data.type ]( + new Curves[ data.path.type ]().fromJSON( data.path ), + data.tubularSegments, + data.radius, + data.radialSegments, + data.closed + ); + + break; + + case 'LatheGeometry': + case 'LatheBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.points, + data.segments, + data.phiStart, + data.phiLength + ); + + break; + + case 'PolyhedronGeometry': + case 'PolyhedronBufferGeometry': + + geometry = new Geometries[ data.type ]( + data.vertices, + data.indices, + data.radius, + data.details + ); + + break; + + case 'ShapeGeometry': + case 'ShapeBufferGeometry': + + geometryShapes = []; + + for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) { + + var shape = shapes[ data.shapes[ j ] ]; + + geometryShapes.push( shape ); + + } + + geometry = new Geometries[ data.type ]( + geometryShapes, + data.curveSegments + ); + + break; + + + case 'ExtrudeGeometry': + case 'ExtrudeBufferGeometry': + + geometryShapes = []; + + for ( var j$1 = 0, jl$1 = data.shapes.length; j$1 < jl$1; j$1 ++ ) { + + var shape$1 = shapes[ data.shapes[ j$1 ] ]; + + geometryShapes.push( shape$1 ); + + } + + var extrudePath = data.options.extrudePath; + + if ( extrudePath !== undefined ) { + + data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath ); + + } + + geometry = new Geometries[ data.type ]( + geometryShapes, + data.options + ); + + break; + + case 'BufferGeometry': + case 'InstancedBufferGeometry': + + geometry = bufferGeometryLoader.parse( data ); + + break; + + case 'Geometry': + + console.error( 'THREE.ObjectLoader: Loading "Geometry" is not supported anymore.' ); + + break; + + default: + + console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' ); + + continue; + + } + + geometry.uuid = data.uuid; + + if ( data.name !== undefined ) { geometry.name = data.name; } + if ( geometry.isBufferGeometry === true && data.userData !== undefined ) { geometry.userData = data.userData; } + + geometries[ data.uuid ] = geometry; + + } + + } + + return geometries; + + }, + + parseMaterials: function ( json, textures ) { + + var cache = {}; // MultiMaterial + var materials = {}; + + if ( json !== undefined ) { + + var loader = new MaterialLoader(); + loader.setTextures( textures ); + + for ( var i = 0, l = json.length; i < l; i ++ ) { + + var data = json[ i ]; + + if ( data.type === 'MultiMaterial' ) { + + // Deprecated + + var array = []; + + for ( var j = 0; j < data.materials.length; j ++ ) { + + var material = data.materials[ j ]; + + if ( cache[ material.uuid ] === undefined ) { + + cache[ material.uuid ] = loader.parse( material ); + + } + + array.push( cache[ material.uuid ] ); + + } + + materials[ data.uuid ] = array; + + } else { + + if ( cache[ data.uuid ] === undefined ) { + + cache[ data.uuid ] = loader.parse( data ); + + } + + materials[ data.uuid ] = cache[ data.uuid ]; + + } + + } + + } + + return materials; + + }, + + parseAnimations: function ( json ) { + + var animations = []; + + for ( var i = 0; i < json.length; i ++ ) { + + var data = json[ i ]; + + var clip = AnimationClip.parse( data ); + + if ( data.uuid !== undefined ) { clip.uuid = data.uuid; } + + animations.push( clip ); + + } + + return animations; + + }, + + parseImages: function ( json, onLoad ) { + + var scope = this; + var images = {}; + + var loader; + + function loadImage( url ) { + + scope.manager.itemStart( url ); + + return loader.load( url, function () { + + scope.manager.itemEnd( url ); + + }, undefined, function () { + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + } ); + + } + + if ( json !== undefined && json.length > 0 ) { + + var manager = new LoadingManager( onLoad ); + + loader = new ImageLoader( manager ); + loader.setCrossOrigin( this.crossOrigin ); + + for ( var i = 0, il = json.length; i < il; i ++ ) { + + var image = json[ i ]; + var url = image.url; + + if ( Array.isArray( url ) ) { + + // load array of images e.g CubeTexture + + images[ image.uuid ] = []; + + for ( var j = 0, jl = url.length; j < jl; j ++ ) { + + var currentUrl = url[ j ]; + + var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl; + + images[ image.uuid ].push( loadImage( path ) ); + + } + + } else { + + // load single image + + var path$1 = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url; + + images[ image.uuid ] = loadImage( path$1 ); + + } + + } + + } + + return images; + + }, + + parseTextures: function ( json, images ) { + + function parseConstant( value, type ) { + + if ( typeof value === 'number' ) { return value; } + + console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value ); + + return type[ value ]; + + } + + var textures = {}; + + if ( json !== undefined ) { + + for ( var i = 0, l = json.length; i < l; i ++ ) { + + var data = json[ i ]; + + if ( data.image === undefined ) { + + console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid ); + + } + + if ( images[ data.image ] === undefined ) { + + console.warn( 'THREE.ObjectLoader: Undefined image', data.image ); + + } + + var texture = (void 0); + + if ( Array.isArray( images[ data.image ] ) ) { + + texture = new CubeTexture( images[ data.image ] ); + + } else { + + texture = new Texture( images[ data.image ] ); + + } + + texture.needsUpdate = true; + + texture.uuid = data.uuid; + + if ( data.name !== undefined ) { texture.name = data.name; } + + if ( data.mapping !== undefined ) { texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING ); } + + if ( data.offset !== undefined ) { texture.offset.fromArray( data.offset ); } + if ( data.repeat !== undefined ) { texture.repeat.fromArray( data.repeat ); } + if ( data.center !== undefined ) { texture.center.fromArray( data.center ); } + if ( data.rotation !== undefined ) { texture.rotation = data.rotation; } + + if ( data.wrap !== undefined ) { + + texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING ); + texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING ); + + } + + if ( data.format !== undefined ) { texture.format = data.format; } + if ( data.type !== undefined ) { texture.type = data.type; } + if ( data.encoding !== undefined ) { texture.encoding = data.encoding; } + + if ( data.minFilter !== undefined ) { texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER ); } + if ( data.magFilter !== undefined ) { texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER ); } + if ( data.anisotropy !== undefined ) { texture.anisotropy = data.anisotropy; } + + if ( data.flipY !== undefined ) { texture.flipY = data.flipY; } + + if ( data.premultiplyAlpha !== undefined ) { texture.premultiplyAlpha = data.premultiplyAlpha; } + if ( data.unpackAlignment !== undefined ) { texture.unpackAlignment = data.unpackAlignment; } + + textures[ data.uuid ] = texture; + + } + + } + + return textures; + + }, + + parseObject: function ( data, geometries, materials ) { + + var object; + + function getGeometry( name ) { + + if ( geometries[ name ] === undefined ) { + + console.warn( 'THREE.ObjectLoader: Undefined geometry', name ); + + } + + return geometries[ name ]; + + } + + function getMaterial( name ) { + + if ( name === undefined ) { return undefined; } + + if ( Array.isArray( name ) ) { + + var array = []; + + for ( var i = 0, l = name.length; i < l; i ++ ) { + + var uuid = name[ i ]; + + if ( materials[ uuid ] === undefined ) { + + console.warn( 'THREE.ObjectLoader: Undefined material', uuid ); + + } + + array.push( materials[ uuid ] ); + + } + + return array; + + } + + if ( materials[ name ] === undefined ) { + + console.warn( 'THREE.ObjectLoader: Undefined material', name ); + + } + + return materials[ name ]; + + } + + var geometry, material; + + switch ( data.type ) { + + case 'Scene': + + object = new Scene(); + + if ( data.background !== undefined ) { + + if ( Number.isInteger( data.background ) ) { + + object.background = new Color( data.background ); + + } + + } + + if ( data.fog !== undefined ) { + + if ( data.fog.type === 'Fog' ) { + + object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far ); + + } else if ( data.fog.type === 'FogExp2' ) { + + object.fog = new FogExp2( data.fog.color, data.fog.density ); + + } + + } + + break; + + case 'PerspectiveCamera': + + object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far ); + + if ( data.focus !== undefined ) { object.focus = data.focus; } + if ( data.zoom !== undefined ) { object.zoom = data.zoom; } + if ( data.filmGauge !== undefined ) { object.filmGauge = data.filmGauge; } + if ( data.filmOffset !== undefined ) { object.filmOffset = data.filmOffset; } + if ( data.view !== undefined ) { object.view = Object.assign( {}, data.view ); } + + break; + + case 'OrthographicCamera': + + object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far ); + + if ( data.zoom !== undefined ) { object.zoom = data.zoom; } + if ( data.view !== undefined ) { object.view = Object.assign( {}, data.view ); } + + break; + + case 'AmbientLight': + + object = new AmbientLight( data.color, data.intensity ); + + break; + + case 'DirectionalLight': + + object = new DirectionalLight( data.color, data.intensity ); + + break; + + case 'PointLight': + + object = new PointLight( data.color, data.intensity, data.distance, data.decay ); + + break; + + case 'RectAreaLight': + + object = new RectAreaLight( data.color, data.intensity, data.width, data.height ); + + break; + + case 'SpotLight': + + object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay ); + + break; + + case 'HemisphereLight': + + object = new HemisphereLight( data.color, data.groundColor, data.intensity ); + + break; + + case 'LightProbe': + + object = new LightProbe().fromJSON( data ); + + break; + + case 'SkinnedMesh': + + console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' ); + + case 'Mesh': + + geometry = getGeometry( data.geometry ); + material = getMaterial( data.material ); + + object = new Mesh( geometry, material ); + + break; + + case 'InstancedMesh': + + geometry = getGeometry( data.geometry ); + material = getMaterial( data.material ); + var count = data.count; + var instanceMatrix = data.instanceMatrix; + + object = new InstancedMesh( geometry, material, count ); + object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 ); + + break; + + case 'LOD': + + object = new LOD(); + + break; + + case 'Line': + + object = new Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode ); + + break; + + case 'LineLoop': + + object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) ); + + break; + + case 'LineSegments': + + object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) ); + + break; + + case 'PointCloud': + case 'Points': + + object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) ); + + break; + + case 'Sprite': + + object = new Sprite( getMaterial( data.material ) ); + + break; + + case 'Group': + + object = new Group(); + + break; + + default: + + object = new Object3D(); + + } + + object.uuid = data.uuid; + + if ( data.name !== undefined ) { object.name = data.name; } + + if ( data.matrix !== undefined ) { + + object.matrix.fromArray( data.matrix ); + + if ( data.matrixAutoUpdate !== undefined ) { object.matrixAutoUpdate = data.matrixAutoUpdate; } + if ( object.matrixAutoUpdate ) { object.matrix.decompose( object.position, object.quaternion, object.scale ); } + + } else { + + if ( data.position !== undefined ) { object.position.fromArray( data.position ); } + if ( data.rotation !== undefined ) { object.rotation.fromArray( data.rotation ); } + if ( data.quaternion !== undefined ) { object.quaternion.fromArray( data.quaternion ); } + if ( data.scale !== undefined ) { object.scale.fromArray( data.scale ); } + + } + + if ( data.castShadow !== undefined ) { object.castShadow = data.castShadow; } + if ( data.receiveShadow !== undefined ) { object.receiveShadow = data.receiveShadow; } + + if ( data.shadow ) { + + if ( data.shadow.bias !== undefined ) { object.shadow.bias = data.shadow.bias; } + if ( data.shadow.normalBias !== undefined ) { object.shadow.normalBias = data.shadow.normalBias; } + if ( data.shadow.radius !== undefined ) { object.shadow.radius = data.shadow.radius; } + if ( data.shadow.mapSize !== undefined ) { object.shadow.mapSize.fromArray( data.shadow.mapSize ); } + if ( data.shadow.camera !== undefined ) { object.shadow.camera = this.parseObject( data.shadow.camera ); } + + } + + if ( data.visible !== undefined ) { object.visible = data.visible; } + if ( data.frustumCulled !== undefined ) { object.frustumCulled = data.frustumCulled; } + if ( data.renderOrder !== undefined ) { object.renderOrder = data.renderOrder; } + if ( data.userData !== undefined ) { object.userData = data.userData; } + if ( data.layers !== undefined ) { object.layers.mask = data.layers; } + + if ( data.children !== undefined ) { + + var children = data.children; + + for ( var i = 0; i < children.length; i ++ ) { + + object.add( this.parseObject( children[ i ], geometries, materials ) ); + + } + + } + + if ( data.type === 'LOD' ) { + + if ( data.autoUpdate !== undefined ) { object.autoUpdate = data.autoUpdate; } + + var levels = data.levels; + + for ( var l = 0; l < levels.length; l ++ ) { + + var level = levels[ l ]; + var child = object.getObjectByProperty( 'uuid', level.object ); + + if ( child !== undefined ) { + + object.addLevel( child, level.distance ); + + } + + } + + } + + return object; + + } + + } ); + + var TEXTURE_MAPPING = { + UVMapping: UVMapping, + CubeReflectionMapping: CubeReflectionMapping, + CubeRefractionMapping: CubeRefractionMapping, + EquirectangularReflectionMapping: EquirectangularReflectionMapping, + EquirectangularRefractionMapping: EquirectangularRefractionMapping, + CubeUVReflectionMapping: CubeUVReflectionMapping, + CubeUVRefractionMapping: CubeUVRefractionMapping + }; + + var TEXTURE_WRAPPING = { + RepeatWrapping: RepeatWrapping, + ClampToEdgeWrapping: ClampToEdgeWrapping, + MirroredRepeatWrapping: MirroredRepeatWrapping + }; + + var TEXTURE_FILTER = { + NearestFilter: NearestFilter, + NearestMipmapNearestFilter: NearestMipmapNearestFilter, + NearestMipmapLinearFilter: NearestMipmapLinearFilter, + LinearFilter: LinearFilter, + LinearMipmapNearestFilter: LinearMipmapNearestFilter, + LinearMipmapLinearFilter: LinearMipmapLinearFilter + }; + + function ImageBitmapLoader( manager ) { + + if ( typeof createImageBitmap === 'undefined' ) { + + console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' ); + + } + + if ( typeof fetch === 'undefined' ) { + + console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' ); + + } + + Loader.call( this, manager ); + + this.options = { premultiplyAlpha: 'none' }; + + } + + ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: ImageBitmapLoader, + + isImageBitmapLoader: true, + + setOptions: function setOptions( options ) { + + this.options = options; + + return this; + + }, + + load: function ( url, onLoad, onProgress, onError ) { + + if ( url === undefined ) { url = ''; } + + if ( this.path !== undefined ) { url = this.path + url; } + + url = this.manager.resolveURL( url ); + + var scope = this; + + var cached = Cache.get( url ); + + if ( cached !== undefined ) { + + scope.manager.itemStart( url ); + + setTimeout( function () { + + if ( onLoad ) { onLoad( cached ); } + + scope.manager.itemEnd( url ); + + }, 0 ); + + return cached; + + } + + fetch( url ).then( function ( res ) { + + return res.blob(); + + } ).then( function ( blob ) { + + return createImageBitmap( blob, scope.options ); + + } ).then( function ( imageBitmap ) { + + Cache.add( url, imageBitmap ); + + if ( onLoad ) { onLoad( imageBitmap ); } + + scope.manager.itemEnd( url ); + + } ).catch( function ( e ) { + + if ( onError ) { onError( e ); } + + scope.manager.itemError( url ); + scope.manager.itemEnd( url ); + + } ); + + scope.manager.itemStart( url ); + + } + + } ); + + function ShapePath() { + + this.type = 'ShapePath'; + + this.color = new Color(); + + this.subPaths = []; + this.currentPath = null; + + } + + Object.assign( ShapePath.prototype, { + + moveTo: function ( x, y ) { + + this.currentPath = new Path(); + this.subPaths.push( this.currentPath ); + this.currentPath.moveTo( x, y ); + + return this; + + }, + + lineTo: function ( x, y ) { + + this.currentPath.lineTo( x, y ); + + return this; + + }, + + quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) { + + this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY ); + + return this; + + }, + + bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) { + + this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ); + + return this; + + }, + + splineThru: function ( pts ) { + + this.currentPath.splineThru( pts ); + + return this; + + }, + + toShapes: function ( isCCW, noHoles ) { + + function toShapesNoHoles( inSubpaths ) { + + var shapes = []; + + for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) { + + var tmpPath = inSubpaths[ i ]; + + var tmpShape = new Shape(); + tmpShape.curves = tmpPath.curves; + + shapes.push( tmpShape ); + + } + + return shapes; + + } + + function isPointInsidePolygon( inPt, inPolygon ) { + + var polyLen = inPolygon.length; + + // inPt on polygon contour => immediate success or + // toggling of inside/outside at every single! intersection point of an edge + // with the horizontal line through inPt, left of inPt + // not counting lowerY endpoints of edges and whole edges on that line + var inside = false; + for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) { + + var edgeLowPt = inPolygon[ p ]; + var edgeHighPt = inPolygon[ q ]; + + var edgeDx = edgeHighPt.x - edgeLowPt.x; + var edgeDy = edgeHighPt.y - edgeLowPt.y; + + if ( Math.abs( edgeDy ) > Number.EPSILON ) { + + // not parallel + if ( edgeDy < 0 ) { + + edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx; + edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy; + + } + + if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) { continue; } + + if ( inPt.y === edgeLowPt.y ) { + + if ( inPt.x === edgeLowPt.x ) { return true; } // inPt is on contour ? + // continue; // no intersection or edgeLowPt => doesn't count !!! + + } else { + + var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y ); + if ( perpEdge === 0 ) { return true; } // inPt is on contour ? + if ( perpEdge < 0 ) { continue; } + inside = ! inside; // true intersection left of inPt + + } + + } else { + + // parallel or collinear + if ( inPt.y !== edgeLowPt.y ) { continue; } // parallel + // edge lies on the same horizontal line as inPt + if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) || + ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) { return true; } // inPt: Point on contour ! + // continue; + + } + + } + + return inside; + + } + + var isClockWise = ShapeUtils.isClockWise; + + var subPaths = this.subPaths; + if ( subPaths.length === 0 ) { return []; } + + if ( noHoles === true ) { return toShapesNoHoles( subPaths ); } + + + var solid, tmpPath, tmpShape, shapes = []; + + if ( subPaths.length === 1 ) { + + tmpPath = subPaths[ 0 ]; + tmpShape = new Shape(); + tmpShape.curves = tmpPath.curves; + shapes.push( tmpShape ); + return shapes; + + } + + var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() ); + holesFirst = isCCW ? ! holesFirst : holesFirst; + + // console.log("Holes first", holesFirst); + + var betterShapeHoles = []; + var newShapes = []; + var newShapeHoles = []; + var mainIdx = 0; + var tmpPoints; + + newShapes[ mainIdx ] = undefined; + newShapeHoles[ mainIdx ] = []; + + for ( var i = 0, l = subPaths.length; i < l; i ++ ) { + + tmpPath = subPaths[ i ]; + tmpPoints = tmpPath.getPoints(); + solid = isClockWise( tmpPoints ); + solid = isCCW ? ! solid : solid; + + if ( solid ) { + + if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) { mainIdx ++; } + + newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints }; + newShapes[ mainIdx ].s.curves = tmpPath.curves; + + if ( holesFirst ) { mainIdx ++; } + newShapeHoles[ mainIdx ] = []; + + //console.log('cw', i); + + } else { + + newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } ); + + //console.log('ccw', i); + + } + + } + + // only Holes? -> probably all Shapes with wrong orientation + if ( ! newShapes[ 0 ] ) { return toShapesNoHoles( subPaths ); } + + + if ( newShapes.length > 1 ) { + + var ambiguous = false; + var toChange = []; + + for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) { + + betterShapeHoles[ sIdx ] = []; + + } + + for ( var sIdx$1 = 0, sLen$1 = newShapes.length; sIdx$1 < sLen$1; sIdx$1 ++ ) { + + var sho = newShapeHoles[ sIdx$1 ]; + + for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) { + + var ho = sho[ hIdx ]; + var hole_unassigned = true; + + for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) { + + if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) { + + if ( sIdx$1 !== s2Idx ) { toChange.push( { froms: sIdx$1, tos: s2Idx, hole: hIdx } ); } + if ( hole_unassigned ) { + + hole_unassigned = false; + betterShapeHoles[ s2Idx ].push( ho ); + + } else { + + ambiguous = true; + + } + + } + + } + + if ( hole_unassigned ) { + + betterShapeHoles[ sIdx$1 ].push( ho ); + + } + + } + + } + // console.log("ambiguous: ", ambiguous); + + if ( toChange.length > 0 ) { + + // console.log("to change: ", toChange); + if ( ! ambiguous ) { newShapeHoles = betterShapeHoles; } + + } + + } + + var tmpHoles; + + for ( var i$1 = 0, il = newShapes.length; i$1 < il; i$1 ++ ) { + + tmpShape = newShapes[ i$1 ].s; + shapes.push( tmpShape ); + tmpHoles = newShapeHoles[ i$1 ]; + + for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) { + + tmpShape.holes.push( tmpHoles[ j ].h ); + + } + + } + + //console.log("shape", shapes); + + return shapes; + + } + + } ); + + function Font( data ) { + + this.type = 'Font'; + + this.data = data; + + } + + Object.assign( Font.prototype, { + + isFont: true, + + generateShapes: function ( text, size ) { + + if ( size === undefined ) { size = 100; } + + var shapes = []; + var paths = createPaths( text, size, this.data ); + + for ( var p = 0, pl = paths.length; p < pl; p ++ ) { + + Array.prototype.push.apply( shapes, paths[ p ].toShapes() ); + + } + + return shapes; + + } + + } ); + + function createPaths( text, size, data ) { + + var chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // workaround for IE11, see #13988 + var scale = size / data.resolution; + var line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale; + + var paths = []; + + var offsetX = 0, offsetY = 0; + + for ( var i = 0; i < chars.length; i ++ ) { + + var char = chars[ i ]; + + if ( char === '\n' ) { + + offsetX = 0; + offsetY -= line_height; + + } else { + + var ret = createPath( char, scale, offsetX, offsetY, data ); + offsetX += ret.offsetX; + paths.push( ret.path ); + + } + + } + + return paths; + + } + + function createPath( char, scale, offsetX, offsetY, data ) { + + var glyph = data.glyphs[ char ] || data.glyphs[ '?' ]; + + if ( ! glyph ) { + + console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' ); + + return; + + } + + var path = new ShapePath(); + + var x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2; + + if ( glyph.o ) { + + var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) ); + + for ( var i = 0, l = outline.length; i < l; ) { + + var action = outline[ i ++ ]; + + switch ( action ) { + + case 'm': // moveTo + + x = outline[ i ++ ] * scale + offsetX; + y = outline[ i ++ ] * scale + offsetY; + + path.moveTo( x, y ); + + break; + + case 'l': // lineTo + + x = outline[ i ++ ] * scale + offsetX; + y = outline[ i ++ ] * scale + offsetY; + + path.lineTo( x, y ); + + break; + + case 'q': // quadraticCurveTo + + cpx = outline[ i ++ ] * scale + offsetX; + cpy = outline[ i ++ ] * scale + offsetY; + cpx1 = outline[ i ++ ] * scale + offsetX; + cpy1 = outline[ i ++ ] * scale + offsetY; + + path.quadraticCurveTo( cpx1, cpy1, cpx, cpy ); + + break; + + case 'b': // bezierCurveTo + + cpx = outline[ i ++ ] * scale + offsetX; + cpy = outline[ i ++ ] * scale + offsetY; + cpx1 = outline[ i ++ ] * scale + offsetX; + cpy1 = outline[ i ++ ] * scale + offsetY; + cpx2 = outline[ i ++ ] * scale + offsetX; + cpy2 = outline[ i ++ ] * scale + offsetY; + + path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy ); + + break; + + } + + } + + } + + return { offsetX: glyph.ha * scale, path: path }; + + } + + function FontLoader( manager ) { + + Loader.call( this, manager ); + + } + + FontLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: FontLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + var scope = this; + + var loader = new FileLoader( this.manager ); + loader.setPath( this.path ); + loader.setRequestHeader( this.requestHeader ); + loader.load( url, function ( text ) { + + var json; + + try { + + json = JSON.parse( text ); + + } catch ( e ) { + + console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' ); + json = JSON.parse( text.substring( 65, text.length - 2 ) ); + + } + + var font = scope.parse( json ); + + if ( onLoad ) { onLoad( font ); } + + }, onProgress, onError ); + + }, + + parse: function ( json ) { + + return new Font( json ); + + } + + } ); + + var _context; + + var AudioContext = { + + getContext: function () { + + if ( _context === undefined ) { + + _context = new ( window.AudioContext || window.webkitAudioContext )(); + + } + + return _context; + + }, + + setContext: function ( value ) { + + _context = value; + + } + + }; + + function AudioLoader( manager ) { + + Loader.call( this, manager ); + + } + + AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), { + + constructor: AudioLoader, + + load: function ( url, onLoad, onProgress, onError ) { + + var scope = this; + + var loader = new FileLoader( scope.manager ); + loader.setResponseType( 'arraybuffer' ); + loader.setPath( scope.path ); + loader.setRequestHeader( scope.requestHeader ); + loader.load( url, function ( buffer ) { + + try { + + // Create a copy of the buffer. The `decodeAudioData` method + // detaches the buffer when complete, preventing reuse. + var bufferCopy = buffer.slice( 0 ); + + var context = AudioContext.getContext(); + context.decodeAudioData( bufferCopy, function ( audioBuffer ) { + + onLoad( audioBuffer ); + + } ); + + } catch ( e ) { + + if ( onError ) { + + onError( e ); + + } else { + + console.error( e ); + + } + + scope.manager.itemError( url ); + + } + + }, onProgress, onError ); + + } + + } ); + + function HemisphereLightProbe( skyColor, groundColor, intensity ) { + + LightProbe.call( this, undefined, intensity ); + + var color1 = new Color().set( skyColor ); + var color2 = new Color().set( groundColor ); + + var sky = new Vector3( color1.r, color1.g, color1.b ); + var ground = new Vector3( color2.r, color2.g, color2.b ); + + // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI ); + var c0 = Math.sqrt( Math.PI ); + var c1 = c0 * Math.sqrt( 0.75 ); + + this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 ); + this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 ); + + } + + HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), { + + constructor: HemisphereLightProbe, + + isHemisphereLightProbe: true, + + copy: function ( source ) { // modifying colors not currently supported + + LightProbe.prototype.copy.call( this, source ); + + return this; + + }, + + toJSON: function ( meta ) { + + var data = LightProbe.prototype.toJSON.call( this, meta ); + + // data.sh = this.sh.toArray(); // todo + + return data; + + } + + } ); + + function AmbientLightProbe( color, intensity ) { + + LightProbe.call( this, undefined, intensity ); + + var color1 = new Color().set( color ); + + // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI ); + this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) ); + + } + + AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), { + + constructor: AmbientLightProbe, + + isAmbientLightProbe: true, + + copy: function ( source ) { // modifying color not currently supported + + LightProbe.prototype.copy.call( this, source ); + + return this; + + }, + + toJSON: function ( meta ) { + + var data = LightProbe.prototype.toJSON.call( this, meta ); + + // data.sh = this.sh.toArray(); // todo + + return data; + + } + + } ); + + var _eyeRight = new Matrix4(); + var _eyeLeft = new Matrix4(); + + function StereoCamera() { + + this.type = 'StereoCamera'; + + this.aspect = 1; + + this.eyeSep = 0.064; + + this.cameraL = new PerspectiveCamera(); + this.cameraL.layers.enable( 1 ); + this.cameraL.matrixAutoUpdate = false; + + this.cameraR = new PerspectiveCamera(); + this.cameraR.layers.enable( 2 ); + this.cameraR.matrixAutoUpdate = false; + + this._cache = { + focus: null, + fov: null, + aspect: null, + near: null, + far: null, + zoom: null, + eyeSep: null + }; + + } + + Object.assign( StereoCamera.prototype, { + + update: function ( camera ) { + + var cache = this._cache; + + 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; + + if ( 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; + + // Off-axis stereoscopic effect based on + // http://paulbourke.net/stereographics/stereorender/ + + var projectionMatrix = camera.projectionMatrix.clone(); + var eyeSepHalf = cache.eyeSep / 2; + var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus; + var ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom; + var xmin, xmax; + + // translate xOffset + + _eyeLeft.elements[ 12 ] = - eyeSepHalf; + _eyeRight.elements[ 12 ] = eyeSepHalf; + + // for left eye + + xmin = - ymax * cache.aspect + eyeSepOnProjection; + xmax = ymax * cache.aspect + eyeSepOnProjection; + + projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin ); + projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin ); + + this.cameraL.projectionMatrix.copy( projectionMatrix ); + + // for right eye + + xmin = - ymax * cache.aspect - eyeSepOnProjection; + xmax = ymax * cache.aspect - eyeSepOnProjection; + + projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin ); + projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin ); + + this.cameraR.projectionMatrix.copy( projectionMatrix ); + + } + + this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft ); + this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight ); + + } + + } ); + + function Clock( autoStart ) { + + this.autoStart = ( autoStart !== undefined ) ? autoStart : true; + + this.startTime = 0; + this.oldTime = 0; + this.elapsedTime = 0; + + this.running = false; + + } + + Object.assign( Clock.prototype, { + + start: function () { + + this.startTime = ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732 + + this.oldTime = this.startTime; + this.elapsedTime = 0; + this.running = true; + + }, + + stop: function () { + + this.getElapsedTime(); + this.running = false; + this.autoStart = false; + + }, + + getElapsedTime: function () { + + this.getDelta(); + return this.elapsedTime; + + }, + + getDelta: function () { + + var diff = 0; + + if ( this.autoStart && ! this.running ) { + + this.start(); + return 0; + + } + + if ( this.running ) { + + var newTime = ( typeof performance === 'undefined' ? Date : performance ).now(); + + diff = ( newTime - this.oldTime ) / 1000; + this.oldTime = newTime; + + this.elapsedTime += diff; + + } + + return diff; + + } + + } ); + + var _position$2 = new Vector3(); + var _quaternion$3 = new Quaternion(); + var _scale$1 = new Vector3(); + var _orientation = new Vector3(); + + function AudioListener() { + + Object3D.call( this ); + + this.type = 'AudioListener'; + + this.context = AudioContext.getContext(); + + this.gain = this.context.createGain(); + this.gain.connect( this.context.destination ); + + this.filter = null; + + this.timeDelta = 0; + + // private + + this._clock = new Clock(); + + } + + AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: AudioListener, + + getInput: function () { + + return this.gain; + + }, + + removeFilter: function ( ) { + + if ( this.filter !== null ) { + + this.gain.disconnect( this.filter ); + this.filter.disconnect( this.context.destination ); + this.gain.connect( this.context.destination ); + this.filter = null; + + } + + return this; + + }, + + getFilter: function () { + + return this.filter; + + }, + + setFilter: function ( value ) { + + if ( this.filter !== null ) { + + this.gain.disconnect( this.filter ); + this.filter.disconnect( this.context.destination ); + + } else { + + this.gain.disconnect( this.context.destination ); + + } + + this.filter = value; + this.gain.connect( this.filter ); + this.filter.connect( this.context.destination ); + + return this; + + }, + + getMasterVolume: function () { + + return this.gain.gain.value; + + }, + + setMasterVolume: function ( value ) { + + this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 ); + + return this; + + }, + + updateMatrixWorld: function ( force ) { + + Object3D.prototype.updateMatrixWorld.call( this, force ); + + var listener = this.context.listener; + var up = this.up; + + this.timeDelta = this._clock.getDelta(); + + this.matrixWorld.decompose( _position$2, _quaternion$3, _scale$1 ); + + _orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion$3 ); + + if ( listener.positionX ) { + + // code path for Chrome (see #14393) + + var endTime = this.context.currentTime + this.timeDelta; + + listener.positionX.linearRampToValueAtTime( _position$2.x, endTime ); + listener.positionY.linearRampToValueAtTime( _position$2.y, endTime ); + listener.positionZ.linearRampToValueAtTime( _position$2.z, endTime ); + listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime ); + listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime ); + listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime ); + listener.upX.linearRampToValueAtTime( up.x, endTime ); + listener.upY.linearRampToValueAtTime( up.y, endTime ); + listener.upZ.linearRampToValueAtTime( up.z, endTime ); + + } else { + + listener.setPosition( _position$2.x, _position$2.y, _position$2.z ); + listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z ); + + } + + } + + } ); + + function Audio( listener ) { + + Object3D.call( this ); + + this.type = 'Audio'; + + this.listener = listener; + this.context = listener.context; + + this.gain = this.context.createGain(); + this.gain.connect( listener.getInput() ); + + this.autoplay = false; + + this.buffer = null; + this.detune = 0; + this.loop = false; + this.loopStart = 0; + this.loopEnd = 0; + this.offset = 0; + this.duration = undefined; + this.playbackRate = 1; + this.isPlaying = false; + this.hasPlaybackControl = true; + this.sourceType = 'empty'; + + this._startedAt = 0; + this._progress = 0; + + this.filters = []; + + } + + Audio.prototype = Object.assign( Object.create( Object3D.prototype ), { + + constructor: Audio, + + getOutput: function () { + + return this.gain; + + }, + + setNodeSource: function ( audioNode ) { + + this.hasPlaybackControl = false; + this.sourceType = 'audioNode'; + this.source = audioNode; + this.connect(); + + return this; + + }, + + setMediaElementSource: function ( mediaElement ) { + + this.hasPlaybackControl = false; + this.sourceType = 'mediaNode'; + this.source = this.context.createMediaElementSource( mediaElement ); + this.connect(); + + return this; + + }, + + setMediaStreamSource: function ( mediaStream ) { + + this.hasPlaybackControl = false; + this.sourceType = 'mediaStreamNode'; + this.source = this.context.createMediaStreamSource( mediaStream ); + this.connect(); + + return this; + + }, + + setBuffer: function ( audioBuffer ) { + + this.buffer = audioBuffer; + this.sourceType = 'buffer'; + + if ( this.autoplay ) { this.play(); } + + return this; + + }, + + play: function ( delay ) { + + if ( delay === undefined ) { delay = 0; } + + if ( this.isPlaying === true ) { + + console.warn( 'THREE.Audio: Audio is already playing.' ); + return; + + } + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return; + + } + + this._startedAt = this.context.currentTime + delay; + + var source = this.context.createBufferSource(); + source.buffer = this.buffer; + source.loop = this.loop; + source.loopStart = this.loopStart; + source.loopEnd = this.loopEnd; + source.onended = this.onEnded.bind( this ); + source.start( this._startedAt, this._progress + this.offset, this.duration ); + + this.isPlaying = true; + + this.source = source; + + this.setDetune( this.detune ); + this.setPlaybackRate( this.playbackRate ); + + return this.connect(); + + }, + + pause: function () { + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return; + + } + + if ( this.isPlaying === true ) { + + // update current progress + + this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate; + + if ( this.loop === true ) { + + // ensure _progress does not exceed duration with looped audios + + this._progress = this._progress % ( this.duration || this.buffer.duration ); + + } + + this.source.stop(); + this.source.onended = null; + + this.isPlaying = false; + + } + + return this; + + }, + + stop: function () { + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return; + + } + + this._progress = 0; + + this.source.stop(); + this.source.onended = null; + this.isPlaying = false; + + return this; + + }, + + connect: function () { + + if ( this.filters.length > 0 ) { + + this.source.connect( this.filters[ 0 ] ); + + for ( var i = 1, l = this.filters.length; i < l; i ++ ) { + + this.filters[ i - 1 ].connect( this.filters[ i ] ); + + } + + this.filters[ this.filters.length - 1 ].connect( this.getOutput() ); + + } else { + + this.source.connect( this.getOutput() ); + + } + + return this; + + }, + + disconnect: function () { + + if ( this.filters.length > 0 ) { + + this.source.disconnect( this.filters[ 0 ] ); + + for ( var i = 1, l = this.filters.length; i < l; i ++ ) { + + this.filters[ i - 1 ].disconnect( this.filters[ i ] ); + + } + + this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() ); + + } else { + + this.source.disconnect( this.getOutput() ); + + } + + return this; + + }, + + getFilters: function () { + + return this.filters; + + }, + + setFilters: function ( value ) { + + if ( ! value ) { value = []; } + + if ( this.isPlaying === true ) { + + this.disconnect(); + this.filters = value; + this.connect(); + + } else { + + this.filters = value; + + } + + return this; + + }, + + setDetune: function ( value ) { + + this.detune = value; + + if ( this.source.detune === undefined ) { return; } // only set detune when available + + if ( this.isPlaying === true ) { + + this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 ); + + } + + return this; + + }, + + getDetune: function () { + + return this.detune; + + }, + + getFilter: function () { + + return this.getFilters()[ 0 ]; + + }, + + setFilter: function ( filter ) { + + return this.setFilters( filter ? [ filter ] : [] ); + + }, + + setPlaybackRate: function ( value ) { + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return; + + } + + this.playbackRate = value; + + if ( this.isPlaying === true ) { + + this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 ); + + } + + return this; + + }, + + getPlaybackRate: function () { + + return this.playbackRate; + + }, + + onEnded: function () { + + this.isPlaying = false; + + }, + + getLoop: function () { + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return false; + + } + + return this.loop; + + }, + + setLoop: function ( value ) { + + if ( this.hasPlaybackControl === false ) { + + console.warn( 'THREE.Audio: this Audio has no playback control.' ); + return; + + } + + this.loop = value; + + if ( this.isPlaying === true ) { + + this.source.loop = this.loop; + + } + + return this; + + }, + + setLoopStart: function ( value ) { + + this.loopStart = value; + + return this; + + }, + + setLoopEnd: function ( value ) { + + this.loopEnd = value; + + return this; + + }, + + getVolume: function () { + + return this.gain.gain.value; + + }, + + setVolume: function ( value ) { + + this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 ); + + return this; + + } + + } ); + + var _position$3 = new Vector3(); + var _quaternion$4 = new Quaternion(); + var _scale$2 = new Vector3(); + var _orientation$1 = new Vector3(); + + function PositionalAudio( listener ) { + + Audio.call( this, listener ); + + this.panner = this.context.createPanner(); + this.panner.panningModel = 'HRTF'; + this.panner.connect( this.gain ); + + } + + PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), { + + constructor: PositionalAudio, + + getOutput: function () { + + return this.panner; + + }, + + getRefDistance: function () { + + return this.panner.refDistance; + + }, + + setRefDistance: function ( value ) { + + this.panner.refDistance = value; + + return this; + + }, + + getRolloffFactor: function () { + + return this.panner.rolloffFactor; + + }, + + setRolloffFactor: function ( value ) { + + this.panner.rolloffFactor = value; + + return this; + + }, + + getDistanceModel: function () { + + return this.panner.distanceModel; + + }, + + setDistanceModel: function ( value ) { + + this.panner.distanceModel = value; + + return this; + + }, + + getMaxDistance: function () { + + return this.panner.maxDistance; + + }, + + setMaxDistance: function ( value ) { + + this.panner.maxDistance = value; + + return this; + + }, + + setDirectionalCone: function ( coneInnerAngle, coneOuterAngle, coneOuterGain ) { + + this.panner.coneInnerAngle = coneInnerAngle; + this.panner.coneOuterAngle = coneOuterAngle; + this.panner.coneOuterGain = coneOuterGain; + + return this; + + }, + + updateMatrixWorld: function ( force ) { + + Object3D.prototype.updateMatrixWorld.call( this, force ); + + if ( this.hasPlaybackControl === true && this.isPlaying === false ) { return; } + + this.matrixWorld.decompose( _position$3, _quaternion$4, _scale$2 ); + + _orientation$1.set( 0, 0, 1 ).applyQuaternion( _quaternion$4 ); + + var panner = this.panner; + + if ( panner.positionX ) { + + // code path for Chrome and Firefox (see #14393) + + var endTime = this.context.currentTime + this.listener.timeDelta; + + panner.positionX.linearRampToValueAtTime( _position$3.x, endTime ); + panner.positionY.linearRampToValueAtTime( _position$3.y, endTime ); + panner.positionZ.linearRampToValueAtTime( _position$3.z, endTime ); + panner.orientationX.linearRampToValueAtTime( _orientation$1.x, endTime ); + panner.orientationY.linearRampToValueAtTime( _orientation$1.y, endTime ); + panner.orientationZ.linearRampToValueAtTime( _orientation$1.z, endTime ); + + } else { + + panner.setPosition( _position$3.x, _position$3.y, _position$3.z ); + panner.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z ); + + } + + } + + } ); + + function AudioAnalyser( audio, fftSize ) { + + this.analyser = audio.context.createAnalyser(); + this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048; + + this.data = new Uint8Array( this.analyser.frequencyBinCount ); + + audio.getOutput().connect( this.analyser ); + + } + + Object.assign( AudioAnalyser.prototype, { + + getFrequencyData: function () { + + this.analyser.getByteFrequencyData( this.data ); + + return this.data; + + }, + + getAverageFrequency: function () { + + var value = 0; + var data = this.getFrequencyData(); + + for ( var i = 0; i < data.length; i ++ ) { + + value += data[ i ]; + + } + + return value / data.length; + + } + + } ); + + function PropertyMixer( binding, typeName, valueSize ) { + + this.binding = binding; + this.valueSize = valueSize; + + var mixFunction, + mixFunctionAdditive, + setIdentity; + + // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ] + // + // interpolators can use .buffer as their .result + // the data then goes to 'incoming' + // + // 'accu0' and 'accu1' are used frame-interleaved for + // the cumulative result and are compared to detect + // changes + // + // 'orig' stores the original state of the property + // + // 'add' is used for additive cumulative results + // + // 'work' is optional and is only present for quaternion types. It is used + // to store intermediate quaternion multiplication results + + switch ( typeName ) { + + case 'quaternion': + mixFunction = this._slerp; + mixFunctionAdditive = this._slerpAdditive; + setIdentity = this._setAdditiveIdentityQuaternion; + + this.buffer = new Float64Array( valueSize * 6 ); + this._workIndex = 5; + break; + + case 'string': + case 'bool': + mixFunction = this._select; + + // Use the regular mix function and for additive on these types, + // additive is not relevant for non-numeric types + mixFunctionAdditive = this._select; + + setIdentity = this._setAdditiveIdentityOther; + + this.buffer = new Array( valueSize * 5 ); + break; + + default: + mixFunction = this._lerp; + mixFunctionAdditive = this._lerpAdditive; + setIdentity = this._setAdditiveIdentityNumeric; + + this.buffer = new Float64Array( valueSize * 5 ); + + } + + this._mixBufferRegion = mixFunction; + this._mixBufferRegionAdditive = mixFunctionAdditive; + this._setIdentity = setIdentity; + this._origIndex = 3; + this._addIndex = 4; + + this.cumulativeWeight = 0; + this.cumulativeWeightAdditive = 0; + + this.useCount = 0; + this.referenceCount = 0; + + } + + Object.assign( PropertyMixer.prototype, { + + // accumulate data in the 'incoming' region into 'accu' + accumulate: function ( accuIndex, weight ) { + + // note: happily accumulating nothing when weight = 0, the caller knows + // the weight and shouldn't have made the call in the first place + + var buffer = this.buffer, + stride = this.valueSize, + offset = accuIndex * stride + stride; + + var currentWeight = this.cumulativeWeight; + + if ( currentWeight === 0 ) { + + // accuN := incoming * weight + + for ( var i = 0; i !== stride; ++ i ) { + + buffer[ offset + i ] = buffer[ i ]; + + } + + currentWeight = weight; + + } else { + + // accuN := accuN + incoming * weight + + currentWeight += weight; + var mix = weight / currentWeight; + this._mixBufferRegion( buffer, offset, 0, mix, stride ); + + } + + this.cumulativeWeight = currentWeight; + + }, + + // accumulate data in the 'incoming' region into 'add' + accumulateAdditive: function ( weight ) { + + var buffer = this.buffer, + stride = this.valueSize, + offset = stride * this._addIndex; + + if ( this.cumulativeWeightAdditive === 0 ) { + + // add = identity + + this._setIdentity(); + + } + + // add := add + incoming * weight + + this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride ); + this.cumulativeWeightAdditive += weight; + + }, + + // apply the state of 'accu' to the binding when accus differ + apply: function ( accuIndex ) { + + var stride = this.valueSize, + buffer = this.buffer, + offset = accuIndex * stride + stride, + + weight = this.cumulativeWeight, + weightAdditive = this.cumulativeWeightAdditive, + + binding = this.binding; + + this.cumulativeWeight = 0; + this.cumulativeWeightAdditive = 0; + + if ( weight < 1 ) { + + // accuN := accuN + original * ( 1 - cumulativeWeight ) + + var originalValueOffset = stride * this._origIndex; + + this._mixBufferRegion( + buffer, offset, originalValueOffset, 1 - weight, stride ); + + } + + if ( weightAdditive > 0 ) { + + // accuN := accuN + additive accuN + + this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride ); + + } + + for ( var i = stride, e = stride + stride; i !== e; ++ i ) { + + if ( buffer[ i ] !== buffer[ i + stride ] ) { + + // value has changed -> update scene graph + + binding.setValue( buffer, offset ); + break; + + } + + } + + }, + + // remember the state of the bound property and copy it to both accus + saveOriginalState: function () { + + var binding = this.binding; + + var buffer = this.buffer, + stride = this.valueSize, + + originalValueOffset = stride * this._origIndex; + + binding.getValue( buffer, originalValueOffset ); + + // accu[0..1] := orig -- initially detect changes against the original + for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) { + + buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ]; + + } + + // Add to identity for additive + this._setIdentity(); + + this.cumulativeWeight = 0; + this.cumulativeWeightAdditive = 0; + + }, + + // apply the state previously taken via 'saveOriginalState' to the binding + restoreOriginalState: function () { + + var originalValueOffset = this.valueSize * 3; + this.binding.setValue( this.buffer, originalValueOffset ); + + }, + + _setAdditiveIdentityNumeric: function () { + + var startIndex = this._addIndex * this.valueSize; + var endIndex = startIndex + this.valueSize; + + for ( var i = startIndex; i < endIndex; i ++ ) { + + this.buffer[ i ] = 0; + + } + + }, + + _setAdditiveIdentityQuaternion: function () { + + this._setAdditiveIdentityNumeric(); + this.buffer[ this._addIndex * 4 + 3 ] = 1; + + }, + + _setAdditiveIdentityOther: function () { + + var startIndex = this._origIndex * this.valueSize; + var targetIndex = this._addIndex * this.valueSize; + + for ( var i = 0; i < this.valueSize; i ++ ) { + + this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ]; + + } + + }, + + + // mix functions + + _select: function ( buffer, dstOffset, srcOffset, t, stride ) { + + if ( t >= 0.5 ) { + + for ( var i = 0; i !== stride; ++ i ) { + + buffer[ dstOffset + i ] = buffer[ srcOffset + i ]; + + } + + } + + }, + + _slerp: function ( buffer, dstOffset, srcOffset, t ) { + + Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t ); + + }, + + _slerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) { + + var workOffset = this._workIndex * stride; + + // Store result in intermediate buffer offset + Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset ); + + // Slerp to the intermediate result + Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t ); + + }, + + _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) { + + var s = 1 - t; + + for ( var i = 0; i !== stride; ++ i ) { + + var j = dstOffset + i; + + buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t; + + } + + }, + + _lerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) { + + for ( var i = 0; i !== stride; ++ i ) { + + var j = dstOffset + i; + + buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t; + + } + + } + + } ); + + // Characters [].:/ are reserved for track binding syntax. + var _RESERVED_CHARS_RE = '\\[\\]\\.:\\/'; + var _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' ); + + // Attempts to allow node names from any language. ES5's `\w` regexp matches + // only latin characters, and the unicode \p{L} is not yet supported. So + // instead, we exclude reserved characters and match everything else. + var _wordChar = '[^' + _RESERVED_CHARS_RE + ']'; + var _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']'; + + // Parent directories, delimited by '/' or ':'. Currently unused, but must + // be matched to parse the rest of the track name. + var _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar ); + + // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'. + var _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot ); + + // Object on target node, and accessor. May not contain reserved + // characters. Accessor may contain any character except closing bracket. + var _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar ); + + // Property and accessor. May not contain reserved characters. Accessor may + // contain any non-bracket characters. + var _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar ); + + var _trackRe = new RegExp( '' + + '^' + + _directoryRe + + _nodeRe + + _objectRe + + _propertyRe + + '$' + ); + + var _supportedObjectNames = [ 'material', 'materials', 'bones' ]; + + function Composite( targetGroup, path, optionalParsedPath ) { + + var parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path ); + + this._targetGroup = targetGroup; + this._bindings = targetGroup.subscribe_( path, parsedPath ); + + } + + Object.assign( Composite.prototype, { + + getValue: function ( array, offset ) { + + this.bind(); // bind all binding + + var firstValidIndex = this._targetGroup.nCachedObjects_, + binding = this._bindings[ firstValidIndex ]; + + // and only call .getValue on the first + if ( binding !== undefined ) { binding.getValue( array, offset ); } + + }, + + setValue: function ( array, offset ) { + + var bindings = this._bindings; + + for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) { + + bindings[ i ].setValue( array, offset ); + + } + + }, + + bind: function () { + + var bindings = this._bindings; + + for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) { + + bindings[ i ].bind(); + + } + + }, + + unbind: function () { + + var bindings = this._bindings; + + for ( var i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) { + + bindings[ i ].unbind(); + + } + + } + + } ); + + + function PropertyBinding( rootNode, path, parsedPath ) { + + this.path = path; + this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path ); + + this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode; + + this.rootNode = rootNode; + + } + + Object.assign( PropertyBinding, { + + Composite: Composite, + + create: function ( root, path, parsedPath ) { + + if ( ! ( root && root.isAnimationObjectGroup ) ) { + + return new PropertyBinding( root, path, parsedPath ); + + } else { + + return new PropertyBinding.Composite( root, path, parsedPath ); + + } + + }, + + /** + * Replaces spaces with underscores and removes unsupported characters from + * node names, to ensure compatibility with parseTrackName(). + * + * @param {string} name Node name to be sanitized. + * @return {string} + */ + sanitizeNodeName: function ( name ) { + + return name.replace( /\s/g, '_' ).replace( _reservedRe, '' ); + + }, + + parseTrackName: function ( trackName ) { + + var matches = _trackRe.exec( trackName ); + + if ( ! matches ) { + + throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName ); + + } + + var results = { + // directoryName: matches[ 1 ], // (tschw) currently unused + nodeName: matches[ 2 ], + objectName: matches[ 3 ], + objectIndex: matches[ 4 ], + propertyName: matches[ 5 ], // required + propertyIndex: matches[ 6 ] + }; + + var lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' ); + + if ( lastDot !== undefined && lastDot !== - 1 ) { + + var objectName = results.nodeName.substring( lastDot + 1 ); + + // Object names must be checked against an allowlist. Otherwise, there + // is no way to parse 'foo.bar.baz': 'baz' must be a property, but + // 'bar' could be the objectName, or part of a nodeName (which can + // include '.' characters). + if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) { + + results.nodeName = results.nodeName.substring( 0, lastDot ); + results.objectName = objectName; + + } + + } + + if ( results.propertyName === null || results.propertyName.length === 0 ) { + + throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName ); + + } + + return results; + + }, + + findNode: function ( root, nodeName ) { + + if ( ! nodeName || nodeName === "" || nodeName === "." || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) { + + return root; + + } + + // search into skeleton bones. + if ( root.skeleton ) { + + var bone = root.skeleton.getBoneByName( nodeName ); + + if ( bone !== undefined ) { + + return bone; + + } + + } + + // search into node subtree. + if ( root.children ) { + + var searchNodeSubtree = function ( children ) { + + for ( var i = 0; i < children.length; i ++ ) { + + var childNode = children[ i ]; + + if ( childNode.name === nodeName || childNode.uuid === nodeName ) { + + return childNode; + + } + + var result = searchNodeSubtree( childNode.children ); + + if ( result ) { return result; } + + } + + return null; + + }; + + var subTreeNode = searchNodeSubtree( root.children ); + + if ( subTreeNode ) { + + return subTreeNode; + + } + + } + + return null; + + } + + } ); + + Object.assign( PropertyBinding.prototype, { // prototype, continued + + // these are used to "bind" a nonexistent property + _getValue_unavailable: function () {}, + _setValue_unavailable: function () {}, + + BindingType: { + Direct: 0, + EntireArray: 1, + ArrayElement: 2, + HasFromToArray: 3 + }, + + Versioning: { + None: 0, + NeedsUpdate: 1, + MatrixWorldNeedsUpdate: 2 + }, + + GetterByBindingType: [ + + function getValue_direct( buffer, offset ) { + + buffer[ offset ] = this.node[ this.propertyName ]; + + }, + + function getValue_array( buffer, offset ) { + + var source = this.resolvedProperty; + + for ( var i = 0, n = source.length; i !== n; ++ i ) { + + buffer[ offset ++ ] = source[ i ]; + + } + + }, + + function getValue_arrayElement( buffer, offset ) { + + buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ]; + + }, + + function getValue_toArray( buffer, offset ) { + + this.resolvedProperty.toArray( buffer, offset ); + + } + + ], + + SetterByBindingTypeAndVersioning: [ + + [ + // Direct + + function setValue_direct( buffer, offset ) { + + this.targetObject[ this.propertyName ] = buffer[ offset ]; + + }, + + function setValue_direct_setNeedsUpdate( buffer, offset ) { + + this.targetObject[ this.propertyName ] = buffer[ offset ]; + this.targetObject.needsUpdate = true; + + }, + + function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) { + + this.targetObject[ this.propertyName ] = buffer[ offset ]; + this.targetObject.matrixWorldNeedsUpdate = true; + + } + + ], [ + + // EntireArray + + function setValue_array( buffer, offset ) { + + var dest = this.resolvedProperty; + + for ( var i = 0, n = dest.length; i !== n; ++ i ) { + + dest[ i ] = buffer[ offset ++ ]; + + } + + }, + + function setValue_array_setNeedsUpdate( buffer, offset ) { + + var dest = this.resolvedProperty; + + for ( var i = 0, n = dest.length; i !== n; ++ i ) { + + dest[ i ] = buffer[ offset ++ ]; + + } + + this.targetObject.needsUpdate = true; + + }, + + function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) { + + var dest = this.resolvedProperty; + + for ( var i = 0, n = dest.length; i !== n; ++ i ) { + + dest[ i ] = buffer[ offset ++ ]; + + } + + this.targetObject.matrixWorldNeedsUpdate = true; + + } + + ], [ + + // ArrayElement + + function setValue_arrayElement( buffer, offset ) { + + this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ]; + + }, + + function setValue_arrayElement_setNeedsUpdate( buffer, offset ) { + + this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ]; + this.targetObject.needsUpdate = true; + + }, + + function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) { + + this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ]; + this.targetObject.matrixWorldNeedsUpdate = true; + + } + + ], [ + + // HasToFromArray + + function setValue_fromArray( buffer, offset ) { + + this.resolvedProperty.fromArray( buffer, offset ); + + }, + + function setValue_fromArray_setNeedsUpdate( buffer, offset ) { + + this.resolvedProperty.fromArray( buffer, offset ); + this.targetObject.needsUpdate = true; + + }, + + function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) { + + this.resolvedProperty.fromArray( buffer, offset ); + this.targetObject.matrixWorldNeedsUpdate = true; + + } + + ] + + ], + + getValue: function getValue_unbound( targetArray, offset ) { + + this.bind(); + this.getValue( targetArray, offset ); + + // Note: This class uses a State pattern on a per-method basis: + // 'bind' sets 'this.getValue' / 'setValue' and shadows the + // prototype version of these methods with one that represents + // the bound state. When the property is not found, the methods + // become no-ops. + + }, + + setValue: function getValue_unbound( sourceArray, offset ) { + + this.bind(); + this.setValue( sourceArray, offset ); + + }, + + // create getter / setter pair for a property in the scene graph + bind: function () { + + var targetObject = this.node, + parsedPath = this.parsedPath, + + objectName = parsedPath.objectName, + propertyName = parsedPath.propertyName, + propertyIndex = parsedPath.propertyIndex; + + if ( ! targetObject ) { + + targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode; + + this.node = targetObject; + + } + + // set fail state so we can just 'return' on error + this.getValue = this._getValue_unavailable; + this.setValue = this._setValue_unavailable; + + // ensure there is a value node + if ( ! targetObject ) { + + console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' ); + return; + + } + + if ( objectName ) { + + var objectIndex = parsedPath.objectIndex; + + // special cases were we need to reach deeper into the hierarchy to get the face materials.... + switch ( objectName ) { + + case 'materials': + + if ( ! targetObject.material ) { + + console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this ); + return; + + } + + if ( ! targetObject.material.materials ) { + + console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this ); + return; + + } + + targetObject = targetObject.material.materials; + + break; + + case 'bones': + + if ( ! targetObject.skeleton ) { + + console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this ); + return; + + } + + // potential future optimization: skip this if propertyIndex is already an integer + // and convert the integer string to a true integer. + + targetObject = targetObject.skeleton.bones; + + // support resolving morphTarget names into indices. + for ( var i = 0; i < targetObject.length; i ++ ) { + + if ( targetObject[ i ].name === objectIndex ) { + + objectIndex = i; + break; + + } + + } + + break; + + default: + + if ( targetObject[ objectName ] === undefined ) { + + console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this ); + return; + + } + + targetObject = targetObject[ objectName ]; + + } + + + if ( objectIndex !== undefined ) { + + if ( targetObject[ objectIndex ] === undefined ) { + + console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject ); + return; + + } + + targetObject = targetObject[ objectIndex ]; + + } + + } + + // resolve property + var nodeProperty = targetObject[ propertyName ]; + + if ( nodeProperty === undefined ) { + + var nodeName = parsedPath.nodeName; + + console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName + + '.' + propertyName + ' but it wasn\'t found.', targetObject ); + return; + + } + + // determine versioning scheme + var versioning = this.Versioning.None; + + this.targetObject = targetObject; + + if ( targetObject.needsUpdate !== undefined ) { // material + + versioning = this.Versioning.NeedsUpdate; + + } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform + + versioning = this.Versioning.MatrixWorldNeedsUpdate; + + } + + // determine how the property gets bound + var bindingType = this.BindingType.Direct; + + if ( propertyIndex !== undefined ) { + + // access a sub element of the property array (only primitives are supported right now) + + if ( propertyName === "morphTargetInfluences" ) { + + // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer. + + // support resolving morphTarget names into indices. + if ( ! targetObject.geometry ) { + + console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this ); + return; + + } + + if ( targetObject.geometry.isBufferGeometry ) { + + if ( ! targetObject.geometry.morphAttributes ) { + + console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this ); + return; + + } + + if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) { + + propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ]; + + } + + + } else { + + console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this ); + return; + + } + + } + + bindingType = this.BindingType.ArrayElement; + + this.resolvedProperty = nodeProperty; + this.propertyIndex = propertyIndex; + + } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) { + + // must use copy for Object3D.Euler/Quaternion + + bindingType = this.BindingType.HasFromToArray; + + this.resolvedProperty = nodeProperty; + + } else if ( Array.isArray( nodeProperty ) ) { + + bindingType = this.BindingType.EntireArray; + + this.resolvedProperty = nodeProperty; + + } else { + + this.propertyName = propertyName; + + } + + // select getter / setter + this.getValue = this.GetterByBindingType[ bindingType ]; + this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ]; + + }, + + unbind: function () { + + this.node = null; + + // back to the prototype version of getValue / setValue + // note: avoiding to mutate the shape of 'this' via 'delete' + this.getValue = this._getValue_unbound; + this.setValue = this._setValue_unbound; + + } + + } ); + + // DECLARE ALIAS AFTER assign prototype + Object.assign( PropertyBinding.prototype, { + + // initial state of these methods that calls 'bind' + _getValue_unbound: PropertyBinding.prototype.getValue, + _setValue_unbound: PropertyBinding.prototype.setValue, + + } ); + + /** + * + * A group of objects that receives a shared animation state. + * + * Usage: + * + * - Add objects you would otherwise pass as 'root' to the + * constructor or the .clipAction method of AnimationMixer. + * + * - Instead pass this object as 'root'. + * + * - You can also add and remove objects later when the mixer + * is running. + * + * Note: + * + * Objects of this class appear as one object to the mixer, + * so cache control of the individual objects must be done + * on the group. + * + * Limitation: + * + * - The animated properties must be compatible among the + * all objects in the group. + * + * - A single property can either be controlled through a + * target group or directly, but not both. + */ + + function AnimationObjectGroup() { + var arguments$1 = arguments; + + + this.uuid = MathUtils.generateUUID(); + + // cached objects followed by the active ones + this._objects = Array.prototype.slice.call( arguments ); + + this.nCachedObjects_ = 0; // threshold + // note: read by PropertyBinding.Composite + + var indices = {}; + this._indicesByUUID = indices; // for bookkeeping + + for ( var i = 0, n = arguments.length; i !== n; ++ i ) { + + indices[ arguments$1[ i ].uuid ] = i; + + } + + this._paths = []; // inside: string + this._parsedPaths = []; // inside: { we don't care, here } + this._bindings = []; // inside: Array< PropertyBinding > + this._bindingsIndicesByPath = {}; // inside: indices in these arrays + + var scope = this; + + this.stats = { + + objects: { + get total() { + + return scope._objects.length; + + }, + get inUse() { + + return this.total - scope.nCachedObjects_; + + } + }, + get bindingsPerObject() { + + return scope._bindings.length; + + } + + }; + + } + + Object.assign( AnimationObjectGroup.prototype, { + + isAnimationObjectGroup: true, + + add: function () { + var arguments$1 = arguments; + + + var objects = this._objects, + indicesByUUID = this._indicesByUUID, + paths = this._paths, + parsedPaths = this._parsedPaths, + bindings = this._bindings, + nBindings = bindings.length; + + var knownObject = undefined, + nObjects = objects.length, + nCachedObjects = this.nCachedObjects_; + + for ( var i = 0, n = arguments.length; i !== n; ++ i ) { + + var object = arguments$1[ i ], + uuid = object.uuid; + var index = indicesByUUID[ uuid ]; + + if ( index === undefined ) { + + // unknown object -> add it to the ACTIVE region + + index = nObjects ++; + indicesByUUID[ uuid ] = index; + objects.push( object ); + + // accounting is done, now do the same for all bindings + + for ( var j = 0, m = nBindings; j !== m; ++ j ) { + + bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) ); + + } + + } else if ( index < nCachedObjects ) { + + knownObject = objects[ index ]; + + // move existing object to the ACTIVE region + + var firstActiveIndex = -- nCachedObjects, + lastCachedObject = objects[ firstActiveIndex ]; + + indicesByUUID[ lastCachedObject.uuid ] = index; + objects[ index ] = lastCachedObject; + + indicesByUUID[ uuid ] = firstActiveIndex; + objects[ firstActiveIndex ] = object; + + // accounting is done, now do the same for all bindings + + for ( var j$1 = 0, m$1 = nBindings; j$1 !== m$1; ++ j$1 ) { + + var bindingsForPath = bindings[ j$1 ], + lastCached = bindingsForPath[ firstActiveIndex ]; + + var binding = bindingsForPath[ index ]; + + bindingsForPath[ index ] = lastCached; + + if ( binding === undefined ) { + + // since we do not bother to create new bindings + // for objects that are cached, the binding may + // or may not exist + + binding = new PropertyBinding( object, paths[ j$1 ], parsedPaths[ j$1 ] ); + + } + + bindingsForPath[ firstActiveIndex ] = binding; + + } + + } else if ( objects[ index ] !== knownObject ) { + + console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' + + 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' ); + + } // else the object is already where we want it to be + + } // for arguments + + this.nCachedObjects_ = nCachedObjects; + + }, + + remove: function () { + var arguments$1 = arguments; + + + var objects = this._objects, + indicesByUUID = this._indicesByUUID, + bindings = this._bindings, + nBindings = bindings.length; + + var nCachedObjects = this.nCachedObjects_; + + for ( var i = 0, n = arguments.length; i !== n; ++ i ) { + + var object = arguments$1[ i ], + uuid = object.uuid, + index = indicesByUUID[ uuid ]; + + if ( index !== undefined && index >= nCachedObjects ) { + + // move existing object into the CACHED region + + var lastCachedIndex = nCachedObjects ++, + firstActiveObject = objects[ lastCachedIndex ]; + + indicesByUUID[ firstActiveObject.uuid ] = index; + objects[ index ] = firstActiveObject; + + indicesByUUID[ uuid ] = lastCachedIndex; + objects[ lastCachedIndex ] = object; + + // accounting is done, now do the same for all bindings + + for ( var j = 0, m = nBindings; j !== m; ++ j ) { + + var bindingsForPath = bindings[ j ], + firstActive = bindingsForPath[ lastCachedIndex ], + binding = bindingsForPath[ index ]; + + bindingsForPath[ index ] = firstActive; + bindingsForPath[ lastCachedIndex ] = binding; + + } + + } + + } // for arguments + + this.nCachedObjects_ = nCachedObjects; + + }, + + // remove & forget + uncache: function () { + var arguments$1 = arguments; + + + var objects = this._objects, + indicesByUUID = this._indicesByUUID, + bindings = this._bindings, + nBindings = bindings.length; + + var nCachedObjects = this.nCachedObjects_, + nObjects = objects.length; + + for ( var i = 0, n = arguments.length; i !== n; ++ i ) { + + var object = arguments$1[ i ], + uuid = object.uuid, + index = indicesByUUID[ uuid ]; + + if ( index !== undefined ) { + + delete indicesByUUID[ uuid ]; + + if ( index < nCachedObjects ) { + + // object is cached, shrink the CACHED region + + var firstActiveIndex = -- nCachedObjects, + lastCachedObject = objects[ firstActiveIndex ], + lastIndex = -- nObjects, + lastObject = objects[ lastIndex ]; + + // last cached object takes this object's place + indicesByUUID[ lastCachedObject.uuid ] = index; + objects[ index ] = lastCachedObject; + + // last object goes to the activated slot and pop + indicesByUUID[ lastObject.uuid ] = firstActiveIndex; + objects[ firstActiveIndex ] = lastObject; + objects.pop(); + + // accounting is done, now do the same for all bindings + + for ( var j = 0, m = nBindings; j !== m; ++ j ) { + + var bindingsForPath = bindings[ j ], + lastCached = bindingsForPath[ firstActiveIndex ], + last = bindingsForPath[ lastIndex ]; + + bindingsForPath[ index ] = lastCached; + bindingsForPath[ firstActiveIndex ] = last; + bindingsForPath.pop(); + + } + + } else { + + // object is active, just swap with the last and pop + + var lastIndex$1 = -- nObjects, + lastObject$1 = objects[ lastIndex$1 ]; + + indicesByUUID[ lastObject$1.uuid ] = index; + objects[ index ] = lastObject$1; + objects.pop(); + + // accounting is done, now do the same for all bindings + + for ( var j$1 = 0, m$1 = nBindings; j$1 !== m$1; ++ j$1 ) { + + var bindingsForPath$1 = bindings[ j$1 ]; + + bindingsForPath$1[ index ] = bindingsForPath$1[ lastIndex$1 ]; + bindingsForPath$1.pop(); + + } + + } // cached or active + + } // if object is known + + } // for arguments + + this.nCachedObjects_ = nCachedObjects; + + }, + + // Internal interface used by befriended PropertyBinding.Composite: + + subscribe_: function ( path, parsedPath ) { + + // returns an array of bindings for the given path that is changed + // according to the contained objects in the group + + var indicesByPath = this._bindingsIndicesByPath, + index = indicesByPath[ path ], + bindings = this._bindings; + + if ( index !== undefined ) { return bindings[ index ]; } + + var paths = this._paths, + parsedPaths = this._parsedPaths, + objects = this._objects, + nObjects = objects.length, + nCachedObjects = this.nCachedObjects_, + bindingsForPath = new Array( nObjects ); + + index = bindings.length; + + indicesByPath[ path ] = index; + + paths.push( path ); + parsedPaths.push( parsedPath ); + bindings.push( bindingsForPath ); + + for ( var i = nCachedObjects, n = objects.length; i !== n; ++ i ) { + + var object = objects[ i ]; + bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath ); + + } + + return bindingsForPath; + + }, + + unsubscribe_: function ( path ) { + + // tells the group to forget about a property path and no longer + // update the array previously obtained with 'subscribe_' + + var indicesByPath = this._bindingsIndicesByPath, + index = indicesByPath[ path ]; + + if ( index !== undefined ) { + + var paths = this._paths, + parsedPaths = this._parsedPaths, + bindings = this._bindings, + lastBindingsIndex = bindings.length - 1, + lastBindings = bindings[ lastBindingsIndex ], + lastBindingsPath = path[ lastBindingsIndex ]; + + indicesByPath[ lastBindingsPath ] = index; + + bindings[ index ] = lastBindings; + bindings.pop(); + + parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ]; + parsedPaths.pop(); + + paths[ index ] = paths[ lastBindingsIndex ]; + paths.pop(); + + } + + } + + } ); + + function AnimationAction( mixer, clip, localRoot, blendMode ) { + + this._mixer = mixer; + this._clip = clip; + this._localRoot = localRoot || null; + this.blendMode = blendMode || clip.blendMode; + + var tracks = clip.tracks, + nTracks = tracks.length, + interpolants = new Array( nTracks ); + + var interpolantSettings = { + endingStart: ZeroCurvatureEnding, + endingEnd: ZeroCurvatureEnding + }; + + for ( var i = 0; i !== nTracks; ++ i ) { + + var interpolant = tracks[ i ].createInterpolant( null ); + interpolants[ i ] = interpolant; + interpolant.settings = interpolantSettings; + + } + + this._interpolantSettings = interpolantSettings; + + this._interpolants = interpolants; // bound by the mixer + + // inside: PropertyMixer (managed by the mixer) + this._propertyBindings = new Array( nTracks ); + + this._cacheIndex = null; // for the memory manager + this._byClipCacheIndex = null; // for the memory manager + + this._timeScaleInterpolant = null; + this._weightInterpolant = null; + + this.loop = LoopRepeat; + this._loopCount = - 1; + + // global mixer time when the action is to be started + // it's set back to 'null' upon start of the action + this._startTime = null; + + // scaled local time of the action + // gets clamped or wrapped to 0..clip.duration according to loop + this.time = 0; + + this.timeScale = 1; + this._effectiveTimeScale = 1; + + this.weight = 1; + this._effectiveWeight = 1; + + this.repetitions = Infinity; // no. of repetitions when looping + + this.paused = false; // true -> zero effective time scale + this.enabled = true; // false -> zero effective weight + + this.clampWhenFinished = false;// keep feeding the last frame? + + this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate + this.zeroSlopeAtEnd = true;// clips for start, loop and end + + } + + Object.assign( AnimationAction.prototype, { + + // State & Scheduling + + play: function () { + + this._mixer._activateAction( this ); + + return this; + + }, + + stop: function () { + + this._mixer._deactivateAction( this ); + + return this.reset(); + + }, + + reset: function () { + + this.paused = false; + this.enabled = true; + + this.time = 0; // restart clip + this._loopCount = - 1;// forget previous loops + this._startTime = null;// forget scheduling + + return this.stopFading().stopWarping(); + + }, + + isRunning: function () { + + return this.enabled && ! this.paused && this.timeScale !== 0 && + this._startTime === null && this._mixer._isActiveAction( this ); + + }, + + // return true when play has been called + isScheduled: function () { + + return this._mixer._isActiveAction( this ); + + }, + + startAt: function ( time ) { + + this._startTime = time; + + return this; + + }, + + setLoop: function ( mode, repetitions ) { + + this.loop = mode; + this.repetitions = repetitions; + + return this; + + }, + + // Weight + + // set the weight stopping any scheduled fading + // although .enabled = false yields an effective weight of zero, this + // method does *not* change .enabled, because it would be confusing + setEffectiveWeight: function ( weight ) { + + this.weight = weight; + + // note: same logic as when updated at runtime + this._effectiveWeight = this.enabled ? weight : 0; + + return this.stopFading(); + + }, + + // return the weight considering fading and .enabled + getEffectiveWeight: function () { + + return this._effectiveWeight; + + }, + + fadeIn: function ( duration ) { + + return this._scheduleFading( duration, 0, 1 ); + + }, + + fadeOut: function ( duration ) { + + return this._scheduleFading( duration, 1, 0 ); + + }, + + crossFadeFrom: function ( fadeOutAction, duration, warp ) { + + fadeOutAction.fadeOut( duration ); + this.fadeIn( duration ); + + if ( warp ) { + + var fadeInDuration = this._clip.duration, + fadeOutDuration = fadeOutAction._clip.duration, + + startEndRatio = fadeOutDuration / fadeInDuration, + endStartRatio = fadeInDuration / fadeOutDuration; + + fadeOutAction.warp( 1.0, startEndRatio, duration ); + this.warp( endStartRatio, 1.0, duration ); + + } + + return this; + + }, + + crossFadeTo: function ( fadeInAction, duration, warp ) { + + return fadeInAction.crossFadeFrom( this, duration, warp ); + + }, + + stopFading: function () { + + var weightInterpolant = this._weightInterpolant; + + if ( weightInterpolant !== null ) { + + this._weightInterpolant = null; + this._mixer._takeBackControlInterpolant( weightInterpolant ); + + } + + return this; + + }, + + // Time Scale Control + + // set the time scale stopping any scheduled warping + // although .paused = true yields an effective time scale of zero, this + // method does *not* change .paused, because it would be confusing + setEffectiveTimeScale: function ( timeScale ) { + + this.timeScale = timeScale; + this._effectiveTimeScale = this.paused ? 0 : timeScale; + + return this.stopWarping(); + + }, + + // return the time scale considering warping and .paused + getEffectiveTimeScale: function () { + + return this._effectiveTimeScale; + + }, + + setDuration: function ( duration ) { + + this.timeScale = this._clip.duration / duration; + + return this.stopWarping(); + + }, + + syncWith: function ( action ) { + + this.time = action.time; + this.timeScale = action.timeScale; + + return this.stopWarping(); + + }, + + halt: function ( duration ) { + + return this.warp( this._effectiveTimeScale, 0, duration ); + + }, + + warp: function ( startTimeScale, endTimeScale, duration ) { + + var mixer = this._mixer, + now = mixer.time, + timeScale = this.timeScale; + + var interpolant = this._timeScaleInterpolant; + + if ( interpolant === null ) { + + interpolant = mixer._lendControlInterpolant(); + this._timeScaleInterpolant = interpolant; + + } + + var times = interpolant.parameterPositions, + values = interpolant.sampleValues; + + times[ 0 ] = now; + times[ 1 ] = now + duration; + + values[ 0 ] = startTimeScale / timeScale; + values[ 1 ] = endTimeScale / timeScale; + + return this; + + }, + + stopWarping: function () { + + var timeScaleInterpolant = this._timeScaleInterpolant; + + if ( timeScaleInterpolant !== null ) { + + this._timeScaleInterpolant = null; + this._mixer._takeBackControlInterpolant( timeScaleInterpolant ); + + } + + return this; + + }, + + // Object Accessors + + getMixer: function () { + + return this._mixer; + + }, + + getClip: function () { + + return this._clip; + + }, + + getRoot: function () { + + return this._localRoot || this._mixer._root; + + }, + + // Interna + + _update: function ( time, deltaTime, timeDirection, accuIndex ) { + + // called by the mixer + + if ( ! this.enabled ) { + + // call ._updateWeight() to update ._effectiveWeight + + this._updateWeight( time ); + return; + + } + + var startTime = this._startTime; + + if ( startTime !== null ) { + + // check for scheduled start of action + + var timeRunning = ( time - startTime ) * timeDirection; + if ( timeRunning < 0 || timeDirection === 0 ) { + + return; // yet to come / don't decide when delta = 0 + + } + + // start + + this._startTime = null; // unschedule + deltaTime = timeDirection * timeRunning; + + } + + // apply time scale and advance time + + deltaTime *= this._updateTimeScale( time ); + var clipTime = this._updateTime( deltaTime ); + + // note: _updateTime may disable the action resulting in + // an effective weight of 0 + + var weight = this._updateWeight( time ); + + if ( weight > 0 ) { + + var interpolants = this._interpolants; + var propertyMixers = this._propertyBindings; + + switch ( this.blendMode ) { + + case AdditiveAnimationBlendMode: + + for ( var j = 0, m = interpolants.length; j !== m; ++ j ) { + + interpolants[ j ].evaluate( clipTime ); + propertyMixers[ j ].accumulateAdditive( weight ); + + } + + break; + + case NormalAnimationBlendMode: + default: + + for ( var j$1 = 0, m$1 = interpolants.length; j$1 !== m$1; ++ j$1 ) { + + interpolants[ j$1 ].evaluate( clipTime ); + propertyMixers[ j$1 ].accumulate( accuIndex, weight ); + + } + + } + + } + + }, + + _updateWeight: function ( time ) { + + var weight = 0; + + if ( this.enabled ) { + + weight = this.weight; + var interpolant = this._weightInterpolant; + + if ( interpolant !== null ) { + + var interpolantValue = interpolant.evaluate( time )[ 0 ]; + + weight *= interpolantValue; + + if ( time > interpolant.parameterPositions[ 1 ] ) { + + this.stopFading(); + + if ( interpolantValue === 0 ) { + + // faded out, disable + this.enabled = false; + + } + + } + + } + + } + + this._effectiveWeight = weight; + return weight; + + }, + + _updateTimeScale: function ( time ) { + + var timeScale = 0; + + if ( ! this.paused ) { + + timeScale = this.timeScale; + + var interpolant = this._timeScaleInterpolant; + + if ( interpolant !== null ) { + + var interpolantValue = interpolant.evaluate( time )[ 0 ]; + + timeScale *= interpolantValue; + + if ( time > interpolant.parameterPositions[ 1 ] ) { + + this.stopWarping(); + + if ( timeScale === 0 ) { + + // motion has halted, pause + this.paused = true; + + } else { + + // warp done - apply final time scale + this.timeScale = timeScale; + + } + + } + + } + + } + + this._effectiveTimeScale = timeScale; + return timeScale; + + }, + + _updateTime: function ( deltaTime ) { + + var duration = this._clip.duration; + var loop = this.loop; + + var time = this.time + deltaTime; + var loopCount = this._loopCount; + + var pingPong = ( loop === LoopPingPong ); + + if ( deltaTime === 0 ) { + + if ( loopCount === - 1 ) { return time; } + + return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time; + + } + + if ( loop === LoopOnce ) { + + if ( loopCount === - 1 ) { + + // just started + + this._loopCount = 0; + this._setEndings( true, true, false ); + + } + + handle_stop: { + + if ( time >= duration ) { + + time = duration; + + } else if ( time < 0 ) { + + time = 0; + + } else { + + this.time = time; + + break handle_stop; + + } + + if ( this.clampWhenFinished ) { this.paused = true; } + else { this.enabled = false; } + + this.time = time; + + this._mixer.dispatchEvent( { + type: 'finished', action: this, + direction: deltaTime < 0 ? - 1 : 1 + } ); + + } + + } else { // repetitive Repeat or PingPong + + if ( loopCount === - 1 ) { + + // just started + + if ( deltaTime >= 0 ) { + + loopCount = 0; + + this._setEndings( true, this.repetitions === 0, pingPong ); + + } else { + + // when looping in reverse direction, the initial + // transition through zero counts as a repetition, + // so leave loopCount at -1 + + this._setEndings( this.repetitions === 0, true, pingPong ); + + } + + } + + if ( time >= duration || time < 0 ) { + + // wrap around + + var loopDelta = Math.floor( time / duration ); // signed + time -= duration * loopDelta; + + loopCount += Math.abs( loopDelta ); + + var pending = this.repetitions - loopCount; + + if ( pending <= 0 ) { + + // have to stop (switch state, clamp time, fire event) + + if ( this.clampWhenFinished ) { this.paused = true; } + else { this.enabled = false; } + + time = deltaTime > 0 ? duration : 0; + + this.time = time; + + this._mixer.dispatchEvent( { + type: 'finished', action: this, + direction: deltaTime > 0 ? 1 : - 1 + } ); + + } else { + + // keep running + + if ( pending === 1 ) { + + // entering the last round + + var atStart = deltaTime < 0; + this._setEndings( atStart, ! atStart, pingPong ); + + } else { + + this._setEndings( false, false, pingPong ); + + } + + this._loopCount = loopCount; + + this.time = time; + + this._mixer.dispatchEvent( { + type: 'loop', action: this, loopDelta: loopDelta + } ); + + } + + } else { + + this.time = time; + + } + + if ( pingPong && ( loopCount & 1 ) === 1 ) { + + // invert time for the "pong round" + + return duration - time; + + } + + } + + return time; + + }, + + _setEndings: function ( atStart, atEnd, pingPong ) { + + var settings = this._interpolantSettings; + + if ( pingPong ) { + + settings.endingStart = ZeroSlopeEnding; + settings.endingEnd = ZeroSlopeEnding; + + } else { + + // assuming for LoopOnce atStart == atEnd == true + + if ( atStart ) { + + settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding; + + } else { + + settings.endingStart = WrapAroundEnding; + + } + + if ( atEnd ) { + + settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding; + + } else { + + settings.endingEnd = WrapAroundEnding; + + } + + } + + }, + + _scheduleFading: function ( duration, weightNow, weightThen ) { + + var mixer = this._mixer, now = mixer.time; + var interpolant = this._weightInterpolant; + + if ( interpolant === null ) { + + interpolant = mixer._lendControlInterpolant(); + this._weightInterpolant = interpolant; + + } + + var times = interpolant.parameterPositions, + values = interpolant.sampleValues; + + times[ 0 ] = now; + values[ 0 ] = weightNow; + times[ 1 ] = now + duration; + values[ 1 ] = weightThen; + + return this; + + } + + } ); + + function AnimationMixer( root ) { + + this._root = root; + this._initMemoryManager(); + this._accuIndex = 0; + + this.time = 0; + + this.timeScale = 1.0; + + } + + AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { + + constructor: AnimationMixer, + + _bindAction: function ( action, prototypeAction ) { + + var root = action._localRoot || this._root, + tracks = action._clip.tracks, + nTracks = tracks.length, + bindings = action._propertyBindings, + interpolants = action._interpolants, + rootUuid = root.uuid, + bindingsByRoot = this._bindingsByRootAndName; + + var bindingsByName = bindingsByRoot[ rootUuid ]; + + if ( bindingsByName === undefined ) { + + bindingsByName = {}; + bindingsByRoot[ rootUuid ] = bindingsByName; + + } + + for ( var i = 0; i !== nTracks; ++ i ) { + + var track = tracks[ i ], + trackName = track.name; + + var binding = bindingsByName[ trackName ]; + + if ( binding !== undefined ) { + + bindings[ i ] = binding; + + } else { + + binding = bindings[ i ]; + + if ( binding !== undefined ) { + + // existing binding, make sure the cache knows + + if ( binding._cacheIndex === null ) { + + ++ binding.referenceCount; + this._addInactiveBinding( binding, rootUuid, trackName ); + + } + + continue; + + } + + var path = prototypeAction && prototypeAction. + _propertyBindings[ i ].binding.parsedPath; + + binding = new PropertyMixer( + PropertyBinding.create( root, trackName, path ), + track.ValueTypeName, track.getValueSize() ); + + ++ binding.referenceCount; + this._addInactiveBinding( binding, rootUuid, trackName ); + + bindings[ i ] = binding; + + } + + interpolants[ i ].resultBuffer = binding.buffer; + + } + + }, + + _activateAction: function ( action ) { + + if ( ! this._isActiveAction( action ) ) { + + if ( action._cacheIndex === null ) { + + // this action has been forgotten by the cache, but the user + // appears to be still using it -> rebind + + var rootUuid = ( action._localRoot || this._root ).uuid, + clipUuid = action._clip.uuid, + actionsForClip = this._actionsByClip[ clipUuid ]; + + this._bindAction( action, + actionsForClip && actionsForClip.knownActions[ 0 ] ); + + this._addInactiveAction( action, clipUuid, rootUuid ); + + } + + var bindings = action._propertyBindings; + + // increment reference counts / sort out state + for ( var i = 0, n = bindings.length; i !== n; ++ i ) { + + var binding = bindings[ i ]; + + if ( binding.useCount ++ === 0 ) { + + this._lendBinding( binding ); + binding.saveOriginalState(); + + } + + } + + this._lendAction( action ); + + } + + }, + + _deactivateAction: function ( action ) { + + if ( this._isActiveAction( action ) ) { + + var bindings = action._propertyBindings; + + // decrement reference counts / sort out state + for ( var i = 0, n = bindings.length; i !== n; ++ i ) { + + var binding = bindings[ i ]; + + if ( -- binding.useCount === 0 ) { + + binding.restoreOriginalState(); + this._takeBackBinding( binding ); + + } + + } + + this._takeBackAction( action ); + + } + + }, + + // Memory manager + + _initMemoryManager: function () { + + this._actions = []; // 'nActiveActions' followed by inactive ones + this._nActiveActions = 0; + + this._actionsByClip = {}; + // inside: + // { + // knownActions: Array< AnimationAction > - used as prototypes + // actionByRoot: AnimationAction - lookup + // } + + + this._bindings = []; // 'nActiveBindings' followed by inactive ones + this._nActiveBindings = 0; + + this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer > + + + this._controlInterpolants = []; // same game as above + this._nActiveControlInterpolants = 0; + + var scope = this; + + this.stats = { + + actions: { + get total() { + + return scope._actions.length; + + }, + get inUse() { + + return scope._nActiveActions; + + } + }, + bindings: { + get total() { + + return scope._bindings.length; + + }, + get inUse() { + + return scope._nActiveBindings; + + } + }, + controlInterpolants: { + get total() { + + return scope._controlInterpolants.length; + + }, + get inUse() { + + return scope._nActiveControlInterpolants; + + } + } + + }; + + }, + + // Memory management for AnimationAction objects + + _isActiveAction: function ( action ) { + + var index = action._cacheIndex; + return index !== null && index < this._nActiveActions; + + }, + + _addInactiveAction: function ( action, clipUuid, rootUuid ) { + + var actions = this._actions, + actionsByClip = this._actionsByClip; + + var actionsForClip = actionsByClip[ clipUuid ]; + + if ( actionsForClip === undefined ) { + + actionsForClip = { + + knownActions: [ action ], + actionByRoot: {} + + }; + + action._byClipCacheIndex = 0; + + actionsByClip[ clipUuid ] = actionsForClip; + + } else { + + var knownActions = actionsForClip.knownActions; + + action._byClipCacheIndex = knownActions.length; + knownActions.push( action ); + + } + + action._cacheIndex = actions.length; + actions.push( action ); + + actionsForClip.actionByRoot[ rootUuid ] = action; + + }, + + _removeInactiveAction: function ( action ) { + + var actions = this._actions, + lastInactiveAction = actions[ actions.length - 1 ], + cacheIndex = action._cacheIndex; + + lastInactiveAction._cacheIndex = cacheIndex; + actions[ cacheIndex ] = lastInactiveAction; + actions.pop(); + + action._cacheIndex = null; + + + var clipUuid = action._clip.uuid, + actionsByClip = this._actionsByClip, + actionsForClip = actionsByClip[ clipUuid ], + knownActionsForClip = actionsForClip.knownActions, + + lastKnownAction = + knownActionsForClip[ knownActionsForClip.length - 1 ], + + byClipCacheIndex = action._byClipCacheIndex; + + lastKnownAction._byClipCacheIndex = byClipCacheIndex; + knownActionsForClip[ byClipCacheIndex ] = lastKnownAction; + knownActionsForClip.pop(); + + action._byClipCacheIndex = null; + + + var actionByRoot = actionsForClip.actionByRoot, + rootUuid = ( action._localRoot || this._root ).uuid; + + delete actionByRoot[ rootUuid ]; + + if ( knownActionsForClip.length === 0 ) { + + delete actionsByClip[ clipUuid ]; + + } + + this._removeInactiveBindingsForAction( action ); + + }, + + _removeInactiveBindingsForAction: function ( action ) { + + var bindings = action._propertyBindings; + + for ( var i = 0, n = bindings.length; i !== n; ++ i ) { + + var binding = bindings[ i ]; + + if ( -- binding.referenceCount === 0 ) { + + this._removeInactiveBinding( binding ); + + } + + } + + }, + + _lendAction: function ( action ) { + + // [ active actions | inactive actions ] + // [ active actions >| inactive actions ] + // s a + // <-swap-> + // a s + + var actions = this._actions, + prevIndex = action._cacheIndex, + + lastActiveIndex = this._nActiveActions ++, + + firstInactiveAction = actions[ lastActiveIndex ]; + + action._cacheIndex = lastActiveIndex; + actions[ lastActiveIndex ] = action; + + firstInactiveAction._cacheIndex = prevIndex; + actions[ prevIndex ] = firstInactiveAction; + + }, + + _takeBackAction: function ( action ) { + + // [ active actions | inactive actions ] + // [ active actions |< inactive actions ] + // a s + // <-swap-> + // s a + + var actions = this._actions, + prevIndex = action._cacheIndex, + + firstInactiveIndex = -- this._nActiveActions, + + lastActiveAction = actions[ firstInactiveIndex ]; + + action._cacheIndex = firstInactiveIndex; + actions[ firstInactiveIndex ] = action; + + lastActiveAction._cacheIndex = prevIndex; + actions[ prevIndex ] = lastActiveAction; + + }, + + // Memory management for PropertyMixer objects + + _addInactiveBinding: function ( binding, rootUuid, trackName ) { + + var bindingsByRoot = this._bindingsByRootAndName, + bindings = this._bindings; + + var bindingByName = bindingsByRoot[ rootUuid ]; + + if ( bindingByName === undefined ) { + + bindingByName = {}; + bindingsByRoot[ rootUuid ] = bindingByName; + + } + + bindingByName[ trackName ] = binding; + + binding._cacheIndex = bindings.length; + bindings.push( binding ); + + }, + + _removeInactiveBinding: function ( binding ) { + + var bindings = this._bindings, + propBinding = binding.binding, + rootUuid = propBinding.rootNode.uuid, + trackName = propBinding.path, + bindingsByRoot = this._bindingsByRootAndName, + bindingByName = bindingsByRoot[ rootUuid ], + + lastInactiveBinding = bindings[ bindings.length - 1 ], + cacheIndex = binding._cacheIndex; + + lastInactiveBinding._cacheIndex = cacheIndex; + bindings[ cacheIndex ] = lastInactiveBinding; + bindings.pop(); + + delete bindingByName[ trackName ]; + + if ( Object.keys( bindingByName ).length === 0 ) { + + delete bindingsByRoot[ rootUuid ]; + + } + + }, + + _lendBinding: function ( binding ) { + + var bindings = this._bindings, + prevIndex = binding._cacheIndex, + + lastActiveIndex = this._nActiveBindings ++, + + firstInactiveBinding = bindings[ lastActiveIndex ]; + + binding._cacheIndex = lastActiveIndex; + bindings[ lastActiveIndex ] = binding; + + firstInactiveBinding._cacheIndex = prevIndex; + bindings[ prevIndex ] = firstInactiveBinding; + + }, + + _takeBackBinding: function ( binding ) { + + var bindings = this._bindings, + prevIndex = binding._cacheIndex, + + firstInactiveIndex = -- this._nActiveBindings, + + lastActiveBinding = bindings[ firstInactiveIndex ]; + + binding._cacheIndex = firstInactiveIndex; + bindings[ firstInactiveIndex ] = binding; + + lastActiveBinding._cacheIndex = prevIndex; + bindings[ prevIndex ] = lastActiveBinding; + + }, + + + // Memory management of Interpolants for weight and time scale + + _lendControlInterpolant: function () { + + var interpolants = this._controlInterpolants, + lastActiveIndex = this._nActiveControlInterpolants ++; + + var interpolant = interpolants[ lastActiveIndex ]; + + if ( interpolant === undefined ) { + + interpolant = new LinearInterpolant( + new Float32Array( 2 ), new Float32Array( 2 ), + 1, this._controlInterpolantsResultBuffer ); + + interpolant.__cacheIndex = lastActiveIndex; + interpolants[ lastActiveIndex ] = interpolant; + + } + + return interpolant; + + }, + + _takeBackControlInterpolant: function ( interpolant ) { + + var interpolants = this._controlInterpolants, + prevIndex = interpolant.__cacheIndex, + + firstInactiveIndex = -- this._nActiveControlInterpolants, + + lastActiveInterpolant = interpolants[ firstInactiveIndex ]; + + interpolant.__cacheIndex = firstInactiveIndex; + interpolants[ firstInactiveIndex ] = interpolant; + + lastActiveInterpolant.__cacheIndex = prevIndex; + interpolants[ prevIndex ] = lastActiveInterpolant; + + }, + + _controlInterpolantsResultBuffer: new Float32Array( 1 ), + + // return an action for a clip optionally using a custom root target + // object (this method allocates a lot of dynamic memory in case a + // previously unknown clip/root combination is specified) + clipAction: function ( clip, optionalRoot, blendMode ) { + + var root = optionalRoot || this._root, + rootUuid = root.uuid; + + var clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip; + + var clipUuid = clipObject !== null ? clipObject.uuid : clip; + + var actionsForClip = this._actionsByClip[ clipUuid ], + prototypeAction = null; + + if ( blendMode === undefined ) { + + if ( clipObject !== null ) { + + blendMode = clipObject.blendMode; + + } else { + + blendMode = NormalAnimationBlendMode; + + } + + } + + if ( actionsForClip !== undefined ) { + + var existingAction = actionsForClip.actionByRoot[ rootUuid ]; + + if ( existingAction !== undefined && existingAction.blendMode === blendMode ) { + + return existingAction; + + } + + // we know the clip, so we don't have to parse all + // the bindings again but can just copy + prototypeAction = actionsForClip.knownActions[ 0 ]; + + // also, take the clip from the prototype action + if ( clipObject === null ) + { clipObject = prototypeAction._clip; } + + } + + // clip must be known when specified via string + if ( clipObject === null ) { return null; } + + // allocate all resources required to run it + var newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode ); + + this._bindAction( newAction, prototypeAction ); + + // and make the action known to the memory manager + this._addInactiveAction( newAction, clipUuid, rootUuid ); + + return newAction; + + }, + + // get an existing action + existingAction: function ( clip, optionalRoot ) { + + var root = optionalRoot || this._root, + rootUuid = root.uuid, + + clipObject = typeof clip === 'string' ? + AnimationClip.findByName( root, clip ) : clip, + + clipUuid = clipObject ? clipObject.uuid : clip, + + actionsForClip = this._actionsByClip[ clipUuid ]; + + if ( actionsForClip !== undefined ) { + + return actionsForClip.actionByRoot[ rootUuid ] || null; + + } + + return null; + + }, + + // deactivates all previously scheduled actions + stopAllAction: function () { + + var actions = this._actions, + nActions = this._nActiveActions; + + for ( var i = nActions - 1; i >= 0; -- i ) { + + actions[ i ].stop(); + + } + + return this; + + }, + + // advance the time and update apply the animation + update: function ( deltaTime ) { + + deltaTime *= this.timeScale; + + var actions = this._actions, + nActions = this._nActiveActions, + + time = this.time += deltaTime, + timeDirection = Math.sign( deltaTime ), + + accuIndex = this._accuIndex ^= 1; + + // run active actions + + for ( var i = 0; i !== nActions; ++ i ) { + + var action = actions[ i ]; + + action._update( time, deltaTime, timeDirection, accuIndex ); + + } + + // update scene graph + + var bindings = this._bindings, + nBindings = this._nActiveBindings; + + for ( var i$1 = 0; i$1 !== nBindings; ++ i$1 ) { + + bindings[ i$1 ].apply( accuIndex ); + + } + + return this; + + }, + + // Allows you to seek to a specific time in an animation. + setTime: function ( timeInSeconds ) { + + this.time = 0; // Zero out time attribute for AnimationMixer object; + for ( var i = 0; i < this._actions.length; i ++ ) { + + this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects. + + } + + return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object. + + }, + + // return this mixer's root target object + getRoot: function () { + + return this._root; + + }, + + // free all resources specific to a particular clip + uncacheClip: function ( clip ) { + + var actions = this._actions, + clipUuid = clip.uuid, + actionsByClip = this._actionsByClip, + actionsForClip = actionsByClip[ clipUuid ]; + + if ( actionsForClip !== undefined ) { + + // note: just calling _removeInactiveAction would mess up the + // iteration state and also require updating the state we can + // just throw away + + var actionsToRemove = actionsForClip.knownActions; + + for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) { + + var action = actionsToRemove[ i ]; + + this._deactivateAction( action ); + + var cacheIndex = action._cacheIndex, + lastInactiveAction = actions[ actions.length - 1 ]; + + action._cacheIndex = null; + action._byClipCacheIndex = null; + + lastInactiveAction._cacheIndex = cacheIndex; + actions[ cacheIndex ] = lastInactiveAction; + actions.pop(); + + this._removeInactiveBindingsForAction( action ); + + } + + delete actionsByClip[ clipUuid ]; + + } + + }, + + // free all resources specific to a particular root target object + uncacheRoot: function ( root ) { + + var rootUuid = root.uuid, + actionsByClip = this._actionsByClip; + + for ( var clipUuid in actionsByClip ) { + + var actionByRoot = actionsByClip[ clipUuid ].actionByRoot, + action = actionByRoot[ rootUuid ]; + + if ( action !== undefined ) { + + this._deactivateAction( action ); + this._removeInactiveAction( action ); + + } + + } + + var bindingsByRoot = this._bindingsByRootAndName, + bindingByName = bindingsByRoot[ rootUuid ]; + + if ( bindingByName !== undefined ) { + + for ( var trackName in bindingByName ) { + + var binding = bindingByName[ trackName ]; + binding.restoreOriginalState(); + this._removeInactiveBinding( binding ); + + } + + } + + }, + + // remove a targeted clip from the cache + uncacheAction: function ( clip, optionalRoot ) { + + var action = this.existingAction( clip, optionalRoot ); + + if ( action !== null ) { + + this._deactivateAction( action ); + this._removeInactiveAction( action ); + + } + + } + + } ); + + function Uniform( value ) { + + if ( typeof value === 'string' ) { + + console.warn( 'THREE.Uniform: Type parameter is no longer needed.' ); + value = arguments[ 1 ]; + + } + + this.value = value; + + } + + Uniform.prototype.clone = function () { + + return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() ); + + }; + + function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) { + + InterleavedBuffer.call( this, array, stride ); + + this.meshPerAttribute = meshPerAttribute || 1; + + } + + InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), { + + constructor: InstancedInterleavedBuffer, + + isInstancedInterleavedBuffer: true, + + copy: function ( source ) { + + InterleavedBuffer.prototype.copy.call( this, source ); + + this.meshPerAttribute = source.meshPerAttribute; + + return this; + + }, + + clone: function ( data ) { + + var ib = InterleavedBuffer.prototype.clone.call( this, data ); + + ib.meshPerAttribute = this.meshPerAttribute; + + return ib; + + }, + + toJSON: function ( data ) { + + var json = InterleavedBuffer.prototype.toJSON.call( this, data ); + + json.isInstancedInterleavedBuffer = true; + json.meshPerAttribute = this.meshPerAttribute; + + return json; + + } + + } ); + + function Raycaster( origin, direction, near, far ) { + + this.ray = new Ray( origin, direction ); + // direction is assumed to be normalized (for accurate distance calculations) + + this.near = near || 0; + this.far = far || Infinity; + this.camera = null; + this.layers = new Layers(); + + this.params = { + Mesh: {}, + Line: { threshold: 1 }, + LOD: {}, + Points: { threshold: 1 }, + Sprite: {} + }; + + Object.defineProperties( this.params, { + PointCloud: { + get: function () { + + console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' ); + return this.Points; + + } + } + } ); + + } + + function ascSort( a, b ) { + + return a.distance - b.distance; + + } + + function intersectObject( object, raycaster, intersects, recursive ) { + + if ( object.layers.test( raycaster.layers ) ) { + + object.raycast( raycaster, intersects ); + + } + + if ( recursive === true ) { + + var children = object.children; + + for ( var i = 0, l = children.length; i < l; i ++ ) { + + intersectObject( children[ i ], raycaster, intersects, true ); + + } + + } + + } + + Object.assign( Raycaster.prototype, { + + set: function ( origin, direction ) { + + // direction is assumed to be normalized (for accurate distance calculations) + + this.ray.set( origin, direction ); + + }, + + setFromCamera: function ( coords, camera ) { + + if ( ( camera && camera.isPerspectiveCamera ) ) { + + this.ray.origin.setFromMatrixPosition( camera.matrixWorld ); + this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize(); + this.camera = camera; + + } else if ( ( camera && camera.isOrthographicCamera ) ) { + + this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera + this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ); + this.camera = camera; + + } else { + + console.error( 'THREE.Raycaster: Unsupported camera type.' ); + + } + + }, + + intersectObject: function ( object, recursive, optionalTarget ) { + + var intersects = optionalTarget || []; + + intersectObject( object, this, intersects, recursive ); + + intersects.sort( ascSort ); + + return intersects; + + }, + + intersectObjects: function ( objects, recursive, optionalTarget ) { + + var intersects = optionalTarget || []; + + if ( Array.isArray( objects ) === false ) { + + console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' ); + return intersects; + + } + + for ( var i = 0, l = objects.length; i < l; i ++ ) { + + intersectObject( objects[ i ], this, intersects, recursive ); + + } + + intersects.sort( ascSort ); + + return intersects; + + } + + } ); + + /** + * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system + * + * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up. + * The azimuthal angle (theta) is measured from the positive z-axis. + */ + + var Spherical = function Spherical( radius, phi, theta ) { + if ( radius === void 0 ) radius = 1; + if ( phi === void 0 ) phi = 0; + if ( theta === void 0 ) theta = 0; + + + this.radius = radius; + this.phi = phi; // polar angle + this.theta = theta; // azimuthal angle + + return this; + + }; + + Spherical.prototype.set = function set ( radius, phi, theta ) { + + this.radius = radius; + this.phi = phi; + this.theta = theta; + + return this; + + }; + + Spherical.prototype.clone = function clone () { + + return new this.constructor().copy( this ); + + }; + + Spherical.prototype.copy = function copy ( other ) { + + this.radius = other.radius; + this.phi = other.phi; + this.theta = other.theta; + + return this; + + }; + + // restrict phi to be betwee EPS and PI-EPS + Spherical.prototype.makeSafe = function makeSafe () { + + var EPS = 0.000001; + this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) ); + + return this; + + }; + + Spherical.prototype.setFromVector3 = function setFromVector3 ( v ) { + + return this.setFromCartesianCoords( v.x, v.y, v.z ); + + }; + + Spherical.prototype.setFromCartesianCoords = function setFromCartesianCoords ( x, y, z ) { + + this.radius = Math.sqrt( x * x + y * y + z * z ); + + if ( this.radius === 0 ) { + + this.theta = 0; + this.phi = 0; + + } else { + + this.theta = Math.atan2( x, z ); + this.phi = Math.acos( MathUtils.clamp( y / this.radius, - 1, 1 ) ); + + } + + return this; + + }; + + /** + * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system + */ + + function Cylindrical( radius, theta, y ) { + + this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane + this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis + this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane + + return this; + + } + + Object.assign( Cylindrical.prototype, { + + set: function ( radius, theta, y ) { + + this.radius = radius; + this.theta = theta; + this.y = y; + + return this; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( other ) { + + this.radius = other.radius; + this.theta = other.theta; + this.y = other.y; + + return this; + + }, + + setFromVector3: function ( v ) { + + return this.setFromCartesianCoords( v.x, v.y, v.z ); + + }, + + setFromCartesianCoords: function ( x, y, z ) { + + this.radius = Math.sqrt( x * x + z * z ); + this.theta = Math.atan2( x, z ); + this.y = y; + + return this; + + } + + } ); + + var _vector$7 = new Vector2(); + + function Box2( min, max ) { + + this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity ); + this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity ); + + } + + Object.assign( Box2.prototype, { + + set: function ( min, max ) { + + this.min.copy( min ); + this.max.copy( max ); + + return this; + + }, + + setFromPoints: function ( points ) { + + this.makeEmpty(); + + for ( var i = 0, il = points.length; i < il; i ++ ) { + + this.expandByPoint( points[ i ] ); + + } + + return this; + + }, + + setFromCenterAndSize: function ( center, size ) { + + var halfSize = _vector$7.copy( size ).multiplyScalar( 0.5 ); + this.min.copy( center ).sub( halfSize ); + this.max.copy( center ).add( halfSize ); + + return this; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( box ) { + + this.min.copy( box.min ); + this.max.copy( box.max ); + + return this; + + }, + + makeEmpty: function () { + + this.min.x = this.min.y = + Infinity; + this.max.x = this.max.y = - Infinity; + + return this; + + }, + + isEmpty: function () { + + // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes + + return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ); + + }, + + getCenter: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Box2: .getCenter() target is now required' ); + target = new Vector2(); + + } + + return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 ); + + }, + + getSize: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Box2: .getSize() target is now required' ); + target = new Vector2(); + + } + + return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min ); + + }, + + expandByPoint: function ( point ) { + + this.min.min( point ); + this.max.max( point ); + + return this; + + }, + + expandByVector: function ( vector ) { + + this.min.sub( vector ); + this.max.add( vector ); + + return this; + + }, + + expandByScalar: function ( scalar ) { + + this.min.addScalar( - scalar ); + this.max.addScalar( scalar ); + + return this; + + }, + + containsPoint: function ( point ) { + + return point.x < this.min.x || point.x > this.max.x || + point.y < this.min.y || point.y > this.max.y ? false : true; + + }, + + containsBox: function ( box ) { + + 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; + + }, + + getParameter: function ( point, target ) { + + // This can potentially have a divide by zero if the box + // has a size dimension of 0. + + if ( target === undefined ) { + + console.warn( 'THREE.Box2: .getParameter() target is now required' ); + target = new Vector2(); + + } + + 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 ) + ); + + }, + + intersectsBox: function ( box ) { + + // using 4 splitting planes to rule out intersections + + 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; + + }, + + clampPoint: function ( point, target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Box2: .clampPoint() target is now required' ); + target = new Vector2(); + + } + + return target.copy( point ).clamp( this.min, this.max ); + + }, + + distanceToPoint: function ( point ) { + + var clampedPoint = _vector$7.copy( point ).clamp( this.min, this.max ); + return clampedPoint.sub( point ).length(); + + }, + + intersect: function ( box ) { + + this.min.max( box.min ); + this.max.min( box.max ); + + return this; + + }, + + union: function ( box ) { + + this.min.min( box.min ); + this.max.max( box.max ); + + return this; + + }, + + translate: function ( offset ) { + + this.min.add( offset ); + this.max.add( offset ); + + return this; + + }, + + equals: function ( box ) { + + return box.min.equals( this.min ) && box.max.equals( this.max ); + + } + + } ); + + var _startP = new Vector3(); + var _startEnd = new Vector3(); + + function Line3( start, end ) { + + this.start = ( start !== undefined ) ? start : new Vector3(); + this.end = ( end !== undefined ) ? end : new Vector3(); + + } + + Object.assign( Line3.prototype, { + + set: function ( start, end ) { + + this.start.copy( start ); + this.end.copy( end ); + + return this; + + }, + + clone: function () { + + return new this.constructor().copy( this ); + + }, + + copy: function ( line ) { + + this.start.copy( line.start ); + this.end.copy( line.end ); + + return this; + + }, + + getCenter: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Line3: .getCenter() target is now required' ); + target = new Vector3(); + + } + + return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 ); + + }, + + delta: function ( target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Line3: .delta() target is now required' ); + target = new Vector3(); + + } + + return target.subVectors( this.end, this.start ); + + }, + + distanceSq: function () { + + return this.start.distanceToSquared( this.end ); + + }, + + distance: function () { + + return this.start.distanceTo( this.end ); + + }, + + at: function ( t, target ) { + + if ( target === undefined ) { + + console.warn( 'THREE.Line3: .at() target is now required' ); + target = new Vector3(); + + } + + return this.delta( target ).multiplyScalar( t ).add( this.start ); + + }, + + closestPointToPointParameter: function ( point, clampToLine ) { + + _startP.subVectors( point, this.start ); + _startEnd.subVectors( this.end, this.start ); + + var startEnd2 = _startEnd.dot( _startEnd ); + var startEnd_startP = _startEnd.dot( _startP ); + + var t = startEnd_startP / startEnd2; + + if ( clampToLine ) { + + t = MathUtils.clamp( t, 0, 1 ); + + } + + return t; + + }, + + closestPointToPoint: function ( point, clampToLine, target ) { + + var t = this.closestPointToPointParameter( point, clampToLine ); + + if ( target === undefined ) { + + console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' ); + target = new Vector3(); + + } + + return this.delta( target ).multiplyScalar( t ).add( this.start ); + + }, + + applyMatrix4: function ( matrix ) { + + this.start.applyMatrix4( matrix ); + this.end.applyMatrix4( matrix ); + + return this; + + }, + + equals: function ( line ) { + + return line.start.equals( this.start ) && line.end.equals( this.end ); + + } + + } ); + + function ImmediateRenderObject( material ) { + + Object3D.call( this ); + + this.material = material; + this.render = function ( /* renderCallback */ ) {}; + + this.hasPositions = false; + this.hasNormals = false; + this.hasColors = false; + this.hasUvs = false; + + this.positionArray = null; + this.normalArray = null; + this.colorArray = null; + this.uvArray = null; + + this.count = 0; + + } + + ImmediateRenderObject.prototype = Object.create( Object3D.prototype ); + ImmediateRenderObject.prototype.constructor = ImmediateRenderObject; + + ImmediateRenderObject.prototype.isImmediateRenderObject = true; + + var _vector$8 = new Vector3(); + + function SpotLightHelper( light, color ) { + + Object3D.call( this ); + + this.light = light; + this.light.updateMatrixWorld(); + + this.matrix = light.matrixWorld; + this.matrixAutoUpdate = false; + + this.color = color; + + var geometry = new BufferGeometry(); + + 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 + ]; + + for ( var i = 0, j = 1, l = 32; i < l; i ++, j ++ ) { + + var p1 = ( i / l ) * Math.PI * 2; + var p2 = ( j / l ) * Math.PI * 2; + + positions.push( + Math.cos( p1 ), Math.sin( p1 ), 1, + Math.cos( p2 ), Math.sin( p2 ), 1 + ); + + } + + geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) ); + + var material = new LineBasicMaterial( { fog: false, toneMapped: false } ); + + this.cone = new LineSegments( geometry, material ); + this.add( this.cone ); + + this.update(); + + } + + SpotLightHelper.prototype = Object.create( Object3D.prototype ); + SpotLightHelper.prototype.constructor = SpotLightHelper; + + SpotLightHelper.prototype.dispose = function () { + + this.cone.geometry.dispose(); + this.cone.material.dispose(); + + }; + + SpotLightHelper.prototype.update = function () { + + this.light.updateMatrixWorld(); + + var coneLength = this.light.distance ? this.light.distance : 1000; + var coneWidth = coneLength * Math.tan( this.light.angle ); + + this.cone.scale.set( coneWidth, coneWidth, coneLength ); + + _vector$8.setFromMatrixPosition( this.light.target.matrixWorld ); + + this.cone.lookAt( _vector$8 ); + + if ( this.color !== undefined ) { + + this.cone.material.color.set( this.color ); + + } else { + + this.cone.material.color.copy( this.light.color ); + + } + + }; + + var _vector$9 = new Vector3(); + var _boneMatrix = new Matrix4(); + var _matrixWorldInv = new Matrix4(); + + function getBoneList( object ) { + + var boneList = []; + + if ( object && object.isBone ) { + + boneList.push( object ); + + } + + for ( var i = 0; i < object.children.length; i ++ ) { + + boneList.push.apply( boneList, getBoneList( object.children[ i ] ) ); + + } + + return boneList; + + } + + function SkeletonHelper( object ) { + + var bones = getBoneList( object ); + + var geometry = new BufferGeometry(); + + var vertices = []; + var colors = []; + + var color1 = new Color( 0, 0, 1 ); + var color2 = new Color( 0, 1, 0 ); + + for ( var i = 0; i < bones.length; i ++ ) { + + var bone = bones[ i ]; + + if ( bone.parent && bone.parent.isBone ) { + + vertices.push( 0, 0, 0 ); + vertices.push( 0, 0, 0 ); + colors.push( color1.r, color1.g, color1.b ); + colors.push( color2.r, color2.g, color2.b ); + + } + + } + + geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) ); + + var material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } ); + + LineSegments.call( this, geometry, material ); + + this.type = 'SkeletonHelper'; + + this.root = object; + this.bones = bones; + + this.matrix = object.matrixWorld; + this.matrixAutoUpdate = false; + + } + + SkeletonHelper.prototype = Object.create( LineSegments.prototype ); + SkeletonHelper.prototype.constructor = SkeletonHelper; + + SkeletonHelper.prototype.isSkeletonHelper = true; + + SkeletonHelper.prototype.updateMatrixWorld = function ( force ) { + + var bones = this.bones; + + var geometry = this.geometry; + var position = geometry.getAttribute( 'position' ); + + _matrixWorldInv.getInverse( this.root.matrixWorld ); + + for ( var i = 0, j = 0; i < bones.length; i ++ ) { + + var bone = bones[ i ]; + + if ( bone.parent && bone.parent.isBone ) { + + _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld ); + _vector$9.setFromMatrixPosition( _boneMatrix ); + position.setXYZ( j, _vector$9.x, _vector$9.y, _vector$9.z ); + + _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld ); + _vector$9.setFromMatrixPosition( _boneMatrix ); + position.setXYZ( j + 1, _vector$9.x, _vector$9.y, _vector$9.z ); + + j += 2; + + } + + } + + geometry.getAttribute( 'position' ).needsUpdate = true; + + Object3D.prototype.updateMatrixWorld.call( this, force ); + + }; + + function PointLightHelper( light, sphereSize, color ) { + + this.light = light; + this.light.updateMatrixWorld(); + + this.color = color; + + var geometry = new SphereBufferGeometry( sphereSize, 4, 2 ); + var material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } ); + + Mesh.call( this, geometry, material ); + + this.type = 'PointLightHelper'; + + this.matrix = this.light.matrixWorld; + this.matrixAutoUpdate = false; + + this.update(); + + + /* + const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 ); + const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } ); + + this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial ); + this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial ); + + const d = light.distance; + + if ( d === 0.0 ) { + + this.lightDistance.visible = false; + + } else { + + this.lightDistance.scale.set( d, d, d ); + + } + + this.add( this.lightDistance ); + */ + + } + + PointLightHelper.prototype = Object.create( Mesh.prototype ); + PointLightHelper.prototype.constructor = PointLightHelper; + + PointLightHelper.prototype.dispose = function () { + + this.geometry.dispose(); + this.material.dispose(); + + }; + + PointLightHelper.prototype.update = function () { + + if ( this.color !== undefined ) { + + this.material.color.set( this.color ); + + } else { + + this.material.color.copy( this.light.color ); + + } + + /* + const d = this.light.distance; + + if ( d === 0.0 ) { + + this.lightDistance.visible = false; + + } else { + + this.lightDistance.visible = true; + this.lightDistance.scale.set( d, d, d ); + + } + */ + + }; + + var _vector$a = new Vector3(); + var _color1 = new Color(); + var _color2 = new Color(); + + function HemisphereLightHelper( light, size, color ) { + + Object3D.call( this ); + + this.light = light; + this.light.updateMatrixWorld(); + + this.matrix = light.matrixWorld; + this.matrixAutoUpdate = false; + + this.color = color; + + var geometry = new OctahedronBufferGeometry( size ); + geometry.rotateY( Math.PI * 0.5 ); + + this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } ); + if ( this.color === undefined ) { this.material.vertexColors = true; } + + var position = geometry.getAttribute( 'position' ); + var colors = new Float32Array( position.count * 3 ); + + geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) ); + + this.add( new Mesh( geometry, this.material ) ); + + this.update(); + + } + + HemisphereLightHelper.prototype = Object.create( Object3D.prototype ); + HemisphereLightHelper.prototype.constructor = HemisphereLightHelper; + + HemisphereLightHelper.prototype.dispose = function () { + + this.children[ 0 ].geometry.dispose(); + this.children[ 0 ].material.dispose(); + + }; + + HemisphereLightHelper.prototype.update = function () { + + var mesh = this.children[ 0 ]; + + if ( this.color !== undefined ) { + + this.material.color.set( this.color ); + + } else { + + var colors = mesh.geometry.getAttribute( 'color' ); + + _color1.copy( this.light.color ); + _color2.copy( this.light.groundColor ); + + for ( var i = 0, l = colors.count; i < l; i ++ ) { + + var color = ( i < ( l / 2 ) ) ? _color1 : _color2; + + colors.setXYZ( i, color.r, color.g, color.b ); + + } + + colors.needsUpdate = true; + + } + + mesh.lookAt( _vector$a.setFromMatrixPosition( this.light.matrixWorld ).negate() ); + + }; + + function GridHelper( size, divisions, color1, color2 ) { + + size = size || 10; + divisions = divisions || 10; + color1 = new Color( color1 !== undefined ? color1 : 0x444444 ); + color2 = new Color( color2 !== undefined ? color2 : 0x888888 ); + + var center = divisions / 2; + var step = size / divisions; + var halfSize = size / 2; + + var vertices = [], colors = []; + + for ( var i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) { + + vertices.push( - halfSize, 0, k, halfSize, 0, k ); + vertices.push( k, 0, - halfSize, k, 0, halfSize ); + + var color = i === center ? color1 : color2; + + color.toArray( colors, j ); j += 3; + color.toArray( colors, j ); j += 3; + color.toArray( colors, j ); j += 3; + color.toArray( colors, j ); j += 3; + + } + + var geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) ); + + var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } ); + + LineSegments.call( this, geometry, material ); + + this.type = 'GridHelper'; + + } + + GridHelper.prototype = Object.create( LineSegments.prototype ); + GridHelper.prototype.constructor = GridHelper; + + function PolarGridHelper( radius, radials, circles, divisions, color1, color2 ) { + + radius = radius || 10; + radials = radials || 16; + circles = circles || 8; + divisions = divisions || 64; + color1 = new Color( color1 !== undefined ? color1 : 0x444444 ); + color2 = new Color( color2 !== undefined ? color2 : 0x888888 ); + + var vertices = []; + var colors = []; + + // create the radials + + for ( var i = 0; i <= radials; i ++ ) { + + var v = ( i / radials ) * ( Math.PI * 2 ); + + var x = Math.sin( v ) * radius; + var z = Math.cos( v ) * radius; + + vertices.push( 0, 0, 0 ); + vertices.push( x, 0, z ); + + var color = ( i & 1 ) ? color1 : color2; + + colors.push( color.r, color.g, color.b ); + colors.push( color.r, color.g, color.b ); + + } + + // create the circles + + for ( var i$1 = 0; i$1 <= circles; i$1 ++ ) { + + var color$1 = ( i$1 & 1 ) ? color1 : color2; + + var r = radius - ( radius / circles * i$1 ); + + for ( var j = 0; j < divisions; j ++ ) { + + // first vertex + + var v$1 = ( j / divisions ) * ( Math.PI * 2 ); + + var x$1 = Math.sin( v$1 ) * r; + var z$1 = Math.cos( v$1 ) * r; + + vertices.push( x$1, 0, z$1 ); + colors.push( color$1.r, color$1.g, color$1.b ); + + // second vertex + + v$1 = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 ); + + x$1 = Math.sin( v$1 ) * r; + z$1 = Math.cos( v$1 ) * r; + + vertices.push( x$1, 0, z$1 ); + colors.push( color$1.r, color$1.g, color$1.b ); + + } + + } + + var geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) ); + + var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } ); + + LineSegments.call( this, geometry, material ); + + this.type = 'PolarGridHelper'; + + } + + PolarGridHelper.prototype = Object.create( LineSegments.prototype ); + PolarGridHelper.prototype.constructor = PolarGridHelper; + + var _v1$5 = new Vector3(); + var _v2$3 = new Vector3(); + var _v3$1 = new Vector3(); + + function DirectionalLightHelper( light, size, color ) { + + Object3D.call( this ); + + this.light = light; + this.light.updateMatrixWorld(); + + this.matrix = light.matrixWorld; + this.matrixAutoUpdate = false; + + this.color = color; + + if ( size === undefined ) { size = 1; } + + var geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( [ + - size, size, 0, + size, size, 0, + size, - size, 0, + - size, - size, 0, + - size, size, 0 + ], 3 ) ); + + var material = new LineBasicMaterial( { fog: false, toneMapped: false } ); + + this.lightPlane = new Line( geometry, material ); + this.add( this.lightPlane ); + + geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) ); + + this.targetLine = new Line( geometry, material ); + this.add( this.targetLine ); + + this.update(); + + } + + DirectionalLightHelper.prototype = Object.create( Object3D.prototype ); + DirectionalLightHelper.prototype.constructor = DirectionalLightHelper; + + DirectionalLightHelper.prototype.dispose = function () { + + this.lightPlane.geometry.dispose(); + this.lightPlane.material.dispose(); + this.targetLine.geometry.dispose(); + this.targetLine.material.dispose(); + + }; + + DirectionalLightHelper.prototype.update = function () { + + _v1$5.setFromMatrixPosition( this.light.matrixWorld ); + _v2$3.setFromMatrixPosition( this.light.target.matrixWorld ); + _v3$1.subVectors( _v2$3, _v1$5 ); + + this.lightPlane.lookAt( _v2$3 ); + + if ( this.color !== undefined ) { + + this.lightPlane.material.color.set( this.color ); + this.targetLine.material.color.set( this.color ); + + } else { + + this.lightPlane.material.color.copy( this.light.color ); + this.targetLine.material.color.copy( this.light.color ); + + } + + this.targetLine.lookAt( _v2$3 ); + this.targetLine.scale.z = _v3$1.length(); + + }; + + var _vector$b = new Vector3(); + var _camera = new Camera(); + + /** + * - shows frustum, line of sight and up of the camera + * - suitable for fast updates + * - based on frustum visualization in lightgl.js shadowmap example + * http://evanw.github.com/lightgl.js/tests/shadowmap.html + */ + + function CameraHelper( camera ) { + + var geometry = new BufferGeometry(); + var material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } ); + + var vertices = []; + var colors = []; + + var pointMap = {}; + + // colors + + var colorFrustum = new Color( 0xffaa00 ); + var colorCone = new Color( 0xff0000 ); + var colorUp = new Color( 0x00aaff ); + var colorTarget = new Color( 0xffffff ); + var colorCross = new Color( 0x333333 ); + + // near + + addLine( 'n1', 'n2', colorFrustum ); + addLine( 'n2', 'n4', colorFrustum ); + addLine( 'n4', 'n3', colorFrustum ); + addLine( 'n3', 'n1', colorFrustum ); + + // far + + addLine( 'f1', 'f2', colorFrustum ); + addLine( 'f2', 'f4', colorFrustum ); + addLine( 'f4', 'f3', colorFrustum ); + addLine( 'f3', 'f1', colorFrustum ); + + // sides + + addLine( 'n1', 'f1', colorFrustum ); + addLine( 'n2', 'f2', colorFrustum ); + addLine( 'n3', 'f3', colorFrustum ); + addLine( 'n4', 'f4', colorFrustum ); + + // cone + + addLine( 'p', 'n1', colorCone ); + addLine( 'p', 'n2', colorCone ); + addLine( 'p', 'n3', colorCone ); + addLine( 'p', 'n4', colorCone ); + + // up + + addLine( 'u1', 'u2', colorUp ); + addLine( 'u2', 'u3', colorUp ); + addLine( 'u3', 'u1', colorUp ); + + // target + + addLine( 'c', 't', colorTarget ); + addLine( 'p', 'c', colorCross ); + + // cross + + addLine( 'cn1', 'cn2', colorCross ); + addLine( 'cn3', 'cn4', colorCross ); + + addLine( 'cf1', 'cf2', colorCross ); + addLine( 'cf3', 'cf4', colorCross ); + + function addLine( a, b, color ) { + + addPoint( a, color ); + addPoint( b, color ); + + } + + function addPoint( id, color ) { + + vertices.push( 0, 0, 0 ); + colors.push( color.r, color.g, color.b ); + + if ( pointMap[ id ] === undefined ) { + + pointMap[ id ] = []; + + } + + pointMap[ id ].push( ( vertices.length / 3 ) - 1 ); + + } + + geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) ); + + LineSegments.call( this, geometry, material ); + + this.type = 'CameraHelper'; + + this.camera = camera; + if ( this.camera.updateProjectionMatrix ) { this.camera.updateProjectionMatrix(); } + + this.matrix = camera.matrixWorld; + this.matrixAutoUpdate = false; + + this.pointMap = pointMap; + + this.update(); + + } + + CameraHelper.prototype = Object.create( LineSegments.prototype ); + CameraHelper.prototype.constructor = CameraHelper; + + CameraHelper.prototype.update = function () { + + var geometry = this.geometry; + var pointMap = this.pointMap; + + var w = 1, h = 1; + + // we need just camera projection matrix inverse + // world matrix must be identity + + _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse ); + + // center / target + + setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 ); + setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 ); + + // near + + setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 ); + setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 ); + setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 ); + setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 ); + + // far + + setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 ); + setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 ); + setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 ); + setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 ); + + // up + + setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 ); + setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 ); + setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 ); + + // cross + + setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 ); + setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 ); + setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 ); + setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 ); + + setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 ); + setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 ); + setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 ); + setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 ); + + geometry.getAttribute( 'position' ).needsUpdate = true; + + }; + + function setPoint( point, pointMap, geometry, camera, x, y, z ) { + + _vector$b.set( x, y, z ).unproject( camera ); + + var points = pointMap[ point ]; + + if ( points !== undefined ) { + + var position = geometry.getAttribute( 'position' ); + + for ( var i = 0, l = points.length; i < l; i ++ ) { + + position.setXYZ( points[ i ], _vector$b.x, _vector$b.y, _vector$b.z ); + + } + + } + + } + + var _box$3 = new Box3(); + + function BoxHelper( object, color ) { + + this.object = object; + + if ( color === undefined ) { color = 0xffff00; } + + 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 ] ); + var positions = new Float32Array( 8 * 3 ); + + var geometry = new BufferGeometry(); + geometry.setIndex( new BufferAttribute( indices, 1 ) ); + geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) ); + + LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) ); + + this.type = 'BoxHelper'; + + this.matrixAutoUpdate = false; + + this.update(); + + } + + BoxHelper.prototype = Object.create( LineSegments.prototype ); + BoxHelper.prototype.constructor = BoxHelper; + + BoxHelper.prototype.update = function ( object ) { + + if ( object !== undefined ) { + + console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' ); + + } + + if ( this.object !== undefined ) { + + _box$3.setFromObject( this.object ); + + } + + if ( _box$3.isEmpty() ) { return; } + + var min = _box$3.min; + var max = _box$3.max; + + /* + 5____4 + 1/___0/| + | 6__|_7 + 2/___3/ + + 0: max.x, max.y, max.z + 1: min.x, max.y, max.z + 2: min.x, min.y, max.z + 3: max.x, min.y, max.z + 4: max.x, max.y, min.z + 5: min.x, max.y, min.z + 6: min.x, min.y, min.z + 7: max.x, min.y, min.z + */ + + var position = this.geometry.attributes.position; + var array = position.array; + + array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z; + array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z; + array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z; + array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z; + array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z; + array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z; + array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z; + array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z; + + position.needsUpdate = true; + + this.geometry.computeBoundingSphere(); + + + }; + + BoxHelper.prototype.setFromObject = function ( object ) { + + this.object = object; + this.update(); + + return this; + + }; + + BoxHelper.prototype.copy = function ( source ) { + + LineSegments.prototype.copy.call( this, source ); + + this.object = source.object; + + return this; + + }; + + function Box3Helper( box, color ) { + + this.type = 'Box3Helper'; + + this.box = box; + + if ( color === undefined ) { color = 0xffff00; } + + 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 ] ); + + 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 ]; + + var geometry = new BufferGeometry(); + + geometry.setIndex( new BufferAttribute( indices, 1 ) ); + + geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) ); + + LineSegments.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) ); + + this.type = 'Box3Helper'; + + this.geometry.computeBoundingSphere(); + + } + + Box3Helper.prototype = Object.create( LineSegments.prototype ); + Box3Helper.prototype.constructor = Box3Helper; + + Box3Helper.prototype.updateMatrixWorld = function ( force ) { + + var box = this.box; + + if ( box.isEmpty() ) { return; } + + box.getCenter( this.position ); + + box.getSize( this.scale ); + + this.scale.multiplyScalar( 0.5 ); + + Object3D.prototype.updateMatrixWorld.call( this, force ); + + }; + + function PlaneHelper( plane, size, hex ) { + + this.plane = plane; + + this.size = ( size === undefined ) ? 1 : size; + + var color = ( hex !== undefined ) ? hex : 0xffff00; + + 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 ]; + + var geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) ); + geometry.computeBoundingSphere(); + + Line.call( this, geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) ); + + this.type = 'PlaneHelper'; + + // + + var positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ]; + + var geometry2 = new BufferGeometry(); + geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) ); + geometry2.computeBoundingSphere(); + + this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) ); + + } + + PlaneHelper.prototype = Object.create( Line.prototype ); + PlaneHelper.prototype.constructor = PlaneHelper; + + PlaneHelper.prototype.updateMatrixWorld = function ( force ) { + + var scale = - this.plane.constant; + + if ( Math.abs( scale ) < 1e-8 ) { scale = 1e-8; } // sign does not matter + + this.scale.set( 0.5 * this.size, 0.5 * this.size, scale ); + + this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here + + this.lookAt( this.plane.normal ); + + Object3D.prototype.updateMatrixWorld.call( this, force ); + + }; + + var _axis = new Vector3(); + var _lineGeometry, _coneGeometry; + + function ArrowHelper( dir, origin, length, color, headLength, headWidth ) { + + // dir is assumed to be normalized + + Object3D.call( this ); + + this.type = 'ArrowHelper'; + + if ( dir === undefined ) { dir = new Vector3( 0, 0, 1 ); } + if ( origin === undefined ) { origin = new Vector3( 0, 0, 0 ); } + if ( length === undefined ) { length = 1; } + if ( color === undefined ) { color = 0xffff00; } + if ( headLength === undefined ) { headLength = 0.2 * length; } + if ( headWidth === undefined ) { headWidth = 0.2 * headLength; } + + if ( _lineGeometry === undefined ) { + + _lineGeometry = new BufferGeometry(); + _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) ); + + _coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 ); + _coneGeometry.translate( 0, - 0.5, 0 ); + + } + + this.position.copy( origin ); + + this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) ); + this.line.matrixAutoUpdate = false; + this.add( this.line ); + + this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) ); + this.cone.matrixAutoUpdate = false; + this.add( this.cone ); + + this.setDirection( dir ); + this.setLength( length, headLength, headWidth ); + + } + + ArrowHelper.prototype = Object.create( Object3D.prototype ); + ArrowHelper.prototype.constructor = ArrowHelper; + + ArrowHelper.prototype.setDirection = function ( dir ) { + + // dir is assumed to be normalized + + if ( dir.y > 0.99999 ) { + + this.quaternion.set( 0, 0, 0, 1 ); + + } else if ( dir.y < - 0.99999 ) { + + this.quaternion.set( 1, 0, 0, 0 ); + + } else { + + _axis.set( dir.z, 0, - dir.x ).normalize(); + + var radians = Math.acos( dir.y ); + + this.quaternion.setFromAxisAngle( _axis, radians ); + + } + + }; + + ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) { + + if ( headLength === undefined ) { headLength = 0.2 * length; } + if ( headWidth === undefined ) { headWidth = 0.2 * headLength; } + + this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458 + this.line.updateMatrix(); + + this.cone.scale.set( headWidth, headLength, headWidth ); + this.cone.position.y = length; + this.cone.updateMatrix(); + + }; + + ArrowHelper.prototype.setColor = function ( color ) { + + this.line.material.color.set( color ); + this.cone.material.color.set( color ); + + }; + + ArrowHelper.prototype.copy = function ( source ) { + + Object3D.prototype.copy.call( this, source, false ); + + this.line.copy( source.line ); + this.cone.copy( source.cone ); + + return this; + + }; + + function AxesHelper( size ) { + + size = size || 1; + + var vertices = [ + 0, 0, 0, size, 0, 0, + 0, 0, 0, 0, size, 0, + 0, 0, 0, 0, 0, size + ]; + + var colors = [ + 1, 0, 0, 1, 0.6, 0, + 0, 1, 0, 0.6, 1, 0, + 0, 0, 1, 0, 0.6, 1 + ]; + + var geometry = new BufferGeometry(); + geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) ); + geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) ); + + var material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } ); + + LineSegments.call( this, geometry, material ); + + this.type = 'AxesHelper'; + + } + + AxesHelper.prototype = Object.create( LineSegments.prototype ); + AxesHelper.prototype.constructor = AxesHelper; + + var LOD_MIN = 4; + var LOD_MAX = 8; + + // The standard deviations (radians) associated with the extra mips. These are + // chosen to approximate a Trowbridge-Reitz distribution function times the + // geometric shadowing function. These sigma values squared must match the + // variance #defines in cube_uv_reflection_fragment.glsl.js. + var EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ]; + + var TOTAL_LODS = LOD_MAX - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length; + + var _flatCamera = new OrthographicCamera(); + var ref = _createPlanes(); + + // Golden Ratio + var PHI = ( 1 + Math.sqrt( 5 ) ) / 2; + var INV_PHI = 1 / PHI; + + // Vertices of a dodecahedron (except the opposites, which represent the + // same axis), used as axis directions evenly spread on a sphere. + var _axisDirections = [ + new Vector3( 1, 1, 1 ), + new Vector3( - 1, 1, 1 ), + new Vector3( 1, 1, - 1 ), + new Vector3( - 1, 1, - 1 ), + new Vector3( 0, PHI, INV_PHI ), + new Vector3( 0, PHI, - INV_PHI ), + new Vector3( INV_PHI, 0, PHI ), + new Vector3( - INV_PHI, 0, PHI ), + new Vector3( PHI, INV_PHI, 0 ), + new Vector3( - PHI, INV_PHI, 0 ) ]; + + function _createPlanes() { + + var _lodPlanes = []; + var _sizeLods = []; + var _sigmas = []; + + var lod = LOD_MAX; + + for ( var i = 0; i < TOTAL_LODS; i ++ ) { + + var sizeLod = Math.pow( 2, lod ); + _sizeLods.push( sizeLod ); + var sigma = 1.0 / sizeLod; + + if ( i > LOD_MAX - LOD_MIN ) { + + sigma = EXTRA_LOD_SIGMA[ i - LOD_MAX + LOD_MIN - 1 ]; + + } else if ( i == 0 ) { + + sigma = 0; + + } + + _sigmas.push( sigma ); + + var texelSize = 1.0 / ( sizeLod - 1 ); + var min = - texelSize / 2; + var max = 1 + texelSize / 2; + var uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ]; + + var cubeFaces = 6; + var vertices = 6; + var positionSize = 3; + var uvSize = 2; + var faceIndexSize = 1; + + var position = new Float32Array( positionSize * vertices * cubeFaces ); + var uv = new Float32Array( uvSize * vertices * cubeFaces ); + var faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces ); + + for ( var face = 0; face < cubeFaces; face ++ ) { + + var x = ( face % 3 ) * 2 / 3 - 1; + var y = face > 2 ? 0 : - 1; + 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 + ]; + position.set( coordinates, positionSize * vertices * face ); + uv.set( uv1, uvSize * vertices * face ); + var fill = [ face, face, face, face, face, face ]; + faceIndex.set( fill, faceIndexSize * vertices * face ); + + } + + var planes = new BufferGeometry(); + planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) ); + planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) ); + planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) ); + _lodPlanes.push( planes ); + + if ( lod > LOD_MIN ) { + + lod --; + + } + + } + + return { _lodPlanes: _lodPlanes, _sizeLods: _sizeLods, _sigmas: _sigmas }; + + } + + // + + Curve.create = function ( construct, getPoint ) { + + console.log( 'THREE.Curve.create() has been deprecated' ); + + construct.prototype = Object.create( Curve.prototype ); + construct.prototype.constructor = construct; + construct.prototype.getPoint = getPoint; + + return construct; + + }; + + // + + Object.assign( CurvePath.prototype, { + + createPointsGeometry: function ( divisions ) { + + 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) + + var pts = this.getPoints( divisions ); + return this.createGeometry( pts ); + + }, + + createSpacedPointsGeometry: function ( divisions ) { + + console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' ); + + // generate geometry from equidistant sampling along the path + + var pts = this.getSpacedPoints( divisions ); + return this.createGeometry( pts ); + + }, + + createGeometry: function ( points ) { + + console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' ); + + var geometry = new Geometry(); + + for ( var i = 0, l = points.length; i < l; i ++ ) { + + var point = points[ i ]; + geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) ); + + } + + return geometry; + + } + + } ); + + // + + Object.assign( Path.prototype, { + + fromPoints: function ( points ) { + + console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' ); + return this.setFromPoints( points ); + + } + + } ); + + // + + function Spline( points ) { + + console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' ); + + CatmullRomCurve3.call( this, points ); + this.type = 'catmullrom'; + + } + + Spline.prototype = Object.create( CatmullRomCurve3.prototype ); + + Object.assign( Spline.prototype, { + + initFromArray: function ( /* a */ ) { + + console.error( 'THREE.Spline: .initFromArray() has been removed.' ); + + }, + getControlPointsArray: function ( /* optionalTarget */ ) { + + console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' ); + + }, + reparametrizeByArcLength: function ( /* samplingCoef */ ) { + + console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' ); + + } + + } ); + + GridHelper.prototype.setColors = function () { + + console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' ); + + }; + + SkeletonHelper.prototype.update = function () { + + console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' ); + + }; + + // + + Object.assign( Loader.prototype, { + + extractUrlBase: function ( url ) { + + console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' ); + return LoaderUtils.extractUrlBase( url ); + + } + + } ); + + Loader.Handlers = { + + add: function ( /* regex, loader */ ) { + + console.error( 'THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.' ); + + }, + + get: function ( /* file */ ) { + + console.error( 'THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.' ); + + } + + }; + + Object.assign( ObjectLoader.prototype, { + + setTexturePath: function ( value ) { + + console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' ); + return this.setResourcePath( value ); + + } + + } ); + + // + + Object.assign( Box2.prototype, { + + center: function ( optionalTarget ) { + + console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' ); + return this.getCenter( optionalTarget ); + + }, + empty: function () { + + console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' ); + return this.isEmpty(); + + }, + isIntersectionBox: function ( box ) { + + console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' ); + return this.intersectsBox( box ); + + }, + size: function ( optionalTarget ) { + + console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' ); + return this.getSize( optionalTarget ); + + } + } ); + + Object.assign( Box3.prototype, { + + center: function ( optionalTarget ) { + + console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' ); + return this.getCenter( optionalTarget ); + + }, + empty: function () { + + console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' ); + return this.isEmpty(); + + }, + isIntersectionBox: function ( box ) { + + console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' ); + return this.intersectsBox( box ); + + }, + isIntersectionSphere: function ( sphere ) { + + console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' ); + return this.intersectsSphere( sphere ); + + }, + size: function ( optionalTarget ) { + + console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' ); + return this.getSize( optionalTarget ); + + } + } ); + + Object.assign( Sphere.prototype, { + + empty: function () { + + console.warn( 'THREE.Sphere: .empty() has been renamed to .isEmpty().' ); + return this.isEmpty(); + + }, + + } ); + + Frustum.prototype.setFromMatrix = function ( m ) { + + console.warn( 'THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().' ); + return this.setFromProjectionMatrix( m ); + + }; + + Line3.prototype.center = function ( optionalTarget ) { + + console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' ); + return this.getCenter( optionalTarget ); + + }; + + Object.assign( MathUtils, { + + random16: function () { + + console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' ); + return Math.random(); + + }, + + nearestPowerOfTwo: function ( value ) { + + console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' ); + return MathUtils.floorPowerOfTwo( value ); + + }, + + nextPowerOfTwo: function ( value ) { + + console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' ); + return MathUtils.ceilPowerOfTwo( value ); + + } + + } ); + + Object.assign( Matrix3.prototype, { + + flattenToArrayOffset: function ( array, offset ) { + + console.warn( "THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." ); + return this.toArray( array, offset ); + + }, + multiplyVector3: function ( vector ) { + + console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' ); + return vector.applyMatrix3( this ); + + }, + multiplyVector3Array: function ( /* a */ ) { + + console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' ); + + }, + applyToBufferAttribute: function ( attribute ) { + + console.warn( 'THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.' ); + return attribute.applyMatrix3( this ); + + }, + applyToVector3Array: function ( /* array, offset, length */ ) { + + console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' ); + + } + + } ); + + Object.assign( Matrix4.prototype, { + + extractPosition: function ( m ) { + + console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' ); + return this.copyPosition( m ); + + }, + flattenToArrayOffset: function ( array, offset ) { + + console.warn( "THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead." ); + return this.toArray( array, offset ); + + }, + getPosition: function () { + + console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' ); + return new Vector3().setFromMatrixColumn( this, 3 ); + + }, + setRotationFromQuaternion: function ( q ) { + + console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' ); + return this.makeRotationFromQuaternion( q ); + + }, + multiplyToArray: function () { + + console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' ); + + }, + multiplyVector3: function ( vector ) { + + console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' ); + return vector.applyMatrix4( this ); + + }, + multiplyVector4: function ( vector ) { + + console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' ); + return vector.applyMatrix4( this ); + + }, + multiplyVector3Array: function ( /* a */ ) { + + console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' ); + + }, + rotateAxis: function ( v ) { + + console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' ); + v.transformDirection( this ); + + }, + crossVector: function ( vector ) { + + console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' ); + return vector.applyMatrix4( this ); + + }, + translate: function () { + + console.error( 'THREE.Matrix4: .translate() has been removed.' ); + + }, + rotateX: function () { + + console.error( 'THREE.Matrix4: .rotateX() has been removed.' ); + + }, + rotateY: function () { + + console.error( 'THREE.Matrix4: .rotateY() has been removed.' ); + + }, + rotateZ: function () { + + console.error( 'THREE.Matrix4: .rotateZ() has been removed.' ); + + }, + rotateByAxis: function () { + + console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' ); + + }, + applyToBufferAttribute: function ( attribute ) { + + console.warn( 'THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.' ); + return attribute.applyMatrix4( this ); + + }, + applyToVector3Array: function ( /* array, offset, length */ ) { + + console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' ); + + }, + makeFrustum: function ( left, right, bottom, top, near, far ) { + + console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' ); + return this.makePerspective( left, right, top, bottom, near, far ); + + } + + } ); + + Plane.prototype.isIntersectionLine = function ( line ) { + + console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' ); + return this.intersectsLine( line ); + + }; + + Quaternion.prototype.multiplyVector3 = function ( vector ) { + + console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' ); + return vector.applyQuaternion( this ); + + }; + + Object.assign( Ray.prototype, { + + isIntersectionBox: function ( box ) { + + console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' ); + return this.intersectsBox( box ); + + }, + isIntersectionPlane: function ( plane ) { + + console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' ); + return this.intersectsPlane( plane ); + + }, + isIntersectionSphere: function ( sphere ) { + + console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' ); + return this.intersectsSphere( sphere ); + + } + + } ); + + Object.assign( Triangle.prototype, { + + area: function () { + + console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' ); + return this.getArea(); + + }, + barycoordFromPoint: function ( point, target ) { + + console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' ); + return this.getBarycoord( point, target ); + + }, + midpoint: function ( target ) { + + console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' ); + return this.getMidpoint( target ); + + }, + normal: function ( target ) { + + console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' ); + return this.getNormal( target ); + + }, + plane: function ( target ) { + + console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' ); + return this.getPlane( target ); + + } + + } ); + + Object.assign( Triangle, { + + barycoordFromPoint: function ( point, a, b, c, target ) { + + console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' ); + return Triangle.getBarycoord( point, a, b, c, target ); + + }, + normal: function ( a, b, c, target ) { + + console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' ); + return Triangle.getNormal( a, b, c, target ); + + } + + } ); + + Object.assign( Shape.prototype, { + + extractAllPoints: function ( divisions ) { + + console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' ); + return this.extractPoints( divisions ); + + }, + extrude: function ( options ) { + + console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' ); + return new ExtrudeGeometry( this, options ); + + }, + makeGeometry: function ( options ) { + + console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' ); + return new ShapeGeometry( this, options ); + + } + + } ); + + Object.assign( Vector2.prototype, { + + fromAttribute: function ( attribute, index, offset ) { + + console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' ); + return this.fromBufferAttribute( attribute, index, offset ); + + }, + distanceToManhattan: function ( v ) { + + console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' ); + return this.manhattanDistanceTo( v ); + + }, + lengthManhattan: function () { + + console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' ); + return this.manhattanLength(); + + } + + } ); + + Object.assign( Vector3.prototype, { + + setEulerFromRotationMatrix: function () { + + console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' ); + + }, + setEulerFromQuaternion: function () { + + console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' ); + + }, + getPositionFromMatrix: function ( m ) { + + console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' ); + return this.setFromMatrixPosition( m ); + + }, + getScaleFromMatrix: function ( m ) { + + console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' ); + return this.setFromMatrixScale( m ); + + }, + getColumnFromMatrix: function ( index, matrix ) { + + console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' ); + return this.setFromMatrixColumn( matrix, index ); + + }, + applyProjection: function ( m ) { + + console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' ); + return this.applyMatrix4( m ); + + }, + fromAttribute: function ( attribute, index, offset ) { + + console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' ); + return this.fromBufferAttribute( attribute, index, offset ); + + }, + distanceToManhattan: function ( v ) { + + console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' ); + return this.manhattanDistanceTo( v ); + + }, + lengthManhattan: function () { + + console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' ); + return this.manhattanLength(); + + } + + } ); + + Object.assign( Vector4.prototype, { + + fromAttribute: function ( attribute, index, offset ) { + + console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' ); + return this.fromBufferAttribute( attribute, index, offset ); + + }, + lengthManhattan: function () { + + console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' ); + return this.manhattanLength(); + + } + + } ); + + // + + Object.assign( Geometry.prototype, { + + computeTangents: function () { + + console.error( 'THREE.Geometry: .computeTangents() has been removed.' ); + + }, + computeLineDistances: function () { + + console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' ); + + }, + applyMatrix: function ( matrix ) { + + console.warn( 'THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().' ); + return this.applyMatrix4( matrix ); + + } + + } ); + + Object.assign( Object3D.prototype, { + + getChildByName: function ( name ) { + + console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' ); + return this.getObjectByName( name ); + + }, + renderDepth: function () { + + console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' ); + + }, + translate: function ( distance, axis ) { + + console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' ); + return this.translateOnAxis( axis, distance ); + + }, + getWorldRotation: function () { + + console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' ); + + }, + applyMatrix: function ( matrix ) { + + console.warn( 'THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().' ); + return this.applyMatrix4( matrix ); + + } + + } ); + + Object.defineProperties( Object3D.prototype, { + + eulerOrder: { + get: function () { + + console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' ); + return this.rotation.order; + + }, + set: function ( value ) { + + console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' ); + this.rotation.order = value; + + } + }, + useQuaternion: { + get: function () { + + console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' ); + + }, + set: function () { + + console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' ); + + } + } + + } ); + + Object.assign( Mesh.prototype, { + + setDrawMode: function () { + + console.error( 'THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' ); + + }, + + } ); + + Object.defineProperties( Mesh.prototype, { + + drawMode: { + get: function () { + + console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.' ); + return TrianglesDrawMode; + + }, + set: function () { + + console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' ); + + } + } + + } ); + + Object.defineProperties( LOD.prototype, { + + objects: { + get: function () { + + console.warn( 'THREE.LOD: .objects has been renamed to .levels.' ); + return this.levels; + + } + } + + } ); + + Object.defineProperty( Skeleton.prototype, 'useVertexTexture', { + + get: function () { + + console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' ); + + }, + set: function () { + + console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' ); + + } + + } ); + + SkinnedMesh.prototype.initBones = function () { + + console.error( 'THREE.SkinnedMesh: initBones() has been removed.' ); + + }; + + Object.defineProperty( Curve.prototype, '__arcLengthDivisions', { + + get: function () { + + console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' ); + return this.arcLengthDivisions; + + }, + set: function ( value ) { + + console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' ); + this.arcLengthDivisions = value; + + } + + } ); + + // + + PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) { + + console.warn( "THREE.PerspectiveCamera.setLens is deprecated. " + + "Use .setFocalLength and .filmGauge for a photographic setup." ); + + if ( filmGauge !== undefined ) { this.filmGauge = filmGauge; } + this.setFocalLength( focalLength ); + + }; + + // + + Object.defineProperties( Light.prototype, { + onlyShadow: { + set: function () { + + console.warn( 'THREE.Light: .onlyShadow has been removed.' ); + + } + }, + shadowCameraFov: { + set: function ( value ) { + + console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' ); + this.shadow.camera.fov = value; + + } + }, + shadowCameraLeft: { + set: function ( value ) { + + console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' ); + this.shadow.camera.left = value; + + } + }, + shadowCameraRight: { + set: function ( value ) { + + console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' ); + this.shadow.camera.right = value; + + } + }, + shadowCameraTop: { + set: function ( value ) { + + console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' ); + this.shadow.camera.top = value; + + } + }, + shadowCameraBottom: { + set: function ( value ) { + + console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' ); + this.shadow.camera.bottom = value; + + } + }, + shadowCameraNear: { + set: function ( value ) { + + console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' ); + this.shadow.camera.near = value; + + } + }, + shadowCameraFar: { + set: function ( value ) { + + console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' ); + this.shadow.camera.far = value; + + } + }, + shadowCameraVisible: { + set: function () { + + console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' ); + + } + }, + shadowBias: { + set: function ( value ) { + + console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' ); + this.shadow.bias = value; + + } + }, + shadowDarkness: { + set: function () { + + console.warn( 'THREE.Light: .shadowDarkness has been removed.' ); + + } + }, + shadowMapWidth: { + set: function ( value ) { + + console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' ); + this.shadow.mapSize.width = value; + + } + }, + shadowMapHeight: { + set: function ( value ) { + + console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' ); + this.shadow.mapSize.height = value; + + } + } + } ); + + // + + Object.defineProperties( BufferAttribute.prototype, { + + length: { + get: function () { + + console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' ); + return this.array.length; + + } + }, + dynamic: { + get: function () { + + console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' ); + return this.usage === DynamicDrawUsage; + + }, + set: function ( /* value */ ) { + + console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' ); + this.setUsage( DynamicDrawUsage ); + + } + } + + } ); + + Object.assign( BufferAttribute.prototype, { + setDynamic: function ( value ) { + + console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' ); + this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage ); + return this; + + }, + copyIndicesArray: function ( /* indices */ ) { + + console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' ); + + }, + setArray: function ( /* array */ ) { + + console.error( 'THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' ); + + } + } ); + + Object.assign( BufferGeometry.prototype, { + + addIndex: function ( index ) { + + console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' ); + this.setIndex( index ); + + }, + addAttribute: function ( name, attribute ) { + + console.warn( 'THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().' ); + + if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) { + + console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' ); + + return this.setAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) ); + + } + + if ( name === 'index' ) { + + console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' ); + this.setIndex( attribute ); + + return this; + + } + + return this.setAttribute( name, attribute ); + + }, + addDrawCall: function ( start, count, indexOffset ) { + + if ( indexOffset !== undefined ) { + + console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' ); + + } + + console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' ); + this.addGroup( start, count ); + + }, + clearDrawCalls: function () { + + console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' ); + this.clearGroups(); + + }, + computeTangents: function () { + + console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' ); + + }, + computeOffsets: function () { + + console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' ); + + }, + removeAttribute: function ( name ) { + + console.warn( 'THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().' ); + + return this.deleteAttribute( name ); + + }, + applyMatrix: function ( matrix ) { + + console.warn( 'THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().' ); + return this.applyMatrix4( matrix ); + + } + + } ); + + Object.defineProperties( BufferGeometry.prototype, { + + drawcalls: { + get: function () { + + console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' ); + return this.groups; + + } + }, + offsets: { + get: function () { + + console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' ); + return this.groups; + + } + } + + } ); + + Object.defineProperties( InstancedBufferGeometry.prototype, { + + maxInstancedCount: { + get: function () { + + console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' ); + return this.instanceCount; + + }, + set: function ( value ) { + + console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' ); + this.instanceCount = value; + + } + } + + } ); + + Object.defineProperties( Raycaster.prototype, { + + linePrecision: { + get: function () { + + console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' ); + return this.params.Line.threshold; + + }, + set: function ( value ) { + + console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' ); + this.params.Line.threshold = value; + + } + } + + } ); + + Object.defineProperties( InterleavedBuffer.prototype, { + + dynamic: { + get: function () { + + console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' ); + return this.usage === DynamicDrawUsage; + + }, + set: function ( value ) { + + console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' ); + this.setUsage( value ); + + } + } + + } ); + + Object.assign( InterleavedBuffer.prototype, { + setDynamic: function ( value ) { + + console.warn( 'THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.' ); + this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage ); + return this; + + }, + setArray: function ( /* array */ ) { + + console.error( 'THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' ); + + } + } ); + + // + + Object.assign( ExtrudeBufferGeometry.prototype, { + + getArrays: function () { + + console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' ); + + }, + + addShapeList: function () { + + console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' ); + + }, + + addShape: function () { + + console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' ); + + } + + } ); + + // + + Object.defineProperties( Uniform.prototype, { + + dynamic: { + set: function () { + + console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' ); + + } + }, + onUpdate: { + value: function () { + + console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' ); + return this; + + } + } + + } ); + + // + + Object.defineProperties( Material.prototype, { + + wrapAround: { + get: function () { + + console.warn( 'THREE.Material: .wrapAround has been removed.' ); + + }, + set: function () { + + console.warn( 'THREE.Material: .wrapAround has been removed.' ); + + } + }, + + overdraw: { + get: function () { + + console.warn( 'THREE.Material: .overdraw has been removed.' ); + + }, + set: function () { + + console.warn( 'THREE.Material: .overdraw has been removed.' ); + + } + }, + + wrapRGB: { + get: function () { + + console.warn( 'THREE.Material: .wrapRGB has been removed.' ); + return new Color(); + + } + }, + + shading: { + get: function () { + + console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' ); + + }, + set: function ( value ) { + + console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' ); + this.flatShading = ( value === FlatShading ); + + } + }, + + stencilMask: { + get: function () { + + console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' ); + return this.stencilFuncMask; + + }, + set: function ( value ) { + + console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' ); + this.stencilFuncMask = value; + + } + } + + } ); + + Object.defineProperties( MeshPhongMaterial.prototype, { + + metal: { + get: function () { + + console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' ); + return false; + + }, + set: function () { + + console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' ); + + } + } + + } ); + + Object.defineProperties( MeshPhysicalMaterial.prototype, { + + transparency: { + get: function () { + + console.warn( 'THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.' ); + return this.transmission; + + }, + set: function ( value ) { + + console.warn( 'THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.' ); + this.transmission = value; + + } + } + + } ); + + Object.defineProperties( ShaderMaterial.prototype, { + + derivatives: { + get: function () { + + console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' ); + return this.extensions.derivatives; + + }, + set: function ( value ) { + + console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' ); + this.extensions.derivatives = value; + + } + } + + } ); + + // + + Object.assign( WebGLRenderer.prototype, { + + clearTarget: function ( renderTarget, color, depth, stencil ) { + + console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' ); + this.setRenderTarget( renderTarget ); + this.clear( color, depth, stencil ); + + }, + animate: function ( callback ) { + + console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' ); + this.setAnimationLoop( callback ); + + }, + getCurrentRenderTarget: function () { + + console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' ); + return this.getRenderTarget(); + + }, + getMaxAnisotropy: function () { + + console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' ); + return this.capabilities.getMaxAnisotropy(); + + }, + getPrecision: function () { + + console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' ); + return this.capabilities.precision; + + }, + resetGLState: function () { + + console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' ); + return this.state.reset(); + + }, + supportsFloatTextures: function () { + + console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' ); + return this.extensions.get( 'OES_texture_float' ); + + }, + supportsHalfFloatTextures: function () { + + console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' ); + return this.extensions.get( 'OES_texture_half_float' ); + + }, + supportsStandardDerivatives: function () { + + console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' ); + return this.extensions.get( 'OES_standard_derivatives' ); + + }, + supportsCompressedTextureS3TC: function () { + + console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' ); + return this.extensions.get( 'WEBGL_compressed_texture_s3tc' ); + + }, + supportsCompressedTexturePVRTC: function () { + + console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' ); + return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' ); + + }, + supportsBlendMinMax: function () { + + console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' ); + return this.extensions.get( 'EXT_blend_minmax' ); + + }, + supportsVertexTextures: function () { + + console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' ); + return this.capabilities.vertexTextures; + + }, + supportsInstancedArrays: function () { + + console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' ); + return this.extensions.get( 'ANGLE_instanced_arrays' ); + + }, + enableScissorTest: function ( boolean ) { + + console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' ); + this.setScissorTest( boolean ); + + }, + initMaterial: function () { + + console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' ); + + }, + addPrePlugin: function () { + + console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' ); + + }, + addPostPlugin: function () { + + console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' ); + + }, + updateShadowMap: function () { + + console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' ); + + }, + setFaceCulling: function () { + + console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' ); + + }, + allocTextureUnit: function () { + + console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' ); + + }, + setTexture: function () { + + console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' ); + + }, + setTexture2D: function () { + + console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' ); + + }, + setTextureCube: function () { + + console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' ); + + }, + getActiveMipMapLevel: function () { + + console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' ); + return this.getActiveMipmapLevel(); + + } + + } ); + + Object.defineProperties( WebGLRenderer.prototype, { + + shadowMapEnabled: { + get: function () { + + return this.shadowMap.enabled; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' ); + this.shadowMap.enabled = value; + + } + }, + shadowMapType: { + get: function () { + + return this.shadowMap.type; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' ); + this.shadowMap.type = value; + + } + }, + shadowMapCullFace: { + get: function () { + + console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' ); + return undefined; + + }, + set: function ( /* value */ ) { + + console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' ); + + } + }, + context: { + get: function () { + + console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' ); + return this.getContext(); + + } + }, + vr: { + get: function () { + + console.warn( 'THREE.WebGLRenderer: .vr has been renamed to .xr' ); + return this.xr; + + } + }, + gammaInput: { + get: function () { + + console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' ); + return false; + + }, + set: function () { + + console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' ); + + } + }, + gammaOutput: { + get: function () { + + console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' ); + return false; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' ); + this.outputEncoding = ( value === true ) ? sRGBEncoding : LinearEncoding; + + } + }, + toneMappingWhitePoint: { + get: function () { + + console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' ); + return 1.0; + + }, + set: function () { + + console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' ); + + } + }, + + } ); + + Object.defineProperties( WebGLShadowMap.prototype, { + + cullFace: { + get: function () { + + console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' ); + return undefined; + + }, + set: function ( /* cullFace */ ) { + + console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' ); + + } + }, + renderReverseSided: { + get: function () { + + console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' ); + return undefined; + + }, + set: function () { + + console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' ); + + } + }, + renderSingleSided: { + get: function () { + + console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' ); + return undefined; + + }, + set: function () { + + console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' ); + + } + } + + } ); + + // + + Object.defineProperties( WebGLRenderTarget.prototype, { + + wrapS: { + get: function () { + + console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' ); + return this.texture.wrapS; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' ); + this.texture.wrapS = value; + + } + }, + wrapT: { + get: function () { + + console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' ); + return this.texture.wrapT; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' ); + this.texture.wrapT = value; + + } + }, + magFilter: { + get: function () { + + console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' ); + return this.texture.magFilter; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' ); + this.texture.magFilter = value; + + } + }, + minFilter: { + get: function () { + + console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' ); + return this.texture.minFilter; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' ); + this.texture.minFilter = value; + + } + }, + anisotropy: { + get: function () { + + console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' ); + return this.texture.anisotropy; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' ); + this.texture.anisotropy = value; + + } + }, + offset: { + get: function () { + + console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' ); + return this.texture.offset; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' ); + this.texture.offset = value; + + } + }, + repeat: { + get: function () { + + console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' ); + return this.texture.repeat; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' ); + this.texture.repeat = value; + + } + }, + format: { + get: function () { + + console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' ); + return this.texture.format; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' ); + this.texture.format = value; + + } + }, + type: { + get: function () { + + console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' ); + return this.texture.type; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' ); + this.texture.type = value; + + } + }, + generateMipmaps: { + get: function () { + + console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' ); + return this.texture.generateMipmaps; + + }, + set: function ( value ) { + + console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' ); + this.texture.generateMipmaps = value; + + } + } + + } ); + + // + + Object.defineProperties( Audio.prototype, { + + load: { + value: function ( file ) { + + console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' ); + var scope = this; + var audioLoader = new AudioLoader(); + audioLoader.load( file, function ( buffer ) { + + scope.setBuffer( buffer ); + + } ); + return this; + + } + }, + startTime: { + set: function () { + + console.warn( 'THREE.Audio: .startTime is now .play( delay ).' ); + + } + } + + } ); + + AudioAnalyser.prototype.getData = function () { + + console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' ); + return this.getFrequencyData(); + + }; + + // + + CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) { + + console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' ); + return this.update( renderer, scene ); + + }; + + ImageUtils.crossOrigin = undefined; + + ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) { + + console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' ); + + var loader = new TextureLoader(); + loader.setCrossOrigin( this.crossOrigin ); + + var texture = loader.load( url, onLoad, undefined, onError ); + + if ( mapping ) { texture.mapping = mapping; } + + return texture; + + }; + + ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) { + + console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' ); + + var loader = new CubeTextureLoader(); + loader.setCrossOrigin( this.crossOrigin ); + + var texture = loader.load( urls, onLoad, undefined, onError ); + + if ( mapping ) { texture.mapping = mapping; } + + return texture; + + }; + + ImageUtils.loadCompressedTexture = function () { + + console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' ); + + }; + + ImageUtils.loadCompressedTextureCube = function () { + + console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' ); + + }; + + if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) { + + /* eslint-disable no-undef */ + __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: { + revision: REVISION, + } } ) ); + /* eslint-enable no-undef */ + + } + + /** + * dat-gui JavaScript Controller Library + * http://code.google.com/p/dat-gui + * + * Copyright 2011 Data Arts Team, Google Creative Lab + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + */ + + function ___$insertStyle(css) { + if (!css) { + return; + } + if (typeof window === 'undefined') { + return; + } + + var style = document.createElement('style'); + + style.setAttribute('type', 'text/css'); + style.innerHTML = css; + document.head.appendChild(style); + + return css; + } + + function colorToString (color, forceCSSHex) { + var colorFormat = color.__state.conversionName.toString(); + var r = Math.round(color.r); + var g = Math.round(color.g); + var b = Math.round(color.b); + var a = color.a; + var h = Math.round(color.h); + var s = color.s.toFixed(1); + var v = color.v.toFixed(1); + if (forceCSSHex || colorFormat === 'THREE_CHAR_HEX' || colorFormat === 'SIX_CHAR_HEX') { + var str = color.hex.toString(16); + while (str.length < 6) { + str = '0' + str; + } + return '#' + str; + } else if (colorFormat === 'CSS_RGB') { + return 'rgb(' + r + ',' + g + ',' + b + ')'; + } else if (colorFormat === 'CSS_RGBA') { + return 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')'; + } else if (colorFormat === 'HEX') { + return '0x' + color.hex.toString(16); + } else if (colorFormat === 'RGB_ARRAY') { + return '[' + r + ',' + g + ',' + b + ']'; + } else if (colorFormat === 'RGBA_ARRAY') { + return '[' + r + ',' + g + ',' + b + ',' + a + ']'; + } else if (colorFormat === 'RGB_OBJ') { + return '{r:' + r + ',g:' + g + ',b:' + b + '}'; + } else if (colorFormat === 'RGBA_OBJ') { + return '{r:' + r + ',g:' + g + ',b:' + b + ',a:' + a + '}'; + } else if (colorFormat === 'HSV_OBJ') { + return '{h:' + h + ',s:' + s + ',v:' + v + '}'; + } else if (colorFormat === 'HSVA_OBJ') { + return '{h:' + h + ',s:' + s + ',v:' + v + ',a:' + a + '}'; + } + return 'unknown format'; + } + + var ARR_EACH = Array.prototype.forEach; + var ARR_SLICE = Array.prototype.slice; + var Common = { + BREAK: {}, + extend: function extend(target) { + this.each(ARR_SLICE.call(arguments, 1), function (obj) { + var keys = this.isObject(obj) ? Object.keys(obj) : []; + keys.forEach(function (key) { + if (!this.isUndefined(obj[key])) { + target[key] = obj[key]; + } + }.bind(this)); + }, this); + return target; + }, + defaults: function defaults(target) { + this.each(ARR_SLICE.call(arguments, 1), function (obj) { + var keys = this.isObject(obj) ? Object.keys(obj) : []; + keys.forEach(function (key) { + if (this.isUndefined(target[key])) { + target[key] = obj[key]; + } + }.bind(this)); + }, this); + return target; + }, + compose: function compose() { + var toCall = ARR_SLICE.call(arguments); + return function () { + var args = ARR_SLICE.call(arguments); + for (var i = toCall.length - 1; i >= 0; i--) { + args = [toCall[i].apply(this, args)]; + } + return args[0]; + }; + }, + each: function each(obj, itr, scope) { + if (!obj) { + return; + } + if (ARR_EACH && obj.forEach && obj.forEach === ARR_EACH) { + obj.forEach(itr, scope); + } else if (obj.length === obj.length + 0) { + var key = void 0; + var l = void 0; + for (key = 0, l = obj.length; key < l; key++) { + if (key in obj && itr.call(scope, obj[key], key) === this.BREAK) { + return; + } + } + } else { + for (var _key in obj) { + if (itr.call(scope, obj[_key], _key) === this.BREAK) { + return; + } + } + } + }, + defer: function defer(fnc) { + setTimeout(fnc, 0); + }, + debounce: function debounce(func, threshold, callImmediately) { + var timeout = void 0; + return function () { + var obj = this; + var args = arguments; + function delayed() { + timeout = null; + if (!callImmediately) { func.apply(obj, args); } + } + var callNow = callImmediately || !timeout; + clearTimeout(timeout); + timeout = setTimeout(delayed, threshold); + if (callNow) { + func.apply(obj, args); + } + }; + }, + toArray: function toArray(obj) { + if (obj.toArray) { return obj.toArray(); } + return ARR_SLICE.call(obj); + }, + isUndefined: function isUndefined(obj) { + return obj === undefined; + }, + isNull: function isNull(obj) { + return obj === null; + }, + isNaN: function (_isNaN) { + function isNaN(_x) { + return _isNaN.apply(this, arguments); + } + isNaN.toString = function () { + return _isNaN.toString(); + }; + return isNaN; + }(function (obj) { + return isNaN(obj); + }), + isArray: Array.isArray || function (obj) { + return obj.constructor === Array; + }, + isObject: function isObject(obj) { + return obj === Object(obj); + }, + isNumber: function isNumber(obj) { + return obj === obj + 0; + }, + isString: function isString(obj) { + return obj === obj + ''; + }, + isBoolean: function isBoolean(obj) { + return obj === false || obj === true; + }, + isFunction: function isFunction(obj) { + return obj instanceof Function; + } + }; + + var INTERPRETATIONS = [ + { + litmus: Common.isString, + conversions: { + THREE_CHAR_HEX: { + read: function read(original) { + var test = original.match(/^#([A-F0-9])([A-F0-9])([A-F0-9])$/i); + if (test === null) { + return false; + } + return { + space: 'HEX', + hex: parseInt('0x' + test[1].toString() + test[1].toString() + test[2].toString() + test[2].toString() + test[3].toString() + test[3].toString(), 0) + }; + }, + write: colorToString + }, + SIX_CHAR_HEX: { + read: function read(original) { + var test = original.match(/^#([A-F0-9]{6})$/i); + if (test === null) { + return false; + } + return { + space: 'HEX', + hex: parseInt('0x' + test[1].toString(), 0) + }; + }, + write: colorToString + }, + CSS_RGB: { + read: function read(original) { + var test = original.match(/^rgb\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/); + if (test === null) { + return false; + } + return { + space: 'RGB', + r: parseFloat(test[1]), + g: parseFloat(test[2]), + b: parseFloat(test[3]) + }; + }, + write: colorToString + }, + CSS_RGBA: { + read: function read(original) { + var test = original.match(/^rgba\(\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*,\s*(.+)\s*\)/); + if (test === null) { + return false; + } + return { + space: 'RGB', + r: parseFloat(test[1]), + g: parseFloat(test[2]), + b: parseFloat(test[3]), + a: parseFloat(test[4]) + }; + }, + write: colorToString + } + } + }, + { + litmus: Common.isNumber, + conversions: { + HEX: { + read: function read(original) { + return { + space: 'HEX', + hex: original, + conversionName: 'HEX' + }; + }, + write: function write(color) { + return color.hex; + } + } + } + }, + { + litmus: Common.isArray, + conversions: { + RGB_ARRAY: { + read: function read(original) { + if (original.length !== 3) { + return false; + } + return { + space: 'RGB', + r: original[0], + g: original[1], + b: original[2] + }; + }, + write: function write(color) { + return [color.r, color.g, color.b]; + } + }, + RGBA_ARRAY: { + read: function read(original) { + if (original.length !== 4) { return false; } + return { + space: 'RGB', + r: original[0], + g: original[1], + b: original[2], + a: original[3] + }; + }, + write: function write(color) { + return [color.r, color.g, color.b, color.a]; + } + } + } + }, + { + litmus: Common.isObject, + conversions: { + RGBA_OBJ: { + read: function read(original) { + if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b) && Common.isNumber(original.a)) { + return { + space: 'RGB', + r: original.r, + g: original.g, + b: original.b, + a: original.a + }; + } + return false; + }, + write: function write(color) { + return { + r: color.r, + g: color.g, + b: color.b, + a: color.a + }; + } + }, + RGB_OBJ: { + read: function read(original) { + if (Common.isNumber(original.r) && Common.isNumber(original.g) && Common.isNumber(original.b)) { + return { + space: 'RGB', + r: original.r, + g: original.g, + b: original.b + }; + } + return false; + }, + write: function write(color) { + return { + r: color.r, + g: color.g, + b: color.b + }; + } + }, + HSVA_OBJ: { + read: function read(original) { + if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v) && Common.isNumber(original.a)) { + return { + space: 'HSV', + h: original.h, + s: original.s, + v: original.v, + a: original.a + }; + } + return false; + }, + write: function write(color) { + return { + h: color.h, + s: color.s, + v: color.v, + a: color.a + }; + } + }, + HSV_OBJ: { + read: function read(original) { + if (Common.isNumber(original.h) && Common.isNumber(original.s) && Common.isNumber(original.v)) { + return { + space: 'HSV', + h: original.h, + s: original.s, + v: original.v + }; + } + return false; + }, + write: function write(color) { + return { + h: color.h, + s: color.s, + v: color.v + }; + } + } + } + }]; + var result = void 0; + var toReturn = void 0; + var interpret = function interpret() { + toReturn = false; + var original = arguments.length > 1 ? Common.toArray(arguments) : arguments[0]; + Common.each(INTERPRETATIONS, function (family) { + if (family.litmus(original)) { + Common.each(family.conversions, function (conversion, conversionName) { + result = conversion.read(original); + if (toReturn === false && result !== false) { + toReturn = result; + result.conversionName = conversionName; + result.conversion = conversion; + return Common.BREAK; + } + }); + return Common.BREAK; + } + }); + return toReturn; + }; + + var tmpComponent = void 0; + var ColorMath = { + hsv_to_rgb: function hsv_to_rgb(h, s, v) { + var hi = Math.floor(h / 60) % 6; + var f = h / 60 - Math.floor(h / 60); + var p = v * (1.0 - s); + var q = v * (1.0 - f * s); + var t = v * (1.0 - (1.0 - f) * s); + var c = [[v, t, p], [q, v, p], [p, v, t], [p, q, v], [t, p, v], [v, p, q]][hi]; + return { + r: c[0] * 255, + g: c[1] * 255, + b: c[2] * 255 + }; + }, + rgb_to_hsv: function rgb_to_hsv(r, g, b) { + var min = Math.min(r, g, b); + var max = Math.max(r, g, b); + var delta = max - min; + var h = void 0; + var s = void 0; + if (max !== 0) { + s = delta / max; + } else { + return { + h: NaN, + s: 0, + v: 0 + }; + } + if (r === max) { + h = (g - b) / delta; + } else if (g === max) { + h = 2 + (b - r) / delta; + } else { + h = 4 + (r - g) / delta; + } + h /= 6; + if (h < 0) { + h += 1; + } + return { + h: h * 360, + s: s, + v: max / 255 + }; + }, + rgb_to_hex: function rgb_to_hex(r, g, b) { + var hex = this.hex_with_component(0, 2, r); + hex = this.hex_with_component(hex, 1, g); + hex = this.hex_with_component(hex, 0, b); + return hex; + }, + component_from_hex: function component_from_hex(hex, componentIndex) { + return hex >> componentIndex * 8 & 0xFF; + }, + hex_with_component: function hex_with_component(hex, componentIndex, value) { + return value << (tmpComponent = componentIndex * 8) | hex & ~(0xFF << tmpComponent); + } + }; + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + + + + + + + + + + + + var classCallCheck = function (instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + }; + + var createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) { descriptor.writable = true; } + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) { defineProperties(Constructor.prototype, protoProps); } + if (staticProps) { defineProperties(Constructor, staticProps); } + return Constructor; + }; + }(); + + + + + + + + var get = function get(object, property, receiver) { + if (object === null) { object = Function.prototype; } + var desc = Object.getOwnPropertyDescriptor(object, property); + + if (desc === undefined) { + var parent = Object.getPrototypeOf(object); + + if (parent === null) { + return undefined; + } else { + return get(parent, property, receiver); + } + } else if ("value" in desc) { + return desc.value; + } else { + var getter = desc.get; + + if (getter === undefined) { + return undefined; + } + + return getter.call(receiver); + } + }; + + var inherits = function (subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) { Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + }; + + + + + + + + + + + + var possibleConstructorReturn = function (self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return call && (typeof call === "object" || typeof call === "function") ? call : self; + }; + + var Color$1 = function () { + function Color() { + classCallCheck(this, Color); + this.__state = interpret.apply(this, arguments); + if (this.__state === false) { + throw new Error('Failed to interpret color arguments'); + } + this.__state.a = this.__state.a || 1; + } + createClass(Color, [{ + key: 'toString', + value: function toString() { + return colorToString(this); + } + }, { + key: 'toHexString', + value: function toHexString() { + return colorToString(this, true); + } + }, { + key: 'toOriginal', + value: function toOriginal() { + return this.__state.conversion.write(this); + } + }]); + return Color; + }(); + function defineRGBComponent(target, component, componentHexIndex) { + Object.defineProperty(target, component, { + get: function get$$1() { + if (this.__state.space === 'RGB') { + return this.__state[component]; + } + Color$1.recalculateRGB(this, component, componentHexIndex); + return this.__state[component]; + }, + set: function set$$1(v) { + if (this.__state.space !== 'RGB') { + Color$1.recalculateRGB(this, component, componentHexIndex); + this.__state.space = 'RGB'; + } + this.__state[component] = v; + } + }); + } + function defineHSVComponent(target, component) { + Object.defineProperty(target, component, { + get: function get$$1() { + if (this.__state.space === 'HSV') { + return this.__state[component]; + } + Color$1.recalculateHSV(this); + return this.__state[component]; + }, + set: function set$$1(v) { + if (this.__state.space !== 'HSV') { + Color$1.recalculateHSV(this); + this.__state.space = 'HSV'; + } + this.__state[component] = v; + } + }); + } + Color$1.recalculateRGB = function (color, component, componentHexIndex) { + if (color.__state.space === 'HEX') { + color.__state[component] = ColorMath.component_from_hex(color.__state.hex, componentHexIndex); + } else if (color.__state.space === 'HSV') { + Common.extend(color.__state, ColorMath.hsv_to_rgb(color.__state.h, color.__state.s, color.__state.v)); + } else { + throw new Error('Corrupted color state'); + } + }; + Color$1.recalculateHSV = function (color) { + var result = ColorMath.rgb_to_hsv(color.r, color.g, color.b); + Common.extend(color.__state, { + s: result.s, + v: result.v + }); + if (!Common.isNaN(result.h)) { + color.__state.h = result.h; + } else if (Common.isUndefined(color.__state.h)) { + color.__state.h = 0; + } + }; + Color$1.COMPONENTS = ['r', 'g', 'b', 'h', 's', 'v', 'hex', 'a']; + defineRGBComponent(Color$1.prototype, 'r', 2); + defineRGBComponent(Color$1.prototype, 'g', 1); + defineRGBComponent(Color$1.prototype, 'b', 0); + defineHSVComponent(Color$1.prototype, 'h'); + defineHSVComponent(Color$1.prototype, 's'); + defineHSVComponent(Color$1.prototype, 'v'); + Object.defineProperty(Color$1.prototype, 'a', { + get: function get$$1() { + return this.__state.a; + }, + set: function set$$1(v) { + this.__state.a = v; + } + }); + Object.defineProperty(Color$1.prototype, 'hex', { + get: function get$$1() { + if (this.__state.space !== 'HEX') { + this.__state.hex = ColorMath.rgb_to_hex(this.r, this.g, this.b); + this.__state.space = 'HEX'; + } + return this.__state.hex; + }, + set: function set$$1(v) { + this.__state.space = 'HEX'; + this.__state.hex = v; + } + }); + + var Controller = function () { + function Controller(object, property) { + classCallCheck(this, Controller); + this.initialValue = object[property]; + this.domElement = document.createElement('div'); + this.object = object; + this.property = property; + this.__onChange = undefined; + this.__onFinishChange = undefined; + } + createClass(Controller, [{ + key: 'onChange', + value: function onChange(fnc) { + this.__onChange = fnc; + return this; + } + }, { + key: 'onFinishChange', + value: function onFinishChange(fnc) { + this.__onFinishChange = fnc; + return this; + } + }, { + key: 'setValue', + value: function setValue(newValue) { + this.object[this.property] = newValue; + if (this.__onChange) { + this.__onChange.call(this, newValue); + } + this.updateDisplay(); + return this; + } + }, { + key: 'getValue', + value: function getValue() { + return this.object[this.property]; + } + }, { + key: 'updateDisplay', + value: function updateDisplay() { + return this; + } + }, { + key: 'isModified', + value: function isModified() { + return this.initialValue !== this.getValue(); + } + }]); + return Controller; + }(); + + var EVENT_MAP = { + HTMLEvents: ['change'], + MouseEvents: ['click', 'mousemove', 'mousedown', 'mouseup', 'mouseover'], + KeyboardEvents: ['keydown'] + }; + var EVENT_MAP_INV = {}; + Common.each(EVENT_MAP, function (v, k) { + Common.each(v, function (e) { + EVENT_MAP_INV[e] = k; + }); + }); + var CSS_VALUE_PIXELS = /(\d+(\.\d+)?)px/; + function cssValueToPixels(val) { + if (val === '0' || Common.isUndefined(val)) { + return 0; + } + var match = val.match(CSS_VALUE_PIXELS); + if (!Common.isNull(match)) { + return parseFloat(match[1]); + } + return 0; + } + var dom = { + makeSelectable: function makeSelectable(elem, selectable) { + if (elem === undefined || elem.style === undefined) { return; } + elem.onselectstart = selectable ? function () { + return false; + } : function () {}; + elem.style.MozUserSelect = selectable ? 'auto' : 'none'; + elem.style.KhtmlUserSelect = selectable ? 'auto' : 'none'; + elem.unselectable = selectable ? 'on' : 'off'; + }, + makeFullscreen: function makeFullscreen(elem, hor, vert) { + var vertical = vert; + var horizontal = hor; + if (Common.isUndefined(horizontal)) { + horizontal = true; + } + if (Common.isUndefined(vertical)) { + vertical = true; + } + elem.style.position = 'absolute'; + if (horizontal) { + elem.style.left = 0; + elem.style.right = 0; + } + if (vertical) { + elem.style.top = 0; + elem.style.bottom = 0; + } + }, + fakeEvent: function fakeEvent(elem, eventType, pars, aux) { + var params = pars || {}; + var className = EVENT_MAP_INV[eventType]; + if (!className) { + throw new Error('Event type ' + eventType + ' not supported.'); + } + var evt = document.createEvent(className); + switch (className) { + case 'MouseEvents': + { + var clientX = params.x || params.clientX || 0; + var clientY = params.y || params.clientY || 0; + evt.initMouseEvent(eventType, params.bubbles || false, params.cancelable || true, window, params.clickCount || 1, 0, + 0, + clientX, + clientY, + false, false, false, false, 0, null); + break; + } + case 'KeyboardEvents': + { + var init = evt.initKeyboardEvent || evt.initKeyEvent; + Common.defaults(params, { + cancelable: true, + ctrlKey: false, + altKey: false, + shiftKey: false, + metaKey: false, + keyCode: undefined, + charCode: undefined + }); + init(eventType, params.bubbles || false, params.cancelable, window, params.ctrlKey, params.altKey, params.shiftKey, params.metaKey, params.keyCode, params.charCode); + break; + } + default: + { + evt.initEvent(eventType, params.bubbles || false, params.cancelable || true); + break; + } + } + Common.defaults(evt, aux); + elem.dispatchEvent(evt); + }, + bind: function bind(elem, event, func, newBool) { + var bool = newBool || false; + if (elem.addEventListener) { + elem.addEventListener(event, func, bool); + } else if (elem.attachEvent) { + elem.attachEvent('on' + event, func); + } + return dom; + }, + unbind: function unbind(elem, event, func, newBool) { + var bool = newBool || false; + if (elem.removeEventListener) { + elem.removeEventListener(event, func, bool); + } else if (elem.detachEvent) { + elem.detachEvent('on' + event, func); + } + return dom; + }, + addClass: function addClass(elem, className) { + if (elem.className === undefined) { + elem.className = className; + } else if (elem.className !== className) { + var classes = elem.className.split(/ +/); + if (classes.indexOf(className) === -1) { + classes.push(className); + elem.className = classes.join(' ').replace(/^\s+/, '').replace(/\s+$/, ''); + } + } + return dom; + }, + removeClass: function removeClass(elem, className) { + if (className) { + if (elem.className === className) { + elem.removeAttribute('class'); + } else { + var classes = elem.className.split(/ +/); + var index = classes.indexOf(className); + if (index !== -1) { + classes.splice(index, 1); + elem.className = classes.join(' '); + } + } + } else { + elem.className = undefined; + } + return dom; + }, + hasClass: function hasClass(elem, className) { + return new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)').test(elem.className) || false; + }, + getWidth: function getWidth(elem) { + var style = getComputedStyle(elem); + return cssValueToPixels(style['border-left-width']) + cssValueToPixels(style['border-right-width']) + cssValueToPixels(style['padding-left']) + cssValueToPixels(style['padding-right']) + cssValueToPixels(style.width); + }, + getHeight: function getHeight(elem) { + var style = getComputedStyle(elem); + return cssValueToPixels(style['border-top-width']) + cssValueToPixels(style['border-bottom-width']) + cssValueToPixels(style['padding-top']) + cssValueToPixels(style['padding-bottom']) + cssValueToPixels(style.height); + }, + getOffset: function getOffset(el) { + var elem = el; + var offset = { left: 0, top: 0 }; + if (elem.offsetParent) { + do { + offset.left += elem.offsetLeft; + offset.top += elem.offsetTop; + elem = elem.offsetParent; + } while (elem); + } + return offset; + }, + isActive: function isActive(elem) { + return elem === document.activeElement && (elem.type || elem.href); + } + }; + + var BooleanController = function (_Controller) { + inherits(BooleanController, _Controller); + function BooleanController(object, property) { + classCallCheck(this, BooleanController); + var _this2 = possibleConstructorReturn(this, (BooleanController.__proto__ || Object.getPrototypeOf(BooleanController)).call(this, object, property)); + var _this = _this2; + _this2.__prev = _this2.getValue(); + _this2.__checkbox = document.createElement('input'); + _this2.__checkbox.setAttribute('type', 'checkbox'); + function onChange() { + _this.setValue(!_this.__prev); + } + dom.bind(_this2.__checkbox, 'change', onChange, false); + _this2.domElement.appendChild(_this2.__checkbox); + _this2.updateDisplay(); + return _this2; + } + createClass(BooleanController, [{ + key: 'setValue', + value: function setValue(v) { + var toReturn = get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'setValue', this).call(this, v); + if (this.__onFinishChange) { + this.__onFinishChange.call(this, this.getValue()); + } + this.__prev = this.getValue(); + return toReturn; + } + }, { + key: 'updateDisplay', + value: function updateDisplay() { + if (this.getValue() === true) { + this.__checkbox.setAttribute('checked', 'checked'); + this.__checkbox.checked = true; + this.__prev = true; + } else { + this.__checkbox.checked = false; + this.__prev = false; + } + return get(BooleanController.prototype.__proto__ || Object.getPrototypeOf(BooleanController.prototype), 'updateDisplay', this).call(this); + } + }]); + return BooleanController; + }(Controller); + + var OptionController = function (_Controller) { + inherits(OptionController, _Controller); + function OptionController(object, property, opts) { + classCallCheck(this, OptionController); + var _this2 = possibleConstructorReturn(this, (OptionController.__proto__ || Object.getPrototypeOf(OptionController)).call(this, object, property)); + var options = opts; + var _this = _this2; + _this2.__select = document.createElement('select'); + if (Common.isArray(options)) { + var map = {}; + Common.each(options, function (element) { + map[element] = element; + }); + options = map; + } + Common.each(options, function (value, key) { + var opt = document.createElement('option'); + opt.innerHTML = key; + opt.setAttribute('value', value); + _this.__select.appendChild(opt); + }); + _this2.updateDisplay(); + dom.bind(_this2.__select, 'change', function () { + var desiredValue = this.options[this.selectedIndex].value; + _this.setValue(desiredValue); + }); + _this2.domElement.appendChild(_this2.__select); + return _this2; + } + createClass(OptionController, [{ + key: 'setValue', + value: function setValue(v) { + var toReturn = get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'setValue', this).call(this, v); + if (this.__onFinishChange) { + this.__onFinishChange.call(this, this.getValue()); + } + return toReturn; + } + }, { + key: 'updateDisplay', + value: function updateDisplay() { + if (dom.isActive(this.__select)) { return this; } + this.__select.value = this.getValue(); + return get(OptionController.prototype.__proto__ || Object.getPrototypeOf(OptionController.prototype), 'updateDisplay', this).call(this); + } + }]); + return OptionController; + }(Controller); + + var StringController = function (_Controller) { + inherits(StringController, _Controller); + function StringController(object, property) { + classCallCheck(this, StringController); + var _this2 = possibleConstructorReturn(this, (StringController.__proto__ || Object.getPrototypeOf(StringController)).call(this, object, property)); + var _this = _this2; + function onChange() { + _this.setValue(_this.__input.value); + } + function onBlur() { + if (_this.__onFinishChange) { + _this.__onFinishChange.call(_this, _this.getValue()); + } + } + _this2.__input = document.createElement('input'); + _this2.__input.setAttribute('type', 'text'); + dom.bind(_this2.__input, 'keyup', onChange); + dom.bind(_this2.__input, 'change', onChange); + dom.bind(_this2.__input, 'blur', onBlur); + dom.bind(_this2.__input, 'keydown', function (e) { + if (e.keyCode === 13) { + this.blur(); + } + }); + _this2.updateDisplay(); + _this2.domElement.appendChild(_this2.__input); + return _this2; + } + createClass(StringController, [{ + key: 'updateDisplay', + value: function updateDisplay() { + if (!dom.isActive(this.__input)) { + this.__input.value = this.getValue(); + } + return get(StringController.prototype.__proto__ || Object.getPrototypeOf(StringController.prototype), 'updateDisplay', this).call(this); + } + }]); + return StringController; + }(Controller); + + function numDecimals(x) { + var _x = x.toString(); + if (_x.indexOf('.') > -1) { + return _x.length - _x.indexOf('.') - 1; + } + return 0; + } + var NumberController = function (_Controller) { + inherits(NumberController, _Controller); + function NumberController(object, property, params) { + classCallCheck(this, NumberController); + var _this = possibleConstructorReturn(this, (NumberController.__proto__ || Object.getPrototypeOf(NumberController)).call(this, object, property)); + var _params = params || {}; + _this.__min = _params.min; + _this.__max = _params.max; + _this.__step = _params.step; + if (Common.isUndefined(_this.__step)) { + if (_this.initialValue === 0) { + _this.__impliedStep = 1; + } else { + _this.__impliedStep = Math.pow(10, Math.floor(Math.log(Math.abs(_this.initialValue)) / Math.LN10)) / 10; + } + } else { + _this.__impliedStep = _this.__step; + } + _this.__precision = numDecimals(_this.__impliedStep); + return _this; + } + createClass(NumberController, [{ + key: 'setValue', + value: function setValue(v) { + var _v = v; + if (this.__min !== undefined && _v < this.__min) { + _v = this.__min; + } else if (this.__max !== undefined && _v > this.__max) { + _v = this.__max; + } + if (this.__step !== undefined && _v % this.__step !== 0) { + _v = Math.round(_v / this.__step) * this.__step; + } + return get(NumberController.prototype.__proto__ || Object.getPrototypeOf(NumberController.prototype), 'setValue', this).call(this, _v); + } + }, { + key: 'min', + value: function min(minValue) { + this.__min = minValue; + return this; + } + }, { + key: 'max', + value: function max(maxValue) { + this.__max = maxValue; + return this; + } + }, { + key: 'step', + value: function step(stepValue) { + this.__step = stepValue; + this.__impliedStep = stepValue; + this.__precision = numDecimals(stepValue); + return this; + } + }]); + return NumberController; + }(Controller); + + function roundToDecimal(value, decimals) { + var tenTo = Math.pow(10, decimals); + return Math.round(value * tenTo) / tenTo; + } + var NumberControllerBox = function (_NumberController) { + inherits(NumberControllerBox, _NumberController); + function NumberControllerBox(object, property, params) { + classCallCheck(this, NumberControllerBox); + var _this2 = possibleConstructorReturn(this, (NumberControllerBox.__proto__ || Object.getPrototypeOf(NumberControllerBox)).call(this, object, property, params)); + _this2.__truncationSuspended = false; + var _this = _this2; + var prevY = void 0; + function onChange() { + var attempted = parseFloat(_this.__input.value); + if (!Common.isNaN(attempted)) { + _this.setValue(attempted); + } + } + function onFinish() { + if (_this.__onFinishChange) { + _this.__onFinishChange.call(_this, _this.getValue()); + } + } + function onBlur() { + onFinish(); + } + function onMouseDrag(e) { + var diff = prevY - e.clientY; + _this.setValue(_this.getValue() + diff * _this.__impliedStep); + prevY = e.clientY; + } + function onMouseUp() { + dom.unbind(window, 'mousemove', onMouseDrag); + dom.unbind(window, 'mouseup', onMouseUp); + onFinish(); + } + function onMouseDown(e) { + dom.bind(window, 'mousemove', onMouseDrag); + dom.bind(window, 'mouseup', onMouseUp); + prevY = e.clientY; + } + _this2.__input = document.createElement('input'); + _this2.__input.setAttribute('type', 'text'); + dom.bind(_this2.__input, 'change', onChange); + dom.bind(_this2.__input, 'blur', onBlur); + dom.bind(_this2.__input, 'mousedown', onMouseDown); + dom.bind(_this2.__input, 'keydown', function (e) { + if (e.keyCode === 13) { + _this.__truncationSuspended = true; + this.blur(); + _this.__truncationSuspended = false; + onFinish(); + } + }); + _this2.updateDisplay(); + _this2.domElement.appendChild(_this2.__input); + return _this2; + } + createClass(NumberControllerBox, [{ + key: 'updateDisplay', + value: function updateDisplay() { + this.__input.value = this.__truncationSuspended ? this.getValue() : roundToDecimal(this.getValue(), this.__precision); + return get(NumberControllerBox.prototype.__proto__ || Object.getPrototypeOf(NumberControllerBox.prototype), 'updateDisplay', this).call(this); + } + }]); + return NumberControllerBox; + }(NumberController); + + function map(v, i1, i2, o1, o2) { + return o1 + (o2 - o1) * ((v - i1) / (i2 - i1)); + } + var NumberControllerSlider = function (_NumberController) { + inherits(NumberControllerSlider, _NumberController); + function NumberControllerSlider(object, property, min, max, step) { + classCallCheck(this, NumberControllerSlider); + var _this2 = possibleConstructorReturn(this, (NumberControllerSlider.__proto__ || Object.getPrototypeOf(NumberControllerSlider)).call(this, object, property, { min: min, max: max, step: step })); + var _this = _this2; + _this2.__background = document.createElement('div'); + _this2.__foreground = document.createElement('div'); + dom.bind(_this2.__background, 'mousedown', onMouseDown); + dom.bind(_this2.__background, 'touchstart', onTouchStart); + dom.addClass(_this2.__background, 'slider'); + dom.addClass(_this2.__foreground, 'slider-fg'); + function onMouseDown(e) { + document.activeElement.blur(); + dom.bind(window, 'mousemove', onMouseDrag); + dom.bind(window, 'mouseup', onMouseUp); + onMouseDrag(e); + } + function onMouseDrag(e) { + e.preventDefault(); + var bgRect = _this.__background.getBoundingClientRect(); + _this.setValue(map(e.clientX, bgRect.left, bgRect.right, _this.__min, _this.__max)); + return false; + } + function onMouseUp() { + dom.unbind(window, 'mousemove', onMouseDrag); + dom.unbind(window, 'mouseup', onMouseUp); + if (_this.__onFinishChange) { + _this.__onFinishChange.call(_this, _this.getValue()); + } + } + function onTouchStart(e) { + if (e.touches.length !== 1) { + return; + } + dom.bind(window, 'touchmove', onTouchMove); + dom.bind(window, 'touchend', onTouchEnd); + onTouchMove(e); + } + function onTouchMove(e) { + var clientX = e.touches[0].clientX; + var bgRect = _this.__background.getBoundingClientRect(); + _this.setValue(map(clientX, bgRect.left, bgRect.right, _this.__min, _this.__max)); + } + function onTouchEnd() { + dom.unbind(window, 'touchmove', onTouchMove); + dom.unbind(window, 'touchend', onTouchEnd); + if (_this.__onFinishChange) { + _this.__onFinishChange.call(_this, _this.getValue()); + } + } + _this2.updateDisplay(); + _this2.__background.appendChild(_this2.__foreground); + _this2.domElement.appendChild(_this2.__background); + return _this2; + } + createClass(NumberControllerSlider, [{ + key: 'updateDisplay', + value: function updateDisplay() { + var pct = (this.getValue() - this.__min) / (this.__max - this.__min); + this.__foreground.style.width = pct * 100 + '%'; + return get(NumberControllerSlider.prototype.__proto__ || Object.getPrototypeOf(NumberControllerSlider.prototype), 'updateDisplay', this).call(this); + } + }]); + return NumberControllerSlider; + }(NumberController); + + var FunctionController = function (_Controller) { + inherits(FunctionController, _Controller); + function FunctionController(object, property, text) { + classCallCheck(this, FunctionController); + var _this2 = possibleConstructorReturn(this, (FunctionController.__proto__ || Object.getPrototypeOf(FunctionController)).call(this, object, property)); + var _this = _this2; + _this2.__button = document.createElement('div'); + _this2.__button.innerHTML = text === undefined ? 'Fire' : text; + dom.bind(_this2.__button, 'click', function (e) { + e.preventDefault(); + _this.fire(); + return false; + }); + dom.addClass(_this2.__button, 'button'); + _this2.domElement.appendChild(_this2.__button); + return _this2; + } + createClass(FunctionController, [{ + key: 'fire', + value: function fire() { + if (this.__onChange) { + this.__onChange.call(this); + } + this.getValue().call(this.object); + if (this.__onFinishChange) { + this.__onFinishChange.call(this, this.getValue()); + } + } + }]); + return FunctionController; + }(Controller); + + var ColorController = function (_Controller) { + inherits(ColorController, _Controller); + function ColorController(object, property) { + classCallCheck(this, ColorController); + var _this2 = possibleConstructorReturn(this, (ColorController.__proto__ || Object.getPrototypeOf(ColorController)).call(this, object, property)); + _this2.__color = new Color$1(_this2.getValue()); + _this2.__temp = new Color$1(0); + var _this = _this2; + _this2.domElement = document.createElement('div'); + dom.makeSelectable(_this2.domElement, false); + _this2.__selector = document.createElement('div'); + _this2.__selector.className = 'selector'; + _this2.__saturation_field = document.createElement('div'); + _this2.__saturation_field.className = 'saturation-field'; + _this2.__field_knob = document.createElement('div'); + _this2.__field_knob.className = 'field-knob'; + _this2.__field_knob_border = '2px solid '; + _this2.__hue_knob = document.createElement('div'); + _this2.__hue_knob.className = 'hue-knob'; + _this2.__hue_field = document.createElement('div'); + _this2.__hue_field.className = 'hue-field'; + _this2.__input = document.createElement('input'); + _this2.__input.type = 'text'; + _this2.__input_textShadow = '0 1px 1px '; + dom.bind(_this2.__input, 'keydown', function (e) { + if (e.keyCode === 13) { + onBlur.call(this); + } + }); + dom.bind(_this2.__input, 'blur', onBlur); + dom.bind(_this2.__selector, 'mousedown', function () { + dom.addClass(this, 'drag').bind(window, 'mouseup', function () { + dom.removeClass(_this.__selector, 'drag'); + }); + }); + dom.bind(_this2.__selector, 'touchstart', function () { + dom.addClass(this, 'drag').bind(window, 'touchend', function () { + dom.removeClass(_this.__selector, 'drag'); + }); + }); + var valueField = document.createElement('div'); + Common.extend(_this2.__selector.style, { + width: '122px', + height: '102px', + padding: '3px', + backgroundColor: '#222', + boxShadow: '0px 1px 3px rgba(0,0,0,0.3)' + }); + Common.extend(_this2.__field_knob.style, { + position: 'absolute', + width: '12px', + height: '12px', + border: _this2.__field_knob_border + (_this2.__color.v < 0.5 ? '#fff' : '#000'), + boxShadow: '0px 1px 3px rgba(0,0,0,0.5)', + borderRadius: '12px', + zIndex: 1 + }); + Common.extend(_this2.__hue_knob.style, { + position: 'absolute', + width: '15px', + height: '2px', + borderRight: '4px solid #fff', + zIndex: 1 + }); + Common.extend(_this2.__saturation_field.style, { + width: '100px', + height: '100px', + border: '1px solid #555', + marginRight: '3px', + display: 'inline-block', + cursor: 'pointer' + }); + Common.extend(valueField.style, { + width: '100%', + height: '100%', + background: 'none' + }); + linearGradient(valueField, 'top', 'rgba(0,0,0,0)', '#000'); + Common.extend(_this2.__hue_field.style, { + width: '15px', + height: '100px', + border: '1px solid #555', + cursor: 'ns-resize', + position: 'absolute', + top: '3px', + right: '3px' + }); + hueGradient(_this2.__hue_field); + Common.extend(_this2.__input.style, { + outline: 'none', + textAlign: 'center', + color: '#fff', + border: 0, + fontWeight: 'bold', + textShadow: _this2.__input_textShadow + 'rgba(0,0,0,0.7)' + }); + dom.bind(_this2.__saturation_field, 'mousedown', fieldDown); + dom.bind(_this2.__saturation_field, 'touchstart', fieldDown); + dom.bind(_this2.__field_knob, 'mousedown', fieldDown); + dom.bind(_this2.__field_knob, 'touchstart', fieldDown); + dom.bind(_this2.__hue_field, 'mousedown', fieldDownH); + dom.bind(_this2.__hue_field, 'touchstart', fieldDownH); + function fieldDown(e) { + setSV(e); + dom.bind(window, 'mousemove', setSV); + dom.bind(window, 'touchmove', setSV); + dom.bind(window, 'mouseup', fieldUpSV); + dom.bind(window, 'touchend', fieldUpSV); + } + function fieldDownH(e) { + setH(e); + dom.bind(window, 'mousemove', setH); + dom.bind(window, 'touchmove', setH); + dom.bind(window, 'mouseup', fieldUpH); + dom.bind(window, 'touchend', fieldUpH); + } + function fieldUpSV() { + dom.unbind(window, 'mousemove', setSV); + dom.unbind(window, 'touchmove', setSV); + dom.unbind(window, 'mouseup', fieldUpSV); + dom.unbind(window, 'touchend', fieldUpSV); + onFinish(); + } + function fieldUpH() { + dom.unbind(window, 'mousemove', setH); + dom.unbind(window, 'touchmove', setH); + dom.unbind(window, 'mouseup', fieldUpH); + dom.unbind(window, 'touchend', fieldUpH); + onFinish(); + } + function onBlur() { + var i = interpret(this.value); + if (i !== false) { + _this.__color.__state = i; + _this.setValue(_this.__color.toOriginal()); + } else { + this.value = _this.__color.toString(); + } + } + function onFinish() { + if (_this.__onFinishChange) { + _this.__onFinishChange.call(_this, _this.__color.toOriginal()); + } + } + _this2.__saturation_field.appendChild(valueField); + _this2.__selector.appendChild(_this2.__field_knob); + _this2.__selector.appendChild(_this2.__saturation_field); + _this2.__selector.appendChild(_this2.__hue_field); + _this2.__hue_field.appendChild(_this2.__hue_knob); + _this2.domElement.appendChild(_this2.__input); + _this2.domElement.appendChild(_this2.__selector); + _this2.updateDisplay(); + function setSV(e) { + if (e.type.indexOf('touch') === -1) { + e.preventDefault(); + } + var fieldRect = _this.__saturation_field.getBoundingClientRect(); + var _ref = e.touches && e.touches[0] || e, + clientX = _ref.clientX, + clientY = _ref.clientY; + var s = (clientX - fieldRect.left) / (fieldRect.right - fieldRect.left); + var v = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top); + if (v > 1) { + v = 1; + } else if (v < 0) { + v = 0; + } + if (s > 1) { + s = 1; + } else if (s < 0) { + s = 0; + } + _this.__color.v = v; + _this.__color.s = s; + _this.setValue(_this.__color.toOriginal()); + return false; + } + function setH(e) { + if (e.type.indexOf('touch') === -1) { + e.preventDefault(); + } + var fieldRect = _this.__hue_field.getBoundingClientRect(); + var _ref2 = e.touches && e.touches[0] || e, + clientY = _ref2.clientY; + var h = 1 - (clientY - fieldRect.top) / (fieldRect.bottom - fieldRect.top); + if (h > 1) { + h = 1; + } else if (h < 0) { + h = 0; + } + _this.__color.h = h * 360; + _this.setValue(_this.__color.toOriginal()); + return false; + } + return _this2; + } + createClass(ColorController, [{ + key: 'updateDisplay', + value: function updateDisplay() { + var i = interpret(this.getValue()); + if (i !== false) { + var mismatch = false; + Common.each(Color$1.COMPONENTS, function (component) { + if (!Common.isUndefined(i[component]) && !Common.isUndefined(this.__color.__state[component]) && i[component] !== this.__color.__state[component]) { + mismatch = true; + return {}; + } + }, this); + if (mismatch) { + Common.extend(this.__color.__state, i); + } + } + Common.extend(this.__temp.__state, this.__color.__state); + this.__temp.a = 1; + var flip = this.__color.v < 0.5 || this.__color.s > 0.5 ? 255 : 0; + var _flip = 255 - flip; + Common.extend(this.__field_knob.style, { + marginLeft: 100 * this.__color.s - 7 + 'px', + marginTop: 100 * (1 - this.__color.v) - 7 + 'px', + backgroundColor: this.__temp.toHexString(), + border: this.__field_knob_border + 'rgb(' + flip + ',' + flip + ',' + flip + ')' + }); + this.__hue_knob.style.marginTop = (1 - this.__color.h / 360) * 100 + 'px'; + this.__temp.s = 1; + this.__temp.v = 1; + linearGradient(this.__saturation_field, 'left', '#fff', this.__temp.toHexString()); + this.__input.value = this.__color.toString(); + Common.extend(this.__input.style, { + backgroundColor: this.__color.toHexString(), + color: 'rgb(' + flip + ',' + flip + ',' + flip + ')', + textShadow: this.__input_textShadow + 'rgba(' + _flip + ',' + _flip + ',' + _flip + ',.7)' + }); + } + }]); + return ColorController; + }(Controller); + var vendors = ['-moz-', '-o-', '-webkit-', '-ms-', '']; + function linearGradient(elem, x, a, b) { + elem.style.background = ''; + Common.each(vendors, function (vendor) { + elem.style.cssText += 'background: ' + vendor + 'linear-gradient(' + x + ', ' + a + ' 0%, ' + b + ' 100%); '; + }); + } + function hueGradient(elem) { + elem.style.background = ''; + elem.style.cssText += 'background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);'; + elem.style.cssText += 'background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; + elem.style.cssText += 'background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; + elem.style.cssText += 'background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; + elem.style.cssText += 'background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);'; + } + + var css = { + load: function load(url, indoc) { + var doc = indoc || document; + var link = doc.createElement('link'); + link.type = 'text/css'; + link.rel = 'stylesheet'; + link.href = url; + doc.getElementsByTagName('head')[0].appendChild(link); + }, + inject: function inject(cssContent, indoc) { + var doc = indoc || document; + var injected = document.createElement('style'); + injected.type = 'text/css'; + injected.innerHTML = cssContent; + var head = doc.getElementsByTagName('head')[0]; + try { + head.appendChild(injected); + } catch (e) { + } + } + }; + + var saveDialogContents = "
\n\n Here's the new load parameter for your GUI's constructor:\n\n \n\n
\n\n Automatically save\n values to localStorage on exit.\n\n
The values saved to localStorage will\n override those passed to dat.GUI's constructor. This makes it\n easier to work incrementally, but localStorage is fragile,\n and your friends may not see the same values you do.\n\n
\n\n
\n\n
"; + + var ControllerFactory = function ControllerFactory(object, property) { + var initialValue = object[property]; + if (Common.isArray(arguments[2]) || Common.isObject(arguments[2])) { + return new OptionController(object, property, arguments[2]); + } + if (Common.isNumber(initialValue)) { + if (Common.isNumber(arguments[2]) && Common.isNumber(arguments[3])) { + if (Common.isNumber(arguments[4])) { + return new NumberControllerSlider(object, property, arguments[2], arguments[3], arguments[4]); + } + return new NumberControllerSlider(object, property, arguments[2], arguments[3]); + } + if (Common.isNumber(arguments[4])) { + return new NumberControllerBox(object, property, { min: arguments[2], max: arguments[3], step: arguments[4] }); + } + return new NumberControllerBox(object, property, { min: arguments[2], max: arguments[3] }); + } + if (Common.isString(initialValue)) { + return new StringController(object, property); + } + if (Common.isFunction(initialValue)) { + return new FunctionController(object, property, ''); + } + if (Common.isBoolean(initialValue)) { + return new BooleanController(object, property); + } + return null; + }; + + function requestAnimationFrame$1(callback) { + setTimeout(callback, 1000 / 60); + } + var requestAnimationFrame$1$1 = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || requestAnimationFrame$1; + + var CenteredDiv = function () { + function CenteredDiv() { + classCallCheck(this, CenteredDiv); + this.backgroundElement = document.createElement('div'); + Common.extend(this.backgroundElement.style, { + backgroundColor: 'rgba(0,0,0,0.8)', + top: 0, + left: 0, + display: 'none', + zIndex: '1000', + opacity: 0, + WebkitTransition: 'opacity 0.2s linear', + transition: 'opacity 0.2s linear' + }); + dom.makeFullscreen(this.backgroundElement); + this.backgroundElement.style.position = 'fixed'; + this.domElement = document.createElement('div'); + Common.extend(this.domElement.style, { + position: 'fixed', + display: 'none', + zIndex: '1001', + opacity: 0, + WebkitTransition: '-webkit-transform 0.2s ease-out, opacity 0.2s linear', + transition: 'transform 0.2s ease-out, opacity 0.2s linear' + }); + document.body.appendChild(this.backgroundElement); + document.body.appendChild(this.domElement); + var _this = this; + dom.bind(this.backgroundElement, 'click', function () { + _this.hide(); + }); + } + createClass(CenteredDiv, [{ + key: 'show', + value: function show() { + var _this = this; + this.backgroundElement.style.display = 'block'; + this.domElement.style.display = 'block'; + this.domElement.style.opacity = 0; + this.domElement.style.webkitTransform = 'scale(1.1)'; + this.layout(); + Common.defer(function () { + _this.backgroundElement.style.opacity = 1; + _this.domElement.style.opacity = 1; + _this.domElement.style.webkitTransform = 'scale(1)'; + }); + } + }, { + key: 'hide', + value: function hide() { + var _this = this; + var hide = function hide() { + _this.domElement.style.display = 'none'; + _this.backgroundElement.style.display = 'none'; + dom.unbind(_this.domElement, 'webkitTransitionEnd', hide); + dom.unbind(_this.domElement, 'transitionend', hide); + dom.unbind(_this.domElement, 'oTransitionEnd', hide); + }; + dom.bind(this.domElement, 'webkitTransitionEnd', hide); + dom.bind(this.domElement, 'transitionend', hide); + dom.bind(this.domElement, 'oTransitionEnd', hide); + this.backgroundElement.style.opacity = 0; + this.domElement.style.opacity = 0; + this.domElement.style.webkitTransform = 'scale(1.1)'; + } + }, { + key: 'layout', + value: function layout() { + this.domElement.style.left = window.innerWidth / 2 - dom.getWidth(this.domElement) / 2 + 'px'; + this.domElement.style.top = window.innerHeight / 2 - dom.getHeight(this.domElement) / 2 + 'px'; + } + }]); + return CenteredDiv; + }(); + + var styleSheet = ___$insertStyle(".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear;border:0;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button.close-top{position:relative}.dg.main .close-button.close-bottom{position:absolute}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-y:visible}.dg.a.has-save>ul.close-top{margin-top:0}.dg.a.has-save>ul.close-bottom{margin-top:27px}.dg.a.has-save>ul.closed{margin-top:0}.dg.a .save-row{top:0;z-index:1002}.dg.a .save-row.close-top{position:relative}.dg.a .save-row.close-bottom{position:fixed}.dg li{-webkit-transition:height .1s ease-out;-o-transition:height .1s ease-out;-moz-transition:height .1s ease-out;transition:height .1s ease-out;-webkit-transition:overflow .1s linear;-o-transition:overflow .1s linear;-moz-transition:overflow .1s linear;transition:overflow .1s linear}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li>*{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px;overflow:hidden}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%;position:relative}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:7px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .cr.color{overflow:visible}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.color{border-left:3px solid}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2FA1D6}.dg .cr.number input[type=text]{color:#2FA1D6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2FA1D6;max-width:100%}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n"); + + css.inject(styleSheet); + var CSS_NAMESPACE = 'dg'; + var HIDE_KEY_CODE = 72; + var CLOSE_BUTTON_HEIGHT = 20; + var DEFAULT_DEFAULT_PRESET_NAME = 'Default'; + var SUPPORTS_LOCAL_STORAGE = function () { + try { + return !!window.localStorage; + } catch (e) { + return false; + } + }(); + var SAVE_DIALOGUE = void 0; + var autoPlaceVirgin = true; + var autoPlaceContainer = void 0; + var hide = false; + var hideableGuis = []; + var GUI = function GUI(pars) { + var _this = this; + var params = pars || {}; + this.domElement = document.createElement('div'); + this.__ul = document.createElement('ul'); + this.domElement.appendChild(this.__ul); + dom.addClass(this.domElement, CSS_NAMESPACE); + this.__folders = {}; + this.__controllers = []; + this.__rememberedObjects = []; + this.__rememberedObjectIndecesToControllers = []; + this.__listening = []; + params = Common.defaults(params, { + closeOnTop: false, + autoPlace: true, + width: GUI.DEFAULT_WIDTH + }); + params = Common.defaults(params, { + resizable: params.autoPlace, + hideable: params.autoPlace + }); + if (!Common.isUndefined(params.load)) { + if (params.preset) { + params.load.preset = params.preset; + } + } else { + params.load = { preset: DEFAULT_DEFAULT_PRESET_NAME }; + } + if (Common.isUndefined(params.parent) && params.hideable) { + hideableGuis.push(this); + } + params.resizable = Common.isUndefined(params.parent) && params.resizable; + if (params.autoPlace && Common.isUndefined(params.scrollable)) { + params.scrollable = true; + } + var useLocalStorage = SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(this, 'isLocal')) === 'true'; + var saveToLocalStorage = void 0; + var titleRow = void 0; + Object.defineProperties(this, + { + parent: { + get: function get$$1() { + return params.parent; + } + }, + scrollable: { + get: function get$$1() { + return params.scrollable; + } + }, + autoPlace: { + get: function get$$1() { + return params.autoPlace; + } + }, + closeOnTop: { + get: function get$$1() { + return params.closeOnTop; + } + }, + preset: { + get: function get$$1() { + if (_this.parent) { + return _this.getRoot().preset; + } + return params.load.preset; + }, + set: function set$$1(v) { + if (_this.parent) { + _this.getRoot().preset = v; + } else { + params.load.preset = v; + } + setPresetSelectIndex(this); + _this.revert(); + } + }, + width: { + get: function get$$1() { + return params.width; + }, + set: function set$$1(v) { + params.width = v; + setWidth(_this, v); + } + }, + name: { + get: function get$$1() { + return params.name; + }, + set: function set$$1(v) { + params.name = v; + if (titleRow) { + titleRow.innerHTML = params.name; + } + } + }, + closed: { + get: function get$$1() { + return params.closed; + }, + set: function set$$1(v) { + params.closed = v; + if (params.closed) { + dom.addClass(_this.__ul, GUI.CLASS_CLOSED); + } else { + dom.removeClass(_this.__ul, GUI.CLASS_CLOSED); + } + this.onResize(); + if (_this.__closeButton) { + _this.__closeButton.innerHTML = v ? GUI.TEXT_OPEN : GUI.TEXT_CLOSED; + } + } + }, + load: { + get: function get$$1() { + return params.load; + } + }, + useLocalStorage: { + get: function get$$1() { + return useLocalStorage; + }, + set: function set$$1(bool) { + if (SUPPORTS_LOCAL_STORAGE) { + useLocalStorage = bool; + if (bool) { + dom.bind(window, 'unload', saveToLocalStorage); + } else { + dom.unbind(window, 'unload', saveToLocalStorage); + } + localStorage.setItem(getLocalStorageHash(_this, 'isLocal'), bool); + } + } + } + }); + if (Common.isUndefined(params.parent)) { + this.closed = params.closed || false; + dom.addClass(this.domElement, GUI.CLASS_MAIN); + dom.makeSelectable(this.domElement, false); + if (SUPPORTS_LOCAL_STORAGE) { + if (useLocalStorage) { + _this.useLocalStorage = true; + var savedGui = localStorage.getItem(getLocalStorageHash(this, 'gui')); + if (savedGui) { + params.load = JSON.parse(savedGui); + } + } + } + this.__closeButton = document.createElement('div'); + this.__closeButton.innerHTML = GUI.TEXT_CLOSED; + dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BUTTON); + if (params.closeOnTop) { + dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_TOP); + this.domElement.insertBefore(this.__closeButton, this.domElement.childNodes[0]); + } else { + dom.addClass(this.__closeButton, GUI.CLASS_CLOSE_BOTTOM); + this.domElement.appendChild(this.__closeButton); + } + dom.bind(this.__closeButton, 'click', function () { + _this.closed = !_this.closed; + }); + } else { + if (params.closed === undefined) { + params.closed = true; + } + var titleRowName = document.createTextNode(params.name); + dom.addClass(titleRowName, 'controller-name'); + titleRow = addRow(_this, titleRowName); + var onClickTitle = function onClickTitle(e) { + e.preventDefault(); + _this.closed = !_this.closed; + return false; + }; + dom.addClass(this.__ul, GUI.CLASS_CLOSED); + dom.addClass(titleRow, 'title'); + dom.bind(titleRow, 'click', onClickTitle); + if (!params.closed) { + this.closed = false; + } + } + if (params.autoPlace) { + if (Common.isUndefined(params.parent)) { + if (autoPlaceVirgin) { + autoPlaceContainer = document.createElement('div'); + dom.addClass(autoPlaceContainer, CSS_NAMESPACE); + dom.addClass(autoPlaceContainer, GUI.CLASS_AUTO_PLACE_CONTAINER); + document.body.appendChild(autoPlaceContainer); + autoPlaceVirgin = false; + } + autoPlaceContainer.appendChild(this.domElement); + dom.addClass(this.domElement, GUI.CLASS_AUTO_PLACE); + } + if (!this.parent) { + setWidth(_this, params.width); + } + } + this.__resizeHandler = function () { + _this.onResizeDebounced(); + }; + dom.bind(window, 'resize', this.__resizeHandler); + dom.bind(this.__ul, 'webkitTransitionEnd', this.__resizeHandler); + dom.bind(this.__ul, 'transitionend', this.__resizeHandler); + dom.bind(this.__ul, 'oTransitionEnd', this.__resizeHandler); + this.onResize(); + if (params.resizable) { + addResizeHandle(this); + } + saveToLocalStorage = function saveToLocalStorage() { + if (SUPPORTS_LOCAL_STORAGE && localStorage.getItem(getLocalStorageHash(_this, 'isLocal')) === 'true') { + localStorage.setItem(getLocalStorageHash(_this, 'gui'), JSON.stringify(_this.getSaveObject())); + } + }; + this.saveToLocalStorageIfPossible = saveToLocalStorage; + function resetWidth() { + var root = _this.getRoot(); + root.width += 1; + Common.defer(function () { + root.width -= 1; + }); + } + if (!params.parent) { + resetWidth(); + } + }; + GUI.toggleHide = function () { + hide = !hide; + Common.each(hideableGuis, function (gui) { + gui.domElement.style.display = hide ? 'none' : ''; + }); + }; + GUI.CLASS_AUTO_PLACE = 'a'; + GUI.CLASS_AUTO_PLACE_CONTAINER = 'ac'; + GUI.CLASS_MAIN = 'main'; + GUI.CLASS_CONTROLLER_ROW = 'cr'; + GUI.CLASS_TOO_TALL = 'taller-than-window'; + GUI.CLASS_CLOSED = 'closed'; + GUI.CLASS_CLOSE_BUTTON = 'close-button'; + GUI.CLASS_CLOSE_TOP = 'close-top'; + GUI.CLASS_CLOSE_BOTTOM = 'close-bottom'; + GUI.CLASS_DRAG = 'drag'; + GUI.DEFAULT_WIDTH = 245; + GUI.TEXT_CLOSED = 'Close Controls'; + GUI.TEXT_OPEN = 'Open Controls'; + GUI._keydownHandler = function (e) { + if (document.activeElement.type !== 'text' && (e.which === HIDE_KEY_CODE || e.keyCode === HIDE_KEY_CODE)) { + GUI.toggleHide(); + } + }; + dom.bind(window, 'keydown', GUI._keydownHandler, false); + Common.extend(GUI.prototype, + { + add: function add(object, property) { + return _add(this, object, property, { + factoryArgs: Array.prototype.slice.call(arguments, 2) + }); + }, + addColor: function addColor(object, property) { + return _add(this, object, property, { + color: true + }); + }, + remove: function remove(controller) { + this.__ul.removeChild(controller.__li); + this.__controllers.splice(this.__controllers.indexOf(controller), 1); + var _this = this; + Common.defer(function () { + _this.onResize(); + }); + }, + destroy: function destroy() { + if (this.parent) { + throw new Error('Only the root GUI should be removed with .destroy(). ' + 'For subfolders, use gui.removeFolder(folder) instead.'); + } + if (this.autoPlace) { + autoPlaceContainer.removeChild(this.domElement); + } + var _this = this; + Common.each(this.__folders, function (subfolder) { + _this.removeFolder(subfolder); + }); + dom.unbind(window, 'keydown', GUI._keydownHandler, false); + removeListeners(this); + }, + addFolder: function addFolder(name) { + if (this.__folders[name] !== undefined) { + throw new Error('You already have a folder in this GUI by the' + ' name "' + name + '"'); + } + var newGuiParams = { name: name, parent: this }; + newGuiParams.autoPlace = this.autoPlace; + if (this.load && + this.load.folders && + this.load.folders[name]) { + newGuiParams.closed = this.load.folders[name].closed; + newGuiParams.load = this.load.folders[name]; + } + var gui = new GUI(newGuiParams); + this.__folders[name] = gui; + var li = addRow(this, gui.domElement); + dom.addClass(li, 'folder'); + return gui; + }, + removeFolder: function removeFolder(folder) { + this.__ul.removeChild(folder.domElement.parentElement); + delete this.__folders[folder.name]; + if (this.load && + this.load.folders && + this.load.folders[folder.name]) { + delete this.load.folders[folder.name]; + } + removeListeners(folder); + var _this = this; + Common.each(folder.__folders, function (subfolder) { + folder.removeFolder(subfolder); + }); + Common.defer(function () { + _this.onResize(); + }); + }, + open: function open() { + this.closed = false; + }, + close: function close() { + this.closed = true; + }, + hide: function hide() { + this.domElement.style.display = 'none'; + }, + show: function show() { + this.domElement.style.display = ''; + }, + onResize: function onResize() { + var root = this.getRoot(); + if (root.scrollable) { + var top = dom.getOffset(root.__ul).top; + var h = 0; + Common.each(root.__ul.childNodes, function (node) { + if (!(root.autoPlace && node === root.__save_row)) { + h += dom.getHeight(node); + } + }); + if (window.innerHeight - top - CLOSE_BUTTON_HEIGHT < h) { + dom.addClass(root.domElement, GUI.CLASS_TOO_TALL); + root.__ul.style.height = window.innerHeight - top - CLOSE_BUTTON_HEIGHT + 'px'; + } else { + dom.removeClass(root.domElement, GUI.CLASS_TOO_TALL); + root.__ul.style.height = 'auto'; + } + } + if (root.__resize_handle) { + Common.defer(function () { + root.__resize_handle.style.height = root.__ul.offsetHeight + 'px'; + }); + } + if (root.__closeButton) { + root.__closeButton.style.width = root.width + 'px'; + } + }, + onResizeDebounced: Common.debounce(function () { + this.onResize(); + }, 50), + remember: function remember() { + if (Common.isUndefined(SAVE_DIALOGUE)) { + SAVE_DIALOGUE = new CenteredDiv(); + SAVE_DIALOGUE.domElement.innerHTML = saveDialogContents; + } + if (this.parent) { + throw new Error('You can only call remember on a top level GUI.'); + } + var _this = this; + Common.each(Array.prototype.slice.call(arguments), function (object) { + if (_this.__rememberedObjects.length === 0) { + addSaveMenu(_this); + } + if (_this.__rememberedObjects.indexOf(object) === -1) { + _this.__rememberedObjects.push(object); + } + }); + if (this.autoPlace) { + setWidth(this, this.width); + } + }, + getRoot: function getRoot() { + var gui = this; + while (gui.parent) { + gui = gui.parent; + } + return gui; + }, + getSaveObject: function getSaveObject() { + var toReturn = this.load; + toReturn.closed = this.closed; + if (this.__rememberedObjects.length > 0) { + toReturn.preset = this.preset; + if (!toReturn.remembered) { + toReturn.remembered = {}; + } + toReturn.remembered[this.preset] = getCurrentPreset(this); + } + toReturn.folders = {}; + Common.each(this.__folders, function (element, key) { + toReturn.folders[key] = element.getSaveObject(); + }); + return toReturn; + }, + save: function save() { + if (!this.load.remembered) { + this.load.remembered = {}; + } + this.load.remembered[this.preset] = getCurrentPreset(this); + markPresetModified(this, false); + this.saveToLocalStorageIfPossible(); + }, + saveAs: function saveAs(presetName) { + if (!this.load.remembered) { + this.load.remembered = {}; + this.load.remembered[DEFAULT_DEFAULT_PRESET_NAME] = getCurrentPreset(this, true); + } + this.load.remembered[presetName] = getCurrentPreset(this); + this.preset = presetName; + addPresetOption(this, presetName, true); + this.saveToLocalStorageIfPossible(); + }, + revert: function revert(gui) { + Common.each(this.__controllers, function (controller) { + if (!this.getRoot().load.remembered) { + controller.setValue(controller.initialValue); + } else { + recallSavedValue(gui || this.getRoot(), controller); + } + if (controller.__onFinishChange) { + controller.__onFinishChange.call(controller, controller.getValue()); + } + }, this); + Common.each(this.__folders, function (folder) { + folder.revert(folder); + }); + if (!gui) { + markPresetModified(this.getRoot(), false); + } + }, + listen: function listen(controller) { + var init = this.__listening.length === 0; + this.__listening.push(controller); + if (init) { + updateDisplays(this.__listening); + } + }, + updateDisplay: function updateDisplay() { + Common.each(this.__controllers, function (controller) { + controller.updateDisplay(); + }); + Common.each(this.__folders, function (folder) { + folder.updateDisplay(); + }); + } + }); + function addRow(gui, newDom, liBefore) { + var li = document.createElement('li'); + if (newDom) { + li.appendChild(newDom); + } + if (liBefore) { + gui.__ul.insertBefore(li, liBefore); + } else { + gui.__ul.appendChild(li); + } + gui.onResize(); + return li; + } + function removeListeners(gui) { + dom.unbind(window, 'resize', gui.__resizeHandler); + if (gui.saveToLocalStorageIfPossible) { + dom.unbind(window, 'unload', gui.saveToLocalStorageIfPossible); + } + } + function markPresetModified(gui, modified) { + var opt = gui.__preset_select[gui.__preset_select.selectedIndex]; + if (modified) { + opt.innerHTML = opt.value + '*'; + } else { + opt.innerHTML = opt.value; + } + } + function augmentController(gui, li, controller) { + controller.__li = li; + controller.__gui = gui; + Common.extend(controller, { + options: function options(_options) { + if (arguments.length > 1) { + var nextSibling = controller.__li.nextElementSibling; + controller.remove(); + return _add(gui, controller.object, controller.property, { + before: nextSibling, + factoryArgs: [Common.toArray(arguments)] + }); + } + if (Common.isArray(_options) || Common.isObject(_options)) { + var _nextSibling = controller.__li.nextElementSibling; + controller.remove(); + return _add(gui, controller.object, controller.property, { + before: _nextSibling, + factoryArgs: [_options] + }); + } + }, + name: function name(_name) { + controller.__li.firstElementChild.firstElementChild.innerHTML = _name; + return controller; + }, + listen: function listen() { + controller.__gui.listen(controller); + return controller; + }, + remove: function remove() { + controller.__gui.remove(controller); + return controller; + } + }); + if (controller instanceof NumberControllerSlider) { + var box = new NumberControllerBox(controller.object, controller.property, { min: controller.__min, max: controller.__max, step: controller.__step }); + Common.each(['updateDisplay', 'onChange', 'onFinishChange', 'step', 'min', 'max'], function (method) { + var pc = controller[method]; + var pb = box[method]; + controller[method] = box[method] = function () { + var args = Array.prototype.slice.call(arguments); + pb.apply(box, args); + return pc.apply(controller, args); + }; + }); + dom.addClass(li, 'has-slider'); + controller.domElement.insertBefore(box.domElement, controller.domElement.firstElementChild); + } else if (controller instanceof NumberControllerBox) { + var r = function r(returned) { + if (Common.isNumber(controller.__min) && Common.isNumber(controller.__max)) { + var oldName = controller.__li.firstElementChild.firstElementChild.innerHTML; + var wasListening = controller.__gui.__listening.indexOf(controller) > -1; + controller.remove(); + var newController = _add(gui, controller.object, controller.property, { + before: controller.__li.nextElementSibling, + factoryArgs: [controller.__min, controller.__max, controller.__step] + }); + newController.name(oldName); + if (wasListening) { newController.listen(); } + return newController; + } + return returned; + }; + controller.min = Common.compose(r, controller.min); + controller.max = Common.compose(r, controller.max); + } else if (controller instanceof BooleanController) { + dom.bind(li, 'click', function () { + dom.fakeEvent(controller.__checkbox, 'click'); + }); + dom.bind(controller.__checkbox, 'click', function (e) { + e.stopPropagation(); + }); + } else if (controller instanceof FunctionController) { + dom.bind(li, 'click', function () { + dom.fakeEvent(controller.__button, 'click'); + }); + dom.bind(li, 'mouseover', function () { + dom.addClass(controller.__button, 'hover'); + }); + dom.bind(li, 'mouseout', function () { + dom.removeClass(controller.__button, 'hover'); + }); + } else if (controller instanceof ColorController) { + dom.addClass(li, 'color'); + controller.updateDisplay = Common.compose(function (val) { + li.style.borderLeftColor = controller.__color.toString(); + return val; + }, controller.updateDisplay); + controller.updateDisplay(); + } + controller.setValue = Common.compose(function (val) { + if (gui.getRoot().__preset_select && controller.isModified()) { + markPresetModified(gui.getRoot(), true); + } + return val; + }, controller.setValue); + } + function recallSavedValue(gui, controller) { + var root = gui.getRoot(); + var matchedIndex = root.__rememberedObjects.indexOf(controller.object); + if (matchedIndex !== -1) { + var controllerMap = root.__rememberedObjectIndecesToControllers[matchedIndex]; + if (controllerMap === undefined) { + controllerMap = {}; + root.__rememberedObjectIndecesToControllers[matchedIndex] = controllerMap; + } + controllerMap[controller.property] = controller; + if (root.load && root.load.remembered) { + var presetMap = root.load.remembered; + var preset = void 0; + if (presetMap[gui.preset]) { + preset = presetMap[gui.preset]; + } else if (presetMap[DEFAULT_DEFAULT_PRESET_NAME]) { + preset = presetMap[DEFAULT_DEFAULT_PRESET_NAME]; + } else { + return; + } + if (preset[matchedIndex] && preset[matchedIndex][controller.property] !== undefined) { + var value = preset[matchedIndex][controller.property]; + controller.initialValue = value; + controller.setValue(value); + } + } + } + } + function _add(gui, object, property, params) { + if (object[property] === undefined) { + throw new Error('Object "' + object + '" has no property "' + property + '"'); + } + var controller = void 0; + if (params.color) { + controller = new ColorController(object, property); + } else { + var factoryArgs = [object, property].concat(params.factoryArgs); + controller = ControllerFactory.apply(gui, factoryArgs); + } + if (params.before instanceof Controller) { + params.before = params.before.__li; + } + recallSavedValue(gui, controller); + dom.addClass(controller.domElement, 'c'); + var name = document.createElement('span'); + dom.addClass(name, 'property-name'); + name.innerHTML = controller.property; + var container = document.createElement('div'); + container.appendChild(name); + container.appendChild(controller.domElement); + var li = addRow(gui, container, params.before); + dom.addClass(li, GUI.CLASS_CONTROLLER_ROW); + if (controller instanceof ColorController) { + dom.addClass(li, 'color'); + } else { + dom.addClass(li, _typeof(controller.getValue())); + } + augmentController(gui, li, controller); + gui.__controllers.push(controller); + return controller; + } + function getLocalStorageHash(gui, key) { + return document.location.href + '.' + key; + } + function addPresetOption(gui, name, setSelected) { + var opt = document.createElement('option'); + opt.innerHTML = name; + opt.value = name; + gui.__preset_select.appendChild(opt); + if (setSelected) { + gui.__preset_select.selectedIndex = gui.__preset_select.length - 1; + } + } + function showHideExplain(gui, explain) { + explain.style.display = gui.useLocalStorage ? 'block' : 'none'; + } + function addSaveMenu(gui) { + var div = gui.__save_row = document.createElement('li'); + dom.addClass(gui.domElement, 'has-save'); + gui.__ul.insertBefore(div, gui.__ul.firstChild); + dom.addClass(div, 'save-row'); + var gears = document.createElement('span'); + gears.innerHTML = ' '; + dom.addClass(gears, 'button gears'); + var button = document.createElement('span'); + button.innerHTML = 'Save'; + dom.addClass(button, 'button'); + dom.addClass(button, 'save'); + var button2 = document.createElement('span'); + button2.innerHTML = 'New'; + dom.addClass(button2, 'button'); + dom.addClass(button2, 'save-as'); + var button3 = document.createElement('span'); + button3.innerHTML = 'Revert'; + dom.addClass(button3, 'button'); + dom.addClass(button3, 'revert'); + var select = gui.__preset_select = document.createElement('select'); + if (gui.load && gui.load.remembered) { + Common.each(gui.load.remembered, function (value, key) { + addPresetOption(gui, key, key === gui.preset); + }); + } else { + addPresetOption(gui, DEFAULT_DEFAULT_PRESET_NAME, false); + } + dom.bind(select, 'change', function () { + for (var index = 0; index < gui.__preset_select.length; index++) { + gui.__preset_select[index].innerHTML = gui.__preset_select[index].value; + } + gui.preset = this.value; + }); + div.appendChild(select); + div.appendChild(gears); + div.appendChild(button); + div.appendChild(button2); + div.appendChild(button3); + if (SUPPORTS_LOCAL_STORAGE) { + var explain = document.getElementById('dg-local-explain'); + var localStorageCheckBox = document.getElementById('dg-local-storage'); + var saveLocally = document.getElementById('dg-save-locally'); + saveLocally.style.display = 'block'; + if (localStorage.getItem(getLocalStorageHash(gui, 'isLocal')) === 'true') { + localStorageCheckBox.setAttribute('checked', 'checked'); + } + showHideExplain(gui, explain); + dom.bind(localStorageCheckBox, 'change', function () { + gui.useLocalStorage = !gui.useLocalStorage; + showHideExplain(gui, explain); + }); + } + var newConstructorTextArea = document.getElementById('dg-new-constructor'); + dom.bind(newConstructorTextArea, 'keydown', function (e) { + if (e.metaKey && (e.which === 67 || e.keyCode === 67)) { + SAVE_DIALOGUE.hide(); + } + }); + dom.bind(gears, 'click', function () { + newConstructorTextArea.innerHTML = JSON.stringify(gui.getSaveObject(), undefined, 2); + SAVE_DIALOGUE.show(); + newConstructorTextArea.focus(); + newConstructorTextArea.select(); + }); + dom.bind(button, 'click', function () { + gui.save(); + }); + dom.bind(button2, 'click', function () { + var presetName = prompt('Enter a new preset name.'); + if (presetName) { + gui.saveAs(presetName); + } + }); + dom.bind(button3, 'click', function () { + gui.revert(); + }); + } + function addResizeHandle(gui) { + var pmouseX = void 0; + gui.__resize_handle = document.createElement('div'); + Common.extend(gui.__resize_handle.style, { + width: '6px', + marginLeft: '-3px', + height: '200px', + cursor: 'ew-resize', + position: 'absolute' + }); + function drag(e) { + e.preventDefault(); + gui.width += pmouseX - e.clientX; + gui.onResize(); + pmouseX = e.clientX; + return false; + } + function dragStop() { + dom.removeClass(gui.__closeButton, GUI.CLASS_DRAG); + dom.unbind(window, 'mousemove', drag); + dom.unbind(window, 'mouseup', dragStop); + } + function dragStart(e) { + e.preventDefault(); + pmouseX = e.clientX; + dom.addClass(gui.__closeButton, GUI.CLASS_DRAG); + dom.bind(window, 'mousemove', drag); + dom.bind(window, 'mouseup', dragStop); + return false; + } + dom.bind(gui.__resize_handle, 'mousedown', dragStart); + dom.bind(gui.__closeButton, 'mousedown', dragStart); + gui.domElement.insertBefore(gui.__resize_handle, gui.domElement.firstElementChild); + } + function setWidth(gui, w) { + gui.domElement.style.width = w + 'px'; + if (gui.__save_row && gui.autoPlace) { + gui.__save_row.style.width = w + 'px'; + } + if (gui.__closeButton) { + gui.__closeButton.style.width = w + 'px'; + } + } + function getCurrentPreset(gui, useInitialValues) { + var toReturn = {}; + Common.each(gui.__rememberedObjects, function (val, index) { + var savedValues = {}; + var controllerMap = gui.__rememberedObjectIndecesToControllers[index]; + Common.each(controllerMap, function (controller, property) { + savedValues[property] = useInitialValues ? controller.initialValue : controller.getValue(); + }); + toReturn[index] = savedValues; + }); + return toReturn; + } + function setPresetSelectIndex(gui) { + for (var index = 0; index < gui.__preset_select.length; index++) { + if (gui.__preset_select[index].value === gui.preset) { + gui.__preset_select.selectedIndex = index; + } + } + } + function updateDisplays(controllerArray) { + if (controllerArray.length !== 0) { + requestAnimationFrame$1$1.call(window, function () { + updateDisplays(controllerArray); + }); + } + Common.each(controllerArray, function (c) { + c.updateDisplay(); + }); + } + var GUI$1 = GUI; + + /** + * three-demo v4.0.1 build Mon Aug 17 2020 + * https://github.com/vanruesc/three-demo + * Copyright 2020 Raoul van Rüschen + * @license Zlib + */ + + var Demo = function Demo(id) { + if ( id === void 0 ) id = "demo"; + + this.scene = new Scene(); + this.id = id; + this.renderer = null; + this.loadingManager = new LoadingManager(); + this.assets = new Map(); + this.scene = new Scene(); + this.camera = null; + this.ready = false; + }; + Demo.prototype.setRenderer = function setRenderer (renderer) { + this.renderer = renderer; + return this; + }; + Demo.prototype.getCamera = function getCamera () { + return this.camera; + }; + Demo.prototype.load = function load () { + return Promise.resolve(); + }; + Demo.prototype.initialize = function initialize () { }; + Demo.prototype.render = function render (deltaTime) { + this.renderer.render(this.scene, this.camera); + }; + Demo.prototype.registerOptions = function registerOptions (menu) { }; + Demo.prototype.reset = function reset () { + this.scene = new Scene(); + this.camera = null; + this.ready = false; + return this; + }; + + var DemoManagerEvent = function DemoManagerEvent(type) { + this.type = type; + this.previousDemo = null; + this.demo = null; + }; + + var change = new DemoManagerEvent("change"); + var load = new DemoManagerEvent("load"); + + var MILLISECONDS_TO_SECONDS = 1.0 / 1e3; + var DemoManager = /*@__PURE__*/(function (EventDispatcher) { + function DemoManager(viewport, ref) { + var aside = ref.aside; if ( aside === void 0 ) aside = viewport; + var renderer = ref.renderer; + + EventDispatcher.call(this); + this.renderer = renderer; + if (this.renderer === undefined) { + var renderer$1 = new WebGLRenderer(); + renderer$1.setSize(viewport.clientWidth, viewport.clientHeight); + renderer$1.setPixelRatio(window.devicePixelRatio); + this.renderer = renderer$1; + } + this.timestamp = 0.0; + this.menu = new GUI$1({ autoPlace: false }); + this.demos = new Map(); + this.demo = null; + this.currentDemo = null; + viewport.appendChild(this.renderer.domElement); + aside.appendChild(this.menu.domElement); + } + + if ( EventDispatcher ) DemoManager.__proto__ = EventDispatcher; + DemoManager.prototype = Object.create( EventDispatcher && EventDispatcher.prototype ); + DemoManager.prototype.constructor = DemoManager; + DemoManager.prototype.resetMenu = function resetMenu () { + var this$1 = this; + + var node = this.menu.domElement.parentNode; + var menu = new GUI$1({ autoPlace: false }); + if (this.demos.size > 1) { + var selection = menu.add(this, "demo", Array.from(this.demos.keys())); + selection.onChange(function () { return this$1.loadDemo(); }); + } + node.removeChild(this.menu.domElement); + node.appendChild(menu.domElement); + this.menu.destroy(); + this.menu = menu; + return menu; + }; + DemoManager.prototype.startDemo = function startDemo (demo) { + if (demo.id === this.demo) { + demo.initialize(); + demo.registerOptions(this.resetMenu()); + demo.ready = true; + load.demo = demo; + this.dispatchEvent(load); + } + }; + DemoManager.prototype.loadDemo = function loadDemo () { + var this$1 = this; + + var nextDemo = this.demos.get(this.demo); + var currentDemo = this.currentDemo; + var renderer = this.renderer; + window.location.hash = nextDemo.id; + if (currentDemo !== null) { + currentDemo.reset(); + } + this.menu.domElement.style.display = "none"; + change.previousDemo = currentDemo; + change.demo = nextDemo; + this.currentDemo = nextDemo; + this.dispatchEvent(change); + renderer.clear(); + nextDemo.load() + .then(function () { return this$1.startDemo(nextDemo); }) + .catch(console.error); + }; + DemoManager.prototype.addDemo = function addDemo (demo) { + var hash = window.location.hash.slice(1); + var currentDemo = this.currentDemo; + this.demos.set(demo.id, demo.setRenderer(this.renderer)); + if ((this.demo === null && hash.length === 0) || demo.id === hash) { + this.demo = demo.id; + this.loadDemo(); + } + this.resetMenu(); + if (currentDemo !== null && currentDemo.ready) { + currentDemo.registerOptions(this.menu); + } + return this; + }; + DemoManager.prototype.removeDemo = function removeDemo (id) { + var demos = this.demos; + if (demos.has(id)) { + demos.delete(id); + if (this.demo === id && demos.size > 0) { + var entries = Array.from(demos.entries()); + var firstEntry = entries[0]; + this.demo = firstEntry[0]; + this.currentDemo = firstEntry[1]; + this.loadDemo(); + } + else { + this.demo = null; + this.currentDemo = null; + this.renderer.clear(); + } + } + return this; + }; + DemoManager.prototype.setSize = function setSize (width, height, updateStyle) { + if ( updateStyle === void 0 ) updateStyle = true; + + var demo = this.currentDemo; + var camera = demo.getCamera(); + this.renderer.setSize(width, height, updateStyle); + if (demo !== null && camera !== null) { + if (camera instanceof OrthographicCamera) { + camera.left = width / -2.0; + camera.right = width / 2.0; + camera.top = height / 2.0; + camera.bottom = height / -2.0; + camera.updateProjectionMatrix(); + } + else if (camera instanceof PerspectiveCamera) { + camera.aspect = width / height; + camera.updateProjectionMatrix(); + } + } + }; + DemoManager.prototype.render = function render (timestamp) { + var elapsed = (timestamp - this.timestamp) * MILLISECONDS_TO_SECONDS; + this.timestamp = timestamp; + var demo = this.currentDemo; + if (demo !== null && demo.ready) { + demo.render(elapsed); + } + }; + + return DemoManager; + }(EventDispatcher)); + + /** + * spatial-controls v3.0.0 build Tue Aug 18 2020 + * https://github.com/vanruesc/spatial-controls + * Copyright 2020 Raoul van Rüschen + * @license Zlib + */ + + var Action; + (function (Action) { + Action[Action["MOVE_FORWARD"] = 0] = "MOVE_FORWARD"; + Action[Action["MOVE_LEFT"] = 1] = "MOVE_LEFT"; + Action[Action["MOVE_BACKWARD"] = 2] = "MOVE_BACKWARD"; + Action[Action["MOVE_RIGHT"] = 3] = "MOVE_RIGHT"; + Action[Action["MOVE_DOWN"] = 4] = "MOVE_DOWN"; + Action[Action["MOVE_UP"] = 5] = "MOVE_UP"; + Action[Action["ZOOM_OUT"] = 6] = "ZOOM_OUT"; + Action[Action["ZOOM_IN"] = 7] = "ZOOM_IN"; + })(Action || (Action = {})); + + var PointerButton; + (function (PointerButton) { + PointerButton[PointerButton["MAIN"] = 0] = "MAIN"; + PointerButton[PointerButton["AUXILIARY"] = 1] = "AUXILIARY"; + PointerButton[PointerButton["SECONDARY"] = 2] = "SECONDARY"; + })(PointerButton || (PointerButton = {})); + + var MovementState = function MovementState() { + this.reset(); + }; + MovementState.prototype.reset = function reset () { + this.left = false; + this.right = false; + this.forward = false; + this.backward = false; + this.up = false; + this.down = false; + return this; + }; + + var TWO_PI = Math.PI * 2; + var v = new Vector3(); + var m = new Matrix4(); + var RotationManager = function RotationManager(position, quaternion, target, settings) { + this.position = position; + this.quaternion = quaternion; + this.target = target; + this.settings = settings; + this.spherical = new Spherical(); + }; + RotationManager.prototype.setPosition = function setPosition (position) { + this.position = position; + return this; + }; + RotationManager.prototype.setQuaternion = function setQuaternion (quaternion) { + this.quaternion = quaternion; + return this; + }; + RotationManager.prototype.setTarget = function setTarget (target) { + this.target = target; + return this; + }; + RotationManager.prototype.updateQuaternion = function updateQuaternion () { + var settings = this.settings; + var rotation = settings.rotation; + if (settings.general.orbit) { + m.lookAt(v.subVectors(this.position, this.target), rotation.pivotOffset, rotation.up); + } + else { + m.lookAt(v.set(0, 0, 0), this.target.setFromSpherical(this.spherical), rotation.up); + } + this.quaternion.setFromRotationMatrix(m); + return this; + }; + RotationManager.prototype.adjustSpherical = function adjustSpherical (theta, phi) { + var settings = this.settings; + var orbit = settings.general.orbit; + var rotation = settings.rotation; + var s = this.spherical; + s.theta = !rotation.invertX ? s.theta - theta : s.theta + theta; + s.phi = ((orbit || rotation.invertY) && !(orbit && rotation.invertY)) ? s.phi - phi : s.phi + phi; + s.theta = Math.min(Math.max(s.theta, rotation.minAzimuthalAngle), rotation.maxAzimuthalAngle); + s.phi = Math.min(Math.max(s.phi, rotation.minPolarAngle), rotation.maxPolarAngle); + s.theta %= TWO_PI; + s.makeSafe(); + if (orbit) { + this.position.setFromSpherical(s).add(this.target); + } + return this; + }; + RotationManager.prototype.zoom = function zoom (sign) { + var settings = this.settings; + var general = settings.general; + var sensitivity = settings.sensitivity; + var zoom = settings.zoom; + var s = this.spherical; + if (general.orbit && zoom.enabled) { + var amount = sign * sensitivity.zoom; + if (zoom.invert) { + amount = -amount; + } + var min = Math.max(zoom.minDistance, 1e-6); + var max = Math.min(zoom.maxDistance, Number.POSITIVE_INFINITY); + s.radius = Math.min(Math.max(s.radius + amount, min), max); + this.position.setFromSpherical(s).add(this.target); + } + return this; + }; + RotationManager.prototype.update = function update (deltaTime) { }; + RotationManager.prototype.lookAt = function lookAt (point) { + var spherical = this.spherical; + var position = this.position; + var target = this.target; + target.copy(point); + if (this.settings.general.orbit) { + v.subVectors(position, target); + } + else { + v.subVectors(target, position).normalize(); + } + spherical.setFromVector3(v); + spherical.radius = Math.max(spherical.radius, 1e-6); + this.updateQuaternion(); + return this; + }; + RotationManager.prototype.getViewDirection = function getViewDirection (view) { + view.setFromSpherical(this.spherical).normalize(); + if (this.settings.general.orbit) { + view.negate(); + } + return view; + }; + + var x = new Vector3(1, 0, 0); + var y = new Vector3(0, 1, 0); + var z = new Vector3(0, 0, 1); + + var v$1 = new Vector3(); + var TranslationManager = function TranslationManager(position, quaternion, target, settings) { + this.position = position; + this.quaternion = quaternion; + this.target = target; + this.settings = settings; + this.movementState = new MovementState(); + }; + TranslationManager.prototype.setPosition = function setPosition (position) { + this.position = position; + return this; + }; + TranslationManager.prototype.setQuaternion = function setQuaternion (quaternion) { + this.quaternion = quaternion; + return this; + }; + TranslationManager.prototype.setTarget = function setTarget (target) { + this.target = target; + return this; + }; + TranslationManager.prototype.translateOnAxis = function translateOnAxis (axis, distance) { + v$1.copy(axis).applyQuaternion(this.quaternion).multiplyScalar(distance); + this.position.add(v$1); + if (this.settings.general.orbit) { + this.target.add(v$1); + } + }; + TranslationManager.prototype.translate = function translate (deltaTime) { + var sensitivity = this.settings.sensitivity; + var state = this.movementState; + var step = deltaTime * sensitivity.translation; + if (state.backward) { + this.translateOnAxis(z, step); + } + else if (state.forward) { + this.translateOnAxis(z, -step); + } + if (state.right) { + this.translateOnAxis(x, step); + } + else if (state.left) { + this.translateOnAxis(x, -step); + } + if (state.up) { + this.translateOnAxis(y, step); + } + else if (state.down) { + this.translateOnAxis(y, -step); + } + }; + TranslationManager.prototype.update = function update (deltaTime) { + if (this.settings.translation.enabled) { + this.translate(deltaTime); + } + }; + TranslationManager.prototype.moveTo = function moveTo (position) { + if (this.settings.general.orbit) { + this.target.copy(position); + } + else { + this.position.copy(position); + } + return this; + }; + + var KeyCode; + (function (KeyCode) { + KeyCode[KeyCode["BACKSPACE"] = 8] = "BACKSPACE"; + KeyCode[KeyCode["TAB"] = 9] = "TAB"; + KeyCode[KeyCode["ENTER"] = 13] = "ENTER"; + KeyCode[KeyCode["SHIFT"] = 16] = "SHIFT"; + KeyCode[KeyCode["CTRL"] = 17] = "CTRL"; + KeyCode[KeyCode["ALT"] = 18] = "ALT"; + KeyCode[KeyCode["PAUSE"] = 19] = "PAUSE"; + KeyCode[KeyCode["CAPS_LOCK"] = 20] = "CAPS_LOCK"; + KeyCode[KeyCode["ESCAPE"] = 27] = "ESCAPE"; + KeyCode[KeyCode["SPACE"] = 32] = "SPACE"; + KeyCode[KeyCode["PAGE_UP"] = 33] = "PAGE_UP"; + KeyCode[KeyCode["PAGE_DOWN"] = 34] = "PAGE_DOWN"; + KeyCode[KeyCode["END"] = 35] = "END"; + KeyCode[KeyCode["HOME"] = 36] = "HOME"; + KeyCode[KeyCode["LEFT"] = 37] = "LEFT"; + KeyCode[KeyCode["UP"] = 38] = "UP"; + KeyCode[KeyCode["RIGHT"] = 39] = "RIGHT"; + KeyCode[KeyCode["DOWN"] = 40] = "DOWN"; + KeyCode[KeyCode["INSERT"] = 45] = "INSERT"; + KeyCode[KeyCode["DELETE"] = 46] = "DELETE"; + KeyCode[KeyCode["DIGIT_0"] = 48] = "DIGIT_0"; + KeyCode[KeyCode["DIGIT_1"] = 49] = "DIGIT_1"; + KeyCode[KeyCode["DIGIT_2"] = 50] = "DIGIT_2"; + KeyCode[KeyCode["DIGIT_3"] = 51] = "DIGIT_3"; + KeyCode[KeyCode["DIGIT_4"] = 52] = "DIGIT_4"; + KeyCode[KeyCode["DIGIT_5"] = 53] = "DIGIT_5"; + KeyCode[KeyCode["DIGIT_6"] = 54] = "DIGIT_6"; + KeyCode[KeyCode["DIGIT_7"] = 55] = "DIGIT_7"; + KeyCode[KeyCode["DIGIT_8"] = 56] = "DIGIT_8"; + KeyCode[KeyCode["DIGIT_9"] = 57] = "DIGIT_9"; + KeyCode[KeyCode["A"] = 65] = "A"; + KeyCode[KeyCode["B"] = 66] = "B"; + KeyCode[KeyCode["C"] = 67] = "C"; + KeyCode[KeyCode["D"] = 68] = "D"; + KeyCode[KeyCode["E"] = 69] = "E"; + KeyCode[KeyCode["F"] = 70] = "F"; + KeyCode[KeyCode["G"] = 71] = "G"; + KeyCode[KeyCode["H"] = 72] = "H"; + KeyCode[KeyCode["I"] = 73] = "I"; + KeyCode[KeyCode["J"] = 74] = "J"; + KeyCode[KeyCode["K"] = 75] = "K"; + KeyCode[KeyCode["L"] = 76] = "L"; + KeyCode[KeyCode["M"] = 77] = "M"; + KeyCode[KeyCode["N"] = 78] = "N"; + KeyCode[KeyCode["O"] = 79] = "O"; + KeyCode[KeyCode["P"] = 80] = "P"; + KeyCode[KeyCode["Q"] = 81] = "Q"; + KeyCode[KeyCode["R"] = 82] = "R"; + KeyCode[KeyCode["S"] = 83] = "S"; + KeyCode[KeyCode["T"] = 84] = "T"; + KeyCode[KeyCode["U"] = 85] = "U"; + KeyCode[KeyCode["V"] = 86] = "V"; + KeyCode[KeyCode["W"] = 87] = "W"; + KeyCode[KeyCode["X"] = 88] = "X"; + KeyCode[KeyCode["Y"] = 89] = "Y"; + KeyCode[KeyCode["Z"] = 90] = "Z"; + KeyCode[KeyCode["META_LEFT"] = 91] = "META_LEFT"; + KeyCode[KeyCode["META_RIGHT"] = 92] = "META_RIGHT"; + KeyCode[KeyCode["SELECT"] = 93] = "SELECT"; + KeyCode[KeyCode["NUMPAD_0"] = 96] = "NUMPAD_0"; + KeyCode[KeyCode["NUMPAD_1"] = 97] = "NUMPAD_1"; + KeyCode[KeyCode["NUMPAD_2"] = 98] = "NUMPAD_2"; + KeyCode[KeyCode["NUMPAD_3"] = 99] = "NUMPAD_3"; + KeyCode[KeyCode["NUMPAD_4"] = 100] = "NUMPAD_4"; + KeyCode[KeyCode["NUMPAD_5"] = 101] = "NUMPAD_5"; + KeyCode[KeyCode["NUMPAD_6"] = 102] = "NUMPAD_6"; + KeyCode[KeyCode["NUMPAD_7"] = 103] = "NUMPAD_7"; + KeyCode[KeyCode["NUMPAD_8"] = 104] = "NUMPAD_8"; + KeyCode[KeyCode["NUMPAD_9"] = 105] = "NUMPAD_9"; + KeyCode[KeyCode["MULTIPLY"] = 106] = "MULTIPLY"; + KeyCode[KeyCode["ADD"] = 107] = "ADD"; + KeyCode[KeyCode["SUBTRACT"] = 109] = "SUBTRACT"; + KeyCode[KeyCode["DECIMAL_POINT"] = 110] = "DECIMAL_POINT"; + KeyCode[KeyCode["DIVIDE"] = 111] = "DIVIDE"; + KeyCode[KeyCode["F1"] = 112] = "F1"; + KeyCode[KeyCode["F2"] = 113] = "F2"; + KeyCode[KeyCode["F3"] = 114] = "F3"; + KeyCode[KeyCode["F4"] = 115] = "F4"; + KeyCode[KeyCode["F5"] = 116] = "F5"; + KeyCode[KeyCode["F6"] = 117] = "F6"; + KeyCode[KeyCode["F7"] = 118] = "F7"; + KeyCode[KeyCode["F8"] = 119] = "F8"; + KeyCode[KeyCode["F9"] = 120] = "F9"; + KeyCode[KeyCode["F10"] = 121] = "F10"; + KeyCode[KeyCode["F11"] = 122] = "F11"; + KeyCode[KeyCode["F12"] = 123] = "F12"; + KeyCode[KeyCode["NUM_LOCK"] = 144] = "NUM_LOCK"; + KeyCode[KeyCode["SCROLL_LOCK"] = 145] = "SCROLL_LOCK"; + KeyCode[KeyCode["SEMICOLON"] = 186] = "SEMICOLON"; + KeyCode[KeyCode["EQUAL_SIGN"] = 187] = "EQUAL_SIGN"; + KeyCode[KeyCode["COMMA"] = 188] = "COMMA"; + KeyCode[KeyCode["DASH"] = 189] = "DASH"; + KeyCode[KeyCode["PERIOD"] = 190] = "PERIOD"; + KeyCode[KeyCode["FORWARD_SLASH"] = 191] = "FORWARD_SLASH"; + KeyCode[KeyCode["GRAVE_ACCENT"] = 192] = "GRAVE_ACCENT"; + KeyCode[KeyCode["OPEN_BRACKET"] = 219] = "OPEN_BRACKET"; + KeyCode[KeyCode["BACK_SLASH"] = 220] = "BACK_SLASH"; + KeyCode[KeyCode["CLOSE_BRACKET"] = 221] = "CLOSE_BRACKET"; + KeyCode[KeyCode["SINGLE_QUOTE"] = 222] = "SINGLE_QUOTE"; + })(KeyCode || (KeyCode = {})); + + var GeneralSettings = function GeneralSettings() { + this.orbit = true; + }; + GeneralSettings.prototype.copy = function copy (settings) { + this.orbit = settings.orbit; + return this; + }; + GeneralSettings.prototype.clone = function clone () { + var clone = new GeneralSettings(); + return clone.copy(this); + }; + + var KeyBindings = function KeyBindings() { + this.defaultActions = new Map(); + this.actions = new Map(); + }; + KeyBindings.prototype.reset = function reset () { + this.actions = new Map(this.defaultActions); + return this; + }; + KeyBindings.prototype.setDefault = function setDefault (actions) { + this.defaultActions = actions; + return this.reset(); + }; + KeyBindings.prototype.copy = function copy (keyBindings) { + this.defaultActions = new Map(keyBindings.defaultActions); + this.actions = new Map(keyBindings.actions); + return this; + }; + KeyBindings.prototype.clearDefault = function clearDefault () { + this.defaultActions.clear(); + return this; + }; + KeyBindings.prototype.clear = function clear () { + this.actions.clear(); + return this; + }; + KeyBindings.prototype.clone = function clone () { + var clone = new KeyBindings(); + return clone.copy(this); + }; + KeyBindings.prototype.has = function has (keyCode) { + return this.actions.has(keyCode); + }; + KeyBindings.prototype.get = function get (keyCode) { + return this.actions.get(keyCode); + }; + KeyBindings.prototype.set = function set (keyCode, action) { + this.actions.set(keyCode, action); + return this; + }; + KeyBindings.prototype.delete = function delete$1 (keyCode) { + return this.actions.delete(keyCode); + }; + KeyBindings.prototype.toJSON = function toJSON () { + return { + defaultActions: [].concat( this.defaultActions ), + actions: [].concat( this.actions ) + }; + }; + + var PointerSettings = function PointerSettings() { + this.hold = false; + this.lock = true; + }; + PointerSettings.prototype.copy = function copy (settings) { + this.hold = settings.hold; + this.lock = settings.lock; + return this; + }; + PointerSettings.prototype.clone = function clone () { + var clone = new PointerSettings(); + return clone.copy(this); + }; + + var RotationSettings = function RotationSettings() { + this.up = new Vector3(); + this.up.copy(y); + this.pivotOffset = new Vector3(); + this.minAzimuthalAngle = Number.NEGATIVE_INFINITY; + this.maxAzimuthalAngle = Number.POSITIVE_INFINITY; + this.minPolarAngle = 0.0; + this.maxPolarAngle = Math.PI; + this.invertX = false; + this.invertY = false; + }; + RotationSettings.prototype.copy = function copy (settings) { + this.up.copy(settings.up); + this.pivotOffset.copy(settings.pivotOffset); + this.minAzimuthalAngle = settings.minAzimuthalAngle; + this.maxAzimuthalAngle = settings.maxAzimuthalAngle; + this.minPolarAngle = settings.minPolarAngle; + this.maxPolarAngle = settings.maxPolarAngle; + this.invertX = settings.invertX; + this.invertY = settings.invertY; + return this; + }; + RotationSettings.prototype.clone = function clone () { + var clone = new RotationSettings(); + return clone.copy(this); + }; + + var SensitivitySettings = function SensitivitySettings() { + this.rotationX = 1.0; + this.rotationY = 1.0; + this.translation = 1.0; + this.zoom = 1.0; + }; + + var prototypeAccessors = { rotation: { configurable: true } }; + prototypeAccessors.rotation.set = function (value) { + this.rotationX = this.rotationY = value; + }; + SensitivitySettings.prototype.copy = function copy (settings) { + this.rotationX = settings.rotationX; + this.rotationY = settings.rotationY; + this.translation = settings.translation; + this.zoom = settings.zoom; + return this; + }; + SensitivitySettings.prototype.clone = function clone () { + var clone = new SensitivitySettings(); + return clone.copy(this); + }; + + Object.defineProperties( SensitivitySettings.prototype, prototypeAccessors ); + + var TranslationSettings = function TranslationSettings() { + this.enabled = true; + }; + TranslationSettings.prototype.copy = function copy (settings) { + this.enabled = settings.enabled; + return this; + }; + TranslationSettings.prototype.clone = function clone () { + var clone = new TranslationSettings(); + return clone.copy(this); + }; + + var ZoomSettings = function ZoomSettings() { + this.enabled = true; + this.invert = false; + this.minDistance = 1e-6; + this.maxDistance = Infinity; + }; + ZoomSettings.prototype.copy = function copy (settings) { + this.enabled = settings.enabled; + this.invert = settings.invert; + this.minDistance = settings.minDistance; + this.maxDistance = settings.maxDistance; + return this; + }; + ZoomSettings.prototype.clone = function clone () { + var clone = new ZoomSettings(); + return clone.copy(this); + }; + + var Settings = function Settings() { + this.general = new GeneralSettings(); + this.keyBindings = new KeyBindings(); + this.keyBindings.setDefault(new Map([ + [KeyCode.W, Action.MOVE_FORWARD], + [KeyCode.UP, Action.MOVE_FORWARD], + [KeyCode.A, Action.MOVE_LEFT], + [KeyCode.LEFT, Action.MOVE_LEFT], + [KeyCode.S, Action.MOVE_BACKWARD], + [KeyCode.DOWN, Action.MOVE_BACKWARD], + [KeyCode.D, Action.MOVE_RIGHT], + [KeyCode.RIGHT, Action.MOVE_RIGHT], + [KeyCode.X, Action.MOVE_DOWN], + [KeyCode.SPACE, Action.MOVE_UP], + [KeyCode.PAGE_DOWN, Action.ZOOM_OUT], + [KeyCode.PAGE_UP, Action.ZOOM_IN] + ])); + this.pointer = new PointerSettings(); + this.rotation = new RotationSettings(); + this.sensitivity = new SensitivitySettings(); + this.translation = new TranslationSettings(); + this.zoom = new ZoomSettings(); + }; + Settings.prototype.copy = function copy (settings) { + this.general.copy(settings.general); + this.keyBindings.copy(settings.keyBindings); + this.pointer.copy(settings.pointer); + this.rotation.copy(settings.rotation); + this.sensitivity.copy(settings.sensitivity); + this.translation.copy(settings.translation); + this.zoom.copy(settings.zoom); + return this; + }; + Settings.prototype.clone = function clone () { + var clone = new Settings(); + return clone.copy(this); + }; + Settings.prototype.toDataURL = function toDataURL () { + return URL.createObjectURL(new Blob([JSON.stringify(this)], { + type: "text/json" + })); + }; + + var MovementStrategy = function MovementStrategy(movementState, direction) { + this.movementState = movementState; + this.direction = direction; + }; + MovementStrategy.prototype.execute = function execute (flag) { + var state = this.movementState; + switch (this.direction) { + case Direction.FORWARD: + state.forward = flag; + break; + case Direction.LEFT: + state.left = flag; + break; + case Direction.BACKWARD: + state.backward = flag; + break; + case Direction.RIGHT: + state.right = flag; + break; + case Direction.DOWN: + state.down = flag; + break; + case Direction.UP: + state.up = flag; + break; + } + }; + var Direction; + (function (Direction) { + Direction[Direction["FORWARD"] = 0] = "FORWARD"; + Direction[Direction["LEFT"] = 1] = "LEFT"; + Direction[Direction["BACKWARD"] = 2] = "BACKWARD"; + Direction[Direction["RIGHT"] = 3] = "RIGHT"; + Direction[Direction["DOWN"] = 4] = "DOWN"; + Direction[Direction["UP"] = 5] = "UP"; + })(Direction || (Direction = {})); + + var ZoomStrategy = function ZoomStrategy(rotationManager, zoomIn) { + this.rotationManager = rotationManager; + this.zoomIn = zoomIn; + }; + ZoomStrategy.prototype.execute = function execute (flag) { + if (flag) { + this.rotationManager.zoom(this.zoomIn ? -1 : 1); + } + }; + + var SpatialControls = function SpatialControls(position, quaternion, domElement) { + if ( position === void 0 ) position = null; + if ( quaternion === void 0 ) quaternion = null; + if ( domElement === void 0 ) domElement = document.body; + + this.domElement = domElement; + this.position = position; + this.quaternion = quaternion; + this.target = new Vector3(); + this.settings = new Settings(); + this.rotationManager = new RotationManager(position, quaternion, this.target, this.settings); + this.translationManager = new TranslationManager(position, quaternion, this.target, this.settings); + var movementState = this.translationManager.movementState; + this.strategies = new Map([ + [Action.MOVE_FORWARD, new MovementStrategy(movementState, Direction.FORWARD)], + [Action.MOVE_LEFT, new MovementStrategy(movementState, Direction.LEFT)], + [Action.MOVE_BACKWARD, new MovementStrategy(movementState, Direction.BACKWARD)], + [Action.MOVE_RIGHT, new MovementStrategy(movementState, Direction.RIGHT)], + [Action.MOVE_DOWN, new MovementStrategy(movementState, Direction.DOWN)], + [Action.MOVE_UP, new MovementStrategy(movementState, Direction.UP)], + [Action.ZOOM_OUT, new ZoomStrategy(this.rotationManager, false)], + [Action.ZOOM_IN, new ZoomStrategy(this.rotationManager, true)] + ]); + this.lastScreenPosition = new Vector2(); + this.dragging = false; + this.enabled = false; + if (position !== null && quaternion !== null) { + this.lookAt(this.target); + if (domElement !== null) { + this.setEnabled(); + } + } + }; + SpatialControls.prototype.getDomElement = function getDomElement () { + return this.domElement; + }; + SpatialControls.prototype.setDomElement = function setDomElement (domElement) { + var enabled = this.enabled; + if (domElement !== null) { + if (enabled) { + this.setEnabled(false); + } + this.domElement = domElement; + this.setEnabled(enabled); + } + return this; + }; + SpatialControls.prototype.getPosition = function getPosition () { + return this.position; + }; + SpatialControls.prototype.setPosition = function setPosition (position) { + this.position = position; + this.rotationManager.setPosition(position); + this.translationManager.setPosition(position); + return this.lookAt(this.target); + }; + SpatialControls.prototype.getQuaternion = function getQuaternion () { + return this.quaternion; + }; + SpatialControls.prototype.setQuaternion = function setQuaternion (quaternion) { + this.quaternion = quaternion; + this.rotationManager.setQuaternion(quaternion); + this.translationManager.setQuaternion(quaternion); + return this.lookAt(this.target); + }; + SpatialControls.prototype.getTarget = function getTarget (target) { + target.copy(this.target); + if (!this.settings.general.orbit) { + target.add(this.position); + } + return target; + }; + SpatialControls.prototype.setTarget = function setTarget (target) { + this.target = target; + this.rotationManager.setTarget(target); + this.translationManager.setTarget(target); + return this.lookAt(this.target); + }; + SpatialControls.prototype.getViewDirection = function getViewDirection (view) { + return this.rotationManager.getViewDirection(view); + }; + SpatialControls.prototype.setOrbitEnabled = function setOrbitEnabled (orbit) { + var general = this.settings.general; + if (general.orbit !== orbit) { + this.getTarget(this.target); + general.orbit = orbit; + this.lookAt(this.target); + } + return this; + }; + SpatialControls.prototype.copy = function copy (controls) { + this.domElement = controls.getDomElement(); + this.position = controls.getPosition(); + this.quaternion = controls.getQuaternion(); + this.target = controls.getTarget(new Vector3()); + this.settings.copy(controls.settings); + this.rotationManager.setPosition(this.position).setQuaternion(this.quaternion).setTarget(this.target); + this.translationManager.setPosition(this.position).setQuaternion(this.quaternion).setTarget(this.target); + return this.lookAt(this.target); + }; + SpatialControls.prototype.clone = function clone () { + var clone = new SpatialControls(); + return clone.copy(this); + }; + SpatialControls.prototype.handlePointerMoveEvent = function handlePointerMoveEvent (event) { + var settings = this.settings; + var pointer = settings.pointer; + var sensitivity = settings.sensitivity; + var rotationManager = this.rotationManager; + var lastScreenPosition = this.lastScreenPosition; + if (document.pointerLockElement === this.domElement) { + if (!pointer.hold || this.dragging) { + rotationManager.adjustSpherical(event.movementX * 0.001 * sensitivity.rotationX, event.movementY * 0.001 * sensitivity.rotationY).updateQuaternion(); + } + } + else { + var movementX = event.screenX - lastScreenPosition.x; + var movementY = event.screenY - lastScreenPosition.y; + lastScreenPosition.set(event.screenX, event.screenY); + rotationManager.adjustSpherical(movementX * 0.001 * sensitivity.rotationX, movementY * 0.001 * sensitivity.rotationY).updateQuaternion(); + } + }; + SpatialControls.prototype.handleTouchMoveEvent = function handleTouchMoveEvent (event) { + var sensitivity = this.settings.sensitivity; + var rotationManager = this.rotationManager; + var lastScreenPosition = this.lastScreenPosition; + var touch = event.touches[0]; + var movementX = touch.screenX - lastScreenPosition.x; + var movementY = touch.screenY - lastScreenPosition.y; + lastScreenPosition.set(touch.screenX, touch.screenY); + event.preventDefault(); + rotationManager.adjustSpherical(movementX * 0.001 * sensitivity.rotationX, movementY * 0.001 * sensitivity.rotationY).updateQuaternion(); + }; + SpatialControls.prototype.handleMainPointerButton = function handleMainPointerButton (event, pressed) { + this.dragging = pressed; + if (this.settings.pointer.lock) { + this.setPointerLocked(); + } + else { + if (pressed) { + this.lastScreenPosition.set(event.screenX, event.screenY); + this.domElement.addEventListener("mousemove", this); + } + else { + this.domElement.removeEventListener("mousemove", this); + } + } + }; + SpatialControls.prototype.handleAuxiliaryPointerButton = function handleAuxiliaryPointerButton (event, pressed) { }; + SpatialControls.prototype.handleSecondaryPointerButton = function handleSecondaryPointerButton (event, pressed) { }; + SpatialControls.prototype.handlePointerButtonEvent = function handlePointerButtonEvent (event, pressed) { + event.preventDefault(); + switch (event.button) { + case PointerButton.MAIN: + this.handleMainPointerButton(event, pressed); + break; + case PointerButton.AUXILIARY: + this.handleAuxiliaryPointerButton(event, pressed); + break; + case PointerButton.SECONDARY: + this.handleSecondaryPointerButton(event, pressed); + break; + } + }; + SpatialControls.prototype.handleTouchEvent = function handleTouchEvent (event, start) { + var touch = event.touches[0]; + event.preventDefault(); + if (start) { + this.lastScreenPosition.set(touch.screenX, touch.screenY); + this.domElement.addEventListener("touchmove", this); + } + else { + this.domElement.removeEventListener("touchmove", this); + } + }; + SpatialControls.prototype.handleKeyboardEvent = function handleKeyboardEvent (event, pressed) { + var keyBindings = this.settings.keyBindings; + if (keyBindings.has(event.keyCode)) { + event.preventDefault(); + this.strategies.get(keyBindings.get(event.keyCode)).execute(pressed); + } + }; + SpatialControls.prototype.handleWheelEvent = function handleWheelEvent (event) { + this.rotationManager.zoom(Math.sign(event.deltaY)); + }; + SpatialControls.prototype.handlePointerLockEvent = function handlePointerLockEvent () { + if (document.pointerLockElement === this.domElement) { + this.domElement.addEventListener("mousemove", this); + } + else { + this.domElement.removeEventListener("mousemove", this); + } + }; + SpatialControls.prototype.handleEvent = function handleEvent (event) { + switch (event.type) { + case "mousemove": + this.handlePointerMoveEvent(event); + break; + case "touchmove": + this.handleTouchMoveEvent(event); + break; + case "mousedown": + this.handlePointerButtonEvent(event, true); + break; + case "mouseup": + this.handlePointerButtonEvent(event, false); + break; + case "touchstart": + this.handleTouchEvent(event, true); + break; + case "touchend": + this.handleTouchEvent(event, false); + break; + case "keydown": + this.handleKeyboardEvent(event, true); + break; + case "keyup": + this.handleKeyboardEvent(event, false); + break; + case "wheel": + this.handleWheelEvent(event); + break; + case "pointerlockchange": + this.handlePointerLockEvent(); + break; + } + }; + SpatialControls.prototype.update = function update (deltaTime) { + this.rotationManager.update(deltaTime); + this.translationManager.update(deltaTime); + }; + SpatialControls.prototype.moveTo = function moveTo (position) { + this.translationManager.moveTo(position); + return this; + }; + SpatialControls.prototype.lookAt = function lookAt (point) { + this.rotationManager.lookAt(point); + return this; + }; + SpatialControls.prototype.setPointerLocked = function setPointerLocked (locked) { + if ( locked === void 0 ) locked = true; + + if (locked) { + if (document.pointerLockElement !== this.domElement && + this.domElement.requestPointerLock !== undefined) { + this.domElement.requestPointerLock(); + } + } + else if (document.exitPointerLock !== undefined) { + document.exitPointerLock(); + } + }; + SpatialControls.prototype.setEnabled = function setEnabled (enabled) { + if ( enabled === void 0 ) enabled = true; + + var domElement = this.domElement; + this.translationManager.movementState.reset(); + if (enabled && !this.enabled) { + document.addEventListener("pointerlockchange", this); + document.body.addEventListener("keyup", this); + document.body.addEventListener("keydown", this); + domElement.addEventListener("mousedown", this); + domElement.addEventListener("mouseup", this); + domElement.addEventListener("touchstart", this); + domElement.addEventListener("touchend", this); + domElement.addEventListener("wheel", this); + } + else if (!enabled && this.enabled) { + document.removeEventListener("pointerlockchange", this); + document.body.removeEventListener("keyup", this); + document.body.removeEventListener("keydown", this); + domElement.removeEventListener("mousedown", this); + domElement.removeEventListener("mouseup", this); + domElement.removeEventListener("touchstart", this); + domElement.removeEventListener("touchend", this); + domElement.removeEventListener("wheel", this); + domElement.removeEventListener("mousemove", this); + domElement.removeEventListener("touchmove", this); + } + this.setPointerLocked(false); + this.enabled = enabled; + return this; + }; + SpatialControls.prototype.dispose = function dispose () { + this.setEnabled(false); + }; + + /** + * octree-helper v1.1.6 build Sun Jun 28 2020 + * https://github.com/vanruesc/octree-helper + * Copyright 2020 Raoul van Rüschen + * @license Zlib + */ + + /** + * sparse-octree v6.0.2 build Sat Jan 18 2020 + * https://github.com/vanruesc/sparse-octree + * Copyright 2020 Raoul van Rüschen + * @license Zlib + */ + + /** + * Describes all possible octant corner connections. + * + * @type {Uint8Array[]} + */ + + var edges = [ + + // X-Axis. + new Uint8Array([0, 4]), + new Uint8Array([1, 5]), + new Uint8Array([2, 6]), + new Uint8Array([3, 7]), + + // Y-Axis. + new Uint8Array([0, 2]), + new Uint8Array([1, 3]), + new Uint8Array([4, 6]), + new Uint8Array([5, 7]), + + // Z-Axis. + new Uint8Array([0, 1]), + new Uint8Array([2, 3]), + new Uint8Array([4, 5]), + new Uint8Array([6, 7]) + + ]; + + /** + * A binary pattern that describes the standard octant layout: + * + * ```text + * 3____7 + * 2/___6/| + * | 1__|_5 + * 0/___4/ + * ``` + * + * This common layout is crucial for positional assumptions. + * + * @type {Uint8Array[]} + */ + + var layout = [ + + new Uint8Array([0, 0, 0]), + new Uint8Array([0, 0, 1]), + new Uint8Array([0, 1, 0]), + new Uint8Array([0, 1, 1]), + + new Uint8Array([1, 0, 0]), + new Uint8Array([1, 0, 1]), + new Uint8Array([1, 1, 0]), + new Uint8Array([1, 1, 1]) + + ]; + + /** + * An octree helper. + */ + + var OctreeHelper = /*@__PURE__*/(function (Group) { + function OctreeHelper(octree) { + if ( octree === void 0 ) octree = null; + + + Group.call(this); + + /** + * The name of this object. + * + * @type {String} + * @protected + */ + + this.name = "OctreeHelper"; + + /** + * The octree. + * + * @type {Tree} + */ + + this.octree = octree; + + this.update(); + + } + + if ( Group ) OctreeHelper.__proto__ = Group; + OctreeHelper.prototype = Object.create( Group && Group.prototype ); + OctreeHelper.prototype.constructor = OctreeHelper; + + /** + * Creates octant geometry. + * + * @private + * @param {Iterator} octants - An octant iterator. + * @param {Number} octantCount - The size of the given sequence. + */ + + OctreeHelper.prototype.createLineSegments = function createLineSegments (octants, octantCount) { + + var maxOctants = (Math.pow(2, 16) / 8) - 1; + var group = new Group(); + + var material = new LineBasicMaterial({ + color: 0xffffff * Math.random() + }); + + var result; + var vertexCount; + var length; + + var indices, positions; + var octant, min, max; + var geometry; + + var i, j, c, d, n; + var corner, edge; + + // Create geometry in multiple runs to limit the amount of vertices. + for(i = 0, length = 0, n = Math.ceil(octantCount / maxOctants); n > 0; --n) { + + length += (octantCount < maxOctants) ? octantCount : maxOctants; + octantCount -= maxOctants; + + vertexCount = length * 8; + indices = new Uint16Array(vertexCount * 3); + positions = new Float32Array(vertexCount * 3); + + // Continue where the previous run left off. + for(c = 0, d = 0, result = octants.next(); !result.done && i < length;) { + + octant = result.value; + min = octant.min; + max = octant.max; + + // Create line connections based on the current vertex count. + for(j = 0; j < 12; ++j) { + + edge = edges[j]; + + indices[d++] = c + edge[0]; + indices[d++] = c + edge[1]; + + } + + // Create the vertices. + for(j = 0; j < 8; ++j, ++c) { + + corner = layout[j]; + + positions[c * 3] = (corner[0] === 0) ? min.x : max.x; + positions[c * 3 + 1] = (corner[1] === 0) ? min.y : max.y; + positions[c * 3 + 2] = (corner[2] === 0) ? min.z : max.z; + + } + + if(++i < length) { + + result = octants.next(); + + } + + } + + geometry = new BufferGeometry(); + geometry.setIndex(new BufferAttribute(indices, 1)); + geometry.setAttribute("position", new BufferAttribute(positions, 3)); + + group.add(new LineSegments(geometry, material)); + + } + + this.add(group); + + }; + + /** + * Updates the helper geometry. + */ + + OctreeHelper.prototype.update = function update () { + + var depth = (this.octree !== null) ? this.octree.getDepth() : -1; + + var level = 0; + var result; + + // Remove existing geometry. + this.dispose(); + + while(level <= depth) { + + result = this.octree.findNodesByLevel(level); + + this.createLineSegments( + result[Symbol.iterator](), + (typeof result.size === "number") ? result.size : result.length + ); + + ++level; + + } + + }; + + /** + * Destroys this helper. + */ + + OctreeHelper.prototype.dispose = function dispose () { + + var groups = this.children; + + var group, children; + var i, j, il, jl; + + for(i = 0, il = groups.length; i < il; ++i) { + + group = groups[i]; + children = group.children; + + for(j = 0, jl = children.length; j < jl; ++j) { + + children[j].geometry.dispose(); + children[j].material.dispose(); + + } + + while(children.length > 0) { + + group.remove(children[0]); + + } + + } + + while(groups.length > 0) { + + this.remove(groups[0]); + + } + + }; + + return OctreeHelper; + }(Group)); + + /** + * A binary pattern that describes the standard octant layout: + * + * ```text + * 3____7 + * 2/___6/| + * | 1__|_5 + * 0/___4/ + * ``` + * + * This common layout is crucial for positional assumptions. + * + * @type {Uint8Array[]} + */ + + var layout$1 = [ + + new Uint8Array([0, 0, 0]), + new Uint8Array([0, 0, 1]), + new Uint8Array([0, 1, 0]), + new Uint8Array([0, 1, 1]), + + new Uint8Array([1, 0, 0]), + new Uint8Array([1, 0, 1]), + new Uint8Array([1, 1, 0]), + new Uint8Array([1, 1, 1]) + + ]; + + /** + * math-ds v1.2.1 build Fri May 01 2020 + * https://github.com/vanruesc/math-ds + * Copyright 2020 Raoul van Rüschen + * @license Zlib + */ + /** + * A vector with three components. + */ + + var Vector3$1 = function Vector3(x, y, z) { + if ( x === void 0 ) x = 0; + if ( y === void 0 ) y = 0; + if ( z === void 0 ) z = 0; + + + /** + * The X component. + * + * @type {Number} + */ + + this.x = x; + + /** + * The Y component. + * + * @type {Number} + */ + + this.y = y; + + /** + * The Z component. + * + * @type {Number} + */ + + this.z = z; + + }; + + /** + * Sets the values of this vector + * + * @param {Number} x - The X component. + * @param {Number} y - The Y component. + * @param {Number} z - The Z component. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.set = function set (x, y, z) { + + this.x = x; + this.y = y; + this.z = z; + + return this; + + }; + + /** + * Randomizes the values of this vector + * + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.random = function random () { + + this.x = Math.random(); + this.y = Math.random(); + this.z = Math.random(); + + return this; + + }; + + /** + * Copies the values of another vector. + * + * @param {Vector3} v - A vector. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.copy = function copy (v) { + + this.x = v.x; + this.y = v.y; + this.z = v.z; + + return this; + + }; + + /** + * Clones this vector. + * + * @return {Vector3} A clone of this vector. + */ + + Vector3$1.prototype.clone = function clone () { + + return new this.constructor(this.x, this.y, this.z); + + }; + + /** + * Copies values from an array. + * + * @param {Number[]} array - An array. + * @param {Number} offset - An offset. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.fromArray = function fromArray (array, offset) { + if ( offset === void 0 ) offset = 0; + + + this.x = array[offset]; + this.y = array[offset + 1]; + this.z = array[offset + 2]; + + return this; + + }; + + /** + * Stores this vector in an array. + * + * @param {Array} [array] - A target array. + * @param {Number} offset - An offset. + * @return {Number[]} The array. + */ + + Vector3$1.prototype.toArray = function toArray (array, offset) { + if ( array === void 0 ) array = []; + if ( offset === void 0 ) offset = 0; + + + array[offset] = this.x; + array[offset + 1] = this.y; + array[offset + 2] = this.z; + + return array; + + }; + + /** + * Sets the values of this vector based on a spherical description. + * + * @param {Spherical} s - A spherical description. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.setFromSpherical = function setFromSpherical (s) { + + return this.setFromSphericalCoords(s.radius, s.phi, s.theta); + + }; + + /** + * Sets the values of this vector based on spherical coordinates. + * + * @param {Number} radius - The radius. + * @param {Number} phi - The polar angle. + * @param {Number} theta - The angle around the equator of the sphere. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.setFromSphericalCoords = function setFromSphericalCoords (radius, phi, theta) { + + var sinPhiRadius = Math.sin(phi) * radius; + + this.x = sinPhiRadius * Math.sin(theta); + this.y = Math.cos(phi) * radius; + this.z = sinPhiRadius * Math.cos(theta); + + return this; + + }; + + /** + * Sets the values of this vector based on a cylindrical description. + * + * @param {Cylindrical} c - A cylindrical description. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.setFromCylindrical = function setFromCylindrical (c) { + + return this.setFromCylindricalCoords(c.radius, c.theta, c.y); + + }; + + /** + * Sets the values of this vector based on cylindrical coordinates. + * + * @param {Number} radius - The radius. + * @param {Number} theta - Theta. + * @param {Number} y - The height. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.setFromCylindricalCoords = function setFromCylindricalCoords (radius, theta, y) { + + this.x = radius * Math.sin(theta); + this.y = y; + this.z = radius * Math.cos(theta); + + return this; + + }; + + /** + * Copies the values of a matrix column. + * + * @param {Matrix4} m - A 3x3 matrix. + * @param {Number} index - A column index of the range [0, 2]. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.setFromMatrix3Column = function setFromMatrix3Column (m, index) { + + return this.fromArray(m.elements, index * 3); + + }; + + /** + * Copies the values of a matrix column. + * + * @param {Matrix4} m - A 4x4 matrix. + * @param {Number} index - A column index of the range [0, 3]. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.setFromMatrixColumn = function setFromMatrixColumn (m, index) { + + return this.fromArray(m.elements, index * 4); + + }; + + /** + * Extracts the position from a matrix. + * + * @param {Matrix4} m - A 4x4 matrix. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.setFromMatrixPosition = function setFromMatrixPosition (m) { + + var me = m.elements; + + this.x = me[12]; + this.y = me[13]; + this.z = me[14]; + + return this; + + }; + + /** + * Extracts the scale from a matrix. + * + * @param {Matrix4} m - A 4x4 matrix. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.setFromMatrixScale = function setFromMatrixScale (m) { + + var sx = this.setFromMatrixColumn(m, 0).length(); + var sy = this.setFromMatrixColumn(m, 1).length(); + var sz = this.setFromMatrixColumn(m, 2).length(); + + this.x = sx; + this.y = sy; + this.z = sz; + + return this; + + }; + + /** + * Adds a vector to this one. + * + * @param {Vector3} v - The vector to add. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.add = function add (v) { + + this.x += v.x; + this.y += v.y; + this.z += v.z; + + return this; + + }; + + /** + * Adds a scalar to this vector. + * + * @param {Number} s - The scalar to add. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.addScalar = function addScalar (s) { + + this.x += s; + this.y += s; + this.z += s; + + return this; + + }; + + /** + * Sets this vector to the sum of two given vectors. + * + * @param {Vector3} a - A vector. + * @param {Vector3} b - Another vector. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.addVectors = function addVectors (a, b) { + + this.x = a.x + b.x; + this.y = a.y + b.y; + this.z = a.z + b.z; + + return this; + + }; + + /** + * Adds a scaled vector to this one. + * + * @param {Vector3} v - The vector to scale and add. + * @param {Number} s - A scalar. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.addScaledVector = function addScaledVector (v, s) { + + this.x += v.x * s; + this.y += v.y * s; + this.z += v.z * s; + + return this; + + }; + + /** + * Subtracts a vector from this vector. + * + * @param {Vector3} v - The vector to subtract. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.sub = function sub (v) { + + this.x -= v.x; + this.y -= v.y; + this.z -= v.z; + + return this; + + }; + + /** + * Subtracts a scalar from this vector. + * + * @param {Number} s - The scalar to subtract. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.subScalar = function subScalar (s) { + + this.x -= s; + this.y -= s; + this.z -= s; + + return this; + + }; + + /** + * Sets this vector to the difference between two given vectors. + * + * @param {Vector3} a - A vector. + * @param {Vector3} b - A second vector. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.subVectors = function subVectors (a, b) { + + this.x = a.x - b.x; + this.y = a.y - b.y; + this.z = a.z - b.z; + + return this; + + }; + + /** + * Multiplies this vector with another vector. + * + * @param {Vector3} v - A vector. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.multiply = function multiply (v) { + + this.x *= v.x; + this.y *= v.y; + this.z *= v.z; + + return this; + + }; + + /** + * Multiplies this vector with a given scalar. + * + * @param {Number} s - A scalar. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.multiplyScalar = function multiplyScalar (s) { + + this.x *= s; + this.y *= s; + this.z *= s; + + return this; + + }; + + /** + * Sets this vector to the product of two given vectors. + * + * @param {Vector3} a - A vector. + * @param {Vector3} b - Another vector. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.multiplyVectors = function multiplyVectors (a, b) { + + this.x = a.x * b.x; + this.y = a.y * b.y; + this.z = a.z * b.z; + + return this; + + }; + + /** + * Divides this vector by another vector. + * + * @param {Vector3} v - A vector. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.divide = function divide (v) { + + this.x /= v.x; + this.y /= v.y; + this.z /= v.z; + + return this; + + }; + + /** + * Divides this vector by a given scalar. + * + * @param {Number} s - A scalar. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.divideScalar = function divideScalar (s) { + + this.x /= s; + this.y /= s; + this.z /= s; + + return this; + + }; + + /** + * Sets this vector to the cross product of the given vectors. + * + * @param {Vector3} a - A vector. + * @param {Vector3} b - Another vector. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.crossVectors = function crossVectors (a, b) { + + var ax = a.x, ay = a.y, az = a.z; + var bx = b.x, by = b.y, bz = b.z; + + this.x = ay * bz - az * by; + this.y = az * bx - ax * bz; + this.z = ax * by - ay * bx; + + return this; + + }; + + /** + * Calculates the cross product of this vector and the given one. + * + * @param {Vector3} v - A vector. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.cross = function cross (v) { + + return this.crossVectors(this, v); + + }; + + /** + * Applies a matrix to this direction vector. + * + * @param {Matrix4} m - A matrix. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.transformDirection = function transformDirection (m) { + + var x = this.x, y = this.y, z = this.z; + var e = m.elements; + + this.x = e[0] * x + e[4] * y + e[8] * z; + this.y = e[1] * x + e[5] * y + e[9] * z; + this.z = e[2] * x + e[6] * y + e[10] * z; + + return this.normalize(); + + }; + + /** + * Applies a matrix to this vector. + * + * @param {Matrix3} m - A matrix. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.applyMatrix3 = function applyMatrix3 (m) { + + var x = this.x, y = this.y, z = this.z; + var e = m.elements; + + this.x = e[0] * x + e[3] * y + e[6] * z; + this.y = e[1] * x + e[4] * y + e[7] * z; + this.z = e[2] * x + e[5] * y + e[8] * z; + + return this; + + }; + + /** + * Applies a normal matrix to this vector and normalizes it. + * + * @param {Matrix3} m - A normal matrix. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.applyNormalMatrix = function applyNormalMatrix (m) { + + return this.applyMatrix3(m).normalize(); + + }; + + /** + * Applies a matrix to this vector. + * + * @param {Matrix4} m - A matrix. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.applyMatrix4 = function applyMatrix4 (m) { + + var x = this.x, y = this.y, z = this.z; + var e = m.elements; + + this.x = e[0] * x + e[4] * y + e[8] * z + e[12]; + this.y = e[1] * x + e[5] * y + e[9] * z + e[13]; + this.z = e[2] * x + e[6] * y + e[10] * z + e[14]; + + return this; + + }; + + /** + * Applies a quaternion to this vector. + * + * @param {Quaternion} q - A quaternion. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.applyQuaternion = function applyQuaternion (q) { + + var x = this.x, y = this.y, z = this.z; + var qx = q.x, qy = q.y, qz = q.z, qw = q.w; + + // Calculate: quaternion * vector. + var ix = qw * x + qy * z - qz * y; + var iy = qw * y + qz * x - qx * z; + var iz = qw * z + qx * y - qy * x; + var iw = -qx * x - qy * y - qz * z; + + // Calculate: result * inverse quaternion. + this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy; + this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz; + this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx; + + return this; + + }; + + /** + * Negates this vector. + * + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.negate = function negate () { + + this.x = -this.x; + this.y = -this.y; + this.z = -this.z; + + return this; + + }; + + /** + * Calculates the dot product with another vector. + * + * @param {Vector3} v - A vector. + * @return {Number} The dot product. + */ + + Vector3$1.prototype.dot = function dot (v) { + + return this.x * v.x + this.y * v.y + this.z * v.z; + + }; + + /** + * Reflects this vector. The given plane normal is assumed to be normalized. + * + * @param {Vector3} n - A normal. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.reflect = function reflect (n) { + + var nx = n.x; + var ny = n.y; + var nz = n.z; + + this.sub(n.multiplyScalar(2 * this.dot(n))); + + // Restore the normal. + n.set(nx, ny, nz); + + return this; + + }; + + /** + * Computes the angle to the given vector. + * + * @param {Vector3} v - A vector. + * @return {Number} The angle in radians. + */ + + Vector3$1.prototype.angleTo = function angleTo (v) { + + var denominator = Math.sqrt(this.lengthSquared() * v.lengthSquared()); + + return (denominator === 0.0) ? (Math.PI * 0.5) : + Math.acos(Math.min(Math.max(this.dot(v) / denominator, -1), 1)); + + }; + + /** + * Calculates the Manhattan length of this vector. + * + * @return {Number} The length. + */ + + Vector3$1.prototype.manhattanLength = function manhattanLength () { + + return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z); + + }; + + /** + * Calculates the squared length of this vector. + * + * @return {Number} The squared length. + */ + + Vector3$1.prototype.lengthSquared = function lengthSquared () { + + return this.x * this.x + this.y * this.y + this.z * this.z; + + }; + + /** + * Calculates the length of this vector. + * + * @return {Number} The length. + */ + + Vector3$1.prototype.length = function length () { + + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); + + }; + + /** + * Calculates the Manhattan distance to a given vector. + * + * @param {Vector3} v - A vector. + * @return {Number} The distance. + */ + + Vector3$1.prototype.manhattanDistanceTo = function manhattanDistanceTo (v) { + + return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z); + + }; + + /** + * Calculates the squared distance to a given vector. + * + * @param {Vector3} v - A vector. + * @return {Number} The squared distance. + */ + + Vector3$1.prototype.distanceToSquared = function distanceToSquared (v) { + + var dx = this.x - v.x; + var dy = this.y - v.y; + var dz = this.z - v.z; + + return dx * dx + dy * dy + dz * dz; + + }; + + /** + * Calculates the distance to a given vector. + * + * @param {Vector3} v - A vector. + * @return {Number} The distance. + */ + + Vector3$1.prototype.distanceTo = function distanceTo (v) { + + return Math.sqrt(this.distanceToSquared(v)); + + }; + + /** + * Normalizes this vector. + * + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.normalize = function normalize () { + + return this.divideScalar(this.length()); + + }; + + /** + * Sets the length of this vector. + * + * @param {Number} length - The new length. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.setLength = function setLength (length) { + + return this.normalize().multiplyScalar(length); + + }; + + /** + * Adopts the min value for each component of this vector and the given one. + * + * @param {Vector3} v - A vector. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.min = function min (v) { + + this.x = Math.min(this.x, v.x); + this.y = Math.min(this.y, v.y); + this.z = Math.min(this.z, v.z); + + return this; + + }; + + /** + * Adopts the max value for each component of this vector and the given one. + * + * @param {Vector3} v - A vector. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.max = function max (v) { + + this.x = Math.max(this.x, v.x); + this.y = Math.max(this.y, v.y); + this.z = Math.max(this.z, v.z); + + return this; + + }; + + /** + * Clamps this vector. + * + * @param {Vector3} min - The lower bounds. Assumed to be smaller than max. + * @param {Vector3} max - The upper bounds. Assumed to be greater than min. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.clamp = function clamp (min, max) { + + this.x = Math.max(min.x, Math.min(max.x, this.x)); + this.y = Math.max(min.y, Math.min(max.y, this.y)); + this.z = Math.max(min.z, Math.min(max.z, this.z)); + + return this; + + }; + + /** + * Floors this vector. + * + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.floor = function floor () { + + this.x = Math.floor(this.x); + this.y = Math.floor(this.y); + this.z = Math.floor(this.z); + + return this; + + }; + + /** + * Ceils this vector. + * + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.ceil = function ceil () { + + this.x = Math.ceil(this.x); + this.y = Math.ceil(this.y); + this.z = Math.ceil(this.z); + + return this; + + }; + + /** + * Rounds this vector. + * + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.round = function round () { + + this.x = Math.round(this.x); + this.y = Math.round(this.y); + this.z = Math.round(this.z); + + return this; + + }; + + /** + * Lerps towards the given vector. + * + * @param {Vector3} v - The target vector. + * @param {Number} alpha - The lerp factor. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.lerp = function lerp (v, alpha) { + + this.x += (v.x - this.x) * alpha; + this.y += (v.y - this.y) * alpha; + this.z += (v.z - this.z) * alpha; + + return this; + + }; + + /** + * Sets this vector to the lerp result of the given vectors. + * + * @param {Vector3} v1 - A base vector. + * @param {Vector3} v2 - The target vector. + * @param {Number} alpha - The lerp factor. + * @return {Vector3} This vector. + */ + + Vector3$1.prototype.lerpVectors = function lerpVectors (v1, v2, alpha) { + + return this.subVectors(v2, v1).multiplyScalar(alpha).add(v1); + + }; + + /** + * Checks if this vector equals the given one. + * + * @param {Vector3} v - A vector. + * @return {Boolean} Whether this vector equals the given one. + */ + + Vector3$1.prototype.equals = function equals (v) { + + return (v.x === this.x && v.y === this.y && v.z === this.z); + + }; + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var v$2 = new Vector3$1(); + + /** + * A list of points. + * + * @type {Vector3[]} + * @private + */ + + var points = [ + new Vector3$1(), + new Vector3$1(), + new Vector3$1(), + new Vector3$1(), + new Vector3$1(), + new Vector3$1(), + new Vector3$1(), + new Vector3$1() + ]; + + /** + * A 3D box. + */ + + var Box3$1 = function Box3( + min, + max + ) { + if ( min === void 0 ) min = new Vector3$1(Infinity, Infinity, Infinity); + if ( max === void 0 ) max = new Vector3$1(-Infinity, -Infinity, -Infinity); + + + /** + * The lower bounds. + * + * @type {Vector3} + */ + + this.min = min; + + /** + * The upper bounds. + * + * @type {Vector3} + */ + + this.max = max; + + }; + + /** + * Sets the values of this box. + * + * @param {Vector3} min - The lower bounds. + * @param {Vector3} max - The upper bounds. + * @return {Box3} This box. + */ + + Box3$1.prototype.set = function set (min, max) { + + this.min.copy(min); + this.max.copy(max); + + return this; + + }; + + /** + * Copies the values of a given box. + * + * @param {Box3} b - A box. + * @return {Box3} This box. + */ + + Box3$1.prototype.copy = function copy (b) { + + this.min.copy(b.min); + this.max.copy(b.max); + + return this; + + }; + + /** + * Clones this box. + * + * @return {Box3} A clone of this box. + */ + + Box3$1.prototype.clone = function clone () { + + return new this.constructor().copy(this); + + }; + + /** + * Makes this box empty. + * + * The lower bounds are set to infinity and the upper bounds to negative + * infinity to create an infinitely small box. + * + * @return {Box3} This box. + */ + + Box3$1.prototype.makeEmpty = function makeEmpty () { + + this.min.x = this.min.y = this.min.z = Infinity; + this.max.x = this.max.y = this.max.z = -Infinity; + + return this; + + }; + + /** + * Indicates whether this box is truly empty. + * + * This is a more robust check for emptiness since the volume can get positive + * with two negative axes. + * + * @return {Box3} This box. + */ + + Box3$1.prototype.isEmpty = function isEmpty () { + + return ( + this.max.x < this.min.x || + this.max.y < this.min.y || + this.max.z < this.min.z + ); + + }; + + /** + * Computes the center of this box. + * + * @param {Vector3} [target] - A target vector. If none is provided, a new one will be created. + * @return {Vector3} A vector that describes the center of this box. + */ + + Box3$1.prototype.getCenter = function getCenter (target) { + if ( target === void 0 ) target = new Vector3$1(); + + + return !this.isEmpty() ? + target.addVectors(this.min, this.max).multiplyScalar(0.5) : + target.set(0, 0, 0); + + }; + + /** + * Computes the size of this box. + * + * @param {Vector3} [target] - A target vector. If none is provided, a new one will be created. + * @return {Vector3} A vector that describes the size of this box. + */ + + Box3$1.prototype.getSize = function getSize (target) { + if ( target === void 0 ) target = new Vector3$1(); + + + return !this.isEmpty() ? + target.subVectors(this.max, this.min) : + target.set(0, 0, 0); + + }; + + /** + * Computes the bounding box of the given sphere. + * + * @param {Sphere} sphere - A sphere. + * @return {Box3} This box. + */ + + Box3$1.prototype.setFromSphere = function setFromSphere (sphere) { + + this.set(sphere.center, sphere.center); + this.expandByScalar(sphere.radius); + + return this; + + }; + + /** + * Expands this box by the given point. + * + * @param {Vector3} p - A point. + * @return {Box3} This box. + */ + + Box3$1.prototype.expandByPoint = function expandByPoint (p) { + + this.min.min(p); + this.max.max(p); + + return this; + + }; + + /** + * Expands this box by the given vector. + * + * @param {Vector3} v - A vector. + * @return {Box3} This box. + */ + + Box3$1.prototype.expandByVector = function expandByVector (v) { + + this.min.sub(v); + this.max.add(v); + + return this; + + }; + + /** + * Expands this box by the given scalar. + * + * @param {Number} s - A scalar. + * @return {Box3} This box. + */ + + Box3$1.prototype.expandByScalar = function expandByScalar (s) { + + this.min.addScalar(-s); + this.max.addScalar(s); + + return this; + + }; + + /** + * Defines this box by the given points. + * + * @param {Vector3[]} points - The points. + * @return {Box3} This box. + */ + + Box3$1.prototype.setFromPoints = function setFromPoints (points) { + + var i, l; + + this.min.set(0, 0, 0); + this.max.set(0, 0, 0); + + for(i = 0, l = points.length; i < l; ++i) { + + this.expandByPoint(points[i]); + + } + + return this; + + }; + + /** + * Defines this box by the given center and size. + * + * @param {Vector3} center - The center. + * @param {Number} size - The size. + * @return {Box3} This box. + */ + + Box3$1.prototype.setFromCenterAndSize = function setFromCenterAndSize (center, size) { + + var halfSize = v$2.copy(size).multiplyScalar(0.5); + + this.min.copy(center).sub(halfSize); + this.max.copy(center).add(halfSize); + + return this; + + }; + + /** + * Clamps the given point to the boundaries of this box. + * + * @param {Vector3} point - A point. + * @param {Vector3} [target] - A target vector. If none is provided, a new one will be created. + * @return {Vector3} The clamped point. + */ + + Box3$1.prototype.clampPoint = function clampPoint (point, target) { + if ( target === void 0 ) target = new Vector3$1(); + + + return target.copy(point).clamp(this.min, this.max); + + }; + + /** + * Calculates the distance from this box to the given point. + * + * @param {Vector3} p - A point. + * @return {Number} The distance. + */ + + Box3$1.prototype.distanceToPoint = function distanceToPoint (p) { + + var clampedPoint = v$2.copy(p).clamp(this.min, this.max); + + return clampedPoint.sub(p).length(); + + }; + + /** + * Applies the given matrix to this box. + * + * @param {Matrix4} m - The matrix. + * @return {Box3} This box. + */ + + Box3$1.prototype.applyMatrix4 = function applyMatrix4 (m) { + + var min = this.min; + var max = this.max; + + if(!this.isEmpty()) { + + points[0].set(min.x, min.y, min.z).applyMatrix4(m); + points[1].set(min.x, min.y, max.z).applyMatrix4(m); + points[2].set(min.x, max.y, min.z).applyMatrix4(m); + points[3].set(min.x, max.y, max.z).applyMatrix4(m); + points[4].set(max.x, min.y, min.z).applyMatrix4(m); + points[5].set(max.x, min.y, max.z).applyMatrix4(m); + points[6].set(max.x, max.y, min.z).applyMatrix4(m); + points[7].set(max.x, max.y, max.z).applyMatrix4(m); + + this.setFromPoints(points); + + } + + return this; + + }; + + /** + * Translates this box. + * + * @param {Vector3} offset - The offset. + * @return {Box3} This box. + */ + + Box3$1.prototype.translate = function translate (offset) { + + this.min.add(offset); + this.max.add(offset); + + return this; + + }; + + /** + * Intersects this box with the given one. + * + * @param {Box3} b - A box. + * @return {Box3} This box. + */ + + Box3$1.prototype.intersect = function intersect (b) { + + this.min.max(b.min); + this.max.min(b.max); + + /* Ensure that if there is no overlap, the result is fully empty to prevent + subsequent intersections to erroneously return valid values. */ + if(this.isEmpty()) { + + this.makeEmpty(); + + } + + return this; + + }; + + /** + * Expands this box by combining it with the given one. + * + * @param {Box3} b - A box. + * @return {Box3} This box. + */ + + Box3$1.prototype.union = function union (b) { + + this.min.min(b.min); + this.max.max(b.max); + + return this; + + }; + + /** + * Checks if the given point lies inside this box. + * + * @param {Vector3} p - A point. + * @return {Boolean} Whether this box contains the point. + */ + + Box3$1.prototype.containsPoint = function containsPoint (p) { + + var min = this.min; + var max = this.max; + + return ( + p.x >= min.x && + p.y >= min.y && + p.z >= min.z && + p.x <= max.x && + p.y <= max.y && + p.z <= max.z + ); + + }; + + /** + * Checks if the given box lies inside this box. + * + * @param {Box3} b - A box. + * @return {Boolean} Whether this box contains the given one. + */ + + Box3$1.prototype.containsBox = function containsBox (b) { + + var tMin = this.min; + var tMax = this.max; + var bMin = b.min; + var bMax = b.max; + + return ( + tMin.x <= bMin.x && bMax.x <= tMax.x && + tMin.y <= bMin.y && bMax.y <= tMax.y && + tMin.z <= bMin.z && bMax.z <= tMax.z + ); + + }; + + /** + * Checks if this box intersects the given one. + * + * @param {Box3} b - A box. + * @return {Boolean} Whether the boxes intersect. + */ + + Box3$1.prototype.intersectsBox = function intersectsBox (b) { + + var tMin = this.min; + var tMax = this.max; + var bMin = b.min; + var bMax = b.max; + + return ( + bMax.x >= tMin.x && + bMax.y >= tMin.y && + bMax.z >= tMin.z && + bMin.x <= tMax.x && + bMin.y <= tMax.y && + bMin.z <= tMax.z + ); + + }; + + /** + * Checks if this box intersects the given sphere. + * + * @param {Sphere} s - A sphere. + * @return {Boolean} Whether the box intersects the sphere. + */ + + Box3$1.prototype.intersectsSphere = function intersectsSphere (s) { + + // Find the point in this box that is closest to the sphere's center. + var closestPoint = this.clampPoint(s.center, v$2); + + // If that point is inside the sphere, it intersects this box. + return (closestPoint.distanceToSquared(s.center) <= (s.radius * s.radius)); + + }; + + /** + * Checks if this box intersects the given plane. + * + * Computes the minimum and maximum dot product values. If those values are on + * the same side (back or front) of the plane, then there is no intersection. + * + * @param {Plane} p - A plane. + * @return {Boolean} Whether the box intersects the plane. + */ + + Box3$1.prototype.intersectsPlane = function intersectsPlane (p) { + + var min, max; + + if(p.normal.x > 0) { + + min = p.normal.x * this.min.x; + max = p.normal.x * this.max.x; + + } else { + + min = p.normal.x * this.max.x; + max = p.normal.x * this.min.x; + + } + + if(p.normal.y > 0) { + + min += p.normal.y * this.min.y; + max += p.normal.y * this.max.y; + + } else { + + min += p.normal.y * this.max.y; + max += p.normal.y * this.min.y; + + } + + if(p.normal.z > 0) { + + min += p.normal.z * this.min.z; + max += p.normal.z * this.max.z; + + } else { + + min += p.normal.z * this.max.z; + max += p.normal.z * this.min.z; + + } + + return (min <= -p.constant && max >= -p.constant); + + }; + + /** + * Checks if this box equals the given one. + * + * @param {Box3} b - A box. + * @return {Boolean} Whether this box equals the given one. + */ + + Box3$1.prototype.equals = function equals (b) { + + return (b.min.equals(this.min) && b.max.equals(this.max)); + + }; + + /** + * A box. + * + * @type {Box3} + * @private + */ + + var box = new Box3$1(); + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var v$1$1 = new Vector3$1(); + + /** + * A vector with two components. + */ + + var Vector2$1 = function Vector2(x, y) { + if ( x === void 0 ) x = 0; + if ( y === void 0 ) y = 0; + + + /** + * The X component. + * + * @type {Number} + */ + + this.x = x; + + /** + * The Y component. + * + * @type {Number} + */ + + this.y = y; + + }; + + var prototypeAccessors$1 = { width: { configurable: true },height: { configurable: true } }; + + /** + * The width. This is an alias for X. + * + * @type {Number} + */ + + prototypeAccessors$1.width.get = function () { + + return this.x; + + }; + + /** + * Sets the width. + * + * @type {Number} + */ + + prototypeAccessors$1.width.set = function (value) { + + return this.x = value; + + }; + + /** + * The height. This is an alias for Y. + * + * @type {Number} + */ + + prototypeAccessors$1.height.get = function () { + + return this.y; + + }; + + /** + * Sets the height. + * + * @type {Number} + */ + + prototypeAccessors$1.height.set = function (value) { + + return this.y = value; + + }; + + /** + * Sets the values of this vector + * + * @param {Number} x - The X component. + * @param {Number} y - The Y component. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.set = function set (x, y) { + + this.x = x; + this.y = y; + + return this; + + }; + + /** + * Randomizes the values of this vector + * + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.random = function random () { + + this.x = Math.random(); + this.y = Math.random(); + + return this; + + }; + + /** + * Copies the values of another vector. + * + * @param {Vector2} v - A vector. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.copy = function copy (v) { + + this.x = v.x; + this.y = v.y; + + return this; + + }; + + /** + * Clones this vector. + * + * @return {Vector2} A clone of this vector. + */ + + Vector2$1.prototype.clone = function clone () { + + return new this.constructor(this.x, this.y); + + }; + + /** + * Copies values from an array. + * + * @param {Number[]} array - An array. + * @param {Number} offset - An offset. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.fromArray = function fromArray (array, offset) { + if ( offset === void 0 ) offset = 0; + + + this.x = array[offset]; + this.y = array[offset + 1]; + + return this; + + }; + + /** + * Stores this vector in an array. + * + * @param {Array} [array] - A target array. + * @param {Number} offset - An offset. + * @return {Number[]} The array. + */ + + Vector2$1.prototype.toArray = function toArray (array, offset) { + if ( array === void 0 ) array = []; + if ( offset === void 0 ) offset = 0; + + + array[offset] = this.x; + array[offset + 1] = this.y; + + return array; + + }; + + /** + * Adds a vector to this one. + * + * @param {Vector2} v - The vector to add. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.add = function add (v) { + + this.x += v.x; + this.y += v.y; + + return this; + + }; + + /** + * Adds a scalar to this vector. + * + * @param {Number} s - The scalar to add. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.addScalar = function addScalar (s) { + + this.x += s; + this.y += s; + + return this; + + }; + + /** + * Sets this vector to the sum of two given vectors. + * + * @param {Vector2} a - A vector. + * @param {Vector2} b - Another vector. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.addVectors = function addVectors (a, b) { + + this.x = a.x + b.x; + this.y = a.y + b.y; + + return this; + + }; + + /** + * Adds a scaled vector to this one. + * + * @param {Vector2} v - The vector to scale and add. + * @param {Number} s - A scalar. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.addScaledVector = function addScaledVector (v, s) { + + this.x += v.x * s; + this.y += v.y * s; + + return this; + + }; + + /** + * Subtracts a vector from this vector. + * + * @param {Vector2} v - The vector to subtract. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.sub = function sub (v) { + + this.x -= v.x; + this.y -= v.y; + + return this; + + }; + + /** + * Subtracts a scalar from this vector. + * + * @param {Number} s - The scalar to subtract. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.subScalar = function subScalar (s) { + + this.x -= s; + this.y -= s; + + return this; + + }; + + /** + * Sets this vector to the difference between two given vectors. + * + * @param {Vector2} a - A vector. + * @param {Vector2} b - A second vector. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.subVectors = function subVectors (a, b) { + + this.x = a.x - b.x; + this.y = a.y - b.y; + + return this; + + }; + + /** + * Multiplies this vector with another vector. + * + * @param {Vector2} v - A vector. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.multiply = function multiply (v) { + + this.x *= v.x; + this.y *= v.y; + + return this; + + }; + + /** + * Multiplies this vector with a given scalar. + * + * @param {Number} s - A scalar. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.multiplyScalar = function multiplyScalar (s) { + + this.x *= s; + this.y *= s; + + return this; + + }; + + /** + * Divides this vector by another vector. + * + * @param {Vector2} v - A vector. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.divide = function divide (v) { + + this.x /= v.x; + this.y /= v.y; + + return this; + + }; + + /** + * Divides this vector by a given scalar. + * + * @param {Number} s - A scalar. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.divideScalar = function divideScalar (s) { + + this.x /= s; + this.y /= s; + + return this; + + }; + + /** + * Applies the given matrix to this vector. + * + * @param {Matrix3} m - A matrix. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.applyMatrix3 = function applyMatrix3 (m) { + + var x = this.x, y = this.y; + var e = m.elements; + + this.x = e[0] * x + e[3] * y + e[6]; + this.y = e[1] * x + e[4] * y + e[7]; + + return this; + + }; + + /** + * Calculates the dot product with another vector. + * + * @param {Vector2} v - A vector. + * @return {Number} The dot product. + */ + + Vector2$1.prototype.dot = function dot (v) { + + return this.x * v.x + this.y * v.y; + + }; + + /** + * Calculates the cross product with another vector. + * + * This method calculates a scalar that would result from a regular 3D cross + * product of the input vectors, while taking their Z values implicitly as 0. + * + * @param {Vector2} v - A vector. + * @return {Number} The cross product. + */ + + Vector2$1.prototype.cross = function cross (v) { + + return this.x * v.y - this.y * v.x; + + }; + + /** + * Calculates the Manhattan length of this vector. + * + * @return {Number} The length. + */ + + Vector2$1.prototype.manhattanLength = function manhattanLength () { + + return Math.abs(this.x) + Math.abs(this.y); + + }; + + /** + * Calculates the squared length of this vector. + * + * @return {Number} The squared length. + */ + + Vector2$1.prototype.lengthSquared = function lengthSquared () { + + return this.x * this.x + this.y * this.y; + + }; + + /** + * Calculates the length of this vector. + * + * @return {Number} The length. + */ + + Vector2$1.prototype.length = function length () { + + return Math.sqrt(this.x * this.x + this.y * this.y); + + }; + + /** + * Calculates the Manhattan distance to a given vector. + * + * @param {Vector2} v - A vector. + * @return {Number} The squared distance. + */ + + Vector2$1.prototype.manhattanDistanceTo = function manhattanDistanceTo (v) { + + return Math.abs(this.x - v.x) + Math.abs(this.y - v.y); + + }; + + /** + * Calculates the squared distance to a given vector. + * + * @param {Vector2} v - A vector. + * @return {Number} The squared distance. + */ + + Vector2$1.prototype.distanceToSquared = function distanceToSquared (v) { + + var dx = this.x - v.x; + var dy = this.y - v.y; + + return dx * dx + dy * dy; + + }; + + /** + * Calculates the distance to a given vector. + * + * @param {Vector2} v - A vector. + * @return {Number} The distance. + */ + + Vector2$1.prototype.distanceTo = function distanceTo (v) { + + return Math.sqrt(this.distanceToSquared(v)); + + }; + + /** + * Normalizes this vector. + * + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.normalize = function normalize () { + + return this.divideScalar(this.length()); + + }; + + /** + * Sets the length of this vector. + * + * @param {Number} length - The new length. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.setLength = function setLength (length) { + + return this.normalize().multiplyScalar(length); + + }; + + /** + * Adopts the min value for each component of this vector and the given one. + * + * @param {Vector2} v - A vector. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.min = function min (v) { + + this.x = Math.min(this.x, v.x); + this.y = Math.min(this.y, v.y); + + return this; + + }; + + /** + * adopts the max value for each component of this vector and the given one. + * + * @param {Vector2} v - A vector. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.max = function max (v) { + + this.x = Math.max(this.x, v.x); + this.y = Math.max(this.y, v.y); + + return this; + + }; + + /** + * Clamps this vector. + * + * @param {Vector2} min - A vector, assumed to be smaller than max. + * @param {Vector2} max - A vector, assumed to be greater than min. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.clamp = function clamp (min, max) { + + this.x = Math.max(min.x, Math.min(max.x, this.x)); + this.y = Math.max(min.y, Math.min(max.y, this.y)); + + return this; + + }; + + /** + * Floors this vector. + * + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.floor = function floor () { + + this.x = Math.floor(this.x); + this.y = Math.floor(this.y); + + return this; + + }; + + /** + * Ceils this vector. + * + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.ceil = function ceil () { + + this.x = Math.ceil(this.x); + this.y = Math.ceil(this.y); + + return this; + + }; + + /** + * Rounds this vector. + * + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.round = function round () { + + this.x = Math.round(this.x); + this.y = Math.round(this.y); + + return this; + + }; + + /** + * Negates this vector. + * + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.negate = function negate () { + + this.x = -this.x; + this.y = -this.y; + + return this; + + }; + + /** + * Computes the angle in radians with respect to the positive X-axis. + * + * @return {Number} The angle. + */ + + Vector2$1.prototype.angle = function angle () { + + return Math.atan2(-this.y, -this.x) + Math.PI; + + }; + + /** + * Lerps towards the given vector. + * + * @param {Vector2} v - The target vector. + * @param {Number} alpha - The lerp factor. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.lerp = function lerp (v, alpha) { + + this.x += (v.x - this.x) * alpha; + this.y += (v.y - this.y) * alpha; + + return this; + + }; + + /** + * Sets this vector to the lerp result of the given vectors. + * + * @param {Vector2} v1 - A base vector. + * @param {Vector2} v2 - The target vector. + * @param {Number} alpha - The lerp factor. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.lerpVectors = function lerpVectors (v1, v2, alpha) { + + return this.subVectors(v2, v1).multiplyScalar(alpha).add(v1); + + }; + + /** + * Rotates this vector around a given center. + * + * @param {Vector2} center - The center. + * @param {Number} angle - The rotation in radians. + * @return {Vector2} This vector. + */ + + Vector2$1.prototype.rotateAround = function rotateAround (center, angle) { + + var c = Math.cos(angle), s = Math.sin(angle); + + var x = this.x - center.x; + var y = this.y - center.y; + + this.x = x * c - y * s + center.x; + this.y = x * s + y * c + center.y; + + return this; + + }; + + /** + * Checks if this vector equals the given one. + * + * @param {Vector2} v - A vector. + * @return {Boolean} Whether this vector equals the given one. + */ + + Vector2$1.prototype.equals = function equals (v) { + + return (v.x === this.x && v.y === this.y); + + }; + + Object.defineProperties( Vector2$1.prototype, prototypeAccessors$1 ); + + /** + * A vector. + * + * @type {Vector2} + * @private + */ + + var v$2$1 = new Vector2$1(); + + /** + * A 3x3 matrix. + */ + + var Matrix3$1 = function Matrix3() { + + /** + * The matrix elements. + * + * @type {Float32Array} + */ + + this.elements = new Float32Array([ + + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + + ]); + + }; + + /** + * Sets the values of this matrix. + * + * @param {Number} m00 - The value of the first row, first column. + * @param {Number} m01 - The value of the first row, second column. + * @param {Number} m02 - The value of the first row, third column. + * @param {Number} m10 - The value of the second row, first column. + * @param {Number} m11 - The value of the second row, second column. + * @param {Number} m12 - The value of the second row, third column. + * @param {Number} m20 - The value of the third row, first column. + * @param {Number} m21 - The value of the third row, second column. + * @param {Number} m22 - The value of the third row, third column. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.set = function set (m00, m01, m02, m10, m11, m12, m20, m21, m22) { + + var te = this.elements; + + te[0] = m00; te[3] = m01; te[6] = m02; + te[1] = m10; te[4] = m11; te[7] = m12; + te[2] = m20; te[5] = m21; te[8] = m22; + + return this; + + }; + + /** + * Sets this matrix to the identity matrix. + * + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.identity = function identity () { + + this.set( + + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 + + ); + + return this; + + }; + + /** + * Copies the values of a given matrix. + * + * @param {Matrix3} matrix - A matrix. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.copy = function copy (matrix) { + + var me = matrix.elements; + var te = this.elements; + + te[0] = me[0]; te[1] = me[1]; te[2] = me[2]; + te[3] = me[3]; te[4] = me[4]; te[5] = me[5]; + te[6] = me[6]; te[7] = me[7]; te[8] = me[8]; + + return this; + + }; + + /** + * Clones this matrix. + * + * @return {Matrix3} A clone of this matrix. + */ + + Matrix3$1.prototype.clone = function clone () { + + return new this.constructor().fromArray(this.elements); + + }; + + /** + * Copies the values of a given array. + * + * @param {Number[]} array - An array. + * @param {Number} [offset=0] - An offset into the array. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.fromArray = function fromArray (array, offset) { + if ( offset === void 0 ) offset = 0; + + + var te = this.elements; + + var i; + + for(i = 0; i < 9; ++i) { + + te[i] = array[i + offset]; + + } + + return this; + + }; + + /** + * Stores this matrix in an array. + * + * @param {Number[]} [array] - A target array. + * @param {Number} [offset=0] - An offset into the array. + * @return {Number[]} The array. + */ + + Matrix3$1.prototype.toArray = function toArray (array, offset) { + if ( array === void 0 ) array = []; + if ( offset === void 0 ) offset = 0; + + + var te = this.elements; + + var i; + + for(i = 0; i < 9; ++i) { + + array[i + offset] = te[i]; + + } + + return array; + + }; + + /** + * Sets this matrix to the product of the given matrices. + * + * @param {Matrix3} a - A matrix. + * @param {Matrix3} b - A matrix. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.multiplyMatrices = function multiplyMatrices (a, b) { + + var ae = a.elements; + var be = b.elements; + var te = this.elements; + + var a11 = ae[0], a12 = ae[3], a13 = ae[6]; + var a21 = ae[1], a22 = ae[4], a23 = ae[7]; + var a31 = ae[2], a32 = ae[5], a33 = ae[8]; + + var b11 = be[0], b12 = be[3], b13 = be[6]; + var b21 = be[1], b22 = be[4], b23 = be[7]; + var b31 = be[2], b32 = be[5], b33 = be[8]; + + te[0] = a11 * b11 + a12 * b21 + a13 * b31; + te[3] = a11 * b12 + a12 * b22 + a13 * b32; + te[6] = a11 * b13 + a12 * b23 + a13 * b33; + + te[1] = a21 * b11 + a22 * b21 + a23 * b31; + te[4] = a21 * b12 + a22 * b22 + a23 * b32; + te[7] = a21 * b13 + a22 * b23 + a23 * b33; + + te[2] = a31 * b11 + a32 * b21 + a33 * b31; + te[5] = a31 * b12 + a32 * b22 + a33 * b32; + te[8] = a31 * b13 + a32 * b23 + a33 * b33; + + return this; + + }; + + /** + * Multiplies this matrix with a given one. + * + * @param {Matrix3} m - A matrix. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.multiply = function multiply (m) { + + return this.multiplyMatrices(this, m); + + }; + + /** + * Multiplies a given matrix with this one. + * + * @param {Matrix3} m - A matrix. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.premultiply = function premultiply (m) { + + return this.multiplyMatrices(m, this); + + }; + + /** + * Multiplies this matrix with a given scalar. + * + * @param {Number} s - A scalar. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.multiplyScalar = function multiplyScalar (s) { + + var te = this.elements; + + te[0] *= s; te[3] *= s; te[6] *= s; + te[1] *= s; te[4] *= s; te[7] *= s; + te[2] *= s; te[5] *= s; te[8] *= s; + + return this; + + }; + + /** + * Calculates the determinant of this matrix. + * + * @return {Number} The determinant. + */ + + Matrix3$1.prototype.determinant = function determinant () { + + var te = this.elements; + + var a = te[0], b = te[1], c = te[2]; + var d = te[3], e = te[4], f = te[5]; + var g = te[6], h = te[7], i = te[8]; + + return ( + + a * e * i - + a * f * h - + b * d * i + + b * f * g + + c * d * h - + c * e * g + + ); + + }; + + /** + * Inverts the given matrix and stores the result in this matrix. + * + * @param {Matrix3} matrix - The matrix that should be inverted. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.getInverse = function getInverse (matrix) { + + var me = matrix.elements; + var te = this.elements; + + var n11 = me[0], n21 = me[1], n31 = me[2]; + var n12 = me[3], n22 = me[4], n32 = me[5]; + var n13 = me[6], n23 = me[7], n33 = me[8]; + + var t11 = n33 * n22 - n32 * n23; + var t12 = n32 * n13 - n33 * n12; + var t13 = n23 * n12 - n22 * n13; + + var det = n11 * t11 + n21 * t12 + n31 * t13; + + var invDet; + + if(det !== 0) { + + invDet = 1.0 / det; + + te[0] = t11 * invDet; + te[1] = (n31 * n23 - n33 * n21) * invDet; + te[2] = (n32 * n21 - n31 * n22) * invDet; + + te[3] = t12 * invDet; + te[4] = (n33 * n11 - n31 * n13) * invDet; + te[5] = (n31 * n12 - n32 * n11) * invDet; + + te[6] = t13 * invDet; + te[7] = (n21 * n13 - n23 * n11) * invDet; + te[8] = (n22 * n11 - n21 * n12) * invDet; + + } else { + + this.set(0, 0, 0, 0, 0, 0, 0, 0, 0); + + } + + return this; + + }; + + /** + * Transposes this matrix. + * + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.transpose = function transpose () { + + var me = this.elements; + + var t; + + t = me[1]; me[1] = me[3]; me[3] = t; + t = me[2]; me[2] = me[6]; me[6] = t; + t = me[5]; me[5] = me[7]; me[7] = t; + + return this; + + }; + + /** + * Scales this matrix. + * + * @param {Number} sx - The X scale. + * @param {Number} sy - The Y scale. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.scale = function scale (sx, sy) { + + var te = this.elements; + + te[0] *= sx; te[3] *= sx; te[6] *= sx; + te[1] *= sy; te[4] *= sy; te[7] *= sy; + + return this; + + }; + + /** + * Rotates this matrix. + * + * @param {Number} theta - The rotation. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.rotate = function rotate (theta) { + + var c = Math.cos(theta); + var s = Math.sin(theta); + + var te = this.elements; + + var a11 = te[0], a12 = te[3], a13 = te[6]; + var a21 = te[1], a22 = te[4], a23 = te[7]; + + te[0] = c * a11 + s * a21; + te[3] = c * a12 + s * a22; + te[6] = c * a13 + s * a23; + + te[1] = -s * a11 + c * a21; + te[4] = -s * a12 + c * a22; + te[7] = -s * a13 + c * a23; + + return this; + + }; + + /** + * Translates this matrix. + * + * @param {Number} tx - The X offset. + * @param {Number} ty - The Y offset. + * @return {Matrix3} This matrix. + */ + + Matrix3$1.prototype.translate = function translate (tx, ty) { + + var te = this.elements; + + te[0] += tx * te[2]; te[3] += tx * te[5]; te[6] += tx * te[8]; + te[1] += ty * te[2]; te[4] += ty * te[5]; te[7] += ty * te[8]; + + return this; + + }; + + /** + * Checks if this matrix equals the given one. + * + * @param {Matrix3} m - A matrix. + * @return {Boolean} Whether the matrix are equal. + */ + + Matrix3$1.prototype.equals = function equals (m) { + + var te = this.elements; + var me = m.elements; + + var result = true; + var i; + + for(i = 0; result && i < 9; ++i) { + + if(te[i] !== me[i]) { + + result = false; + + } + + } + + return result; + + }; + + /** + * An enumeration of Euler rotation orders. + * + * @type {Object} + * @property {String} XYZ - X -> Y -> Z. + * @property {String} YZX - Y -> Z -> X. + * @property {String} ZXY - Z -> X -> Y. + * @property {String} XZY - X -> Z -> Y. + * @property {String} YXZ - Y -> X -> Z. + * @property {String} ZYX - Z -> Y -> X. + */ + + var RotationOrder = { + + XYZ: "XYZ", + YZX: "YZX", + ZXY: "ZXY", + XZY: "XZY", + YXZ: "YXZ", + ZYX: "ZYX" + + }; + + /** + * A quaternion. + */ + + var Quaternion$1 = function Quaternion(x, y, z, w) { + if ( x === void 0 ) x = 0; + if ( y === void 0 ) y = 0; + if ( z === void 0 ) z = 0; + if ( w === void 0 ) w = 0; + + + /** + * The X component. + * + * @type {Number} + */ + + this.x = x; + + /** + * The Y component. + * + * @type {Number} + */ + + this.y = y; + + /** + * The Z component. + * + * @type {Number} + */ + + this.z = z; + + /** + * The W component. + * + * @type {Number} + */ + + this.w = w; + + }; + + /** + * Sets the components of this quaternion. + * + * @param {Number} x - The X component. + * @param {Number} y - The Y component. + * @param {Number} z - The Z component. + * @param {Number} w - The W component. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.set = function set (x, y, z, w) { + + this.x = x; + this.y = y; + this.z = z; + this.w = w; + + return this; + + }; + + /** + * Copies the components of the given quaternion. + * + * @param {Quaternion} q - The quaternion. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.copy = function copy (q) { + + this.x = q.x; + this.y = q.y; + this.z = q.z; + this.w = q.w; + + return this; + + }; + + /** + * Clones this quaternion. + * + * @return {Quaternion} The cloned quaternion. + */ + + Quaternion$1.prototype.clone = function clone () { + + return new this.constructor(this.x, this.y, this.z, this.w); + + }; + + /** + * Copies values from an array. + * + * @param {Number[]} array - An array. + * @param {Number} offset - An offset. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.fromArray = function fromArray (array, offset) { + if ( offset === void 0 ) offset = 0; + + + this.x = array[offset]; + this.y = array[offset + 1]; + this.z = array[offset + 2]; + this.w = array[offset + 3]; + + return this; + + }; + + /** + * Stores this quaternion in an array. + * + * @param {Array} [array] - A target array. + * @param {Number} offset - An offset. + * @return {Number[]} The array. + */ + + Quaternion$1.prototype.toArray = function toArray (array, offset) { + if ( array === void 0 ) array = []; + if ( offset === void 0 ) offset = 0; + + + array[offset] = this.x; + array[offset + 1] = this.y; + array[offset + 2] = this.z; + array[offset + 3] = this.w; + + return array; + + }; + + /** + * Sets the components of this quaternion based on the given Euler angles. + * + * For more details see: https://goo.gl/XRD1kr + * + * @param {Euler} euler - The euler angles. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.setFromEuler = function setFromEuler (euler) { + + var x = euler.x; + var y = euler.y; + var z = euler.z; + + var cos = Math.cos; + var sin = Math.sin; + + var c1 = cos(x / 2); + var c2 = cos(y / 2); + var c3 = cos(z / 2); + + var s1 = sin(x / 2); + var s2 = sin(y / 2); + var s3 = sin(z / 2); + + switch(euler.order) { + + case RotationOrder.XYZ: + this.x = s1 * c2 * c3 + c1 * s2 * s3; + this.y = c1 * s2 * c3 - s1 * c2 * s3; + this.z = c1 * c2 * s3 + s1 * s2 * c3; + this.w = c1 * c2 * c3 - s1 * s2 * s3; + break; + + case RotationOrder.YXZ: + this.x = s1 * c2 * c3 + c1 * s2 * s3; + this.y = c1 * s2 * c3 - s1 * c2 * s3; + this.z = c1 * c2 * s3 - s1 * s2 * c3; + this.w = c1 * c2 * c3 + s1 * s2 * s3; + break; + + case RotationOrder.ZXY: + this.x = s1 * c2 * c3 - c1 * s2 * s3; + this.y = c1 * s2 * c3 + s1 * c2 * s3; + this.z = c1 * c2 * s3 + s1 * s2 * c3; + this.w = c1 * c2 * c3 - s1 * s2 * s3; + break; + + case RotationOrder.ZYX: + this.x = s1 * c2 * c3 - c1 * s2 * s3; + this.y = c1 * s2 * c3 + s1 * c2 * s3; + this.z = c1 * c2 * s3 - s1 * s2 * c3; + this.w = c1 * c2 * c3 + s1 * s2 * s3; + break; + + case RotationOrder.YZX: + this.x = s1 * c2 * c3 + c1 * s2 * s3; + this.y = c1 * s2 * c3 + s1 * c2 * s3; + this.z = c1 * c2 * s3 - s1 * s2 * c3; + this.w = c1 * c2 * c3 - s1 * s2 * s3; + break; + + case RotationOrder.XZY: + this.x = s1 * c2 * c3 - c1 * s2 * s3; + this.y = c1 * s2 * c3 - s1 * c2 * s3; + this.z = c1 * c2 * s3 + s1 * s2 * c3; + this.w = c1 * c2 * c3 + s1 * s2 * s3; + break; + + } + + return this; + + }; + + /** + * Sets the components of this quaternion based on a given axis angle. + * + * For more information see: + * http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm + * + * @param {Vector3} axis - The axis. Assumed to be normalized. + * @param {Number} angle - The angle in radians. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.setFromAxisAngle = function setFromAxisAngle (axis, angle) { + + var halfAngle = angle / 2.0; + var s = Math.sin(halfAngle); + + this.x = axis.x * s; + this.y = axis.y * s; + this.z = axis.z * s; + this.w = Math.cos(halfAngle); + + return this; + + }; + + /** + * Sets the components of this quaternion based on a given rotation matrix. + * + * For more information see: + * http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm + * + * @param {Matrix4} m - The rotation matrix. The upper 3x3 is assumed to be a pure rotation matrix (i.e. unscaled). + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.setFromRotationMatrix = function setFromRotationMatrix (m) { + + var te = m.elements; + + var m00 = te[0], m01 = te[4], m02 = te[8]; + var m10 = te[1], m11 = te[5], m12 = te[9]; + var m20 = te[2], m21 = te[6], m22 = te[10]; + + var trace = m00 + m11 + m22; + + var s; + + if(trace > 0) { + + s = 0.5 / Math.sqrt(trace + 1.0); + + this.w = 0.25 / s; + this.x = (m21 - m12) * s; + this.y = (m02 - m20) * s; + this.z = (m10 - m01) * s; + + } else if(m00 > m11 && m00 > m22) { + + s = 2.0 * Math.sqrt(1.0 + m00 - m11 - m22); + + this.w = (m21 - m12) / s; + this.x = 0.25 * s; + this.y = (m01 + m10) / s; + this.z = (m02 + m20) / s; + + } else if(m11 > m22) { + + s = 2.0 * Math.sqrt(1.0 + m11 - m00 - m22); + + this.w = (m02 - m20) / s; + this.x = (m01 + m10) / s; + this.y = 0.25 * s; + this.z = (m12 + m21) / s; + + } else { + + s = 2.0 * Math.sqrt(1.0 + m22 - m00 - m11); + + this.w = (m10 - m01) / s; + this.x = (m02 + m20) / s; + this.y = (m12 + m21) / s; + this.z = 0.25 * s; + + } + + return this; + + }; + + /** + * Sets the components of this quaternion based on unit vectors. + * + * @param {Vector3} vFrom - A unit vector. Assumed to be normalized. + * @param {Vector3} vTo - A unit vector. Assumed to be normalized. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.setFromUnitVectors = function setFromUnitVectors (vFrom, vTo) { + + var r = vFrom.dot(vTo) + 1; + + if(r < 1e-6) { + + r = 0; + + if(Math.abs(vFrom.x) > Math.abs(vFrom.z)) { + + this.x = -vFrom.y; + this.y = vFrom.x; + this.z = 0; + this.w = r; + + } else { + + this.x = 0; + this.y = -vFrom.z; + this.z = vFrom.y; + this.w = r; + + } + + } else { + + // crossVectors(vFrom, vTo) + this.x = vFrom.y * vTo.z - vFrom.z * vTo.y; + this.y = vFrom.z * vTo.x - vFrom.x * vTo.z; + this.z = vFrom.x * vTo.y - vFrom.y * vTo.x; + this.w = r; + + } + + return this.normalize(); + + }; + + /** + * Calculates the angle to another quaternion. + * + * @param {Quaternion} q - A quaternion. + * @return {Number} The angle in radians. + */ + + Quaternion$1.prototype.angleTo = function angleTo (q) { + + return 2.0 * Math.acos(Math.abs(Math.min(Math.max(this.dot(q), -1.0), 1.0))); + + }; + + /** + * Rotates this quaternion towards the given one by a given step size. + * + * @param {Quaternion} q - The target quaternion. + * @param {Number} step - The step size. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.rotateTowards = function rotateTowards (q, step) { + + var angle = this.angleTo(q); + + if(angle !== 0.0) { + + this.slerp(q, Math.min(1.0, step / angle)); + + } + + return this; + + }; + + /** + * Inverts this quaternion. The quaternion is assumed to have unit length. + * + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.invert = function invert () { + + return this.conjugate(); + + }; + + /** + * Conjugates this quaternion. + * + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.conjugate = function conjugate () { + + this.x *= -1; + this.y *= -1; + this.z *= -1; + + return this; + + }; + + /** + * Calculates the squared length of this quaternion. + * + * @return {Number} The squared length. + */ + + Quaternion$1.prototype.lengthSquared = function lengthSquared () { + + return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; + + }; + + /** + * Calculates the length of this quaternion. + * + * @return {Number} The length. + */ + + Quaternion$1.prototype.length = function length () { + + return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); + + }; + + /** + * Normalizes this quaternion. + * + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.normalize = function normalize () { + + var l = this.length(); + + var invLength; + + if(l === 0) { + + this.x = 0; + this.y = 0; + this.z = 0; + this.w = 1; + + } else { + + invLength = 1.0 / l; + + this.x = this.x * invLength; + this.y = this.y * invLength; + this.z = this.z * invLength; + this.w = this.w * invLength; + + } + + return this; + + }; + + /** + * Calculates the dot product with a given vector. + * + * @param {Vector4} v - A vector. + * @return {Number} The dot product. + */ + + Quaternion$1.prototype.dot = function dot (v) { + + return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w; + + }; + + /** + * Multiplies the given quaternions and stores the result in this quaternion. + * + * For more details see: + * http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm + * + * @param {Quaternion} a - A quaternion. + * @param {Quaternion} b - Another quaternion. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.multiplyQuaternions = function multiplyQuaternions (a, b) { + + var qax = a.x, qay = a.y, qaz = a.z, qaw = a.w; + var qbx = b.x, qby = b.y, qbz = b.z, qbw = b.w; + + this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby; + this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz; + this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx; + this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz; + + return this; + + }; + + /** + * Multiplies this quaternion with the given one and stores the result in + * this quaternion. + * + * @param {Quaternion} q - A quaternion. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.multiply = function multiply (q) { + + return this.multiplyQuaternions(this, q); + + }; + + /** + * Multiplies the given quaternion with this one and stores the result in + * this quaternion. + * + * @param {Quaternion} q - A quaternion. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.premultiply = function premultiply (q) { + + return this.multiplyQuaternions(q, this); + + }; + + /** + * Performs a spherical linear interpolation towards the given quaternion. + * + * For more details see: + * http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/ + * + * @param {Quaternion} q - A quaternion. + * @param {Number} t - The slerp factor. + * @return {Quaternion} This quaternion. + */ + + Quaternion$1.prototype.slerp = function slerp (q, t) { + + var x = this.x, y = this.y, z = this.z, w = this.w; + + var cosHalfTheta, sinHalfThetaSquared, sinHalfTheta, halfTheta; + var s, ratioA, ratioB; + + if(t === 1) { + + this.copy(q); + + } else if(t > 0) { + + cosHalfTheta = w * q.w + x * q.x + y * q.y + z * q.z; + + if(cosHalfTheta < 0.0) { + + this.w = -q.w; + this.x = -q.x; + this.y = -q.y; + this.z = -q.z; + + cosHalfTheta = -cosHalfTheta; + + } else { + + this.copy(q); + + } + + if(cosHalfTheta >= 1.0) { + + this.w = w; + this.x = x; + this.y = y; + this.z = z; + + } else { + + sinHalfThetaSquared = 1.0 - cosHalfTheta * cosHalfTheta; + s = 1.0 - t; + + if(sinHalfThetaSquared <= Number.EPSILON) { + + this.w = s * w + t * this.w; + this.x = s * x + t * this.x; + this.y = s * y + t * this.y; + this.z = s * z + t * this.z; + + this.normalize(); + + } else { + + sinHalfTheta = Math.sqrt(sinHalfThetaSquared); + halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta); + ratioA = Math.sin(s * halfTheta) / sinHalfTheta; + ratioB = Math.sin(t * halfTheta) / sinHalfTheta; + + this.w = (w * ratioA + this.w * ratioB); + this.x = (x * ratioA + this.x * ratioB); + this.y = (y * ratioA + this.y * ratioB); + this.z = (z * ratioA + this.z * ratioB); + + } + + } + + } + + return this; + + }; + + /** + * Checks if this quaternions equals the given one. + * + * @param {Quaternion} q - A quaternion. + * @return {Boolean} Whether the quaternions are equal. + */ + + Quaternion$1.prototype.equals = function equals (q) { + + return (q.x === this.x) && (q.y === this.y) && (q.z === this.z) && (q.w === this.w); + + }; + + /** + * Performs a spherical linear interpolation. + * + * @param {Quaternion} qa - The base quaternion. + * @param {Quaternion} qb - The target quaternion. + * @param {Quaternion} qr - A quaternion to store the result in. + * @param {Number} t - The slerp factor. + * @return {Quaternion} The resulting quaternion. + */ + + Quaternion$1.slerp = function slerp (qa, qb, qr, t) { + + return qr.copy(qa).slerp(qb, t); + + }; + + /** + * Performs an array-based spherical linear interpolation. + * + * @param {Number[]} dst - An array to store the result in. + * @param {Number} dstOffset - An offset into the destination array. + * @param {Number[]} src0 - An array that contains the base quaternion values. + * @param {Number} srcOffset0 - An offset into the base array. + * @param {Number[]} src1 - An array that contains the target quaternion values. + * @param {Number} srcOffset1 - An offset into the target array. + * @param {Number} t - The slerp factor. + */ + + Quaternion$1.slerpFlat = function slerpFlat (dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) { + + var x1 = src1[srcOffset1]; + var y1 = src1[srcOffset1 + 1]; + var z1 = src1[srcOffset1 + 2]; + var w1 = src1[srcOffset1 + 3]; + + var x0 = src0[srcOffset0]; + var y0 = src0[srcOffset0 + 1]; + var z0 = src0[srcOffset0 + 2]; + var w0 = src0[srcOffset0 + 3]; + + var s, f; + var sin, cos, sqrSin; + var dir, len, tDir; + + if(w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) { + + s = 1.0 - t; + cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1; + + dir = (cos >= 0) ? 1 : -1; + sqrSin = 1.0 - cos * cos; + + // Skip the Slerp for tiny steps to avoid numeric problems. + if(sqrSin > Number.EPSILON) { + + sin = Math.sqrt(sqrSin); + len = Math.atan2(sin, cos * dir); + + s = Math.sin(s * len) / sin; + t = Math.sin(t * len) / sin; + + } + + tDir = t * dir; + + x0 = x0 * s + x1 * tDir; + y0 = y0 * s + y1 * tDir; + z0 = z0 * s + z1 * tDir; + w0 = w0 * s + w1 * tDir; + + // Normalize in case a lerp has just been performed. + if(s === 1.0 - t) { + + f = 1.0 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0); + + x0 *= f; + y0 *= f; + z0 *= f; + w0 *= f; + + } + + } + + dst[dstOffset] = x0; + dst[dstOffset + 1] = y0; + dst[dstOffset + 2] = z0; + dst[dstOffset + 3] = w0; + + }; + + /** + * Clamps the given value. + * + * @private + * @param {Number} value - The value. + * @param {Number} min - The lower limit. + * @param {Number} max - The upper limit. + * @return {Number} The clamped value. + */ + + function clamp(value, min, max) { + + return Math.max(Math.min(value, max), min); + + } + + /** + * A matrix. + * + * @type {Matrix3} + * @private + */ + + var m$1 = new Matrix3$1(); + + /** + * A quaternion. + * + * @type {Quaternion} + * @private + */ + + var q = new Quaternion$1(); + + /** + * Euler angles. + */ + + var Euler$1 = function Euler(x, y, z) { + if ( x === void 0 ) x = 0; + if ( y === void 0 ) y = 0; + if ( z === void 0 ) z = 0; + + + /** + * The rotation around the X-axis. + * + * @type {Number} + */ + + this.x = x; + + /** + * The rotation around the Y-axis. + * + * @type {Number} + */ + + this.y = y; + + /** + * The rotation around the Z-axis. + * + * @type {Number} + */ + + this.z = z; + + /** + * The rotation order. + * + * @type {RotationOrder} + * @default Euler.defaultOrder + */ + + this.order = Euler.defaultOrder; + + }; + + var staticAccessors = { defaultOrder: { configurable: true } }; + + /** + * Sets the Euler angles and rotation order. + * + * @param {Number} x - The rotation around the X-axis. + * @param {Number} y - The rotation around the Y-axis. + * @param {Number} z - The rotation around the Z-axis. + * @param {Number} order - The rotation order. + * @return {Euler} This set of Euler angles. + */ + + Euler$1.prototype.set = function set (x, y, z, order) { + + this.x = x; + this.y = y; + this.z = z; + this.order = order; + + return this; + + }; + + /** + * Copies the values of another set of Euler angles. + * + * @param {Euler} e - A set of Euler angles. + * @return {Euler} This set of Euler angles. + */ + + Euler$1.prototype.copy = function copy (e) { + + this.x = e.x; + this.y = e.y; + this.z = e.z; + this.order = e.order; + + return this; + + }; + + /** + * Clones this set of Euler angles. + * + * @return {Euler} A clone of this set of Euler angles. + */ + + Euler$1.prototype.clone = function clone () { + + return new this.constructor(this.x, this.y, this.z, this.order); + + }; + + /** + * Copies angles and the rotation order from an array. + * + * @param {Number[]} array - An array. + * @param {Number} offset - An offset. + * @return {Euler} This set of Euler angles. + */ + + Euler$1.prototype.fromArray = function fromArray (array, offset) { + if ( offset === void 0 ) offset = 0; + + + this.x = array[offset]; + this.y = array[offset + 1]; + this.z = array[offset + 2]; + this.order = array[offset + 3]; + + return this; + + }; + + /** + * Stores this set of Euler angles and the rotation order in an array. + * + * @param {Array} [array] - A target array. + * @param {Number} offset - An offset. + * @return {Number[]} The array. + */ + + Euler$1.prototype.toArray = function toArray (array, offset) { + if ( array === void 0 ) array = []; + if ( offset === void 0 ) offset = 0; + + + array[offset] = this.x; + array[offset + 1] = this.y; + array[offset + 2] = this.z; + array[offset + 3] = this.order; + + return array; + + }; + + /** + * Stores this set of Euler angles in a vector. + * + * @param {Vector3} [vector] - A target vector. If none is provided, a new one will be created. + * @return {Vector3} The vector. + */ + + Euler$1.prototype.toVector3 = function toVector3 (vector) { + if ( vector === void 0 ) vector = new Vector3$1(); + + + return vector.set(this.x, this.y, this.z); + + }; + + /** + * Copies the rotation from a given matrix. + * + * @param {Matrix4} m - A rotation matrix. The upper 3x3 is assumed to be a pure rotation matrix (i.e. unscaled). + * @param {RotationOrder} [order] - An override rotation order. + * @return {Euler} This set of Euler angles. + */ + + Euler$1.prototype.setFromRotationMatrix = function setFromRotationMatrix (m, order) { + if ( order === void 0 ) order = this.order; + + + var te = m.elements; + var m00 = te[0], m01 = te[4], m02 = te[8]; + var m10 = te[1], m11 = te[5], m12 = te[9]; + var m20 = te[2], m21 = te[6], m22 = te[10]; + + var THRESHOLD = 1.0 - 1e-7; + + switch(order) { + + case RotationOrder.XYZ: { + + this.y = Math.asin(clamp(m02, -1, 1)); + + if(Math.abs(m02) < THRESHOLD) { + + this.x = Math.atan2(-m12, m22); + this.z = Math.atan2(-m01, m00); + + } else { + + this.x = Math.atan2(m21, m11); + this.z = 0; + + } + + break; + + } + + case RotationOrder.YXZ: { + + this.x = Math.asin(-clamp(m12, -1, 1)); + + if(Math.abs(m12) < THRESHOLD) { + + this.y = Math.atan2(m02, m22); + this.z = Math.atan2(m10, m11); + + } else { + + this.y = Math.atan2(-m20, m00); + this.z = 0; + + } + + break; + + } + + case RotationOrder.ZXY: { + + this.x = Math.asin(clamp(m21, -1, 1)); + + if(Math.abs(m21) < THRESHOLD) { + + this.y = Math.atan2(-m20, m22); + this.z = Math.atan2(-m01, m11); + + } else { + + this.y = 0; + this.z = Math.atan2(m10, m00); + + } + + break; + + } + + case RotationOrder.ZYX: { + + this.y = Math.asin(-clamp(m20, -1, 1)); + + if(Math.abs(m20) < THRESHOLD) { + + this.x = Math.atan2(m21, m22); + this.z = Math.atan2(m10, m00); + + } else { + + this.x = 0; + this.z = Math.atan2(-m01, m11); + + } + + break; + + } + + case RotationOrder.YZX: { + + this.z = Math.asin(clamp(m10, -1, 1)); + + if(Math.abs(m10) < THRESHOLD) { + + this.x = Math.atan2(-m12, m11); + this.y = Math.atan2(-m20, m00); + + } else { + + this.x = 0; + this.y = Math.atan2(m02, m22); + + } + + break; + + } + + case RotationOrder.XZY: { + + this.z = Math.asin(-clamp(m01, -1, 1)); + + if(Math.abs(m01) < THRESHOLD) { + + this.x = Math.atan2(m21, m11); + this.y = Math.atan2(m02, m00); + + } else { + + this.x = Math.atan2(-m12, m22); + this.y = 0; + + } + + break; + + } + + } + + this.order = order; + + return this; + + }; + + /** + * Copies the rotation from a given quaternion. + * + * @param {Matrix4} q - A quaternion. + * @param {RotationOrder} [order] - An override rotation order. + * @return {Euler} This set of Euler angles. + */ + + Euler$1.prototype.setFromQuaternion = function setFromQuaternion (q, order) { + + m$1.makeRotationFromQuaternion(q); + + return this.setFromRotationMatrix(m$1, order); + + }; + + /** + * Copies the rotation from a given vector. + * + * @param {Matrix4} v - A vector. + * @param {RotationOrder} [order] - A rotation order. + * @return {Euler} This set of Euler angles. + */ + + Euler$1.prototype.setFromVector3 = function setFromVector3 (v, order) { + if ( order === void 0 ) order = this.order; + + + return this.set(v.x, v.y, v.z, order); + + }; + + /** + * Reorder the rotation angles. + * + * WARNING: this operation discards revolution information! + * + * @param {RotationOrder} newOrder - The new rotation order. + * @return {Euler} This set of Euler angles. + */ + + Euler$1.prototype.reorder = function reorder (newOrder) { + + q.setFromEuler(this); + + return this.setFromQuaternion(q, newOrder); + + }; + + /** + * Checks if this set of Euler angles equals the given one. + * + * @param {Euler} e - Euler angles. + * @return {Boolean} Whether this set of Euler angles equals the given one. + */ + + Euler$1.prototype.equals = function equals (e) { + + return (e.x === this.x && e.y === this.y && e.z === this.z && e.order === this.order); + + }; + + /** + * The default rotation order. + * + * @type {RotationOrder} + * @final + */ + + staticAccessors.defaultOrder.get = function () { + + return RotationOrder.XYZ; + + }; + + Object.defineProperties( Euler$1, staticAccessors ); + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var a = new Vector3$1(); + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var b = new Vector3$1(); + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var v$3 = new Vector3$1(); + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var a$1 = new Vector3$1(); + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var b$1 = new Vector3$1(); + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var a$2 = new Vector3$1(); + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var b$2 = new Vector3$1(); + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var c = new Vector3$1(); + + /** + * A list of vectors. + * + * @type {Vector3[]} + * @private + */ + + var v$4 = [ + new Vector3$1(), + new Vector3$1(), + new Vector3$1(), + new Vector3$1() + ]; + + /** + * A ray. + */ + + var Ray$1 = function Ray(origin, direction) { + if ( origin === void 0 ) origin = new Vector3$1(); + if ( direction === void 0 ) direction = new Vector3$1(0, 0, -1); + + + /** + * The origin. + * + * @type {Vector3} + */ + + this.origin = origin; + + /** + * The direction. + * + * @type {Vector3} + */ + + this.direction = direction; + + }; + + /** + * Sets the origin and the direction. + * + * @param {Vector3} origin - The origin. + * @param {Vector3} direction - The direction. Should be normalized. + * @return {Ray} This ray. + */ + + Ray$1.prototype.set = function set (origin, direction) { + + this.origin.copy(origin); + this.direction.copy(direction); + + return this; + + }; + + /** + * Copies the given ray. + * + * @param {Ray} r - A ray. + * @return {Ray} This ray. + */ + + Ray$1.prototype.copy = function copy (r) { + + this.origin.copy(r.origin); + this.direction.copy(r.direction); + + return this; + + }; + + /** + * Clones this ray. + * + * @return {Ray} The cloned ray. + */ + + Ray$1.prototype.clone = function clone () { + + return new this.constructor().copy(this); + + }; + + /** + * Computes a point along the ray based on a given scalar t. + * + * @param {Number} t - The scalar. + * @param {Vector3} [target] - A target vector. If none is provided, a new one will be created. + * @return {Vector3} The point. + */ + + Ray$1.prototype.at = function at (t, target) { + if ( target === void 0 ) target = new Vector3$1(); + + + return target.copy(this.direction).multiplyScalar(t).add(this.origin); + + }; + + /** + * Rotates this ray to look at the given target. + * + * @param {Vector3} target - A point to look at. + * @return {Ray} This ray. + */ + + Ray$1.prototype.lookAt = function lookAt (target) { + + this.direction.copy(target).sub(this.origin).normalize(); + + return this; + + }; + + /** + * Moves the origin along the ray by a given scalar t. + * + * @param {Number} t - The scalar. + * @return {Ray} This ray. + */ + + Ray$1.prototype.recast = function recast (t) { + + this.origin.copy(this.at(t, v$4[0])); + + return this; + + }; + + /** + * Finds the closest point along this ray to a given point. + * + * @param {Vector3} p - A point. + * @param {Vector3} [target] - A target vector. If none is provided, a new one will be created. + * @return {Vector3} The point. + */ + + Ray$1.prototype.closestPointToPoint = function closestPointToPoint (p, target) { + if ( target === void 0 ) target = new Vector3$1(); + + + var directionDistance = target.subVectors(p, this.origin).dot(this.direction); + + return (directionDistance >= 0.0) ? + target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin) : + target.copy(this.origin); + + }; + + /** + * Calculates the squared distance from this ray to the given point. + * + * @param {Vector3} p - The point. + * @return {Number} The squared distance. + */ + + Ray$1.prototype.distanceSquaredToPoint = function distanceSquaredToPoint (p) { + + var directionDistance = v$4[0].subVectors(p, this.origin).dot(this.direction); + + // Check if the point is behind the ray. + return (directionDistance < 0.0) ? + this.origin.distanceToSquared(p) : + v$4[0].copy(this.direction).multiplyScalar(directionDistance).add(this.origin).distanceToSquared(p); + + }; + + /** + * Calculates the distance from this ray to the given point. + * + * @param {Vector3} p - The point. + * @return {Number} The distance. + */ + + Ray$1.prototype.distanceToPoint = function distanceToPoint (p) { + + return Math.sqrt(this.distanceSquaredToPoint(p)); + + }; + + /** + * Calculates the distance from this ray to the given plane. + * + * @param {Plane} p - The plane. + * @return {Number} The distance, or null if the denominator is zero. + */ + + Ray$1.prototype.distanceToPlane = function distanceToPlane (p) { + + var denominator = p.normal.dot(this.direction); + + var t = (denominator !== 0.0) ? + -(this.origin.dot(p.normal) + p.constant) / denominator : + ((p.distanceToPoint(this.origin) === 0.0) ? 0.0 : -1.0); + + return (t >= 0.0) ? t : null; + + }; + + /** + * Calculates the distance from this ray to a given line segment. + * + * Based on: + * http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h + * + * @param {Vector3} v0 - The start of the segment. + * @param {Vector3} v1 - The end of the segment. + * @param {Vector3} [pointOnRay] - If provided, the point on this Ray that is closest to the segment will be stored in this vector. + * @param {Vector3} [pointOnSegment] - If provided, the point on the line segment that is closest to this ray will be stored in this vector. + * @return {Number} The smallest distance between the ray and the segment defined by v0 and v1. + */ + + Ray$1.prototype.distanceSquaredToSegment = function distanceSquaredToSegment (v0, v1, pointOnRay, pointOnSegment) { + + var segCenter = v$4[0].copy(v0).add(v1).multiplyScalar(0.5); + var segDir = v$4[1].copy(v1).sub(v0).normalize(); + var diff = v$4[2].copy(this.origin).sub(segCenter); + + var segExtent = v0.distanceTo(v1) * 0.5; + var a01 = -this.direction.dot(segDir); + var b0 = diff.dot(this.direction); + var b1 = -diff.dot(segDir); + var c = diff.lengthSq(); + var det = Math.abs(1.0 - a01 * a01); + + var s0, s1, extDet, invDet, sqrDist; + + if(det > 0.0) { + + // The ray and segment are not parallel. + s0 = a01 * b1 - b0; + s1 = a01 * b0 - b1; + extDet = segExtent * det; + + if(s0 >= 0.0) { + + if(s1 >= -extDet) { + + if(s1 <= extDet) { + + // Region 0. + // Minimum at interior points of ray and segment. + invDet = 1.0 / det; + s0 *= invDet; + s1 *= invDet; + sqrDist = s0 * (s0 + a01 * s1 + 2.0 * b0) + s1 * (a01 * s0 + s1 + 2.0 * b1) + c; + + } else { + + // Region 1. + s1 = segExtent; + s0 = Math.max(0.0, -(a01 * s1 + b0)); + sqrDist = -s0 * s0 + s1 * (s1 + 2.0 * b1) + c; + + } + + } else { + + // Region 5. + s1 = -segExtent; + s0 = Math.max(0.0, -(a01 * s1 + b0)); + sqrDist = -s0 * s0 + s1 * (s1 + 2.0 * b1) + c; + + } + + } else { + + if(s1 <= -extDet) { + + // Region 4. + s0 = Math.max(0.0, -(-a01 * segExtent + b0)); + s1 = (s0 > 0.0) ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent); + sqrDist = -s0 * s0 + s1 * (s1 + 2.0 * b1) + c; + + } else if(s1 <= extDet) { + + // Region 3. + s0 = 0.0; + s1 = Math.min(Math.max(-segExtent, -b1), segExtent); + sqrDist = s1 * (s1 + 2.0 * b1) + c; + + } else { + + // Region 2. + s0 = Math.max(0.0, -(a01 * segExtent + b0)); + s1 = (s0 > 0.0) ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent); + sqrDist = -s0 * s0 + s1 * (s1 + 2.0 * b1) + c; + + } + + } + + } else { + + // Ray and segment are parallel. + s1 = (a01 > 0.0) ? -segExtent : segExtent; + s0 = Math.max(0.0, -(a01 * s1 + b0)); + sqrDist = -s0 * s0 + s1 * (s1 + 2.0 * b1) + c; + + } + + if(pointOnRay !== undefined) { + + pointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin); + + } + + if(pointOnSegment !== undefined) { + + pointOnSegment.copy(segDir).multiplyScalar(s1).add(segCenter); + + } + + return sqrDist; + + }; + + /** + * Finds the point where this ray intersects the given sphere. + * + * @param {Sphere} s - A sphere. + * @param {Vector3} [target] - A target vector. If none is provided, a new one will be created. + * @return {Vector3} The point of intersection, or null if there is none. + */ + + Ray$1.prototype.intersectSphere = function intersectSphere (s, target) { + if ( target === void 0 ) target = new Vector3$1(); + + + var ab = v$4[0].subVectors(s.center, this.origin); + var tca = ab.dot(this.direction); + var d2 = ab.dot(ab) - tca * tca; + var radius2 = s.radius * s.radius; + + var result = null; + var thc, t0, t1; + + if(d2 <= radius2) { + + thc = Math.sqrt(radius2 - d2); + + // t0 = first intersection point - entrance on front of sphere. + t0 = tca - thc; + + // t1 = second intersection point - exit point on back of sphere. + t1 = tca + thc; + + // Check if both t0 and t1 are behind the ray - if so, return null. + if(t0 >= 0.0 || t1 >= 0.0) { + + /* Check if t0 is behind the ray. If it is, the ray is inside the + sphere, so return the second exit point scaled by t1 in order to always + return an intersection point that is in front of the ray. If t0 is in + front of the ray, return the first collision point scaled by t0. */ + result = (t0 < 0.0) ? this.at(t1, target) : this.at(t0, target); + + } + + } + + return result; + + }; + + /** + * Determines whether this ray intersects the given sphere. + * + * @param {Sphere} s - A sphere. + * @return {Boolean} Whether this ray intersects the given sphere. + */ + + Ray$1.prototype.intersectsSphere = function intersectsSphere (s) { + + return (this.distanceSqToPoint(s.center) <= (s.radius * s.radius)); + + }; + + /** + * Finds the point where this ray intersects the given plane. + * + * @param {Plane} p - A plane. + * @param {Vector3} [target] - A target vector. If none is provided, a new one will be created. + * @return {Vector3} The point of intersection, or null if there is none. + */ + + Ray$1.prototype.intersectPlane = function intersectPlane (p, target) { + if ( target === void 0 ) target = new Vector3$1(); + + + var t = this.distanceToPlane(p); + + return (t === null) ? null : this.at(t, target); + + }; + + /** + * Determines whether this ray intersects the given plane. + * + * @param {Plane} p - A plane. + * @return {Boolean} Whether this ray intersects the given plane. + */ + + Ray$1.prototype.intersectsPlane = function intersectsPlane (p) { + + var distanceToPoint = p.distanceToPoint(this.origin); + + return (distanceToPoint === 0.0 || p.normal.dot(this.direction) * distanceToPoint < 0.0); + + }; + + /** + * Finds the point where this ray intersects the given box. + * + * @param {Plane} b - A box. + * @param {Vector3} [target] - A target vector. If none is provided, a new one will be created. + * @return {Vector3} The point of intersection, or null if there is none. + */ + + Ray$1.prototype.intersectBox = function intersectBox (b, target) { + if ( target === void 0 ) target = new Vector3$1(); + + + var origin = this.origin; + var direction = this.direction; + var min = b.min; + var max = b.max; + + var invDirX = 1.0 / direction.x; + var invDirY = 1.0 / direction.y; + var invDirZ = 1.0 / direction.z; + + var result = null; + var tmin, tmax, tymin, tymax, tzmin, tzmax; + + if(invDirX >= 0.0) { + + tmin = (min.x - origin.x) * invDirX; + tmax = (max.x - origin.x) * invDirX; + + } else { + + tmin = (max.x - origin.x) * invDirX; + tmax = (min.x - origin.x) * invDirX; + + } + + if(invDirY >= 0.0) { + + tymin = (min.y - origin.y) * invDirY; + tymax = (max.y - origin.y) * invDirY; + + } else { + + tymin = (max.y - origin.y) * invDirY; + tymax = (min.y - origin.y) * invDirY; + + } + + if(tmin <= tymax && tymin <= tmax) { + + /* Handle the case where tmin or tmax is NaN (result of 0 * Infinity). + Note: x !== x returns true if x is NaN. */ + if(tymin > tmin || tmin !== tmin) { + + tmin = tymin; + + } + + if(tymax < tmax || tmax !== tmax) { + + tmax = tymax; + + } + + if(invDirZ >= 0.0) { + + tzmin = (min.z - origin.z) * invDirZ; + tzmax = (max.z - origin.z) * invDirZ; + + } else { + + tzmin = (max.z - origin.z) * invDirZ; + tzmax = (min.z - origin.z) * invDirZ; + + } + + if(tmin <= tzmax && tzmin <= tmax) { + + if(tzmin > tmin || tmin !== tmin) { + + tmin = tzmin; + + } + + if(tzmax < tmax || tmax !== tmax) { + + tmax = tzmax; + + } + + // Return the closest point (positive side). + if(tmax >= 0.0) { + + result = this.at((tmin >= 0.0) ? tmin : tmax, target); + + } + + } + + } + + return result; + + }; + + /** + * Determines whether this ray intersects the given box. + * + * @param {Box3} b - A box. + * @return {Boolean} Whether this ray intersects the given box. + */ + + Ray$1.prototype.intersectsBox = function intersectsBox (b) { + + return (this.intersectBox(b, v$4[0]) !== null); + + }; + + /** + * Finds the point where this ray intersects the given triangle. + * + * Based on: + * http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h + * + * @param {Vector3} a - A triangle vertex. + * @param {Vector3} b - A triangle vertex. + * @param {Vector3} c - A triangle vertex. + * @param {Boolean} [backfaceCulling=false] - Whether backface culling should be considered. + * @param {Vector3} [target] - A target vector. If none is provided, a new one will be created. + * @return {Vector3} The point of intersection, or null if there is none. + */ + + Ray$1.prototype.intersectTriangle = function intersectTriangle (a, b, c, backfaceCulling, target) { + + var direction = this.direction; + + // Compute the offset origin, edges, and normal. + var diff = v$4[0]; + var edge1 = v$4[1]; + var edge2 = v$4[2]; + var normal = v$4[3]; + + var result = null; + var DdN, sign, DdQxE2, DdE1xQ, QdN; + + edge1.subVectors(b, a); + edge2.subVectors(c, a); + normal.crossVectors(edge1, edge2); + + /* Solve Q + t * D = b1 * E1 + b2 * E2 + * (Q = kDiff, D = ray direction, E1 = kEdge1, E2 = kEdge2, + * N = Cross(E1, E2)): + * + * | Dot(D, N) | * b1 = sign(Dot(D, N)) * Dot(D, Cross(Q, E2)) + * | Dot(D, N) | * b2 = sign(Dot(D, N)) * Dot(D, Cross(E1, Q)) + * | Dot(D, N) | * t = -sign(Dot(D, N)) * Dot(Q, N) + */ + + DdN = direction.dot(normal); + + // Discard coplanar constellations and cull backfaces. + if(DdN !== 0.0 && !(backfaceCulling && DdN > 0.0)) { + + if(DdN > 0.0) { + + sign = 1.0; + + } else { + + sign = -1.0; + DdN = -DdN; + + } + + diff.subVectors(this.origin, a); + DdQxE2 = sign * direction.dot(edge2.crossVectors(diff, edge2)); + + // b1 < 0, no intersection. + if(DdQxE2 >= 0.0) { + + DdE1xQ = sign * direction.dot(edge1.cross(diff)); + + // b2 < 0, or b1 + b2 > 1, no intersection. + if(DdE1xQ >= 0.0 && DdQxE2 + DdE1xQ <= DdN) { + + // The line intersects the triangle, check if the ray does. + QdN = -sign * diff.dot(normal); + + // t < 0, no intersection. + if(QdN >= 0.0) { + + // Ray intersects triangle. + result = this.at(QdN / DdN, target); + + } + + } + + } + + } + + return result; + + }; + + /** + * Applies the given matrix to this ray. + * + * @param {Matrix4} m - A matrix. + * @return {Ray} This ray. + */ + + Ray$1.prototype.applyMatrix4 = function applyMatrix4 (m) { + + this.origin.applyMatrix4(m); + this.direction.transformDirection(m); + + return this; + + }; + + /** + * Checks if this ray equals the given one. + * + * @param {Ray} r - A ray. + * @return {Boolean} Whether the rays are equal. + */ + + Ray$1.prototype.equals = function equals (r) { + + return (r.origin.equals(this.origin) && r.direction.equals(this.direction)); + + }; + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var c$1 = new Vector3$1(); + + /** + * An octant. + * + * @implements {Node} + */ + + var Octant = function Octant(min, max) { + if ( min === void 0 ) min = new Vector3$1(); + if ( max === void 0 ) max = new Vector3$1(); + + + /** + * The lower bounds of this octant. + * + * @type {Vector3} + */ + + this.min = min; + + /** + * The upper bounds of the octant. + * + * @type {Vector3} + */ + + this.max = max; + + /** + * The children of this octant. + * + * @type {Octant[]} + */ + + this.children = null; + + }; + + /** + * Computes the center of this octant. + * + * @param {Vector3} target - A target vector. + * @return {Vector3} The center. + */ + + Octant.prototype.getCenter = function getCenter (target) { + + return target.addVectors(this.min, this.max).multiplyScalar(0.5); + + }; + + /** + * Computes the size of this octant. + * + * @param {Vector3} target - A target vector. + * @return {Vector3} The size. + */ + + Octant.prototype.getDimensions = function getDimensions (target) { + + return target.subVectors(this.max, this.min); + + }; + + /** + * Splits this octant into eight smaller ones. + */ + + Octant.prototype.split = function split () { + + var min = this.min; + var max = this.max; + var mid = this.getCenter(c$1); + + var children = this.children = [ + null, null, null, null, + null, null, null, null + ]; + + var i, combination; + + for(i = 0; i < 8; ++i) { + + combination = layout$1[i]; + + children[i] = new this.constructor( + + new Vector3$1( + (combination[0] === 0) ? min.x : mid.x, + (combination[1] === 0) ? min.y : mid.y, + (combination[2] === 0) ? min.z : mid.z + ), + + new Vector3$1( + (combination[0] === 0) ? mid.x : max.x, + (combination[1] === 0) ? mid.y : max.y, + (combination[2] === 0) ? mid.z : max.z + ) + + ); + + } + + }; + + /** + * A collection of ray-point intersection data. + */ + + var RayPointIntersection = function RayPointIntersection(distance, distanceToRay, point, object) { + if ( object === void 0 ) object = null; + + + /** + * The distance from the origin of the ray to the point. + * + * @type {Number} + */ + + this.distance = distance; + + /** + * The shortest distance from the point to the ray. + * + * @type {Number} + */ + + this.distanceToRay = distanceToRay; + + /** + * The point. + * + * @type {Vector3} + */ + + this.point = point; + + /** + * The point's data. + * + * @type {Object} + */ + + this.object = object; + + }; + + /** + * Collects points that intersect with the given ray. + * + * @param {PointOctant[]} octants - An array containing octants that intersect with the ray. + * @param {Raycaster} raycaster - The raycaster. + * @param {RayPointIntersection[]} intersects - An array to be filled with intersecting points. + */ + + function testPoints(octants, raycaster, intersects) { + + var threshold = raycaster.params.Points.threshold; + var thresholdSq = threshold * threshold; + + var intersectPoint; + var distance, distanceToRay; + var rayPointDistanceSq; + + var i, j, il, jl; + var octant, points, point; + + for(i = 0, il = octants.length; i < il; ++i) { + + octant = octants[i]; + points = octant.points; + + if(points !== null) { + + for(j = 0, jl = points.length; j < jl; ++j) { + + point = points[j]; + rayPointDistanceSq = raycaster.ray.distanceSqToPoint(point); + + if(rayPointDistanceSq < thresholdSq) { + + intersectPoint = raycaster.ray.closestPointToPoint(point, new Vector3$1()); + distance = raycaster.ray.origin.distanceTo(intersectPoint); + + if(distance >= raycaster.near && distance <= raycaster.far) { + + distanceToRay = Math.sqrt(rayPointDistanceSq); + + intersects.push(new RayPointIntersection( + distance, + distanceToRay, + intersectPoint, + octant.data[j] + )); + + } + + } + + } + + } + + } + + } + + /** + * A container for raycasting flags. + */ + + var Flags = function Flags() { + + /** + * The current flags. + * + * @type {Number} + */ + + this.value = 0; + + }; + + /** + * Finds the entry plane of the first octant that a ray travels through. + * + * Determining the first octant requires knowing which of the t0s is the + * largest. The tms of the other axes must also be compared against that + * largest t0. + * + * @param {Number} tx0 - Ray projection parameter. + * @param {Number} ty0 - Ray projection parameter. + * @param {Number} tz0 - Ray projection parameter. + * @param {Number} txm - Ray projection parameter mean. + * @param {Number} tym - Ray projection parameter mean. + * @param {Number} tzm - Ray projection parameter mean. + * @return {Number} The index of the first octant that the ray travels through. + */ + + function findEntryOctant(tx0, ty0, tz0, txm, tym, tzm) { + + var entry = 0; + + // Find the entry plane. + if(tx0 > ty0 && tx0 > tz0) { + + // YZ-plane. + if(tym < tx0) { + + entry |= 2; + + } + + if(tzm < tx0) { + + entry |= 1; + + } + + } else if(ty0 > tz0) { + + // XZ-plane. + if(txm < ty0) { + + entry |= 4; + + } + + if(tzm < ty0) { + + entry |= 1; + + } + + } else { + + // XY-plane. + if(txm < tz0) { + + entry |= 4; + + } + + if(tym < tz0) { + + entry |= 2; + + } + + } + + return entry; + + } + + /** + * A lookup-table containing octant ids. Used to determine the exit plane from + * an octant. + * + * @type {Uint8Array[]} + * @private + */ + + var octantTable = [ + + new Uint8Array([4, 2, 1]), + new Uint8Array([5, 3, 8]), + new Uint8Array([6, 8, 3]), + new Uint8Array([7, 8, 8]), + new Uint8Array([8, 6, 5]), + new Uint8Array([8, 7, 8]), + new Uint8Array([8, 8, 7]), + new Uint8Array([8, 8, 8]) + + ]; + + /** + * Finds the next octant that intersects with the ray based on the exit plane of + * the current one. + * + * @param {Number} currentOctant - The index of the current octant. + * @param {Number} tx1 - Ray projection parameter. + * @param {Number} ty1 - Ray projection parameter. + * @param {Number} tz1 - Ray projection parameter. + * @return {Number} The index of the next octant that the ray travels through. + */ + + function findNextOctant(currentOctant, tx1, ty1, tz1) { + + var min; + var exit = 0; + + // Find the exit plane. + if(tx1 < ty1) { + + min = tx1; + exit = 0; // YZ-plane. + + } else { + + min = ty1; + exit = 1; // XZ-plane. + + } + + if(tz1 < min) { + + exit = 2; // XY-plane. + + } + + return octantTable[currentOctant][exit]; + + } + + /** + * A vector. + * + * @type {Vector3} + * @private + */ + + var v$5 = new Vector3$1(); + + /** + * A box. + * + * @type {Box3} + * @private + */ + + var b$3 = new Box3$1(); + + /** + * A box. + * + * @type {Box3} + * @private + */ + + var d = new Box3$1(); + + /** + * A ray. + * + * @type {Ray} + * @private + */ + + var r = new Ray$1(); + + /** + * Calculates ray projection parameters for the given octree and ray setup. + * + * @param {Octree} octree - The octree. + * @param {Ray} ray - A ray. + * @param {Flags} flags - Raycasting flags. + * @return {Number[]} The ray parameters tx0, ty0, tz0, tx1, ty1 and tz1, in that order, or null if the ray doesn't hit the octree. + */ + + function intersectOctree(octree, ray, flags) { + + // Translate the octant extents to the scene origin. + var min = b$3.min.set(0, 0, 0); + var max = b$3.max.subVectors(octree.max, octree.min); + + var dimensions = octree.getDimensions(d.min); + var halfDimensions = d.max.copy(dimensions).multiplyScalar(0.5); + + var origin = r.origin.copy(ray.origin); + var direction = r.direction.copy(ray.direction); + + var invDirX, invDirY, invDirZ; + var tx0, tx1, ty0, ty1, tz0, tz1; + + // Translate the ray to the center of the octant. + origin.sub(octree.getCenter(v$5)).add(halfDimensions); + + // Reset all flags. + flags.value = 0; + + // Handle rays with negative directions. + if(direction.x < 0.0) { + + origin.x = dimensions.x - origin.x; + direction.x = -direction.x; + flags.value |= 4; + + } + + if(direction.y < 0.0) { + + origin.y = dimensions.y - origin.y; + direction.y = -direction.y; + flags.value |= 2; + + } + + if(direction.z < 0.0) { + + origin.z = dimensions.z - origin.z; + direction.z = -direction.z; + flags.value |= 1; + + } + + // Improve IEEE double stability. + invDirX = 1.0 / direction.x; + invDirY = 1.0 / direction.y; + invDirZ = 1.0 / direction.z; + + // Project the ray to the octant's boundaries. + tx0 = (min.x - origin.x) * invDirX; + tx1 = (max.x - origin.x) * invDirX; + ty0 = (min.y - origin.y) * invDirY; + ty1 = (max.y - origin.y) * invDirY; + tz0 = (min.z - origin.z) * invDirZ; + tz1 = (max.z - origin.z) * invDirZ; + + // Check if the ray hits the octree. + return (Math.max(Math.max(tx0, ty0), tz0) < Math.min(Math.min(tx1, ty1), tz1)) ? + [tx0, ty0, tz0, tx1, ty1, tz1] : null; + + } + + /** + * Raycasting flags. + * + * @type {Flags} + */ + + var flags = new Flags(); + + /** + * Finds all octants that intersect with the given ray. + * + * @private + * @param {Octant} octant - The current octant. + * @param {Number} tx0 - A ray projection parameter. + * @param {Number} ty0 - A ray projection parameter. + * @param {Number} tz0 - A ray projection parameter. + * @param {Number} tx1 - A ray projection parameter. + * @param {Number} ty1 - A ray projection parameter. + * @param {Number} tz1 - A ray projection parameter. + * @param {Array} intersects - An array to be filled with the intersecting octants. + */ + + function raycastOctant(octant, tx0, ty0, tz0, tx1, ty1, tz1, intersects) { + + if(tx1 >= 0.0 && ty1 >= 0.0 && tz1 >= 0.0) { + + var children = octant.children; + + if(children === null) { + + // Leaf. + intersects.push(octant); + + } else { + + // Compute means. + var txm = 0.5 * (tx0 + tx1); + var tym = 0.5 * (ty0 + ty1); + var tzm = 0.5 * (tz0 + tz1); + + var f = flags.value; + var currentOctant = findEntryOctant(tx0, ty0, tz0, txm, tym, tzm); + + /* The possibilities for the next node are passed in the same respective + order as the t-values. Hence, if the first value is found to be the + greatest, the fourth one will be returned. If the second value is the + greatest, the fifth one will be returned, etc. */ + + do { + + switch(currentOctant) { + + case 0: + raycastOctant(children[f], tx0, ty0, tz0, txm, tym, tzm, intersects); + currentOctant = findNextOctant(currentOctant, txm, tym, tzm); + break; + + case 1: + raycastOctant(children[f ^ 1], tx0, ty0, tzm, txm, tym, tz1, intersects); + currentOctant = findNextOctant(currentOctant, txm, tym, tz1); + break; + + case 2: + raycastOctant(children[f ^ 2], tx0, tym, tz0, txm, ty1, tzm, intersects); + currentOctant = findNextOctant(currentOctant, txm, ty1, tzm); + break; + + case 3: + raycastOctant(children[f ^ 3], tx0, tym, tzm, txm, ty1, tz1, intersects); + currentOctant = findNextOctant(currentOctant, txm, ty1, tz1); + break; + + case 4: + raycastOctant(children[f ^ 4], txm, ty0, tz0, tx1, tym, tzm, intersects); + currentOctant = findNextOctant(currentOctant, tx1, tym, tzm); + break; + + case 5: + raycastOctant(children[f ^ 5], txm, ty0, tzm, tx1, tym, tz1, intersects); + currentOctant = findNextOctant(currentOctant, tx1, tym, tz1); + break; + + case 6: + raycastOctant(children[f ^ 6], txm, tym, tz0, tx1, ty1, tzm, intersects); + currentOctant = findNextOctant(currentOctant, tx1, ty1, tzm); + break; + + case 7: + raycastOctant(children[f ^ 7], txm, tym, tzm, tx1, ty1, tz1, intersects); + // Far top right octant. No other octants can be reached from here. + currentOctant = 8; + break; + + } + + } while(currentOctant < 8); + + } + + } + + } + + /** + * A raycaster for pointer-based octrees. + * + * Reference: + * "An Efficient Parametric Algorithm for Octree Traversal" + * by J. Revelles et al. (2000) + */ + + var OctreeRaycaster = function OctreeRaycaster () {}; + + OctreeRaycaster.intersectOctree = function intersectOctree$1 (octree, ray, intersects) { + if ( intersects === void 0 ) intersects = []; + + + var parameters = intersectOctree(octree, ray, flags); + + if(parameters !== null) { + + raycastOctant.apply(void 0, [ octree.root ].concat( parameters, [intersects] )); + + } + + }; + + /** + * iterator-result v1.0.0 build Fri Dec 27 2019 + * https://github.com/vanruesc/iterator-result + * Copyright 2019 Raoul van Rüschen, Zlib + */ + /** + * A basic iterator result. + */ + + var IteratorResult = function IteratorResult(value, done) { + if ( value === void 0 ) value = null; + if ( done === void 0 ) done = false; + + + /** + * The value returned by the iterator. + * + * @type {Object} + */ + + this.value = value; + + /** + * Whether this result is past the end of the iterated sequence. + * + * @type {Boolean} + */ + + this.done = done; + + }; + + /** + * Resets this iterator result. + */ + + IteratorResult.prototype.reset = function reset () { + + this.value = null; + this.done = false; + + }; + + /** + * A 3D box. + * + * @type {Box3} + * @private + */ + + var b$4 = new Box3$1(); + + /** + * An octree iterator. + * + * @implements {Iterator} + * @implements {Iterable} + */ + + var OctreeIterator = function OctreeIterator(octree, region) { + if ( region === void 0 ) region = null; + + + /** + * The octree. + * + * @type {Octree} + * @private + */ + + this.octree = octree; + + /** + * A region used for octree culling. + * + * @type {Frustum|Box3} + */ + + this.region = region; + + /** + * Whether this iterator should respect the cull region. + * + * @type {Boolean} + */ + + this.cull = (region !== null); + + /** + * An iterator result. + * + * @type {IteratorResult} + * @private + */ + + this.result = new IteratorResult(); + + /** + * An octant trace. + * + * @type {Octant[]} + * @private + */ + + this.trace = null; + + /** + * Iteration indices. + * + * @type {Number[]} + * @private + */ + + this.indices = null; + + this.reset(); + + }; + + /** + * Resets this iterator. + * + * @return {OctreeIterator} This iterator. + */ + + OctreeIterator.prototype.reset = function reset () { + + var root = this.octree.root; + + this.trace = []; + this.indices = []; + + if(root !== null) { + + b$4.min = root.min; + b$4.max = root.max; + + if(!this.cull || this.region.intersectsBox(b$4)) { + + this.trace.push(root); + this.indices.push(0); + + } + + } + + this.result.reset(); + + return this; + + }; + + /** + * Iterates over the leaf octants. + * + * @return {IteratorResult} The next leaf octant. + */ + + OctreeIterator.prototype.next = function next () { + + var cull = this.cull; + var region = this.region; + var indices = this.indices; + var trace = this.trace; + + var octant = null; + var depth = trace.length - 1; + + var index, children, child; + + while(octant === null && depth >= 0) { + + index = indices[depth]++; + children = trace[depth].children; + + if(index < 8) { + + if(children !== null) { + + child = children[index]; + + if(cull) { + + b$4.min = child.min; + b$4.max = child.max; + + if(!region.intersectsBox(b$4)) { + + // Cull this octant. + continue; + + } + + } + + trace.push(child); + indices.push(0); + + ++depth; + + } else { + + octant = trace.pop(); + indices.pop(); + + } + + } else { + + trace.pop(); + indices.pop(); + + --depth; + + } + + } + + this.result.value = octant; + this.result.done = (octant === null); + + return this.result; + + }; + + /** + * Called when this iterator will no longer be run to completion. + * + * @param {Object} value - An interator result value. + * @return {IteratorResult} - A premature completion result. + */ + + OctreeIterator.prototype.return = function return$1 (value) { + + this.result.value = value; + this.result.done = true; + + return this.result; + + }; + + /** + * Returns this iterator. + * + * @return {Iterator} An iterator. + */ + + OctreeIterator.prototype[Symbol.iterator] = function () { + + return this; + + }; + + /** + * A 3D box. + * + * @type {Box3} + * @private + */ + + var b$5 = new Box3$1(); + + /** + * Recursively calculates the depth of the given octree. + * + * @private + * @param {Node} octant - An octant. + * @return {Number} The depth. + */ + + function getDepth(octant) { + + var children = octant.children; + + var result = 0; + var i, l, d; + + if(children !== null) { + + for(i = 0, l = children.length; i < l; ++i) { + + d = 1 + getDepth(children[i]); + + if(d > result) { + + result = d; + + } + + } + + } + + return result; + + } + + /** + * Recursively collects octants that lie inside the specified region. + * + * @private + * @param {Node} octant - An octant. + * @param {Frustum|Box3} region - A region. + * @param {Node[]} result - A list to be filled with octants that intersect with the region. + */ + + function cull(octant, region, result) { + + var children = octant.children; + + var i, l; + + b$5.min = octant.min; + b$5.max = octant.max; + + if(region.intersectsBox(b$5)) { + + if(children !== null) { + + for(i = 0, l = children.length; i < l; ++i) { + + cull(children[i], region, result); + + } + + } else { + + result.push(octant); + + } + + } + + } + + /** + * Recursively fetches all octants with the specified depth level. + * + * @private + * @param {Node} octant - An octant. + * @param {Number} level - The target depth level. + * @param {Number} depth - The current depth level. + * @param {Node[]} result - A list to be filled with the identified octants. + */ + + function findNodesByLevel(octant, level, depth, result) { + + var children = octant.children; + + var i, l; + + if(depth === level) { + + result.push(octant); + + } else if(children !== null) { + + ++depth; + + for(i = 0, l = children.length; i < l; ++i) { + + findNodesByLevel(children[i], level, depth, result); + + } + + } + + } + + /** + * A pointer-based octree that subdivides space for fast spatial searches. + * + * @implements {Iterable} + * @implements {Node} + * @implements {Tree} + */ + + var Octree = function Octree(root) { + + /** + * The root octant. + * + * @type {Node} + * @protected + */ + + this.root = root; + + }; + + var prototypeAccessors$2 = { min: { configurable: true },max: { configurable: true },children: { configurable: true } }; + + /** + * The lower bounds of the root octant. + * + * @type {Vector3} + */ + + prototypeAccessors$2.min.get = function () { + + return this.root.min; + + }; + + /** + * The upper bounds of the root octant. + * + * @type {Vector3} + */ + + prototypeAccessors$2.max.get = function () { + + return this.root.max; + + }; + + /** + * The children of the root node. + * + * @type {Node[]} + */ + + prototypeAccessors$2.children.get = function () { + + return this.root.children; + + }; + + /** + * Calculates the center of this octree. + * + * @param {Vector3} target - A target vector. + * @return {Vector3} A vector that describes the center of this octree. + */ + + Octree.prototype.getCenter = function getCenter (target) { + + return this.root.getCenter(target); + + }; + + /** + * Calculates the size of this octree. + * + * @param {Vector3} target - A target vector. + * @return {Vector3} A vector that describes the size of this octree. + */ + + Octree.prototype.getDimensions = function getDimensions (target) { + + return this.root.getDimensions(target); + + }; + + /** + * Recursively collects nodes that intersect with the specified region. + * + * @param {Frustum|Box3} region - A region. + * @return {Node[]} The nodes. + */ + + Octree.prototype.cull = function cull$1 (region) { + + var result = []; + + cull(this.root, region, result); + + return result; + + }; + + /** + * Calculates the current depth of this octree. + * + * @return {Number} The depth. + */ + + Octree.prototype.getDepth = function getDepth$1 () { + + return getDepth(this.root); + + }; + + /** + * Fetches all nodes of a specific depth level. + * + * @param {Number} level - The depth level. + * @return {Node[]} The nodes. + */ + + Octree.prototype.findNodesByLevel = function findNodesByLevel$1 (level) { + + var result = []; + + findNodesByLevel(this.root, level, 0, result); + + return result; + + }; + + /** + * Finds the nodes that intersect with the given ray. The intersecting + * nodes are sorted by distance, closest first. + * + * @param {Raycaster} raycaster - A raycaster. + * @param {Node[]} [intersects] - An optional target list to be filled with the intersecting nodes. + * @return {Node[]} The intersecting nodes. + */ + + Octree.prototype.raycast = function raycast (raycaster, intersects) { + if ( intersects === void 0 ) intersects = []; + + + OctreeRaycaster.intersectOctree(this, raycaster.ray, intersects); + + return intersects; + + }; + + /** + * Returns an iterator that traverses the octree and returns leaf nodes. + * + * When a cull region is provided, the iterator will only return leaves that + * intersect with that region. + * + * @param {Frustum|Box3} [region] - A cull region. + * @return {Iterator} An iterator. + */ + + Octree.prototype.leaves = function leaves (region) { + + return new OctreeIterator(this, region); + + }; + + /** + * Returns an iterator that traverses the octree and returns all leaf nodes. + * + * @return {Iterator} An iterator. + */ + + Octree.prototype[Symbol.iterator] = function () { + + return new OctreeIterator(this); + + }; + + Object.defineProperties( Octree.prototype, prototypeAccessors$2 ); + + /** + * A point. + * + * @type {Vector3} + * @private + */ + + var p = new Vector3$1(); + + /** + * An octant that maintains points. + */ + + var PointOctant = /*@__PURE__*/(function (Octant) { + function PointOctant(min, max) { + + Octant.call(this, min, max); + + /** + * The points. + * + * @type {Vector3[]} + */ + + this.points = null; + + /** + * Point data. + * + * @type {Array} + */ + + this.data = null; + + } + + if ( Octant ) PointOctant.__proto__ = Octant; + PointOctant.prototype = Object.create( Octant && Octant.prototype ); + PointOctant.prototype.constructor = PointOctant; + + /** + * Calculates the distance squared from this octant to the given point. + * + * @param {Vector3} point - A point. + * @return {Number} The distance squared. + */ + + PointOctant.prototype.distanceToSquared = function distanceToSquared (point) { + + var clampedPoint = p.copy(point).clamp(this.min, this.max); + + return clampedPoint.sub(point).lengthSquared(); + + }; + + /** + * Calculates the distance squared from the center of this octant to the given + * point. + * + * @param {Vector3} point - A point. + * @return {Number} The distance squared. + */ + + PointOctant.prototype.distanceToCenterSquared = function distanceToCenterSquared (point) { + + var center = this.getCenter(p); + + var dx = point.x - center.x; + var dy = point.y - center.x; + var dz = point.z - center.z; + + return dx * dx + dy * dy + dz * dz; + + }; + + /** + * Checks if the given point lies inside this octant's boundaries. + * + * This method can also be used to check if this octant intersects a sphere by + * providing a radius as bias. + * + * @param {Vector3} point - A point. + * @param {Number} bias - A padding that extends the boundaries temporarily. + * @return {Boolean} Whether the given point lies inside this octant. + */ + + PointOctant.prototype.contains = function contains (point, bias) { + + var min = this.min; + var max = this.max; + + return ( + point.x >= min.x - bias && + point.y >= min.y - bias && + point.z >= min.z - bias && + point.x <= max.x + bias && + point.y <= max.y + bias && + point.z <= max.z + bias + ); + + }; + + /** + * Redistributes the points of this octant to its children. + * + * Has no effect if there are no points or if this octant has no children. + * + * @param {Number} bias - A proximity threshold. + */ + + PointOctant.prototype.redistribute = function redistribute (bias) { + + var children = this.children; + var points = this.points; + var data = this.data; + + var i, j, il, jl; + var child, point, entry; + + if(children !== null && points !== null) { + + for(i = 0, il = points.length; i < il; ++i) { + + point = points[i]; + entry = data[i]; + + for(j = 0, jl = children.length; j < jl; ++j) { + + child = children[j]; + + if(child.contains(point, bias)) { + + if(child.points === null) { + + child.points = []; + child.data = []; + + } + + child.points.push(point); + child.data.push(entry); + + break; + + } + + } + + } + + this.points = null; + this.data = null; + + } + + }; + + /** + * Deletes all child nodes and collects their points. + */ + + PointOctant.prototype.merge = function merge () { + + var children = this.children; + + if(children !== null) { + + var points = []; + var data = []; + + var i, l, child; + + for(i = 0, l = children.length; i < l; ++i) { + + child = children[i]; + + if(child.points !== null) { + + points = points.concat(child.points); + data = data.concat(child.data); + + } + + } + + /** @ignore */ + this.children = null; + this.points = points; + this.data = data; + + } + + }; + + return PointOctant; + }(Octant)); + + /** + * Recursively counts how many points are in the given octant. + * + * @private + * @param {Octant} octant - An octant. + * @return {Number} The amount of points. + */ + + function countPoints(octant) { + + var children = octant.children; + + var result = 0; + var i, l; + + if(children !== null) { + + for(i = 0, l = children.length; i < l; ++i) { + + result += countPoints(children[i]); + + } + + } else if(octant.points !== null) { + + result = octant.points.length; + + } + + return result; + + } + + /** + * Recursively inserts a point into the octree. + * + * @private + * @param {Vector3} point - A point. + * @param {Object} data - An object that the point represents. + * @param {Octree} octree - The octree. + * @param {Octant} octant - The current octant. + * @param {Number} depth - The current depth. + * @return {Boolean} Whether the operation was successful. + */ + + function insert(point, data, octree, octant, depth) { + + var children = octant.children; + var exists = false; + var done = false; + var i, l; + + if(octant.contains(point, octree.bias)) { + + if(children === null) { + + if(octant.points === null) { + + octant.points = []; + octant.data = []; + + } else { + + for(i = 0, l = octant.points.length; !exists && i < l; ++i) { + + exists = octant.points[i].equals(point); + + } + + } + + if(exists) { + + octant.data[i - 1] = data; + done = true; + + } else if(octant.points.length < octree.maxPoints || depth === octree.maxDepth) { + + octant.points.push(point.clone()); + octant.data.push(data); + ++octree.pointCount; + done = true; + + } else { + + octant.split(); + octant.redistribute(octree.bias); + children = octant.children; + + } + + } + + if(children !== null) { + + ++depth; + + for(i = 0, l = children.length; !done && i < l; ++i) { + + done = insert(point, data, octree, children[i], depth); + + } + + } + + } + + return done; + + } + + /** + * Recursively finds a point in the octree and removes it. + * + * @private + * @param {Vector3} point - A point. + * @param {Octree} octree - The octree. + * @param {Octant} octant - The current octant. + * @param {Octant} parent - The parent of the current octant. + * @return {Object} The data entry of the removed point or null if it didn't exist. + */ + + function remove(point, octree, octant, parent) { + + var children = octant.children; + + var result = null; + + var i, l; + var points, data, last; + + if(octant.contains(point, octree.bias)) { + + if(children !== null) { + + for(i = 0, l = children.length; result === null && i < l; ++i) { + + result = remove(point, octree, children[i], octant); + + } + + } else if(octant.points !== null) { + + points = octant.points; + data = octant.data; + + for(i = 0, l = points.length; i < l; ++i) { + + if(points[i].equals(point)) { + + last = l - 1; + result = data[i]; + + // If the point is NOT the last one in the array: + if(i < last) { + + // Overwrite with the last point and data entry. + points[i] = points[last]; + data[i] = data[last]; + + } + + // Drop the last entry. + points.pop(); + data.pop(); + + --octree.pointCount; + + if(parent !== null && countPoints(parent) <= octree.maxPoints) { + + parent.merge(); + + } + + break; + + } + + } + + } + + } + + return result; + + } + + /** + * Recursively finds a point in the octree and fetches the associated data. + * + * @private + * @param {Vector3} point - A point. + * @param {Octree} octree - The octree. + * @param {Octant} octant - The current octant octant. + * @return {Object} The data entry that is associated with the given point or null if it doesn't exist. + */ + + function get$1(point, octree, octant) { + + var children = octant.children; + + var result = null; + + var i, l; + var points; + + if(octant.contains(point, octree.bias)) { + + if(children !== null) { + + for(i = 0, l = children.length; result === null && i < l; ++i) { + + result = get$1(point, octree, children[i]); + + } + + } else if(octant.points !== null) { + + points = octant.points; + + for(i = 0, l = points.length; result === null && i < l; ++i) { + + if(point.equals(points[i])) { + + result = octant.data[i]; + + } + + } + + } + + } + + return result; + + } + + /** + * Recursively moves an existing point to a new position. + * + * @private + * @param {Vector3} point - The point. + * @param {Vector3} position - The new position. + * @param {Octree} octree - The octree. + * @param {Octant} octant - The current octant. + * @param {Octant} parent - The parent of the current octant. + * @param {Number} depth - The current depth. + * @return {Object} The data entry of the updated point or null if it didn't exist. + */ + + function move(point, position, octree, octant, parent, depth) { + + var children = octant.children; + + var result = null; + + var i, l; + var points; + + if(octant.contains(point, octree.bias)) { + + if(octant.contains(position, octree.bias)) { + + // The point and the new position both fall into the current octant. + if(children !== null) { + + ++depth; + + for(i = 0, l = children.length; result === null && i < l; ++i) { + + result = move(point, position, octree, children[i], octant, depth); + + } + + } else if(octant.points !== null) { + + // No divergence - the point can be updated in place. + points = octant.points; + + for(i = 0, l = points.length; i < l; ++i) { + + if(point.equals(points[i])) { + + // The point exists! Update its position. + points[i].copy(position); + result = octant.data[i]; + + break; + + } + + } + + } + + } else { + + // Retrieve the point and remove it. + result = remove(point, octree, octant, parent); + + // Go back to the parent octant and add the updated point. + insert(position, result, octree, parent, depth - 1); + + } + + } + + return result; + + } + + /** + * Recursively finds the closest point to the given one. + * + * @private + * @param {Vector3} point - The point. + * @param {Number} maxDistance - The maximum distance. + * @param {Boolean} skipSelf - Whether a point that is exactly at the given position should be skipped. + * @param {Octant} octant - The current octant. + * @return {Object} An object representing the nearest point or null if there is none. + * @property {Vector3} point - The nearest point. + * @property {Object} data - The data that belongs to the point. + * @property {Number} distance - The distance to the given point. + */ + + function findNearestPoint(point, maxDistance, skipSelf, octant) { + + var result = null; + var bestDistance = maxDistance; + var i, l; + + if(octant.children !== null) { + + // Sort the children: smallest distance to the point first, ASC. + var sortedChildren = octant.children.map(function (child) { + + // Precompute distances. + return { + octant: child, + distance: child.distanceToCenterSquared(point) + }; + + }).sort(function (a, b) { return a.distance - b.distance; }); + + var child, intermediateResult; + + // Traverse from closest to furthest. + for(i = 0, l = sortedChildren.length; i < l; ++i) { + + child = sortedChildren[i].octant; + + if(child.contains(point, bestDistance)) { + + intermediateResult = findNearestPoint(point, bestDistance, skipSelf, child); + + if(intermediateResult !== null) { + + bestDistance = intermediateResult.distance; + result = intermediateResult; + + if(bestDistance === 0.0) { + + break; + + } + + } + + } + + } + + } else if(octant.points !== null) { + + var points = octant.points; + + var index = -1; + var distance; + + for(i = 0, l = points.length; i < l; ++i) { + + if(points[i].equals(point)) { + + if(!skipSelf) { + + bestDistance = 0.0; + index = i; + break; + + } + + } else { + + distance = point.distanceTo(points[i]); + + if(distance < bestDistance) { + + bestDistance = distance; + index = i; + + } + + } + + } + + if(index >= 0) { + + result = { + point: points[index], + data: octant.data[index], + distance: bestDistance + }; + + } + + } + + return result; + + } + + /** + * Recursively finds points that are inside the specified radius around a given + * position. + * + * @private + * @param {Vector3} point - A position. + * @param {Number} radius - A radius. + * @param {Boolean} skipSelf - Whether a point that is exactly at the given position should be skipped. + * @param {Octant} octant - The current octant. + * @param {Array} result - An array to be filled with objects. + * @property {Vector3} point - A point. + * @property {Object} data - The data that belongs to the point. + */ + + function findPoints(point, radius, skipSelf, octant, result) { + + var children = octant.children; + + var i, l; + + if(children !== null) { + + var child; + + for(i = 0, l = children.length; i < l; ++i) { + + child = children[i]; + + if(child.contains(point, radius)) { + + findPoints(point, radius, skipSelf, child, result); + + } + + } + + } else if(octant.points !== null) { + + var points = octant.points; + var rSq = radius * radius; + + var p; + + for(i = 0, l = points.length; i < l; ++i) { + + p = points[i]; + + if(p.equals(point)) { + + if(!skipSelf) { + + result.push({ + point: p.clone(), + data: octant.data[i] + }); + + } + + } else if(p.distanceToSquared(point) <= rSq) { + + result.push({ + point: p.clone(), + data: octant.data[i] + }); + + } + + } + + } + + } + + /** + * An octree that manages points. + */ + + var PointOctree = /*@__PURE__*/(function (Octree) { + function PointOctree(min, max, bias, maxPoints, maxDepth) { + if ( bias === void 0 ) bias = 0.0; + if ( maxPoints === void 0 ) maxPoints = 8; + if ( maxDepth === void 0 ) maxDepth = 8; + + + Octree.call(this, new PointOctant(min, max)); + + /** + * An octant boundary bias. + * + * @type {Number} + * @private + */ + + this.bias = Math.max(0.0, bias); + + /** + * The number of points per octant before a split occurs. + * + * This value works together with the maximum depth as a secondary limiting + * factor. Smaller values cause splits to occur earlier which results in a + * faster and deeper tree growth. + * + * @type {Number} + * @private + */ + + this.maxPoints = Math.max(1, Math.round(maxPoints)); + + /** + * The maximum tree depth level. + * + * It's possible to use Infinity, but keep in mind that allowing infinitely + * small octants can have a severely negative impact on performance. + * Finding a value that works best for a specific scene is advisable. + * + * @type {Number} + * @private + */ + + this.maxDepth = Math.max(0, Math.round(maxDepth)); + + /** + * The amount of points that are currently in this octree. + * + * @type {Number} + */ + + this.pointCount = 0; + + } + + if ( Octree ) PointOctree.__proto__ = Octree; + PointOctree.prototype = Object.create( Octree && Octree.prototype ); + PointOctree.prototype.constructor = PointOctree; + + /** + * Counts how many points are in the given octant. + * + * @param {Octant} octant - An octant. + * @return {Number} The amount of points. + */ + + PointOctree.prototype.countPoints = function countPoints$1 (octant) { + + return countPoints(octant); + + }; + + /** + * Puts a point into the octree. + * + * @param {Vector3} point - A point. If it's already in the octree, the data entry will be updated. + * @param {Object} data - A data object that belongs to the point. + * @return {Boolean} Whether the operation was successful. + */ + + PointOctree.prototype.insert = function insert$1 (point, data) { + + return insert(point, data, this, this.root, 0); + + }; + + /** + * Removes a point from the tree. + * + * @param {Vector3} point - A point. + * @return {Object} The data entry of the removed point or null if it didn't exist. + */ + + PointOctree.prototype.remove = function remove$1 (point) { + + return remove(point, this, this.root, null); + + }; + + /** + * Retrieves the data of the specified point. + * + * @param {Vector3} point - A position. + * @return {Object} The data entry that is associated with the given point or null if it doesn't exist. + */ + + PointOctree.prototype.get = function get$1$1 (point) { + + return get$1(point, this, this.root); + + }; + + /** + * Moves an existing point to a new position. Has no effect if the point + * doesn't exist. + * + * @param {Vector3} point - The point. + * @param {Vector3} position - The new position. + * @return {Object} The data entry of the updated point or null if it didn't exist. + */ + + PointOctree.prototype.move = function move$1 (point, position) { + + return move(point, position, this, this.root, null, 0); + + }; + + /** + * Finds the closest point to the given one. + * + * @param {Vector3} point - A point. + * @param {Number} [maxDistance=Infinity] - An upper limit for the distance between the points. + * @param {Boolean} [skipSelf=false] - Whether a point that is exactly at the given position should be skipped. + * @return {Object} An object representing the nearest point or null if there is none. + * @property {Vector3} point - The nearest point. + * @property {Object} data - The data that belongs to the point. + * @property {Number} distance - The distance to the given point. + */ + + PointOctree.prototype.findNearestPoint = function findNearestPoint$1 (point, maxDistance, skipSelf) { + if ( maxDistance === void 0 ) maxDistance = Infinity; + if ( skipSelf === void 0 ) skipSelf = false; + + + var result = findNearestPoint(point, maxDistance, skipSelf, this.root); + + if(result !== null) { + + result.point = result.point.clone(); + + } + + return result; + + }; + + /** + * Finds points that are in the specified radius around the given position. + * + * @param {Vector3} point - A position. + * @param {Number} radius - A radius. + * @param {Boolean} [skipSelf=false] - Whether a point that is exactly at the given position should be skipped. + * @return {Array} An array of objects. + * @property {Vector3} point - A point. + * @property {Object} data - The data that belongs to the point. + */ + + PointOctree.prototype.findPoints = function findPoints$1 (point, radius, skipSelf) { + if ( skipSelf === void 0 ) skipSelf = false; + + + var result = []; + + findPoints(point, radius, skipSelf, this.root, result); + + return result; + + }; + + /** + * Finds the points that intersect with the given ray. + * + * @param {Raycaster} raycaster - The raycaster. + * @param {Array} [intersects] - An array to be filled with the intersecting points. + * @return {RayPointIntersection[]} The intersecting points. + */ + + PointOctree.prototype.raycast = function raycast (raycaster, intersects) { + if ( intersects === void 0 ) intersects = []; + + + var octants = Octree.prototype.raycast.call(this, raycaster); + + if(octants.length > 0) { + + testPoints(octants, raycaster, intersects); + + } + + return intersects; + + }; + + return PointOctree; + }(Octree)); + + /** + * A mouse position. + * + * @type {Vector2} + * @private + */ + + var mouse = new Vector2(); + + /** + * An octree raycaster. + * + * @implements {EventListener} + */ + + var OctreeRaycaster$1 = /*@__PURE__*/(function (Raycaster) { + function OctreeRaycaster(octree, camera, object) { + + Raycaster.call(this); + + /** + * A picking accuracy threshold for points. + */ + + this.params.Points.threshold = 1e-1; + + /** + * An octree. + * + * @type {Octree} + * @private + */ + + this.octree = octree; + + /** + * A camera. + * + * @type {PerspectiveCamera} + * @private + */ + + this.camera = camera; + + /** + * An object to raycast with a brute force approach. + * + * @type {Object3D} + */ + + this.object = object; + + /** + * Indicates whether the raycaster is active. + * + * @type {Boolean} + */ + + this.enabled = true; + + /** + * A delta time. + * + * @type {String} + */ + + this.delta = ""; + + /** + * A selected object. + * + * @type {Object3D} + * @private + */ + + this.selectedObject = null; + + /** + * The currently selected point. + * + * @type {Mesh} + */ + + this.selectedPoint = new Mesh( + new SphereBufferGeometry(0.2, 16, 16), + new MeshBasicMaterial({ + transparent: true, + color: 0x00ccff, + opacity: 0.75 + }) + ); + + this.selectedPoint.visible = false; + + } + + if ( Raycaster ) OctreeRaycaster.__proto__ = Raycaster; + OctreeRaycaster.prototype = Object.create( Raycaster && Raycaster.prototype ); + OctreeRaycaster.prototype.constructor = OctreeRaycaster; + + /** + * Raycasts on mouse move events. + * + * @param {Event} event - An event. + */ + + OctreeRaycaster.prototype.handleEvent = function handleEvent (event) { + + switch(event.type) { + + case "mousemove": + this.raycast(event); + break; + + } + + }; + + /** + * Raycasts the octree. + * + * @param {Event} event - An event. + */ + + OctreeRaycaster.prototype.raycast = function raycast (event) { + + var intersects; + var t0, t, x; + + mouse.x = (event.clientX / window.innerWidth) * 2 - 1; + mouse.y = -(event.clientY / window.innerHeight) * 2 + 1; + + this.setFromCamera(mouse, this.camera); + + if(this.enabled) { + + // Use the octree raycasting capabilities. + t0 = performance.now(); + intersects = this.octree.raycast(this); + t = performance.now(); + + } else { + + // Brute force alternative. + t0 = performance.now(); + intersects = this.intersectObjects(this.object.children); + t = performance.now(); + + } + + this.delta = (t - t0).toFixed(2) + " ms"; + + if(this.selectedObject !== null) { + + this.selectedObject.material.color.setHex(0xc00000); + this.selectedObject = null; + this.selectedPoint.visible = false; + + } + + if(intersects.length > 0) { + + x = intersects[0]; + + if(x.object !== undefined) { + + this.selectedObject = x.object; + this.selectedObject.material.color.setHex(0xccff00); + + this.selectedPoint.visible = x.object.parent.visible; + this.selectedPoint.position.copy(x.point); + + } else { + + console.warn(intersects); + + } + + } + + }; + + /** + * Registers configuration options. + * + * @param {GUI} menu - A menu. + */ + + OctreeRaycaster.prototype.registerOptions = function registerOptions (menu) { + + var folder = menu.addFolder("Raycasting"); + + folder.add(this, "enabled"); + folder.add(this, "delta").listen(); + + folder.open(); + + }; + + return OctreeRaycaster; + }(Raycaster)); + + /** + * A matrix. + * + * @type {Matrix4} + * @private + */ + + var matrix4 = new Matrix4(); + + /** + * A frustum. + * + * @type {Frustum} + * @private + */ + + var frustum = new Frustum(); + + /** + * A frustum-based octree culler. + */ + + var FrustumCuller = function FrustumCuller(octree, scene) { + + /** + * An octree. + * + * @type {Octree} + * @private + */ + + this.octree = octree; + + /** + * A scene. + * + * @type {Scene} + */ + + this.scene = scene; + + /** + * Indicates whether the frustum culling is active. + * + * @type {Boolean} + */ + + this.enabled = false; + + /** + * A camera. + * + * @type {PerspectiveCamera} + */ + + this.cullCamera = new PerspectiveCamera(20, 1.77, 0.5, 5); + + /** + * A spherical coordinate system. + * + * @type {Spherical} + */ + + this.s = new Spherical(5, Math.PI / 3, Math.PI * 1.75); + + /** + * A delta time. + * + * @type {String} + */ + + this.delta = ""; + + /** + * A point cloud that visualises the culled octants. + * + * @type {Points} + */ + + this.culledOctants = new Points( + new BufferGeometry(), + new PointsMaterial({ + color: 0xccff00, + sizeAttenuation: false, + size: 2 + }) + ); + + this.culledOctants.visible = false; + + /** + * A camera helper. + * + * @type {CameraHelper} + */ + + this.cameraHelper = new CameraHelper(this.cullCamera); + this.cameraHelper.visible = false; + + }; + + /** + * Updates the cull camera. + * + * @private + */ + + FrustumCuller.prototype.updateCamera = function updateCamera () { + + var cullCamera = this.cullCamera; + + cullCamera.position.setFromSpherical(this.s); + cullCamera.lookAt(this.scene.position); + cullCamera.updateMatrixWorld(true); + + frustum.setFromProjectionMatrix( + matrix4.multiplyMatrices( + cullCamera.projectionMatrix, + cullCamera.matrixWorldInverse + ) + ); + + }; + + /** + * Culls the octree. + */ + + FrustumCuller.prototype.cull = function cull () { + + var culledOctants = this.culledOctants; + + var t0; + var i, j, l; + var octant, octants; + var positions; + + if(this.enabled) { + + this.updateCamera(); + + t0 = performance.now(); + octants = this.octree.cull(frustum); + + this.delta = (performance.now() - t0).toFixed(2) + " ms"; + + if(octants.length > 0) { + + positions = new Float32Array(octants.length * 3 * 2); + + for(i = 0, j = 0, l = octants.length; i < l; ++i) { + + octant = octants[i]; + positions[j++] = octant.min.x; + positions[j++] = octant.min.y; + positions[j++] = octant.min.z; + positions[j++] = octant.max.x; + positions[j++] = octant.max.y; + positions[j++] = octant.max.z; + + } + + culledOctants.geometry.deleteAttribute("position"); + culledOctants.geometry.setAttribute("position", new BufferAttribute(positions, 3)); + + this.scene.remove(culledOctants); + this.scene.add(culledOctants); + + } else { + + this.scene.remove(culledOctants); + + } + + } + + }; + + /** + * Registers configuration options. + * + * @param {GUI} menu - A menu. + */ + + FrustumCuller.prototype.registerOptions = function registerOptions (menu) { + var this$1 = this; + + + var folder = menu.addFolder("Frustum Culling"); + + folder.add(this, "enabled").onChange(function () { + + this$1.cameraHelper.visible = this$1.culledOctants.visible = this$1.enabled; + this$1.cull(); + + }); + + folder.add(this, "delta").listen(); + folder.open(); + + var subFolder = folder.addFolder("Camera Adjustment"); + + subFolder.add(this.s, "radius").min(0.1).max(10.0).step(0.1).onChange(function () { + + this$1.cull(); + + }); + + subFolder.add(this.s, "phi").min(1e-6).max(Math.PI - 1e-6).onChange(function () { + + this$1.cull(); + + }); + + subFolder.add(this.s, "theta").min(0.0).max(Math.PI * 2.0).onChange(function () { + + this$1.cull(); + + }); + + }; + + /** + * A point octree demo application. + */ + + var PointOctreeDemo = /*@__PURE__*/(function (Demo) { + function PointOctreeDemo() { + + Demo.call(this, "point-octree"); + + /** + * Spatial controls. + * + * @type {SpatialControls} + * @private + */ + + this.controls = null; + + /** + * A point cloud. + * + * @type {Points} + * @private + */ + + this.points = null; + + /** + * An octree helper. + * + * @type {OctreeHelper} + * @private + */ + + this.octreeHelper = null; + + /** + * An octree raycaster. + * + * @type {OctreeRaycaster} + * @private + */ + + this.octreeRaycaster = null; + + /** + * A frustum culler. + * + * @type {FrustumCuller} + * @private + */ + + this.frustumCuller = null; + + } + + if ( Demo ) PointOctreeDemo.__proto__ = Demo; + PointOctreeDemo.prototype = Object.create( Demo && Demo.prototype ); + PointOctreeDemo.prototype.constructor = PointOctreeDemo; + + /** + * Creates the scene. + */ + + PointOctreeDemo.prototype.initialize = function initialize () { + + var scene = this.scene; + var renderer = this.renderer; + + // Camera. + + var aspect = window.innerWidth / window.innerHeight; + var camera = new PerspectiveCamera(50, aspect, 0.3, 2000); + camera.position.set(10, 6, 10); + this.camera = camera; + + // Controls. + + var controls = new SpatialControls( + camera.position, + camera.quaternion, + renderer.domElement + ); + + controls.settings.pointer.lock = false; + controls.settings.zoom.maxDistance = 60.0; + controls.settings.sensitivity.rotation = 2.0; + controls.settings.sensitivity.translation = 10.0; + controls.settings.sensitivity.zoom = 1.0; + controls.lookAt(scene.position); + this.controls = controls; + + camera.updateMatrixWorld(); + + // Fog. + + scene.fog = new FogExp2(0x0d0d0d, 0.025); + renderer.setClearColor(scene.fog.color); + + // Points. + + var points = (function generatePoints() { + + function createPlaneGeometry(particles, n, zBase, zBias) { + + var geometry = new BufferGeometry(); + var positions = new Float32Array(particles * 3); + var n2 = n / 2; + + for(var i = 0, l = positions.length; i < l; i += 3) { + + var x = Math.random() * n - n2; + var y = Math.random() * n - n2; + var z = zBase + (Math.random() * zBias * 2 - zBias); + + positions[i] = x; + positions[i + 1] = y; + positions[i + 2] = z; + + } + + geometry.setAttribute("position", new BufferAttribute(positions, 3)); + + return geometry; + + } + + var points = new Object3D(); + + var w = 256; + var h = 256; + + var d = 8; + + var size = 6; + var zStep = size / (d - 1); + + var z = size * -0.5; + var p; + + var material = new PointsMaterial({ + color: 0xc00000, + sizeAttenuation: false, + size: 1 + }); + + console.log("Generating", w * h * d, "points..."); + + while(d-- > 0) { + + p = new Points(createPlaneGeometry(w * h, size, z, 0.25), material); + material = material.clone(); + z += zStep; + + points.add(p); + + } + + return points; + + }()); + + this.points = points; + scene.add(points); + + // Octree. + + var octree = (function createOctree(points) { + + var v = new Vector3(); + var bbox = new Box3(); + bbox.setFromObject(scene); + + var t0 = performance.now(); + var octree = new PointOctree(bbox.min, bbox.max, 0.0, 8, 5); + + for(var d = points.children.length - 1; d >= 0; --d) { + + var p = points.children[d]; + var array = p.geometry.getAttribute("position").array; + + for(var i = 0, l = array.length; i < l; i += 3) { + + octree.insert(v.fromArray(array, i), p); + + } + + } + + console.log("Octree:", octree, "created in", (performance.now() - t0).toFixed(2) + " ms"); + + return octree; + + }(points)); + + // Octree Helper. + + var octreeHelper = (function createOctreeHelper(octree) { + + var t0 = performance.now(); + var octreeHelper = new OctreeHelper(octree); + octreeHelper.visible = false; + + console.log("OctreeHelper:", octreeHelper, "created in", (performance.now() - t0).toFixed(2) + " ms"); + + return octreeHelper; + + }(octree)); + + this.octreeHelper = octreeHelper; + scene.add(octreeHelper); + + // Raycasting. + + this.raycaster = new OctreeRaycaster$1(octree, camera, points); + renderer.domElement.addEventListener("mousemove", this.raycaster); + scene.add(this.raycaster.selectedPoint); + + // Frustum culling. + + this.frustumCuller = new FrustumCuller(octree, scene); + scene.add(this.frustumCuller.cameraHelper); + + }; + + /** + * Renders this demo. + * + * @param {Number} deltaTime - The time since the last frame in seconds. + */ + + PointOctreeDemo.prototype.render = function render (deltaTime) { + + this.controls.update(deltaTime); + Demo.prototype.render.call(this, deltaTime); + + }; + + /** + * Registers configuration options. + * + * @param {GUI} menu - A menu. + */ + + PointOctreeDemo.prototype.registerOptions = function registerOptions (menu) { + + var points = this.points; + var octreeHelper = this.octreeHelper; + + this.raycaster.registerOptions(menu); + this.frustumCuller.registerOptions(menu); + + var params = { + "level mask": octreeHelper.children.length + }; + + var folder = menu.addFolder("Points"); + folder.add(points, "visible"); + folder.open(); + + folder = menu.addFolder("Octree Helper"); + folder.add(octreeHelper, "visible"); + + folder.add(params, "level mask").min(0).max(octreeHelper.children.length).step(1).onChange(function () { + + for(var i = 0, l = octreeHelper.children.length; i < l; ++i) { + + octreeHelper.children[i].visible = ( + params["level mask"] === octreeHelper.children.length || + i === params["level mask"] + ); + + } + + }); + + folder.open(); + + }; + + /** + * Resets this demo. + * + * @return {Demo} This demo. + */ + + PointOctreeDemo.prototype.reset = function reset () { + + this.renderer.domElement.removeEventListener("mousemove", this.raycaster); + return Demo.prototype.reset.call(this); + + }; + + return PointOctreeDemo; + }(Demo)); + + /** + * A demo manager. + * + * @type {DemoManager} + * @private + */ + + var manager; + + /** + * The main render loop. + * + * @private + * @param {DOMHighResTimeStamp} now - The current time. + */ + + function render(now) { + + requestAnimationFrame(render); + manager.render(now); + + } + + /** + * Handles demo change events. + * + * @private + * @param {Event} event - An event. + */ + + function onChange(event) { + + document.getElementById("viewport").children[0].style.display = "initial"; + + } + + /** + * Handles demo load events. + * + * @private + * @param {Event} event - An event. + */ + + function onLoad(event) { + + document.getElementById("viewport").children[0].style.display = "none"; + + } + + /** + * Starts the program. + * + * @private + * @param {Event} event - An event. + */ + + window.addEventListener("load", function main(event) { + + var viewport = document.getElementById("viewport"); + + // Create a custom renderer. + var renderer = new WebGLRenderer({ antialias: true }); + renderer.setSize(viewport.clientWidth, viewport.clientHeight); + renderer.setPixelRatio(window.devicePixelRatio); + renderer.setClearColor(0x000000); + + // Initialize the demo manager. + manager = new DemoManager(viewport, { + aside: document.getElementById("aside"), + renderer: renderer + }); + + // Setup demo switch and load event handlers. + manager.addEventListener("change", onChange); + manager.addEventListener("load", onLoad); + + // Register demos. + var demo = new PointOctreeDemo(); + + if(demo.id !== window.location.hash.slice(1)) { + + window.location.hash = ""; + + } + + manager.addDemo(demo); + + // Start rendering. + render(); + + }); + + /** + * Handles browser resizing. + * + * @private + * @param {Event} event - An event. + */ + + window.addEventListener("resize", (function() { + + var timeoutId = 0; + + function handleResize(event) { + + var width = event.target.innerWidth; + var height = event.target.innerHeight; + + manager.setSize(width, height); + + timeoutId = 0; + + } + + return function onResize(event) { + + if(timeoutId === 0) { + + timeoutId = setTimeout(handleResize, 66, event); + + } + + }; + + }())); + + /** + * Toggles the visibility of the interface on Alt key press. + * + * @private + * @param {Event} event - An event. + */ + + document.addEventListener("keydown", function onKeyDown(event) { + + var aside = this.getElementById("aside"); + + if(event.altKey && aside !== null) { + + event.preventDefault(); + aside.style.visibility = (aside.style.visibility === "hidden") ? "visible" : "hidden"; + + } + + }); + +}()); diff --git a/public/demo/index.min.js b/public/demo/index.min.js index 6220cd4..2f08081 100644 --- a/public/demo/index.min.js +++ b/public/demo/index.min.js @@ -1 +1,20 @@ -!function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:this,i=n.listenerFunctions,o=n.listenerObjects;if(t.target=n,i.has(t.type)){e=i.get(t.type);var r=!0,s=!1,a=void 0;try{for(var l,u=e[Symbol.iterator]();!(r=(l=u.next()).done);r=!0)l.value.call(n,t)}catch(t){s=!0,a=t}finally{try{r||null==u.return||u.return()}finally{if(s)throw a}}}if(o.has(t.type)){e=o.get(t.type);var h=!0,c=!1,d=void 0;try{for(var f,m=e[Symbol.iterator]();!(h=(f=m.next()).done);h=!0)f.value.handleEvent(t)}catch(t){c=!0,d=t}finally{try{h||null==m.return||m.return()}finally{if(c)throw d}}}}}]),t}();function d(t,e){var n=t.__state.conversionName.toString(),i=Math.round(t.r),o=Math.round(t.g),r=Math.round(t.b),s=t.a,a=Math.round(t.h),l=t.s.toFixed(1),u=t.v.toFixed(1);if(e||"THREE_CHAR_HEX"===n||"SIX_CHAR_HEX"===n){for(var h=t.hex.toString(16);h.length<6;)h="0"+h;return"#"+h}return"CSS_RGB"===n?"rgb("+i+","+o+","+r+")":"CSS_RGBA"===n?"rgba("+i+","+o+","+r+","+s+")":"HEX"===n?"0x"+t.hex.toString(16):"RGB_ARRAY"===n?"["+i+","+o+","+r+"]":"RGBA_ARRAY"===n?"["+i+","+o+","+r+","+s+"]":"RGB_OBJ"===n?"{r:"+i+",g:"+o+",b:"+r+"}":"RGBA_OBJ"===n?"{r:"+i+",g:"+o+",b:"+r+",a:"+s+"}":"HSV_OBJ"===n?"{h:"+a+",s:"+l+",v:"+u+"}":"HSVA_OBJ"===n?"{h:"+a+",s:"+l+",v:"+u+",a:"+s+"}":"unknown format"}var f=Array.prototype.forEach,m=Array.prototype.slice,p={BREAK:{},extend:function(t){return this.each(m.call(arguments,1),(function(e){(this.isObject(e)?Object.keys(e):[]).forEach(function(n){this.isUndefined(e[n])||(t[n]=e[n])}.bind(this))}),this),t},defaults:function(t){return this.each(m.call(arguments,1),(function(e){(this.isObject(e)?Object.keys(e):[]).forEach(function(n){this.isUndefined(t[n])&&(t[n]=e[n])}.bind(this))}),this),t},compose:function(){var t=m.call(arguments);return function(){for(var e=m.call(arguments),n=t.length-1;n>=0;n--)e=[t[n].apply(this,e)];return e[0]}},each:function(t,e,n){if(t)if(f&&t.forEach&&t.forEach===f)t.forEach(e,n);else if(t.length===t.length+0){var i,o=void 0;for(o=0,i=t.length;o1?p.toArray(arguments):arguments[0];return p.each(y,(function(e){if(e.litmus(t))return p.each(e.conversions,(function(e,n){if(v=e.read(t),!1===g&&!1!==v)return g=v,v.conversionName=n,v.conversion=e,p.BREAK})),p.BREAK})),g},b=void 0,x={hsv_to_rgb:function(t,e,n){var i=Math.floor(t/60)%6,o=t/60-Math.floor(t/60),r=n*(1-e),s=n*(1-o*e),a=n*(1-(1-o)*e),l=[[n,a,r],[s,n,r],[r,n,a],[r,s,n],[a,r,n],[n,r,s]][i];return{r:255*l[0],g:255*l[1],b:255*l[2]}},rgb_to_hsv:function(t,e,n){var i=Math.min(t,e,n),o=Math.max(t,e,n),r=o-i,s=void 0;return 0===o?{h:NaN,s:0,v:0}:(s=t===o?(e-n)/r:e===o?2+(n-t)/r:4+(t-e)/r,(s/=6)<0&&(s+=1),{h:360*s,s:r/o,v:o/255})},rgb_to_hex:function(t,e,n){var i=this.hex_with_component(0,2,t);return i=this.hex_with_component(i,1,e),i=this.hex_with_component(i,0,n)},component_from_hex:function(t,e){return t>>8*e&255},hex_with_component:function(t,e,n){return n<<(b=8*e)|t&~(255<-1?e.length-e.indexOf(".")-1:0}var V=function(t){function e(t,n,i){w(this,e);var o=C(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n)),r=i||{};return o.__min=r.min,o.__max=r.max,o.__step=r.step,p.isUndefined(o.__step)?0===o.initialValue?o.__impliedStep=1:o.__impliedStep=Math.pow(10,Math.floor(Math.log(Math.abs(o.initialValue))/Math.LN10))/10:o.__impliedStep=o.__step,o.__precision=H(o.__impliedStep),o}return S(e,t),A(e,[{key:"setValue",value:function(t){var n=t;return void 0!==this.__min&&nthis.__max&&(n=this.__max),void 0!==this.__step&&n%this.__step!=0&&(n=Math.round(n/this.__step)*this.__step),E(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setValue",this).call(this,n)}},{key:"min",value:function(t){return this.__min=t,this}},{key:"max",value:function(t){return this.__max=t,this}},{key:"step",value:function(t){return this.__step=t,this.__impliedStep=t,this.__precision=H(t),this}}]),e}(P);var j=function(t){function e(t,n,i){w(this,e);var o=C(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n,i));o.__truncationSuspended=!1;var r=o,s=void 0;function a(){r.__onFinishChange&&r.__onFinishChange.call(r,r.getValue())}function l(t){var e=s-t.clientY;r.setValue(r.getValue()+e*r.__impliedStep),s=t.clientY}function u(){F.unbind(window,"mousemove",l),F.unbind(window,"mouseup",u),a()}return o.__input=document.createElement("input"),o.__input.setAttribute("type","text"),F.bind(o.__input,"change",(function(){var t=parseFloat(r.__input.value);p.isNaN(t)||r.setValue(t)})),F.bind(o.__input,"blur",(function(){a()})),F.bind(o.__input,"mousedown",(function(t){F.bind(window,"mousemove",l),F.bind(window,"mouseup",u),s=t.clientY})),F.bind(o.__input,"keydown",(function(t){13===t.keyCode&&(r.__truncationSuspended=!0,this.blur(),r.__truncationSuspended=!1,a())})),o.updateDisplay(),o.domElement.appendChild(o.__input),o}return S(e,t),A(e,[{key:"updateDisplay",value:function(){var t,n,i;return this.__input.value=this.__truncationSuspended?this.getValue():(t=this.getValue(),n=this.__precision,i=Math.pow(10,n),Math.round(t*i)/i),E(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"updateDisplay",this).call(this)}}]),e}(V);function U(t,e,n,i,o){return i+(t-e)/(n-e)*(o-i)}var I=function(t){function e(t,n,i,o,r){w(this,e);var s=C(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n,{min:i,max:o,step:r})),a=s;function l(t){t.preventDefault();var e=a.__background.getBoundingClientRect();return a.setValue(U(t.clientX,e.left,e.right,a.__min,a.__max)),!1}function u(){F.unbind(window,"mousemove",l),F.unbind(window,"mouseup",u),a.__onFinishChange&&a.__onFinishChange.call(a,a.getValue())}function h(t){var e=t.touches[0].clientX,n=a.__background.getBoundingClientRect();a.setValue(U(e,n.left,n.right,a.__min,a.__max))}function c(){F.unbind(window,"touchmove",h),F.unbind(window,"touchend",c),a.__onFinishChange&&a.__onFinishChange.call(a,a.getValue())}return s.__background=document.createElement("div"),s.__foreground=document.createElement("div"),F.bind(s.__background,"mousedown",(function(t){document.activeElement.blur(),F.bind(window,"mousemove",l),F.bind(window,"mouseup",u),l(t)})),F.bind(s.__background,"touchstart",(function(t){if(1!==t.touches.length)return;F.bind(window,"touchmove",h),F.bind(window,"touchend",c),h(t)})),F.addClass(s.__background,"slider"),F.addClass(s.__foreground,"slider-fg"),s.updateDisplay(),s.__background.appendChild(s.__foreground),s.domElement.appendChild(s.__background),s}return S(e,t),A(e,[{key:"updateDisplay",value:function(){var t=(this.getValue()-this.__min)/(this.__max-this.__min);return this.__foreground.style.width=100*t+"%",E(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"updateDisplay",this).call(this)}}]),e}(V),q=function(t){function e(t,n,i){w(this,e);var o=C(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n)),r=o;return o.__button=document.createElement("div"),o.__button.innerHTML=void 0===i?"Fire":i,F.bind(o.__button,"click",(function(t){return t.preventDefault(),r.fire(),!1})),F.addClass(o.__button,"button"),o.domElement.appendChild(o.__button),o}return S(e,t),A(e,[{key:"fire",value:function(){this.__onChange&&this.__onChange.call(this),this.getValue().call(this.object),this.__onFinishChange&&this.__onFinishChange.call(this,this.getValue())}}]),e}(P),G=function(t){function e(t,n){w(this,e);var i=C(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));i.__color=new M(i.getValue()),i.__temp=new M(0);var o=i;i.domElement=document.createElement("div"),F.makeSelectable(i.domElement,!1),i.__selector=document.createElement("div"),i.__selector.className="selector",i.__saturation_field=document.createElement("div"),i.__saturation_field.className="saturation-field",i.__field_knob=document.createElement("div"),i.__field_knob.className="field-knob",i.__field_knob_border="2px solid ",i.__hue_knob=document.createElement("div"),i.__hue_knob.className="hue-knob",i.__hue_field=document.createElement("div"),i.__hue_field.className="hue-field",i.__input=document.createElement("input"),i.__input.type="text",i.__input_textShadow="0 1px 1px ",F.bind(i.__input,"keydown",(function(t){13===t.keyCode&&c.call(this)})),F.bind(i.__input,"blur",c),F.bind(i.__selector,"mousedown",(function(){F.addClass(this,"drag").bind(window,"mouseup",(function(){F.removeClass(o.__selector,"drag")}))})),F.bind(i.__selector,"touchstart",(function(){F.addClass(this,"drag").bind(window,"touchend",(function(){F.removeClass(o.__selector,"drag")}))}));var r,s=document.createElement("div");function a(t){f(t),F.bind(window,"mousemove",f),F.bind(window,"touchmove",f),F.bind(window,"mouseup",u),F.bind(window,"touchend",u)}function l(t){m(t),F.bind(window,"mousemove",m),F.bind(window,"touchmove",m),F.bind(window,"mouseup",h),F.bind(window,"touchend",h)}function u(){F.unbind(window,"mousemove",f),F.unbind(window,"touchmove",f),F.unbind(window,"mouseup",u),F.unbind(window,"touchend",u),d()}function h(){F.unbind(window,"mousemove",m),F.unbind(window,"touchmove",m),F.unbind(window,"mouseup",h),F.unbind(window,"touchend",h),d()}function c(){var t=_(this.value);!1!==t?(o.__color.__state=t,o.setValue(o.__color.toOriginal())):this.value=o.__color.toString()}function d(){o.__onFinishChange&&o.__onFinishChange.call(o,o.__color.toOriginal())}function f(t){-1===t.type.indexOf("touch")&&t.preventDefault();var e=o.__saturation_field.getBoundingClientRect(),n=t.touches&&t.touches[0]||t,i=n.clientX,r=n.clientY,s=(i-e.left)/(e.right-e.left),a=1-(r-e.top)/(e.bottom-e.top);return a>1?a=1:a<0&&(a=0),s>1?s=1:s<0&&(s=0),o.__color.v=a,o.__color.s=s,o.setValue(o.__color.toOriginal()),!1}function m(t){-1===t.type.indexOf("touch")&&t.preventDefault();var e=o.__hue_field.getBoundingClientRect(),n=1-((t.touches&&t.touches[0]||t).clientY-e.top)/(e.bottom-e.top);return n>1?n=1:n<0&&(n=0),o.__color.h=360*n,o.setValue(o.__color.toOriginal()),!1}return p.extend(i.__selector.style,{width:"122px",height:"102px",padding:"3px",backgroundColor:"#222",boxShadow:"0px 1px 3px rgba(0,0,0,0.3)"}),p.extend(i.__field_knob.style,{position:"absolute",width:"12px",height:"12px",border:i.__field_knob_border+(i.__color.v<.5?"#fff":"#000"),boxShadow:"0px 1px 3px rgba(0,0,0,0.5)",borderRadius:"12px",zIndex:1}),p.extend(i.__hue_knob.style,{position:"absolute",width:"15px",height:"2px",borderRight:"4px solid #fff",zIndex:1}),p.extend(i.__saturation_field.style,{width:"100px",height:"100px",border:"1px solid #555",marginRight:"3px",display:"inline-block",cursor:"pointer"}),p.extend(s.style,{width:"100%",height:"100%",background:"none"}),W(s,"top","rgba(0,0,0,0)","#000"),p.extend(i.__hue_field.style,{width:"15px",height:"100px",border:"1px solid #555",cursor:"ns-resize",position:"absolute",top:"3px",right:"3px"}),(r=i.__hue_field).style.background="",r.style.cssText+="background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);",r.style.cssText+="background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);",r.style.cssText+="background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);",r.style.cssText+="background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);",r.style.cssText+="background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);",p.extend(i.__input.style,{outline:"none",textAlign:"center",color:"#fff",border:0,fontWeight:"bold",textShadow:i.__input_textShadow+"rgba(0,0,0,0.7)"}),F.bind(i.__saturation_field,"mousedown",a),F.bind(i.__saturation_field,"touchstart",a),F.bind(i.__field_knob,"mousedown",a),F.bind(i.__field_knob,"touchstart",a),F.bind(i.__hue_field,"mousedown",l),F.bind(i.__hue_field,"touchstart",l),i.__saturation_field.appendChild(s),i.__selector.appendChild(i.__field_knob),i.__selector.appendChild(i.__saturation_field),i.__selector.appendChild(i.__hue_field),i.__hue_field.appendChild(i.__hue_knob),i.domElement.appendChild(i.__input),i.domElement.appendChild(i.__selector),i.updateDisplay(),i}return S(e,t),A(e,[{key:"updateDisplay",value:function(){var t=_(this.getValue());if(!1!==t){var e=!1;p.each(M.COMPONENTS,(function(n){if(!p.isUndefined(t[n])&&!p.isUndefined(this.__color.__state[n])&&t[n]!==this.__color.__state[n])return e=!0,{}}),this),e&&p.extend(this.__color.__state,t)}p.extend(this.__temp.__state,this.__color.__state),this.__temp.a=1;var n=this.__color.v<.5||this.__color.s>.5?255:0,i=255-n;p.extend(this.__field_knob.style,{marginLeft:100*this.__color.s-7+"px",marginTop:100*(1-this.__color.v)-7+"px",backgroundColor:this.__temp.toHexString(),border:this.__field_knob_border+"rgb("+n+","+n+","+n+")"}),this.__hue_knob.style.marginTop=100*(1-this.__color.h/360)+"px",this.__temp.s=1,this.__temp.v=1,W(this.__saturation_field,"left","#fff",this.__temp.toHexString()),this.__input.value=this.__color.toString(),p.extend(this.__input.style,{backgroundColor:this.__color.toHexString(),color:"rgb("+n+","+n+","+n+")",textShadow:this.__input_textShadow+"rgba("+i+","+i+","+i+",.7)"})}}]),e}(P),X=["-moz-","-o-","-webkit-","-ms-",""];function W(t,e,n,i){t.style.background="",p.each(X,(function(o){t.style.cssText+="background: "+o+"linear-gradient("+e+", "+n+" 0%, "+i+" 100%); "}))}var Y=function(t,e){var n=e||document,i=document.createElement("style");i.type="text/css",i.innerHTML=t;var o=n.getElementsByTagName("head")[0];try{o.appendChild(i)}catch(t){}},K='
\n\n Here\'s the new load parameter for your GUI\'s constructor:\n\n \n\n
\n\n Automatically save\n values to localStorage on exit.\n\n
The values saved to localStorage will\n override those passed to dat.GUI\'s constructor. This makes it\n easier to work incrementally, but localStorage is fragile,\n and your friends may not see the same values you do.\n\n
\n\n
\n\n
',Q=function(t,e){var n=t[e];return p.isArray(arguments[2])||p.isObject(arguments[2])?new B(t,e,arguments[2]):p.isNumber(n)?p.isNumber(arguments[2])&&p.isNumber(arguments[3])?p.isNumber(arguments[4])?new I(t,e,arguments[2],arguments[3],arguments[4]):new I(t,e,arguments[2],arguments[3]):p.isNumber(arguments[4])?new j(t,e,{min:arguments[2],max:arguments[3],step:arguments[4]}):new j(t,e,{min:arguments[2],max:arguments[3]}):p.isString(n)?new N(t,e):p.isFunction(n)?new q(t,e,""):p.isBoolean(n)?new R(t,e):null};var J=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){setTimeout(t,1e3/60)},Z=function(){function t(){w(this,t),this.backgroundElement=document.createElement("div"),p.extend(this.backgroundElement.style,{backgroundColor:"rgba(0,0,0,0.8)",top:0,left:0,display:"none",zIndex:"1000",opacity:0,WebkitTransition:"opacity 0.2s linear",transition:"opacity 0.2s linear"}),F.makeFullscreen(this.backgroundElement),this.backgroundElement.style.position="fixed",this.domElement=document.createElement("div"),p.extend(this.domElement.style,{position:"fixed",display:"none",zIndex:"1001",opacity:0,WebkitTransition:"-webkit-transform 0.2s ease-out, opacity 0.2s linear",transition:"transform 0.2s ease-out, opacity 0.2s linear"}),document.body.appendChild(this.backgroundElement),document.body.appendChild(this.domElement);var e=this;F.bind(this.backgroundElement,"click",(function(){e.hide()}))}return A(t,[{key:"show",value:function(){var t=this;this.backgroundElement.style.display="block",this.domElement.style.display="block",this.domElement.style.opacity=0,this.domElement.style.webkitTransform="scale(1.1)",this.layout(),p.defer((function(){t.backgroundElement.style.opacity=1,t.domElement.style.opacity=1,t.domElement.style.webkitTransform="scale(1)"}))}},{key:"hide",value:function(){var t=this,e=function e(){t.domElement.style.display="none",t.backgroundElement.style.display="none",F.unbind(t.domElement,"webkitTransitionEnd",e),F.unbind(t.domElement,"transitionend",e),F.unbind(t.domElement,"oTransitionEnd",e)};F.bind(this.domElement,"webkitTransitionEnd",e),F.bind(this.domElement,"transitionend",e),F.bind(this.domElement,"oTransitionEnd",e),this.backgroundElement.style.opacity=0,this.domElement.style.opacity=0,this.domElement.style.webkitTransform="scale(1.1)"}},{key:"layout",value:function(){this.domElement.style.left=window.innerWidth/2-F.getWidth(this.domElement)/2+"px",this.domElement.style.top=window.innerHeight/2-F.getHeight(this.domElement)/2+"px"}}]),t}();Y(function(t){if(t&&"undefined"!=typeof window){var e=document.createElement("style");return e.setAttribute("type","text/css"),e.innerHTML=t,document.head.appendChild(e),t}}(".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear;border:0;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button.close-top{position:relative}.dg.main .close-button.close-bottom{position:absolute}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-y:visible}.dg.a.has-save>ul.close-top{margin-top:0}.dg.a.has-save>ul.close-bottom{margin-top:27px}.dg.a.has-save>ul.closed{margin-top:0}.dg.a .save-row{top:0;z-index:1002}.dg.a .save-row.close-top{position:relative}.dg.a .save-row.close-bottom{position:fixed}.dg li{-webkit-transition:height .1s ease-out;-o-transition:height .1s ease-out;-moz-transition:height .1s ease-out;transition:height .1s ease-out;-webkit-transition:overflow .1s linear;-o-transition:overflow .1s linear;-moz-transition:overflow .1s linear;transition:overflow .1s linear}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li>*{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px;overflow:hidden}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%;position:relative}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:7px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .cr.color{overflow:visible}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.color{border-left:3px solid}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2FA1D6}.dg .cr.number input[type=text]{color:#2FA1D6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2FA1D6;max-width:100%}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n"));var $=function(){try{return!!window.localStorage}catch(t){return!1}}(),tt=void 0,et=!0,nt=void 0,it=!1,ot=[],rt=function t(e){var n=this,i=e||{};this.domElement=document.createElement("div"),this.__ul=document.createElement("ul"),this.domElement.appendChild(this.__ul),F.addClass(this.domElement,"dg"),this.__folders={},this.__controllers=[],this.__rememberedObjects=[],this.__rememberedObjectIndecesToControllers=[],this.__listening=[],i=p.defaults(i,{closeOnTop:!1,autoPlace:!0,width:t.DEFAULT_WIDTH}),i=p.defaults(i,{resizable:i.autoPlace,hideable:i.autoPlace}),p.isUndefined(i.load)?i.load={preset:"Default"}:i.preset&&(i.load.preset=i.preset),p.isUndefined(i.parent)&&i.hideable&&ot.push(this),i.resizable=p.isUndefined(i.parent)&&i.resizable,i.autoPlace&&p.isUndefined(i.scrollable)&&(i.scrollable=!0);var o,r=$&&"true"===localStorage.getItem(ct(this,"isLocal")),s=void 0,a=void 0;if(Object.defineProperties(this,{parent:{get:function(){return i.parent}},scrollable:{get:function(){return i.scrollable}},autoPlace:{get:function(){return i.autoPlace}},closeOnTop:{get:function(){return i.closeOnTop}},preset:{get:function(){return n.parent?n.getRoot().preset:i.load.preset},set:function(t){n.parent?n.getRoot().preset=t:i.load.preset=t,function(t){for(var e=0;e1){var i=n.__li.nextElementSibling;return n.remove(),ht(t,n.object,n.property,{before:i,factoryArgs:[p.toArray(arguments)]})}if(p.isArray(e)||p.isObject(e)){var o=n.__li.nextElementSibling;return n.remove(),ht(t,n.object,n.property,{before:o,factoryArgs:[e]})}},name:function(t){return n.__li.firstElementChild.firstElementChild.innerHTML=t,n},listen:function(){return n.__gui.listen(n),n},remove:function(){return n.__gui.remove(n),n}}),n instanceof I){var i=new j(n.object,n.property,{min:n.__min,max:n.__max,step:n.__step});p.each(["updateDisplay","onChange","onFinishChange","step","min","max"],(function(t){var e=n[t],o=i[t];n[t]=i[t]=function(){var t=Array.prototype.slice.call(arguments);return o.apply(i,t),e.apply(n,t)}})),F.addClass(e,"has-slider"),n.domElement.insertBefore(i.domElement,n.domElement.firstElementChild)}else if(n instanceof j){var o=function(e){if(p.isNumber(n.__min)&&p.isNumber(n.__max)){var i=n.__li.firstElementChild.firstElementChild.innerHTML,o=n.__gui.__listening.indexOf(n)>-1;n.remove();var r=ht(t,n.object,n.property,{before:n.__li.nextElementSibling,factoryArgs:[n.__min,n.__max,n.__step]});return r.name(i),o&&r.listen(),r}return e};n.min=p.compose(o,n.min),n.max=p.compose(o,n.max)}else n instanceof R?(F.bind(e,"click",(function(){F.fakeEvent(n.__checkbox,"click")})),F.bind(n.__checkbox,"click",(function(t){t.stopPropagation()}))):n instanceof q?(F.bind(e,"click",(function(){F.fakeEvent(n.__button,"click")})),F.bind(e,"mouseover",(function(){F.addClass(n.__button,"hover")})),F.bind(e,"mouseout",(function(){F.removeClass(n.__button,"hover")}))):n instanceof G&&(F.addClass(e,"color"),n.updateDisplay=p.compose((function(t){return e.style.borderLeftColor=n.__color.toString(),t}),n.updateDisplay),n.updateDisplay());n.setValue=p.compose((function(e){return t.getRoot().__preset_select&&n.isModified()&<(t.getRoot(),!0),e}),n.setValue)}(t,l,o),t.__controllers.push(o),o}function ct(t,e){return document.location.href+"."+e}function dt(t,e,n){var i=document.createElement("option");i.innerHTML=e,i.value=e,t.__preset_select.appendChild(i),n&&(t.__preset_select.selectedIndex=t.__preset_select.length-1)}function ft(t,e){e.style.display=t.useLocalStorage?"block":"none"}function mt(t){var e=t.__save_row=document.createElement("li");F.addClass(t.domElement,"has-save"),t.__ul.insertBefore(e,t.__ul.firstChild),F.addClass(e,"save-row");var n=document.createElement("span");n.innerHTML=" ",F.addClass(n,"button gears");var i=document.createElement("span");i.innerHTML="Save",F.addClass(i,"button"),F.addClass(i,"save");var o=document.createElement("span");o.innerHTML="New",F.addClass(o,"button"),F.addClass(o,"save-as");var r=document.createElement("span");r.innerHTML="Revert",F.addClass(r,"button"),F.addClass(r,"revert");var s=t.__preset_select=document.createElement("select");if(t.load&&t.load.remembered?p.each(t.load.remembered,(function(e,n){dt(t,n,n===t.preset)})):dt(t,"Default",!1),F.bind(s,"change",(function(){for(var e=0;e0&&(t.preset=this.preset,t.remembered||(t.remembered={}),t.remembered[this.preset]=vt(this)),t.folders={},p.each(this.__folders,(function(e,n){t.folders[n]=e.getSaveObject()})),t},save:function(){this.load.remembered||(this.load.remembered={}),this.load.remembered[this.preset]=vt(this),lt(this,!1),this.saveToLocalStorageIfPossible()},saveAs:function(t){this.load.remembered||(this.load.remembered={},this.load.remembered.Default=vt(this,!0)),this.load.remembered[t]=vt(this),this.preset=t,dt(this,t,!0),this.saveToLocalStorageIfPossible()},revert:function(t){p.each(this.__controllers,(function(e){this.getRoot().load.remembered?ut(t||this.getRoot(),e):e.setValue(e.initialValue),e.__onFinishChange&&e.__onFinishChange.call(e,e.getValue())}),this),p.each(this.__folders,(function(t){t.revert(t)})),t||lt(this.getRoot(),!1)},listen:function(t){var e=0===this.__listening.length;this.__listening.push(t),e&&function t(e){0!==e.length&&J.call(window,(function(){t(e)}));p.each(e,(function(t){t.updateDisplay()}))}(this.__listening)},updateDisplay:function(){p.each(this.__controllers,(function(t){t.updateDisplay()})),p.each(this.__folders,(function(t){t.updateDisplay()}))}});var gt=rt,_t=function(){function e(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"demo";n(this,e),this.id=i,this.renderer=null,this.loadingManager=new t.LoadingManager,this.assets=new Map,this.scene=new t.Scene,this.camera=null,this.controls=null,this.ready=!1}return o(e,[{key:"setRenderer",value:function(t){return this.renderer=t,this}},{key:"load",value:function(){return Promise.resolve()}},{key:"initialize",value:function(){}},{key:"render",value:function(t){this.renderer.render(this.scene,this.camera)}},{key:"registerOptions",value:function(t){}},{key:"reset",value:function(){return this.scene=new t.Scene,this.camera=null,null!==this.controls&&(this.controls.dispose(),this.controls=null),this.ready=!1,this}}]),e}(),bt=function(t){function e(t){var i;return n(this,e),(i=l(this,s(e).call(this,t))).previousDemo=null,i.demo=null,i}return r(e,t),e}((function t(e){n(this,t),this.type=e,this.target=null})),xt=new bt("change"),kt=new bt("load"),wt=function(e){function i(e){var o,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=r.aside,u=void 0===a?e:a,h=r.renderer;return n(this,i),(o=l(this,s(i).call(this))).renderer=void 0!==h?h:function(){var n=new t.WebGLRenderer;return n.setSize(e.clientWidth,e.clientHeight),n.setPixelRatio(window.devicePixelRatio),n}(),e.appendChild(o.renderer.domElement),o.clock=new t.Clock,o.menu=new gt({autoPlace:!1}),u.appendChild(o.menu.domElement),o.demos=new Map,o.demo=null,o.currentDemo=null,o}return r(i,e),o(i,[{key:"resetMenu",value:function(){var t=this,e=this.menu.domElement.parentNode,n=new gt({autoPlace:!1});this.demos.size>1&&n.add(this,"demo",Array.from(this.demos.keys())).onChange((function(){return t.loadDemo()}));return e.removeChild(this.menu.domElement),e.appendChild(n.domElement),this.menu.destroy(),this.menu=n,n}},{key:"startDemo",value:function(t){t.id===this.demo&&(t.initialize(),t.registerOptions(this.resetMenu()),t.ready=!0,kt.demo=t,this.dispatchEvent(kt))}},{key:"loadDemo",value:function(){var t=this,e=this.demos.get(this.demo),n=this.currentDemo,i=this.renderer;window.location.hash=e.id,null!==n&&n.reset(),this.menu.domElement.style.display="none",xt.previousDemo=n,xt.demo=e,this.currentDemo=e,this.dispatchEvent(xt),i.clear(),e.load().then((function(){return t.startDemo(e)})).catch(console.error)}},{key:"addDemo",value:function(t){var e=window.location.hash.slice(1),n=this.currentDemo;return this.demos.set(t.id,t.setRenderer(this.renderer)),(null===this.demo&&0===e.length||t.id===e)&&(this.demo=t.id,this.loadDemo()),this.resetMenu(),null!==n&&n.ready&&n.registerOptions(this.menu),this}},{key:"removeDemo",value:function(t){var e,n=this.demos;return n.has(t)&&(n.delete(t),this.demo===t&&n.size>0?(e=n.entries().next().value,this.demo=e[0],this.currentDemo=e[1],this.loadDemo()):(this.demo=null,this.currentDemo=null,this.renderer.clear())),this}},{key:"setSize",value:function(e,n,i){var o=this.currentDemo;if(this.renderer.setSize(e,n,i),null!==o&&null!==o.camera){var r=o.camera;r instanceof t.OrthographicCamera?(r.left=e/-2,r.right=e/2,r.top=n/2,r.bottom=n/-2,r.updateProjectionMatrix()):r instanceof t.CubeCamera||(r.aspect=e/n,r.updateProjectionMatrix())}}},{key:"render",value:function(t){var e=this.currentDemo,n=this.clock.getDelta();null!==e&&e.ready&&e.render(n)}}]),i}(c),At=0,Et=1,St=2,Ct=3,Mt=4,zt=5,Ot=6,Pt=7,Tt=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n(this,t),this.x=e,this.y=i,this.z=o}return o(t,[{key:"set",value:function(t,e,n){return this.x=t,this.y=e,this.z=n,this}},{key:"copy",value:function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}},{key:"clone",value:function(){return new this.constructor(this.x,this.y,this.z)}},{key:"fromArray",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}},{key:"toArray",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}},{key:"setFromSpherical",value:function(t){this.setFromSphericalCoords(t.radius,t.phi,t.theta)}},{key:"setFromSphericalCoords",value:function(t,e,n){var i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this}},{key:"setFromCylindrical",value:function(t){this.setFromCylindricalCoords(t.radius,t.theta,t.y)}},{key:"setFromCylindricalCoords",value:function(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this}},{key:"setFromMatrixColumn",value:function(t,e){return this.fromArray(t.elements,4*e)}},{key:"setFromMatrixPosition",value:function(t){var e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}},{key:"setFromMatrixScale",value:function(t){var e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=i,this}},{key:"add",value:function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}},{key:"addScalar",value:function(t){return this.x+=t,this.y+=t,this.z+=t,this}},{key:"addVectors",value:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}},{key:"addScaledVector",value:function(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}},{key:"sub",value:function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}},{key:"subScalar",value:function(t){return this.x-=t,this.y-=t,this.z-=t,this}},{key:"subVectors",value:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}},{key:"multiply",value:function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}},{key:"multiplyScalar",value:function(t){return this.x*=t,this.y*=t,this.z*=t,this}},{key:"multiplyVectors",value:function(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}},{key:"divide",value:function(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}},{key:"divideScalar",value:function(t){return this.x/=t,this.y/=t,this.z/=t,this}},{key:"crossVectors",value:function(t,e){var n=t.x,i=t.y,o=t.z,r=e.x,s=e.y,a=e.z;return this.x=i*a-o*s,this.y=o*r-n*a,this.z=n*s-i*r,this}},{key:"cross",value:function(t){return this.crossVectors(this,t)}},{key:"transformDirection",value:function(t){var e=this.x,n=this.y,i=this.z,o=t.elements;return this.x=o[0]*e+o[4]*n+o[8]*i,this.y=o[1]*e+o[5]*n+o[9]*i,this.z=o[2]*e+o[6]*n+o[10]*i,this.normalize()}},{key:"applyMatrix3",value:function(t){var e=this.x,n=this.y,i=this.z,o=t.elements;return this.x=o[0]*e+o[3]*n+o[6]*i,this.y=o[1]*e+o[4]*n+o[7]*i,this.z=o[2]*e+o[5]*n+o[8]*i,this}},{key:"applyMatrix4",value:function(t){var e=this.x,n=this.y,i=this.z,o=t.elements;return this.x=o[0]*e+o[4]*n+o[8]*i+o[12],this.y=o[1]*e+o[5]*n+o[9]*i+o[13],this.z=o[2]*e+o[6]*n+o[10]*i+o[14],this}},{key:"applyQuaternion",value:function(t){var e=this.x,n=this.y,i=this.z,o=t.x,r=t.y,s=t.z,a=t.w,l=a*e+r*i-s*n,u=a*n+s*e-o*i,h=a*i+o*n-r*e,c=-o*e-r*n-s*i;return this.x=l*a+c*-o+u*-s-h*-r,this.y=u*a+c*-r+h*-o-l*-s,this.z=h*a+c*-s+l*-r-u*-o,this}},{key:"negate",value:function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}},{key:"dot",value:function(t){return this.x*t.x+this.y*t.y+this.z*t.z}},{key:"reflect",value:function(t){var e=t.x,n=t.y,i=t.z;return this.sub(t.multiplyScalar(2*this.dot(t))),t.set(e,n,i),this}},{key:"angleTo",value:function(t){var e=this.dot(t)/Math.sqrt(this.lengthSquared()*t.lengthSquared());return Math.acos(Math.min(Math.max(e,-1),1))}},{key:"manhattanLength",value:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}},{key:"lengthSquared",value:function(){return this.x*this.x+this.y*this.y+this.z*this.z}},{key:"length",value:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}},{key:"manhattanDistanceTo",value:function(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}},{key:"distanceToSquared",value:function(t){var e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i}},{key:"distanceTo",value:function(t){return Math.sqrt(this.distanceToSquared(t))}},{key:"normalize",value:function(){return this.divideScalar(this.length())}},{key:"setLength",value:function(t){return this.normalize().multiplyScalar(t)}},{key:"min",value:function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}},{key:"max",value:function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}},{key:"clamp",value:function(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}},{key:"floor",value:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}},{key:"ceil",value:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}},{key:"round",value:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}},{key:"lerp",value:function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}},{key:"lerpVectors",value:function(t,e,n){return this.subVectors(e,t).multiplyScalar(n).add(t)}},{key:"equals",value:function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}}]),t}(),Lt=new Tt,Dt=[new Tt,new Tt,new Tt,new Tt,new Tt,new Tt,new Tt,new Tt],Ft=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Tt(1/0,1/0,1/0),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Tt(-1/0,-1/0,-1/0);n(this,t),this.min=e,this.max=i}return o(t,[{key:"set",value:function(t,e){return this.min.copy(t),this.max.copy(e),this}},{key:"copy",value:function(t){return this.min.copy(t.min),this.max.copy(t.max),this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}},{key:"makeEmpty",value:function(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this}},{key:"isEmpty",value:function(){return this.max.x0&&void 0!==arguments[0]?arguments[0]:new Tt;return this.isEmpty()?t.set(0,0,0):t.addVectors(this.min,this.max).multiplyScalar(.5)}},{key:"getSize",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Tt;return this.isEmpty()?t.set(0,0,0):t.subVectors(this.max,this.min)}},{key:"setFromSphere",value:function(t){return this.set(t.center,t.center),this.expandByScalar(t.radius),this}},{key:"expandByPoint",value:function(t){return this.min.min(t),this.max.max(t),this}},{key:"expandByVector",value:function(t){return this.min.sub(t),this.max.add(t),this}},{key:"expandByScalar",value:function(t){return this.min.addScalar(-t),this.max.addScalar(t),this}},{key:"setFromPoints",value:function(t){var e,n;for(this.min.set(0,0,0),this.max.set(0,0,0),e=0,n=t.length;e1&&void 0!==arguments[1]?arguments[1]:new Tt;return e.copy(t).clamp(this.min,this.max)}},{key:"distanceToPoint",value:function(t){return Lt.copy(t).clamp(this.min,this.max).sub(t).length()}},{key:"applyMatrix4",value:function(t){var e=this.min,n=this.max;return this.isEmpty()||(Dt[0].set(e.x,e.y,e.z).applyMatrix4(t),Dt[1].set(e.x,e.y,n.z).applyMatrix4(t),Dt[2].set(e.x,n.y,e.z).applyMatrix4(t),Dt[3].set(e.x,n.y,n.z).applyMatrix4(t),Dt[4].set(n.x,e.y,e.z).applyMatrix4(t),Dt[5].set(n.x,e.y,n.z).applyMatrix4(t),Dt[6].set(n.x,n.y,e.z).applyMatrix4(t),Dt[7].set(n.x,n.y,n.z).applyMatrix4(t),this.setFromPoints(Dt)),this}},{key:"translate",value:function(t){return this.min.add(t),this.max.add(t),this}},{key:"intersect",value:function(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this}},{key:"union",value:function(t){return this.min.min(t.min),this.max.max(t.max),this}},{key:"containsPoint",value:function(t){var e=this.min,n=this.max;return t.x>=e.x&&t.y>=e.y&&t.z>=e.z&&t.x<=n.x&&t.y<=n.y&&t.z<=n.z}},{key:"containsBox",value:function(t){var e=this.min,n=this.max,i=t.min,o=t.max;return e.x<=i.x&&o.x<=n.x&&e.y<=i.y&&o.y<=n.y&&e.z<=i.z&&o.z<=n.z}},{key:"intersectsBox",value:function(t){var e=this.min,n=this.max,i=t.min,o=t.max;return o.x>=e.x&&o.y>=e.y&&o.z>=e.z&&i.x<=n.x&&i.y<=n.y&&i.z<=n.z}},{key:"intersectsSphere",value:function(t){return this.clampPoint(t.center,Lt).distanceToSquared(t.center)<=t.radius*t.radius}},{key:"intersectsPlane",value:function(t){var e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant}},{key:"equals",value:function(t){return t.min.equals(this.min)&&t.max.equals(this.max)}}]),t}(),Rt=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;n(this,t),this.x=e,this.y=i}return o(t,[{key:"set",value:function(t,e){return this.x=t,this.y=e,this}},{key:"copy",value:function(t){return this.x=t.x,this.y=t.y,this}},{key:"clone",value:function(){return new this.constructor(this.x,this.y)}},{key:"fromArray",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.x=t[e],this.y=t[e+1],this}},{key:"toArray",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return t[e]=this.x,t[e+1]=this.y,t}},{key:"add",value:function(t){return this.x+=t.x,this.y+=t.y,this}},{key:"addScalar",value:function(t){return this.x+=t,this.y+=t,this}},{key:"addVectors",value:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}},{key:"addScaledVector",value:function(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}},{key:"sub",value:function(t){return this.x-=t.x,this.y-=t.y,this}},{key:"subScalar",value:function(t){return this.x-=t,this.y-=t,this}},{key:"subVectors",value:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}},{key:"multiply",value:function(t){return this.x*=t.x,this.y*=t.y,this}},{key:"multiplyScalar",value:function(t){return this.x*=t,this.y*=t,this}},{key:"divide",value:function(t){return this.x/=t.x,this.y/=t.y,this}},{key:"divideScalar",value:function(t){return this.x/=t,this.y/=t,this}},{key:"applyMatrix3",value:function(t){var e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this}},{key:"dot",value:function(t){return this.x*t.x+this.y*t.y}},{key:"cross",value:function(t){return this.x*t.y-this.y*t.x}},{key:"manhattanLength",value:function(){return Math.abs(this.x)+Math.abs(this.y)}},{key:"lengthSquared",value:function(){return this.x*this.x+this.y*this.y}},{key:"length",value:function(){return Math.sqrt(this.x*this.x+this.y*this.y)}},{key:"manhattanDistanceTo",value:function(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}},{key:"distanceToSquared",value:function(t){var e=this.x-t.x,n=this.y-t.y;return e*e+n*n}},{key:"distanceTo",value:function(t){return Math.sqrt(this.distanceToSquared(t))}},{key:"normalize",value:function(){return this.divideScalar(this.length())}},{key:"setLength",value:function(t){return this.normalize().multiplyScalar(t)}},{key:"min",value:function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}},{key:"max",value:function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}},{key:"clamp",value:function(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}},{key:"floor",value:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}},{key:"ceil",value:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}},{key:"round",value:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}},{key:"negate",value:function(){return this.x=-this.x,this.y=-this.y,this}},{key:"angle",value:function(){var t=Math.atan2(this.y,this.x);return t<0&&(t+=2*Math.PI),t}},{key:"lerp",value:function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}},{key:"lerpVectors",value:function(t,e,n){return this.subVectors(e,t).multiplyScalar(n).add(t)}},{key:"rotateAround",value:function(t,e){var n=Math.cos(e),i=Math.sin(e),o=this.x-t.x,r=this.y-t.y;return this.x=o*n-r*i+t.x,this.y=o*i+r*n+t.y,this}},{key:"equals",value:function(t){return t.x===this.x&&t.y===this.y}},{key:"width",get:function(){return this.x},set:function(t){return this.x=t}},{key:"height",get:function(){return this.y},set:function(t){return this.y=t}}]),t}(),Bt="XYZ",Nt="YZX",Ht="ZXY",Vt="XZY",jt="YXZ",Ut="ZYX",It=new Tt,qt=new Tt,Gt=new Tt,Xt=function(){function t(){n(this,t),this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return o(t,[{key:"set",value:function(t,e,n,i,o,r,s,a,l,u,h,c,d,f,m,p){var y=this.elements;return y[0]=t,y[4]=e,y[8]=n,y[12]=i,y[1]=o,y[5]=r,y[9]=s,y[13]=a,y[2]=l,y[6]=u,y[10]=h,y[14]=c,y[3]=d,y[7]=f,y[11]=m,y[15]=p,this}},{key:"identity",value:function(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this}},{key:"copy",value:function(t){var e=t.elements,n=this.elements;return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],n[9]=e[9],n[10]=e[10],n[11]=e[11],n[12]=e[12],n[13]=e[13],n[14]=e[14],n[15]=e[15],this}},{key:"clone",value:function(){return(new this.constructor).fromArray(this.elements)}},{key:"fromArray",value:function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=this.elements;for(e=0;e<16;++e)i[e]=t[e+n];return this}},{key:"toArray",value:function(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,i=this.elements;for(t=0;t<16;++t)e[t+n]=i[t];return e}},{key:"getMaxScaleOnAxis",value:function(){var t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,i))}},{key:"copyPosition",value:function(t){var e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this}},{key:"setPosition",value:function(t){var e=this.elements;return e[12]=t.x,e[13]=t.y,e[14]=t.z,this}},{key:"extractBasis",value:function(t,e,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this}},{key:"makeBasis",value:function(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this}},{key:"extractRotation",value:function(t){var e=this.elements,n=t.elements,i=1/It.setFromMatrixColumn(t,0).length(),o=1/It.setFromMatrixColumn(t,1).length(),r=1/It.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*o,e[5]=n[5]*o,e[6]=n[6]*o,e[7]=0,e[8]=n[8]*r,e[9]=n[9]*r,e[10]=n[10]*r,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this}},{key:"makeRotationFromEuler",value:function(t){var e,n,i,o,r,s,a,l,u,h,c,d,f=this.elements,m=t.x,p=t.y,y=t.z,v=Math.cos(m),g=Math.sin(m),_=Math.cos(p),b=Math.sin(p),x=Math.cos(y),k=Math.sin(y);switch(t.order){case Bt:e=v*x,n=v*k,i=g*x,o=g*k,f[0]=_*x,f[4]=-_*k,f[8]=b,f[1]=n+i*b,f[5]=e-o*b,f[9]=-g*_,f[2]=o-e*b,f[6]=i+n*b,f[10]=v*_;break;case jt:r=_*x,s=_*k,a=b*x,l=b*k,f[0]=r+l*g,f[4]=a*g-s,f[8]=v*b,f[1]=v*k,f[5]=v*x,f[9]=-g,f[2]=s*g-a,f[6]=l+r*g,f[10]=v*_;break;case Ht:r=_*x,s=_*k,a=b*x,l=b*k,f[0]=r-l*g,f[4]=-v*k,f[8]=a+s*g,f[1]=s+a*g,f[5]=v*x,f[9]=l-r*g,f[2]=-v*b,f[6]=g,f[10]=v*_;break;case Ut:e=v*x,n=v*k,i=g*x,o=g*k,f[0]=_*x,f[4]=i*b-n,f[8]=e*b+o,f[1]=_*k,f[5]=o*b+e,f[9]=n*b-i,f[2]=-b,f[6]=g*_,f[10]=v*_;break;case Nt:u=v*_,h=v*b,c=g*_,d=g*b,f[0]=_*x,f[4]=d-u*k,f[8]=c*k+h,f[1]=k,f[5]=v*x,f[9]=-g*x,f[2]=-b*x,f[6]=h*k+c,f[10]=u-d*k;break;case Vt:u=v*_,h=v*b,c=g*_,d=g*b,f[0]=_*x,f[4]=-k,f[8]=b*x,f[1]=u*k+d,f[5]=v*x,f[9]=h*k-c,f[2]=c*k-h,f[6]=g*x,f[10]=d*k+u}return f[3]=0,f[7]=0,f[11]=0,f[12]=0,f[13]=0,f[14]=0,f[15]=1,this}},{key:"makeRotationFromQuaternion",value:function(t){return this.compose(It.set(0,0,0),t,qt.set(1,1,1))}},{key:"lookAt",value:function(t,e,n){var i=this.elements,o=It,r=qt,s=Gt;return s.subVectors(t,e),0===s.lengthSquared()&&(s.z=1),s.normalize(),o.crossVectors(n,s),0===o.lengthSquared()&&(1===Math.abs(n.z)?s.x+=1e-4:s.z+=1e-4,s.normalize(),o.crossVectors(n,s)),o.normalize(),r.crossVectors(s,o),i[0]=o.x,i[4]=r.x,i[8]=s.x,i[1]=o.y,i[5]=r.y,i[9]=s.y,i[2]=o.z,i[6]=r.z,i[10]=s.z,this}},{key:"multiplyMatrices",value:function(t,e){var n=this.elements,i=t.elements,o=e.elements,r=i[0],s=i[4],a=i[8],l=i[12],u=i[1],h=i[5],c=i[9],d=i[13],f=i[2],m=i[6],p=i[10],y=i[14],v=i[3],g=i[7],_=i[11],b=i[15],x=o[0],k=o[4],w=o[8],A=o[12],E=o[1],S=o[5],C=o[9],M=o[13],z=o[2],O=o[6],P=o[10],T=o[14],L=o[3],D=o[7],F=o[11],R=o[15];return n[0]=r*x+s*E+a*z+l*L,n[4]=r*k+s*S+a*O+l*D,n[8]=r*w+s*C+a*P+l*F,n[12]=r*A+s*M+a*T+l*R,n[1]=u*x+h*E+c*z+d*L,n[5]=u*k+h*S+c*O+d*D,n[9]=u*w+h*C+c*P+d*F,n[13]=u*A+h*M+c*T+d*R,n[2]=f*x+m*E+p*z+y*L,n[6]=f*k+m*S+p*O+y*D,n[10]=f*w+m*C+p*P+y*F,n[14]=f*A+m*M+p*T+y*R,n[3]=v*x+g*E+_*z+b*L,n[7]=v*k+g*S+_*O+b*D,n[11]=v*w+g*C+_*P+b*F,n[15]=v*A+g*M+_*T+b*R,this}},{key:"multiply",value:function(t){return this.multiplyMatrices(this,t)}},{key:"premultiply",value:function(t){return this.multiplyMatrices(t,this)}},{key:"multiplyScalar",value:function(t){var e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this}},{key:"determinant",value:function(){var t=this.elements,e=t[0],n=t[4],i=t[8],o=t[12],r=t[1],s=t[5],a=t[9],l=t[13],u=t[2],h=t[6],c=t[10],d=t[14],f=e*s,m=e*a,p=e*l,y=n*r,v=n*a,g=n*l,_=i*r,b=i*s,x=i*l,k=o*r,w=o*s,A=o*a;return t[3]*(A*h-x*h-w*c+g*c+b*d-v*d)+t[7]*(m*d-p*c+k*c-_*d+x*u-A*u)+t[11]*(p*h-f*d-k*h+y*d+w*u-g*u)+t[15]*(-b*u-m*h+f*c+_*h-y*c+v*u)}},{key:"getInverse",value:function(t){var e,n=this.elements,i=t.elements,o=i[0],r=i[1],s=i[2],a=i[3],l=i[4],u=i[5],h=i[6],c=i[7],d=i[8],f=i[9],m=i[10],p=i[11],y=i[12],v=i[13],g=i[14],_=i[15],b=f*g*c-v*m*c+v*h*p-u*g*p-f*h*_+u*m*_,x=y*m*c-d*g*c-y*h*p+l*g*p+d*h*_-l*m*_,k=d*v*c-y*f*c+y*u*p-l*v*p-d*u*_+l*f*_,w=y*f*h-d*v*h-y*u*m+l*v*m+d*u*g-l*f*g,A=o*b+r*x+s*k+a*w;return 0!==A?(e=1/A,n[0]=b*e,n[1]=(v*m*a-f*g*a-v*s*p+r*g*p+f*s*_-r*m*_)*e,n[2]=(u*g*a-v*h*a+v*s*c-r*g*c-u*s*_+r*h*_)*e,n[3]=(f*h*a-u*m*a-f*s*c+r*m*c+u*s*p-r*h*p)*e,n[4]=x*e,n[5]=(d*g*a-y*m*a+y*s*p-o*g*p-d*s*_+o*m*_)*e,n[6]=(y*h*a-l*g*a-y*s*c+o*g*c+l*s*_-o*h*_)*e,n[7]=(l*m*a-d*h*a+d*s*c-o*m*c-l*s*p+o*h*p)*e,n[8]=k*e,n[9]=(y*f*a-d*v*a-y*r*p+o*v*p+d*r*_-o*f*_)*e,n[10]=(l*v*a-y*u*a+y*r*c-o*v*c-l*r*_+o*u*_)*e,n[11]=(d*u*a-l*f*a-d*r*c+o*f*c+l*r*p-o*u*p)*e,n[12]=w*e,n[13]=(d*v*s-y*f*s+y*r*m-o*v*m-d*r*g+o*f*g)*e,n[14]=(y*u*s-l*v*s-y*r*h+o*v*h+l*r*g-o*u*g)*e,n[15]=(l*f*s-d*u*s+d*r*h-o*f*h-l*r*m+o*u*m)*e):(console.error("Can't invert matrix, determinant is zero",t),this.identity()),this}},{key:"transpose",value:function(){var t,e=this.elements;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this}},{key:"scale",value:function(t,e,n){var i=this.elements;return i[0]*=t,i[4]*=e,i[8]*=n,i[1]*=t,i[5]*=e,i[9]*=n,i[2]*=t,i[6]*=e,i[10]*=n,i[3]*=t,i[7]*=e,i[11]*=n,this}},{key:"makeScale",value:function(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this}},{key:"makeTranslation",value:function(t,e,n){return this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this}},{key:"makeRotationX",value:function(t){var e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this}},{key:"makeRotationY",value:function(t){var e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this}},{key:"makeRotationZ",value:function(t){var e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this}},{key:"makeRotationAxis",value:function(t,e){var n=Math.cos(e),i=Math.sin(e),o=1-n,r=t.x,s=t.y,a=t.z,l=o*r,u=o*s;return this.set(l*r+n,l*s-i*a,l*a+i*s,0,l*s+i*a,u*s+n,u*a-i*r,0,l*a-i*s,u*a+i*r,o*a*a+n,0,0,0,0,1),this}},{key:"makeShear",value:function(t,e,n){return this.set(1,e,n,0,t,1,n,0,t,e,1,0,0,0,0,1),this}},{key:"compose",value:function(t,e,n){var i=this.elements,o=e.x,r=e.y,s=e.z,a=e.w,l=o+o,u=r+r,h=s+s,c=o*l,d=o*u,f=o*h,m=r*u,p=r*h,y=s*h,v=a*l,g=a*u,_=a*h,b=n.x,x=n.y,k=n.z;return i[0]=(1-(m+y))*b,i[1]=(d+_)*b,i[2]=(f-g)*b,i[3]=0,i[4]=(d-_)*x,i[5]=(1-(c+y))*x,i[6]=(p+v)*x,i[7]=0,i[8]=(f+g)*k,i[9]=(p-v)*k,i[10]=(1-(c+m))*k,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this}},{key:"decompose",value:function(t,e,n){var i=this.elements,o=i[0],r=i[1],s=i[2],a=i[4],l=i[5],u=i[6],h=i[8],c=i[9],d=i[10],f=this.determinant(),m=It.set(o,r,s).length()*(f<0?-1:1),p=It.set(a,l,u).length(),y=It.set(h,c,d).length(),v=1/m,g=1/p,_=1/y;return t.x=i[12],t.y=i[13],t.z=i[14],i[0]*=v,i[1]*=v,i[2]*=v,i[4]*=g,i[5]*=g,i[6]*=g,i[8]*=_,i[9]*=_,i[10]*=_,e.setFromRotationMatrix(this),i[0]=o,i[1]=r,i[2]=s,i[4]=a,i[5]=l,i[6]=u,i[8]=h,i[9]=c,i[10]=d,n.x=m,n.y=p,n.z=y,this}},{key:"makePerspective",value:function(t,e,n,i,o,r){var s=this.elements,a=2*o/(e-t),l=2*o/(n-i),u=(e+t)/(e-t),h=(n+i)/(n-i),c=-(r+o)/(r-o),d=-2*r*o/(r-o);return s[0]=a,s[4]=0,s[8]=u,s[12]=0,s[1]=0,s[5]=l,s[9]=h,s[13]=0,s[2]=0,s[6]=0,s[10]=c,s[14]=d,s[3]=0,s[7]=0,s[11]=-1,s[15]=0,this}},{key:"makeOrthographic",value:function(t,e,n,i,o,r){var s=this.elements,a=1/(e-t),l=1/(n-i),u=1/(r-o),h=(e+t)*a,c=(n+i)*l,d=(r+o)*u;return s[0]=2*a,s[4]=0,s[8]=0,s[12]=-h,s[1]=0,s[5]=2*l,s[9]=0,s[13]=-c,s[2]=0,s[6]=0,s[10]=-2*u,s[14]=-d,s[3]=0,s[7]=0,s[11]=0,s[15]=1,this}},{key:"equals",value:function(t){var e,n=this.elements,i=t.elements,o=!0;for(e=0;o&&e<16;++e)n[e]!==i[e]&&(o=!1);return o}}]),t}(),Wt=[new Tt,new Tt,new Tt,new Tt],Yt=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Tt,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Tt;n(this,t),this.origin=e,this.direction=i}return o(t,[{key:"set",value:function(t,e){return this.origin.copy(t),this.direction.copy(e),this}},{key:"copy",value:function(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}},{key:"at",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Tt;return e.copy(this.direction).multiplyScalar(t).add(this.origin)}},{key:"lookAt",value:function(t){return this.direction.copy(t).sub(this.origin).normalize(),this}},{key:"recast",value:function(t){return this.origin.copy(this.at(t,Wt[0])),this}},{key:"closestPointToPoint",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Tt,n=e.subVectors(t,this.origin).dot(this.direction);return n>=0?e.copy(this.direction).multiplyScalar(n).add(this.origin):e.copy(this.origin)}},{key:"distanceSquaredToPoint",value:function(t){var e=Wt[0].subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):Wt[0].copy(this.direction).multiplyScalar(e).add(this.origin).distanceToSquared(t)}},{key:"distanceToPoint",value:function(t){return Math.sqrt(this.distanceSquaredToPoint(t))}},{key:"distanceToPlane",value:function(t){var e=t.normal.dot(this.direction),n=0!==e?-(this.origin.dot(t.normal)+t.constant)/e:0===t.distanceToPoint(this.origin)?0:-1;return n>=0?n:null}},{key:"distanceSquaredToSegment",value:function(t,e,n,i){var o,r,s,a,l,u=Wt[0].copy(t).add(e).multiplyScalar(.5),h=Wt[1].copy(e).sub(t).normalize(),c=Wt[2].copy(this.origin).sub(u),d=.5*t.distanceTo(e),f=-this.direction.dot(h),m=c.dot(this.direction),p=-c.dot(h),y=c.lengthSq(),v=Math.abs(1-f*f);return v>0?(r=f*m-p,s=d*v,(o=f*p-m)>=0?r>=-s?r<=s?l=(o*=a=1/v)*(o+f*(r*=a)+2*m)+r*(f*o+r+2*p)+y:(r=d,l=-(o=Math.max(0,-(f*r+m)))*o+r*(r+2*p)+y):(r=-d,l=-(o=Math.max(0,-(f*r+m)))*o+r*(r+2*p)+y):r<=-s?l=-(o=Math.max(0,-(-f*d+m)))*o+(r=o>0?-d:Math.min(Math.max(-d,-p),d))*(r+2*p)+y:r<=s?(o=0,l=(r=Math.min(Math.max(-d,-p),d))*(r+2*p)+y):l=-(o=Math.max(0,-(f*d+m)))*o+(r=o>0?d:Math.min(Math.max(-d,-p),d))*(r+2*p)+y):(r=f>0?-d:d,l=-(o=Math.max(0,-(f*r+m)))*o+r*(r+2*p)+y),void 0!==n&&n.copy(this.direction).multiplyScalar(o).add(this.origin),void 0!==i&&i.copy(h).multiplyScalar(r).add(u),l}},{key:"intersectSphere",value:function(t){var e,n,i,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Tt,r=Wt[0].subVectors(t.center,this.origin),s=r.dot(this.direction),a=r.dot(r)-s*s,l=t.radius*t.radius,u=null;return a<=l&&(i=s+(e=Math.sqrt(l-a)),((n=s-e)>=0||i>=0)&&(u=n<0?this.at(i,o):this.at(n,o))),u}},{key:"intersectsSphere",value:function(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius}},{key:"intersectPlane",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Tt,n=this.distanceToPlane(t);return null===n?null:this.at(n,e)}},{key:"intersectsPlane",value:function(t){var e=t.distanceToPoint(this.origin);return 0===e||t.normal.dot(this.direction)*e<0}},{key:"intersectBox",value:function(t){var e,n,i,o,r,s,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Tt,l=this.origin,u=this.direction,h=t.min,c=t.max,d=1/u.x,f=1/u.y,m=1/u.z,p=null;return d>=0?(e=(h.x-l.x)*d,n=(c.x-l.x)*d):(e=(c.x-l.x)*d,n=(h.x-l.x)*d),f>=0?(i=(h.y-l.y)*f,o=(c.y-l.y)*f):(i=(c.y-l.y)*f,o=(h.y-l.y)*f),e<=o&&i<=n&&((i>e||e!=e)&&(e=i),(o=0?(r=(h.z-l.z)*m,s=(c.z-l.z)*m):(r=(c.z-l.z)*m,s=(h.z-l.z)*m),e<=s&&r<=n&&((r>e||e!=e)&&(e=r),(s=0&&(p=this.at(e>=0?e:n,a)))),p}},{key:"intersectsBox",value:function(t){return null!==this.intersectBox(t,Wt[0])}},{key:"intersectTriangle",value:function(t,e,n,i,o){var r,s,a,l,u,h=this.direction,c=Wt[0],d=Wt[1],f=Wt[2],m=Wt[3],p=null;return d.subVectors(e,t),f.subVectors(n,t),m.crossVectors(d,f),0===(r=h.dot(m))||i&&r>0||(r>0?s=1:(s=-1,r=-r),c.subVectors(this.origin,t),(a=s*h.dot(f.crossVectors(c,f)))>=0&&(l=s*h.dot(d.cross(c)))>=0&&a+l<=r&&(u=-s*c.dot(m))>=0&&(p=this.at(u/r,o))),p}},{key:"applyMatrix4",value:function(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this}},{key:"equals",value:function(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}}]),t}(),Kt=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n(this,t),this.radius=e,this.phi=i,this.theta=o}return o(t,[{key:"set",value:function(t,e,n){return this.radius=t,this.phi=e,this.theta=n,this}},{key:"copy",value:function(t){return this.radius=t.radius,this.phi=t.phi,this.theta=t.theta,this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}},{key:"makeSafe",value:function(){return this.phi=Math.max(1e-6,Math.min(Math.PI-1e-6,this.phi)),this}},{key:"setFromVector3",value:function(t){return this.setFromCartesianCoords(t.x,t.y,t.z)}},{key:"setFromCartesianCoords",value:function(t,e,n){return this.radius=Math.sqrt(t*t+e*e+n*n),0===this.radius?(this.theta=0,this.phi=0):(this.theta=Math.atan2(t,n),this.phi=Math.acos(Math.min(Math.max(e/this.radius,-1),1))),this}}]),t}(),Qt=0,Jt=1,Zt=2,$t=2*Math.PI,te=new Tt,ee=new Xt,ne=function(){function t(e,i,o,r){n(this,t),this.position=e,this.quaternion=i,this.target=o,this.settings=r,this.spherical=new Kt}return o(t,[{key:"setPosition",value:function(t){return this.position=t,this}},{key:"setQuaternion",value:function(t){return this.quaternion=t,this}},{key:"setTarget",value:function(t){return this.target=t,this}},{key:"updateQuaternion",value:function(){var t=this.settings,e=t.rotation;return t.general.orbit?ee.lookAt(te.subVectors(this.position,this.target),e.pivotOffset,e.up):ee.lookAt(te.set(0,0,0),this.target.setFromSpherical(this.spherical),e.up),this.quaternion.setFromRotationMatrix(ee),this}},{key:"adjustSpherical",value:function(t,e){var n=this.settings,i=n.general.orbit,o=n.rotation,r=this.spherical;return r.theta=o.invertX?r.theta+t:r.theta-t,r.phi=!i&&!o.invertY||i&&o.invertY?r.phi+e:r.phi-e,r.theta=Math.min(Math.max(r.theta,o.minAzimuthalAngle),o.maxAzimuthalAngle),r.phi=Math.min(Math.max(r.phi,o.minPolarAngle),o.maxPolarAngle),r.theta%=$t,r.makeSafe(),i&&this.position.setFromSpherical(r).add(this.target),this}},{key:"zoom",value:function(t){var e,n,i,o=this.settings,r=o.general,s=o.sensitivity,a=o.zoom,l=this.spherical;return r.orbit&&a.enabled&&(e=t*s.zoom,a.invert&&(e=-e),n=Math.max(a.minDistance,1e-6),i=Math.min(a.maxDistance,1/0),l.radius=Math.min(Math.max(l.radius+e,n),i),this.position.setFromSpherical(l).add(this.target)),this}},{key:"update",value:function(t){}},{key:"lookAt",value:function(t){var e=this.spherical,n=this.position,i=this.target;return i.copy(t),this.settings.general.orbit?te.subVectors(n,i):te.subVectors(i,n).normalize(),e.setFromVector3(te),e.radius=Math.max(e.radius,1e-6),this.updateQuaternion(),this}},{key:"getViewDirection",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Tt;return t.setFromSpherical(this.spherical).normalize(),this.settings.general.orbit&&t.negate(),t}}]),t}(),ie=function(){function t(){n(this,t),this.left=!1,this.right=!1,this.forward=!1,this.backward=!1,this.up=!1,this.down=!1}return o(t,[{key:"reset",value:function(){return this.left=!1,this.right=!1,this.forward=!1,this.backward=!1,this.up=!1,this.down=!1,this}}]),t}(),oe=new Tt(1,0,0),re=new Tt(0,1,0),se=new Tt(0,0,1),ae=new Tt,le=function(){function t(e,i,o,r){n(this,t),this.position=e,this.quaternion=i,this.target=o,this.settings=r,this.movementState=new ie}return o(t,[{key:"setPosition",value:function(t){return this.position=t,this}},{key:"setQuaternion",value:function(t){return this.quaternion=t,this}},{key:"setTarget",value:function(t){return this.target=t,this}},{key:"translateOnAxis",value:function(t,e){ae.copy(t).applyQuaternion(this.quaternion).multiplyScalar(e),this.position.add(ae),this.settings.general.orbit&&this.target.add(ae)}},{key:"translate",value:function(t){var e=this.settings.sensitivity,n=this.movementState,i=t*e.translation;n.backward?this.translateOnAxis(se,i):n.forward&&this.translateOnAxis(se,-i),n.right?this.translateOnAxis(oe,i):n.left&&this.translateOnAxis(oe,-i),n.up?this.translateOnAxis(re,i):n.down&&this.translateOnAxis(re,-i)}},{key:"update",value:function(t){this.settings.translation.enabled&&this.translate(t)}},{key:"moveTo",value:function(t){return this.settings.general.orbit?this.target.copy(t):this.position.copy(t),this}}]),t}(),ue=new Proxy({BACKSPACE:8,TAB:9,ENTER:13,SHIFT:16,CTRL:17,ALT:18,PAUSE:19,CAPS_LOCK:20,ESCAPE:27,SPACE:32,PAGE_UP:33,PAGE_DOWN:34,END:35,HOME:36,LEFT:37,UP:38,RIGHT:39,DOWN:40,INSERT:45,DELETE:46,META_LEFT:91,META_RIGHT:92,SELECT:93,NUMPAD_0:96,NUMPAD_1:97,NUMPAD_2:98,NUMPAD_3:99,NUMPAD_4:100,NUMPAD_5:101,NUMPAD_6:102,NUMPAD_7:103,NUMPAD_8:104,NUMPAD_9:105,MULTIPLY:106,ADD:107,SUBTRACT:109,DECIMAL_POINT:110,DIVIDE:111,F1:112,F2:113,F3:114,F4:115,F5:116,F6:117,F7:118,F8:119,F9:120,F10:121,F11:122,F12:123,NUM_LOCK:144,SCROLL_LOCK:145,SEMICOLON:186,EQUAL_SIGN:187,COMMA:188,DASH:189,PERIOD:190,FORWARD_SLASH:191,GRAVE_ACCENT:192,OPEN_BRACKET:219,BACK_SLASH:220,CLOSE_BRACKET:221,SINGLE_QUOTE:222},{get:function(t,e){return e in t?t[e]:1===e.length?e.toUpperCase().charCodeAt(0):void 0}}),he=function(){function t(){n(this,t),this.orbit=!0}return o(t,[{key:"copy",value:function(t){return this.orbit=t.orbit,this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}}]),t}(),ce=function(){function t(){n(this,t),this.defaultActions=new Map,this.actions=new Map}return o(t,[{key:"reset",value:function(){return this.actions=new Map(this.defaultActions),this}},{key:"setDefault",value:function(t){return this.defaultActions=t,this.reset()}},{key:"copy",value:function(t){return this.defaultActions=new Map(t.defaultActions),this.actions=new Map(t.actions),this}},{key:"clearDefault",value:function(){return this.defaultActions.clear(),this}},{key:"clear",value:function(){return this.actions.clear(),this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}},{key:"has",value:function(t){return this.actions.has(t)}},{key:"get",value:function(t){return this.actions.get(t)}},{key:"set",value:function(t,e){return this.actions.set(t,e),this}},{key:"delete",value:function(t){return this.actions.delete(t)}},{key:"toJSON",value:function(){return{defaultActions:h(this.defaultActions),actions:h(this.actions)}}}]),t}(),de=function(){function t(){n(this,t),this.hold=!1,this.lock=!0}return o(t,[{key:"copy",value:function(t){return this.hold=t.hold,this.lock=t.lock,this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}}]),t}(),fe=function(){function t(){n(this,t),this.up=new Tt,this.up.copy(re),this.pivotOffset=new Tt,this.minAzimuthalAngle=-1/0,this.maxAzimuthalAngle=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.invertX=!1,this.invertY=!1}return o(t,[{key:"copy",value:function(t){return this.up.copy(t.up),this.pivotOffset.copy(t.pivotOffset),this.minAzimuthalAngle=null!==t.minAzimuthalAngle?t.minAzimuthalAngle:-1/0,this.maxAzimuthalAngle=null!==t.maxAzimuthalAngle?t.maxAzimuthalAngle:1/0,this.minPolarAngle=t.minPolarAngle,this.maxPolarAngle=t.maxPolarAngle,this.invertX=t.invertX,this.invertY=t.invertY,this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}}]),t}(),me=function(){function t(){n(this,t),this.rotation=.0025,this.translation=1,this.zoom=.1}return o(t,[{key:"copy",value:function(t){return this.rotation=t.rotation,this.translation=t.translation,this.zoom=t.zoom,this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}}]),t}(),pe=function(){function t(){n(this,t),this.enabled=!0}return o(t,[{key:"copy",value:function(t){return this.enabled=t.enabled,this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}}]),t}(),ye=function(){function t(){n(this,t),this.enabled=!0,this.invert=!1,this.minDistance=1e-6,this.maxDistance=1/0}return o(t,[{key:"copy",value:function(t){return this.enabled=t.enabled,this.invert=t.invert,this.minDistance=t.minDistance,this.maxDistance=t.maxDistance,this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}}]),t}(),ve=function(){function t(){n(this,t),this.general=new he,this.keyBindings=new ce,this.keyBindings.setDefault(new Map([[ue.W,At],[ue.UP,At],[ue.A,Et],[ue.LEFT,Et],[ue.S,St],[ue.DOWN,St],[ue.D,Ct],[ue.RIGHT,Ct],[ue.X,Mt],[ue.SPACE,zt],[ue.PAGE_DOWN,Ot],[ue.PAGE_UP,Pt]])),this.pointer=new de,this.rotation=new fe,this.sensitivity=new me,this.translation=new pe,this.zoom=new ye}return o(t,[{key:"copy",value:function(t){return this.general.copy(t.general),this.keyBindings.copy(t.keyBindings),this.pointer.copy(t.pointer),this.rotation.copy(t.rotation),this.sensitivity.copy(t.sensitivity),this.translation.copy(t.translation),this.zoom.copy(t.zoom),this}},{key:"clone",value:function(){return(new this.constructor).copy(this)}},{key:"toDataURL",value:function(){return URL.createObjectURL(new Blob([JSON.stringify(this)],{type:"text/json"}))}}]),t}(),ge=function(){function t(){n(this,t)}return o(t,[{key:"execute",value:function(t){throw new Error("Strategy#execute method not implemented!")}}]),t}(),_e=function(t){function e(t,i){var o;return n(this,e),(o=l(this,s(e).call(this))).movementState=t,o.direction=i,o}return r(e,t),o(e,[{key:"execute",value:function(t){var e=this.movementState;switch(this.direction){case be.FORWARD:e.forward=t;break;case be.LEFT:e.left=t;break;case be.BACKWARD:e.backward=t;break;case be.RIGHT:e.right=t;break;case be.DOWN:e.down=t;break;case be.UP:e.up=t}}}]),e}(ge),be={FORWARD:0,LEFT:1,BACKWARD:2,RIGHT:3,DOWN:4,UP:5},xe=function(t){function e(t,i){var o;return n(this,e),(o=l(this,s(e).call(this))).rotationManager=t,o.zoomIn=i,o}return r(e,t),o(e,[{key:"execute",value:function(t){t&&this.rotationManager.zoom(this.zoomIn?-1:1)}}]),e}(ge),ke=function(){function t(){var e,i,o,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:document.body;n(this,t),this.dom=a,this.position=r,this.quaternion=s,this.target=new Tt,this.settings=new ve,this.rotationManager=new ne(r,s,this.target,this.settings),this.translationManager=new le(r,s,this.target,this.settings),this.strategies=(e=this.rotationManager,i=this.translationManager,o=i.movementState,new Map([[At,new _e(o,be.FORWARD)],[Et,new _e(o,be.LEFT)],[St,new _e(o,be.BACKWARD)],[Ct,new _e(o,be.RIGHT)],[Mt,new _e(o,be.DOWN)],[zt,new _e(o,be.UP)],[Ot,new xe(e,!1)],[Pt,new xe(e,!0)]])),this.lastScreenPosition=new Rt,this.dragging=!1,this.enabled=!1,null!==r&&null!==s&&(this.lookAt(this.target),null!==a&&this.setEnabled())}return o(t,[{key:"getDom",value:function(){return this.dom}},{key:"getPosition",value:function(){return this.position}},{key:"getQuaternion",value:function(){return this.quaternion}},{key:"getTarget",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Tt;return t.copy(this.target),this.settings.general.orbit||t.add(this.position),t}},{key:"getViewDirection",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Tt;return this.rotationManager.getViewDirection(t)}},{key:"setDom",value:function(t){var e=this.enabled;return null!==t&&(e&&this.setEnabled(!1),this.dom=t,this.setEnabled(e)),this}},{key:"setPosition",value:function(t){return this.position=t,this.rotationManager.setPosition(t),this.translationManager.setPosition(t),this.lookAt(this.target)}},{key:"setQuaternion",value:function(t){return this.quaternion=t,this.rotationManager.setQuaternion(t),this.translationManager.setQuaternion(t),this.lookAt(this.target)}},{key:"setTarget",value:function(t){return this.target=t,this.rotationManager.setTarget(t),this.translationManager.setTarget(t),this.lookAt(this.target)}},{key:"setOrbitEnabled",value:function(t){var e=this.settings.general;return e.orbit!==t&&(this.getTarget(this.target),e.orbit=t,this.lookAt(this.target)),this}},{key:"copy",value:function(t){return this.dom=t.getDom(),this.position=t.getPosition(),this.quaternion=t.getQuaternion(),this.target=t.getTarget(),this.settings.copy(t.settings),this.rotationManager.setPosition(this.position).setQuaternion(this.quaternion).setTarget(this.target),this.translationManager.setPosition(this.position).setQuaternion(this.quaternion).setTarget(this.target),this.lookAt(this.target)}},{key:"clone",value:function(){return(new this.constructor).copy(this)}},{key:"handlePointerMoveEvent",value:function(t){var e,n,i=this.settings,o=i.pointer,r=i.sensitivity,s=this.rotationManager,a=this.lastScreenPosition;document.pointerLockElement===this.dom?o.hold&&!this.dragging||s.adjustSpherical(t.movementX*r.rotation,t.movementY*r.rotation).updateQuaternion():(e=t.screenX-a.x,n=t.screenY-a.y,a.set(t.screenX,t.screenY),s.adjustSpherical(e*r.rotation,n*r.rotation).updateQuaternion())}},{key:"handleTouchMoveEvent",value:function(t){var e=this.settings.sensitivity,n=this.rotationManager,i=this.lastScreenPosition,o=t.touches[0],r=o.screenX-i.x,s=o.screenY-i.y;i.set(o.screenX,o.screenY),t.preventDefault(),n.adjustSpherical(r*e.rotation,s*e.rotation).updateQuaternion()}},{key:"handleMainPointerButton",value:function(t,e){this.dragging=e,this.settings.pointer.lock?this.setPointerLocked():e?(this.lastScreenPosition.set(t.screenX,t.screenY),this.dom.addEventListener("mousemove",this)):this.dom.removeEventListener("mousemove",this)}},{key:"handleAuxiliaryPointerButton",value:function(t,e){}},{key:"handleSecondaryPointerButton",value:function(t,e){}},{key:"handlePointerButtonEvent",value:function(t,e){switch(t.preventDefault(),t.button){case Qt:this.handleMainPointerButton(t,e);break;case Jt:this.handleAuxiliaryPointerButton(t,e);break;case Zt:this.handleSecondaryPointerButton(t,e)}}},{key:"handleTouchEvent",value:function(t,e){var n=t.touches[0];t.preventDefault(),e?(this.lastScreenPosition.set(n.screenX,n.screenY),this.dom.addEventListener("touchmove",this)):this.dom.removeEventListener("touchmove",this)}},{key:"handleKeyboardEvent",value:function(t,e){var n=this.settings.keyBindings;n.has(t.keyCode)&&(t.preventDefault(),this.strategies.get(n.get(t.keyCode)).execute(e))}},{key:"handleWheelEvent",value:function(t){this.rotationManager.zoom(Math.sign(t.deltaY))}},{key:"handlePointerLockEvent",value:function(){document.pointerLockElement===this.dom?this.dom.addEventListener("mousemove",this):this.dom.removeEventListener("mousemove",this)}},{key:"handleEvent",value:function(t){switch(t.type){case"mousemove":this.handlePointerMoveEvent(t);break;case"touchmove":this.handleTouchMoveEvent(t);break;case"mousedown":this.handlePointerButtonEvent(t,!0);break;case"mouseup":this.handlePointerButtonEvent(t,!1);break;case"touchstart":this.handleTouchEvent(t,!0);break;case"touchend":this.handleTouchEvent(t,!1);break;case"keydown":this.handleKeyboardEvent(t,!0);break;case"keyup":this.handleKeyboardEvent(t,!1);break;case"wheel":this.handleWheelEvent(t);break;case"pointerlockchange":this.handlePointerLockEvent()}}},{key:"update",value:function(t){this.rotationManager.update(t),this.translationManager.update(t)}},{key:"moveTo",value:function(t){return this.rotationManager.moveTo(t),this}},{key:"lookAt",value:function(t){return this.rotationManager.lookAt(t),this}},{key:"setPointerLocked",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];t?document.pointerLockElement!==this.dom&&void 0!==this.dom.requestPointerLock&&this.dom.requestPointerLock():void 0!==document.exitPointerLock&&document.exitPointerLock()}},{key:"setEnabled",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0],e=this.dom;return this.translationManager.movementState.reset(),t&&!this.enabled?(document.addEventListener("pointerlockchange",this),document.body.addEventListener("keyup",this),document.body.addEventListener("keydown",this),e.addEventListener("mousedown",this),e.addEventListener("mouseup",this),e.addEventListener("touchstart",this),e.addEventListener("touchend",this),e.addEventListener("wheel",this)):!t&&this.enabled&&(document.removeEventListener("pointerlockchange",this),document.body.removeEventListener("keyup",this),document.body.removeEventListener("keydown",this),e.removeEventListener("mousedown",this),e.removeEventListener("mouseup",this),e.removeEventListener("touchstart",this),e.removeEventListener("touchend",this),e.removeEventListener("wheel",this),e.removeEventListener("mousemove",this),e.removeEventListener("touchmove",this)),this.setPointerLocked(!1),this.enabled=t,this}},{key:"dispose",value:function(){this.setEnabled(!1)}}]),t}(),we=[new Uint8Array([0,4]),new Uint8Array([1,5]),new Uint8Array([2,6]),new Uint8Array([3,7]),new Uint8Array([0,2]),new Uint8Array([1,3]),new Uint8Array([4,6]),new Uint8Array([5,7]),new Uint8Array([0,1]),new Uint8Array([2,3]),new Uint8Array([4,5]),new Uint8Array([6,7])],Ae=[new Uint8Array([0,0,0]),new Uint8Array([0,0,1]),new Uint8Array([0,1,0]),new Uint8Array([0,1,1]),new Uint8Array([1,0,0]),new Uint8Array([1,0,1]),new Uint8Array([1,1,0]),new Uint8Array([1,1,1])],Ee=function(e){function i(){var t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;return n(this,i),(t=l(this,s(i).call(this))).name="OctreeHelper",t.octree=e,t.update(),t}return r(i,e),o(i,[{key:"createLineSegments",value:function(e,n){var i,o,r,s,a,l,u,h,c,d,f,m,p,y,v,g,_=Math.pow(2,16)/8-1,b=new t.Group,x=new t.LineBasicMaterial({color:16777215*Math.random()});for(d=0,r=0,y=Math.ceil(n/_);y>0;--y){for(r+=n<_?n:_,n-=_,o=8*r,s=new Uint16Array(3*o),a=new Float32Array(3*o),m=0,p=0,i=e.next();!i.done&&d0;)t.remove(e[0])}for(;s.length>0;)this.remove(s[0])}}]),i}(t.Group),Se=[new Uint8Array([0,0,0]),new Uint8Array([0,0,1]),new Uint8Array([0,1,0]),new Uint8Array([0,1,1]),new Uint8Array([1,0,0]),new Uint8Array([1,0,1]),new Uint8Array([1,1,0]),new Uint8Array([1,1,1])],Ce=new Tt,Me=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Tt,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Tt;n(this,t),this.min=e,this.max=i,this.children=null}return o(t,[{key:"getCenter",value:function(t){return t.addVectors(this.min,this.max).multiplyScalar(.5)}},{key:"getDimensions",value:function(t){return t.subVectors(this.max,this.min)}},{key:"split",value:function(){var t,e,n=this.min,i=this.max,o=this.getCenter(Ce),r=this.children=[null,null,null,null,null,null,null,null];for(t=0;t<8;++t)e=Se[t],r[t]=new this.constructor(new Tt(0===e[0]?n.x:o.x,0===e[1]?n.y:o.y,0===e[2]?n.z:o.z),new Tt(0===e[0]?o.x:i.x,0===e[1]?o.y:i.y,0===e[2]?o.z:i.z))}}]),t}(),ze=function t(e,i,o){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;n(this,t),this.distance=e,this.distanceToRay=i,this.point=o,this.object=r};function Oe(t,e,n){var i,o,r,s,a,l,u,h,c,d,f,m=e.params.Points.threshold,p=m*m;for(a=0,u=t.length;a=e.near&&o<=e.far&&(r=Math.sqrt(s),n.push(new ze(o,r,i,c.data[l]))))}var Pe=[new Uint8Array([4,2,1]),new Uint8Array([5,3,8]),new Uint8Array([6,8,3]),new Uint8Array([7,8,8]),new Uint8Array([8,6,5]),new Uint8Array([8,7,8]),new Uint8Array([8,8,7]),new Uint8Array([8,8,8])];function Te(t,e,n,i){var o,r=0;return e=0&&r>=0&&s>=0){var l=t.children;if(null===l)a.push(t);else{var u=.5*(e+o),h=.5*(n+r),c=.5*(i+s),d=Ne.value,f=function(t,e,n,i,o,r){var s=0;return t>e&&t>n?(on?(i2&&void 0!==arguments[2]?arguments[2]:[],i=Be(t,e,Ne);null!==i&&He.apply(void 0,[t.root].concat(h(i),[n]))}}]),t}(),je=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];n(this,t),this.value=e,this.done=i}return o(t,[{key:"reset",value:function(){this.value=null,this.done=!1}}]),t}(),Ue=new Ft,Ie=function(){function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;n(this,t),this.octree=e,this.region=i,this.cull=null!==i,this.result=new je,this.trace=null,this.indices=null,this.reset()}return o(t,[{key:"reset",value:function(){var t=this.octree.root;return this.trace=[],this.indices=[],null!==t&&(Ue.min=t.min,Ue.max=t.max,this.cull&&!this.region.intersectsBox(Ue)||(this.trace.push(t),this.indices.push(0))),this.result.reset(),this}},{key:"next",value:function(){for(var t,e,n,i=this.cull,o=this.region,r=this.indices,s=this.trace,a=null,l=s.length-1;null===a&&l>=0;)if(t=r[l]++,e=s[l].children,t<8)if(null!==e){if(n=e[t],i&&(Ue.min=n.min,Ue.max=n.max,!o.intersectsBox(Ue)))continue;s.push(n),r.push(0),++l}else a=s.pop(),r.pop();else s.pop(),r.pop(),--l;return this.result.value=a,this.result.done=null===a,this.result}},{key:"return",value:function(t){return this.result.value=t,this.result.done=!0,this.result}},{key:Symbol.iterator,value:function(){return this}}]),t}(),qe=new Ft;var Ge=function(){function t(e){n(this,t),this.root=e}return o(t,[{key:"getCenter",value:function(t){return this.root.getCenter(t)}},{key:"getDimensions",value:function(t){return this.root.getDimensions(t)}},{key:"cull",value:function(t){var e=[];return function t(e,n,i){var o,r,s=e.children;if(qe.min=e.min,qe.max=e.max,n.intersectsBox(qe))if(null!==s)for(o=0,r=s.length;os&&(s=o);return s}(this.root)}},{key:"findNodesByLevel",value:function(t){var e=[];return function t(e,n,i,o){var r,s,a=e.children;if(i===n)o.push(e);else if(null!==a)for(++i,r=0,s=a.length;r1&&void 0!==arguments[1]?arguments[1]:[];return Ve.intersectOctree(this,t.ray,e),e}},{key:"leaves",value:function(t){return new Ie(this,t)}},{key:Symbol.iterator,value:function(){return new Ie(this)}},{key:"min",get:function(){return this.root.min}},{key:"max",get:function(){return this.root.max}},{key:"children",get:function(){return this.root.children}}]),t}(),Xe=new Tt,We=function(t){function e(t,i){var o;return n(this,e),(o=l(this,s(e).call(this,t,i))).points=null,o.data=null,o}return r(e,t),o(e,[{key:"distanceToSquared",value:function(t){return Xe.copy(t).clamp(this.min,this.max).sub(t).lengthSquared()}},{key:"distanceToCenterSquared",value:function(t){var e=this.getCenter(Xe),n=t.x-e.x,i=t.y-e.x,o=t.z-e.z;return n*n+i*i+o*o}},{key:"contains",value:function(t,e){var n=this.min,i=this.max;return t.x>=n.x-e&&t.y>=n.y-e&&t.z>=n.z-e&&t.x<=i.x+e&&t.y<=i.y+e&&t.z<=i.z+e}},{key:"redistribute",value:function(t){var e,n,i,o,r,s,a,l=this.children,u=this.points,h=this.data;if(null!==l&&null!==u){for(e=0,i=u.length;e=0&&(s={point:d[f],data:i.data[f],distance:a})}return s}function Ze(t,e,n,i,o){var r,s,a,l=i.children;if(null!==l)for(r=0,s=l.length;r2&&void 0!==arguments[2]?arguments[2]:0,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:8,u=arguments.length>4&&void 0!==arguments[4]?arguments[4]:8;return n(this,e),(o=l(this,s(e).call(this,new We(t,i)))).bias=Math.max(0,r),o.maxPoints=Math.max(1,Math.round(a)),o.maxDepth=Math.max(0,Math.round(u)),o.pointCount=0,o}return r(e,t),o(e,[{key:"countPoints",value:function(t){return Ye(t)}},{key:"insert",value:function(t,e){return Ke(t,e,this,this.root,0)}},{key:"remove",value:function(t){return Qe(t,this,this.root,null)}},{key:"get",value:function(t){return function t(e,n,i){var o,r,s,a=i.children,l=null;if(i.contains(e,n.bias))if(null!==a)for(o=0,r=a.length;null===l&&o1&&void 0!==arguments[1]?arguments[1]:1/0,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=Je(t,e,n,this.root);return null!==i&&(i.point=i.point.clone()),i}},{key:"findPoints",value:function(t,e){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=[];return Ze(t,e,n,this.root,i),i}},{key:"raycast",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],i=u(s(e.prototype),"raycast",this).call(this,t);return i.length>0&&Oe(i,t,n),n}}]),e}(Ge),en=new t.Vector2,nn=function(e){function i(e,o,r){var a;return n(this,i),(a=l(this,s(i).call(this))).params.Points.threshold=.1,a.octree=e,a.camera=o,a.object=r,a.enabled=!0,a.delta="",a.selectedObject=null,a.selectedPoint=new t.Mesh(new t.SphereBufferGeometry(.2,16,16),new t.MeshBasicMaterial({transparent:!0,color:52479,opacity:.75})),a.selectedPoint.visible=!1,a}return r(i,e),o(i,[{key:"handleEvent",value:function(t){switch(t.type){case"mousemove":this.raycast(t)}}},{key:"raycast",value:function(t){var e,n,i,o;en.x=t.clientX/window.innerWidth*2-1,en.y=-t.clientY/window.innerHeight*2+1,this.setFromCamera(en,this.camera),this.enabled?(n=performance.now(),e=this.octree.raycast(this),i=performance.now()):(n=performance.now(),e=this.intersectObjects(this.object.children),i=performance.now()),this.delta=(i-n).toFixed(2)+" ms",null!==this.selectedObject&&(this.selectedObject.material.color.setHex(12582912),this.selectedObject=null,this.selectedPoint.visible=!1),e.length>0&&(void 0!==(o=e[0]).object?(this.selectedObject=o.object,this.selectedObject.material.color.setHex(13434624),this.selectedPoint.visible=o.object.parent.visible,this.selectedPoint.position.copy(o.point)):console.warn(e))}},{key:"registerOptions",value:function(t){var e=t.addFolder("Raycasting");e.add(this,"enabled"),e.add(this,"delta").listen(),e.open()}}]),i}(t.Raycaster),on=new t.Matrix4,rn=new t.Frustum,sn=function(){function e(i,o){n(this,e),this.octree=i,this.scene=o,this.enabled=!1,this.cullCamera=new t.PerspectiveCamera(20,1.77,.5,5),this.s=new t.Spherical(5,Math.PI/3,1.75*Math.PI),this.delta="",this.culledOctants=new t.Points(new t.BufferGeometry,new t.PointsMaterial({color:13434624,sizeAttenuation:!1,size:2})),this.culledOctants.visible=!1,this.cameraHelper=new t.CameraHelper(this.cullCamera),this.cameraHelper.visible=!1}return o(e,[{key:"updateCamera",value:function(){var t=this.cullCamera;t.position.setFromSpherical(this.s),t.lookAt(this.scene.position),t.updateMatrixWorld(!0),rn.setFromMatrix(on.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse))}},{key:"cull",value:function(){var e,n,i,o,r,s,a,l=this.culledOctants;if(this.enabled)if(this.updateCamera(),e=performance.now(),s=this.octree.cull(rn),this.delta=(performance.now()-e).toFixed(2)+" ms",s.length>0){for(a=new Float32Array(3*s.length*2),n=0,i=0,o=s.length;n0;)n=new t.Points(e(65536,6,s,.25),a),a=a.clone(),s+=r,i.add(n);return i}();this.points=r,e.add(r);var s=function(n){var i=new t.Vector3,o=new t.Box3;o.setFromObject(e);var r,s,a,l,u,h=performance.now(),c=new tn(o.min,o.max,0,8,5);for(r=n.children.length-1;r>=0;--r)for(a=0,l=(u=(s=n.children[r]).geometry.getAttribute("position").array).length;a0?1:+t}),"name"in Function.prototype==!1&&Object.defineProperty(Function.prototype,"name",{get:function(){return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1]}}),void 0===Object.assign&&(Object.assign=function(t){var e=arguments;if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var n=Object(t),i=1;i>8&255]+N[t>>16&255]+N[t>>24&255]+"-"+N[255&e]+N[e>>8&255]+"-"+N[e>>16&15|64]+N[e>>24&255]+"-"+N[63&n|128]+N[n>>8&255]+"-"+N[n>>16&255]+N[n>>24&255]+N[255&i]+N[i>>8&255]+N[i>>16&255]+N[i>>24&255]).toUpperCase()},clamp:function(t,e,n){return Math.max(e,Math.min(n,t))},euclideanModulo:function(t,e){return(t%e+e)%e},mapLinear:function(t,e,n,i,r){return i+(t-e)*(r-i)/(n-e)},lerp:function(t,e,n){return(1-n)*t+n*e},smoothstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-e))*t*(3-2*t)},smootherstep:function(t,e,n){return t<=e?0:t>=n?1:(t=(t-e)/(n-e))*t*t*(t*(6*t-15)+10)},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},seededRandom:function(t){return void 0!==t&&(z=t%2147483647),((z=16807*z%2147483647)-1)/2147483646},degToRad:function(t){return t*B.DEG2RAD},radToDeg:function(t){return t*B.RAD2DEG},isPowerOfTwo:function(t){return 0==(t&t-1)&&0!==t},ceilPowerOfTwo:function(t){return Math.pow(2,Math.ceil(Math.log(t)/Math.LN2))},floorPowerOfTwo:function(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))},setQuaternionFromProperEuler:function(t,e,n,i,r){var a=Math.cos,o=Math.sin,s=a(n/2),c=o(n/2),h=a((e+i)/2),l=o((e+i)/2),u=a((e-i)/2),d=o((e-i)/2),p=a((i-e)/2),f=o((i-e)/2);switch(r){case"XYX":t.set(s*l,c*u,c*d,s*h);break;case"YZY":t.set(c*d,s*l,c*u,s*h);break;case"ZXZ":t.set(c*u,c*d,s*l,s*h);break;case"XZX":t.set(s*l,c*f,c*p,s*h);break;case"YXY":t.set(c*p,s*l,c*f,s*h);break;case"ZYZ":t.set(c*f,c*p,s*l,s*h);break;default:console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: "+r)}}};function U(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.x=t,this.y=e}function F(){this.elements=[1,0,0,0,1,0,0,0,1],arguments.length>0&&console.error("THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.")}Object.defineProperties(U.prototype,{width:{get:function(){return this.x},set:function(t){this.x=t}},height:{get:function(){return this.y},set:function(t){this.y=t}}}),Object.assign(U.prototype,{isVector2:!0,set:function(t,e){return this.x=t,this.y=e,this},setScalar:function(t){return this.x=t,this.y=t,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setComponent:function(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this},getComponent:function(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}},clone:function(){return new this.constructor(this.x,this.y)},copy:function(t){return this.x=t.x,this.y=t.y,this},add:function(t,e){return void 0!==e?(console.warn("THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(t,e)):(this.x+=t.x,this.y+=t.y,this)},addScalar:function(t){return this.x+=t,this.y+=t,this},addVectors:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this},addScaledVector:function(t,e){return this.x+=t.x*e,this.y+=t.y*e,this},sub:function(t,e){return void 0!==e?(console.warn("THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(t,e)):(this.x-=t.x,this.y-=t.y,this)},subScalar:function(t){return this.x-=t,this.y-=t,this},subVectors:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this},multiply:function(t){return this.x*=t.x,this.y*=t.y,this},multiplyScalar:function(t){return this.x*=t,this.y*=t,this},divide:function(t){return this.x/=t.x,this.y/=t.y,this},divideScalar:function(t){return this.multiplyScalar(1/t)},applyMatrix3:function(t){var e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this},min:function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this},max:function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this},clamp:function(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this},clampScalar:function(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this},clampLength:function(t,e){var n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))},floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this},negate:function(){return this.x=-this.x,this.y=-this.y,this},dot:function(t){return this.x*t.x+this.y*t.y},cross:function(t){return this.x*t.y-this.y*t.x},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},manhattanLength:function(){return Math.abs(this.x)+Math.abs(this.y)},normalize:function(){return this.divideScalar(this.length()||1)},angle:function(){return Math.atan2(-this.y,-this.x)+Math.PI},distanceTo:function(t){return Math.sqrt(this.distanceToSquared(t))},distanceToSquared:function(t){var e=this.x-t.x,n=this.y-t.y;return e*e+n*n},manhattanDistanceTo:function(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)},setLength:function(t){return this.normalize().multiplyScalar(t)},lerp:function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this},lerpVectors:function(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this},equals:function(t){return t.x===this.x&&t.y===this.y},fromArray:function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t},fromBufferAttribute:function(t,e,n){return void 0!==n&&console.warn("THREE.Vector2: offset has been removed from .fromBufferAttribute()."),this.x=t.getX(e),this.y=t.getY(e),this},rotateAround:function(t,e){var n=Math.cos(e),i=Math.sin(e),r=this.x-t.x,a=this.y-t.y;return this.x=r*n-a*i+t.x,this.y=r*i+a*n+t.y,this},random:function(){return this.x=Math.random(),this.y=Math.random(),this}}),Object.assign(F.prototype,{isMatrix3:!0,set:function(t,e,n,i,r,a,o,s,c){var h=this.elements;return h[0]=t,h[1]=i,h[2]=o,h[3]=e,h[4]=r,h[5]=s,h[6]=n,h[7]=a,h[8]=c,this},identity:function(){return this.set(1,0,0,0,1,0,0,0,1),this},clone:function(){return(new this.constructor).fromArray(this.elements)},copy:function(t){var e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this},extractBasis:function(t,e,n){return t.setFromMatrix3Column(this,0),e.setFromMatrix3Column(this,1),n.setFromMatrix3Column(this,2),this},setFromMatrix4:function(t){var e=t.elements;return this.set(e[0],e[4],e[8],e[1],e[5],e[9],e[2],e[6],e[10]),this},multiply:function(t){return this.multiplyMatrices(this,t)},premultiply:function(t){return this.multiplyMatrices(t,this)},multiplyMatrices:function(t,e){var n=t.elements,i=e.elements,r=this.elements,a=n[0],o=n[3],s=n[6],c=n[1],h=n[4],l=n[7],u=n[2],d=n[5],p=n[8],f=i[0],m=i[3],v=i[6],g=i[1],y=i[4],x=i[7],_=i[2],b=i[5],w=i[8];return r[0]=a*f+o*g+s*_,r[3]=a*m+o*y+s*b,r[6]=a*v+o*x+s*w,r[1]=c*f+h*g+l*_,r[4]=c*m+h*y+l*b,r[7]=c*v+h*x+l*w,r[2]=u*f+d*g+p*_,r[5]=u*m+d*y+p*b,r[8]=u*v+d*x+p*w,this},multiplyScalar:function(t){var e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this},determinant:function(){var t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],a=t[4],o=t[5],s=t[6],c=t[7],h=t[8];return e*a*h-e*o*c-n*r*h+n*o*s+i*r*c-i*a*s},getInverse:function(t,e){void 0!==e&&console.warn("THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate.");var n=t.elements,i=this.elements,r=n[0],a=n[1],o=n[2],s=n[3],c=n[4],h=n[5],l=n[6],u=n[7],d=n[8],p=d*c-h*u,f=h*l-d*s,m=u*s-c*l,v=r*p+a*f+o*m;if(0===v)return this.set(0,0,0,0,0,0,0,0,0);var g=1/v;return i[0]=p*g,i[1]=(o*u-d*a)*g,i[2]=(h*a-o*c)*g,i[3]=f*g,i[4]=(d*r-o*l)*g,i[5]=(o*s-h*r)*g,i[6]=m*g,i[7]=(a*l-u*r)*g,i[8]=(c*r-a*s)*g,this},transpose:function(){var t,e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this},getNormalMatrix:function(t){return this.setFromMatrix4(t).getInverse(this).transpose()},transposeIntoArray:function(t){var e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this},setUvTransform:function(t,e,n,i,r,a,o){var s=Math.cos(r),c=Math.sin(r);this.set(n*s,n*c,-n*(s*a+c*o)+a+t,-i*c,i*s,-i*(-c*a+s*o)+o+e,0,0,1)},scale:function(t,e){var n=this.elements;return n[0]*=t,n[3]*=t,n[6]*=t,n[1]*=e,n[4]*=e,n[7]*=e,this},rotate:function(t){var e=Math.cos(t),n=Math.sin(t),i=this.elements,r=i[0],a=i[3],o=i[6],s=i[1],c=i[4],h=i[7];return i[0]=e*r+n*s,i[3]=e*a+n*c,i[6]=e*o+n*h,i[1]=-n*r+e*s,i[4]=-n*a+e*c,i[7]=-n*o+e*h,this},translate:function(t,e){var n=this.elements;return n[0]+=t*n[2],n[3]+=t*n[5],n[6]+=t*n[8],n[1]+=e*n[2],n[4]+=e*n[5],n[7]+=e*n[8],this},equals:function(t){for(var e=this.elements,n=t.elements,i=0;i<9;i++)if(e[i]!==n[i])return!1;return!0},fromArray:function(t,e){void 0===e&&(e=0);for(var n=0;n<9;n++)this.elements[n]=t[n+e];return this},toArray:function(t,e){void 0===t&&(t=[]),void 0===e&&(e=0);var n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t}});var k={getDataURL:function(t){if(/^data:/i.test(t.src))return t.src;if("undefined"==typeof HTMLCanvasElement)return t.src;var e;if(t instanceof HTMLCanvasElement)e=t;else{void 0===I&&(I=document.createElementNS("http://www.w3.org/1999/xhtml","canvas")),I.width=t.width,I.height=t.height;var n=I.getContext("2d");t instanceof ImageData?n.putImageData(t,0,0):n.drawImage(t,0,0,t.width,t.height),e=I}return e.width>2048||e.height>2048?e.toDataURL("image/jpeg",.6):e.toDataURL("image/png")}},H=0;function G(t,e,n,i,a,o,s,c,d,p){Object.defineProperty(this,"id",{value:H++}),this.uuid=B.generateUUID(),this.name="",this.image=void 0!==t?t:G.DEFAULT_IMAGE,this.mipmaps=[],this.mapping=void 0!==e?e:G.DEFAULT_MAPPING,this.wrapS=void 0!==n?n:r,this.wrapT=void 0!==i?i:r,this.magFilter=void 0!==a?a:h,this.minFilter=void 0!==o?o:l,this.anisotropy=void 0!==d?d:1,this.format=void 0!==s?s:y,this.internalFormat=null,this.type=void 0!==c?c:u,this.offset=new U(0,0),this.repeat=new U(1,1),this.center=new U(0,0),this.rotation=0,this.matrixAutoUpdate=!0,this.matrix=new F,this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this.encoding=void 0!==p?p:L,this.version=0,this.onUpdate=null}function V(t,e,n,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=1),this.x=t,this.y=e,this.z=n,this.w=i}function j(t,e,n){this.width=t,this.height=e,this.scissor=new V(0,0,t,e),this.scissorTest=!1,this.viewport=new V(0,0,t,e),n=n||{},this.texture=new G(void 0,n.mapping,n.wrapS,n.wrapT,n.magFilter,n.minFilter,n.format,n.type,n.anisotropy,n.encoding),this.texture.image={},this.texture.image.width=t,this.texture.image.height=e,this.texture.generateMipmaps=void 0!==n.generateMipmaps&&n.generateMipmaps,this.texture.minFilter=void 0!==n.minFilter?n.minFilter:h,this.depthBuffer=void 0===n.depthBuffer||n.depthBuffer,this.stencilBuffer=void 0===n.stencilBuffer||n.stencilBuffer,this.depthTexture=void 0!==n.depthTexture?n.depthTexture:null}function W(t,e,n){j.call(this,t,e,n),this.samples=4}function q(t,e,n,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=1),this._x=t,this._y=e,this._z=n,this._w=i}G.DEFAULT_IMAGE=void 0,G.DEFAULT_MAPPING=300,G.prototype=Object.assign(Object.create(O.prototype),{constructor:G,isTexture:!0,updateMatrix:function(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y)},clone:function(){return(new this.constructor).copy(this)},copy:function(t){return this.name=t.name,this.image=t.image,this.mipmaps=t.mipmaps.slice(0),this.mapping=t.mapping,this.wrapS=t.wrapS,this.wrapT=t.wrapT,this.magFilter=t.magFilter,this.minFilter=t.minFilter,this.anisotropy=t.anisotropy,this.format=t.format,this.internalFormat=t.internalFormat,this.type=t.type,this.offset.copy(t.offset),this.repeat.copy(t.repeat),this.center.copy(t.center),this.rotation=t.rotation,this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrix.copy(t.matrix),this.generateMipmaps=t.generateMipmaps,this.premultiplyAlpha=t.premultiplyAlpha,this.flipY=t.flipY,this.unpackAlignment=t.unpackAlignment,this.encoding=t.encoding,this},toJSON:function(t){var e=void 0===t||"string"==typeof t;if(!e&&void 0!==t.textures[this.uuid])return t.textures[this.uuid];var n={metadata:{version:4.5,type:"Texture",generator:"Texture.toJSON"},uuid:this.uuid,name:this.name,mapping:this.mapping,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,type:this.type,encoding:this.encoding,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};if(void 0!==this.image){var i=this.image;if(void 0===i.uuid&&(i.uuid=B.generateUUID()),!e&&void 0===t.images[i.uuid]){var r;if(Array.isArray(i)){r=[];for(var a=0,o=i.length;a1)switch(this.wrapS){case i:t.x=t.x-Math.floor(t.x);break;case r:t.x=t.x<0?0:1;break;case a:1===Math.abs(Math.floor(t.x)%2)?t.x=Math.ceil(t.x)-t.x:t.x=t.x-Math.floor(t.x)}if(t.y<0||t.y>1)switch(this.wrapT){case i:t.y=t.y-Math.floor(t.y);break;case r:t.y=t.y<0?0:1;break;case a:1===Math.abs(Math.floor(t.y)%2)?t.y=Math.ceil(t.y)-t.y:t.y=t.y-Math.floor(t.y)}return this.flipY&&(t.y=1-t.y),t}}),Object.defineProperty(G.prototype,"needsUpdate",{set:function(t){!0===t&&this.version++}}),Object.defineProperties(V.prototype,{width:{get:function(){return this.z},set:function(t){this.z=t}},height:{get:function(){return this.w},set:function(t){this.w=t}}}),Object.assign(V.prototype,{isVector4:!0,set:function(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.w=i,this},setScalar:function(t){return this.x=t,this.y=t,this.z=t,this.w=t,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setZ:function(t){return this.z=t,this},setW:function(t){return this.w=t,this},setComponent:function(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}return this},getComponent:function(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error("index is out of range: "+t)}},clone:function(){return new this.constructor(this.x,this.y,this.z,this.w)},copy:function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this},add:function(t,e){return void 0!==e?(console.warn("THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(t,e)):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this)},addScalar:function(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this},addVectors:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this},addScaledVector:function(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this.w+=t.w*e,this},sub:function(t,e){return void 0!==e?(console.warn("THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(t,e)):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this)},subScalar:function(t){return this.x-=t,this.y-=t,this.z-=t,this.w-=t,this},subVectors:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this},multiplyScalar:function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},applyMatrix4:function(t){var e=this.x,n=this.y,i=this.z,r=this.w,a=t.elements;return this.x=a[0]*e+a[4]*n+a[8]*i+a[12]*r,this.y=a[1]*e+a[5]*n+a[9]*i+a[13]*r,this.z=a[2]*e+a[6]*n+a[10]*i+a[14]*r,this.w=a[3]*e+a[7]*n+a[11]*i+a[15]*r,this},divideScalar:function(t){return this.multiplyScalar(1/t)},setAxisAngleFromQuaternion:function(t){this.w=2*Math.acos(t.w);var e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this},setAxisAngleFromRotationMatrix:function(t){var e,n,i,r,a=.01,o=.1,s=t.elements,c=s[0],h=s[4],l=s[8],u=s[1],d=s[5],p=s[9],f=s[2],m=s[6],v=s[10];if(Math.abs(h-u)y&&g>x?gx?y=0?1:-1,y=1-v*v;if(y>Number.EPSILON){var x=Math.sqrt(y),_=Math.atan2(x,v*g);m=Math.sin(m*_)/x,o=Math.sin(o*_)/x}var b=o*g;if(s=s*m+u*b,c=c*m+d*b,h=h*m+p*b,l=l*m+f*b,m===1-o){var w=1/Math.sqrt(s*s+c*c+h*h+l*l);s*=w,c*=w,h*=w,l*=w}}t[e]=s,t[e+1]=c,t[e+2]=h,t[e+3]=l},multiplyQuaternionsFlat:function(t,e,n,i,r,a){var o=n[i],s=n[i+1],c=n[i+2],h=n[i+3],l=r[a],u=r[a+1],d=r[a+2],p=r[a+3];return t[e]=o*p+h*l+s*d-c*u,t[e+1]=s*p+h*u+c*l-o*d,t[e+2]=c*p+h*d+o*u-s*l,t[e+3]=h*p-o*l-s*u-c*d,t}}),Object.defineProperties(q.prototype,{x:{get:function(){return this._x},set:function(t){this._x=t,this._onChangeCallback()}},y:{get:function(){return this._y},set:function(t){this._y=t,this._onChangeCallback()}},z:{get:function(){return this._z},set:function(t){this._z=t,this._onChangeCallback()}},w:{get:function(){return this._w},set:function(t){this._w=t,this._onChangeCallback()}}}),Object.assign(q.prototype,{isQuaternion:!0,set:function(t,e,n,i){return this._x=t,this._y=e,this._z=n,this._w=i,this._onChangeCallback(),this},clone:function(){return new this.constructor(this._x,this._y,this._z,this._w)},copy:function(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this},setFromEuler:function(t,e){if(!t||!t.isEuler)throw new Error("THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.");var n=t._x,i=t._y,r=t._z,a=t.order,o=Math.cos,s=Math.sin,c=o(n/2),h=o(i/2),l=o(r/2),u=s(n/2),d=s(i/2),p=s(r/2);switch(a){case"XYZ":this._x=u*h*l+c*d*p,this._y=c*d*l-u*h*p,this._z=c*h*p+u*d*l,this._w=c*h*l-u*d*p;break;case"YXZ":this._x=u*h*l+c*d*p,this._y=c*d*l-u*h*p,this._z=c*h*p-u*d*l,this._w=c*h*l+u*d*p;break;case"ZXY":this._x=u*h*l-c*d*p,this._y=c*d*l+u*h*p,this._z=c*h*p+u*d*l,this._w=c*h*l-u*d*p;break;case"ZYX":this._x=u*h*l-c*d*p,this._y=c*d*l+u*h*p,this._z=c*h*p-u*d*l,this._w=c*h*l+u*d*p;break;case"YZX":this._x=u*h*l+c*d*p,this._y=c*d*l+u*h*p,this._z=c*h*p-u*d*l,this._w=c*h*l-u*d*p;break;case"XZY":this._x=u*h*l-c*d*p,this._y=c*d*l-u*h*p,this._z=c*h*p+u*d*l,this._w=c*h*l+u*d*p;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return!1!==e&&this._onChangeCallback(),this},setFromAxisAngle:function(t,e){var n=e/2,i=Math.sin(n);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(n),this._onChangeCallback(),this},setFromRotationMatrix:function(t){var e=t.elements,n=e[0],i=e[4],r=e[8],a=e[1],o=e[5],s=e[9],c=e[2],h=e[6],l=e[10],u=n+o+l;if(u>0){var d=.5/Math.sqrt(u+1);this._w=.25/d,this._x=(h-s)*d,this._y=(r-c)*d,this._z=(a-i)*d}else if(n>o&&n>l){var p=2*Math.sqrt(1+n-o-l);this._w=(h-s)/p,this._x=.25*p,this._y=(i+a)/p,this._z=(r+c)/p}else if(o>l){var f=2*Math.sqrt(1+o-n-l);this._w=(r-c)/f,this._x=(i+a)/f,this._y=.25*f,this._z=(s+h)/f}else{var m=2*Math.sqrt(1+l-n-o);this._w=(a-i)/m,this._x=(r+c)/m,this._y=(s+h)/m,this._z=.25*m}return this._onChangeCallback(),this},setFromUnitVectors:function(t,e){var n=t.dot(e)+1;return n<1e-6?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=n):(this._x=0,this._y=-t.z,this._z=t.y,this._w=n)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=n),this.normalize()},angleTo:function(t){return 2*Math.acos(Math.abs(B.clamp(this.dot(t),-1,1)))},rotateTowards:function(t,e){var n=this.angleTo(t);if(0===n)return this;var i=Math.min(1,e/n);return this.slerp(t,i),this},identity:function(){return this.set(0,0,0,1)},inverse:function(){return this.conjugate()},conjugate:function(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this},dot:function(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w},lengthSq:function(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w},length:function(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)},normalize:function(){var t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this},multiply:function(t,e){return void 0!==e?(console.warn("THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead."),this.multiplyQuaternions(t,e)):this.multiplyQuaternions(this,t)},premultiply:function(t){return this.multiplyQuaternions(t,this)},multiplyQuaternions:function(t,e){var n=t._x,i=t._y,r=t._z,a=t._w,o=e._x,s=e._y,c=e._z,h=e._w;return this._x=n*h+a*o+i*c-r*s,this._y=i*h+a*s+r*o-n*c,this._z=r*h+a*c+n*s-i*o,this._w=a*h-n*o-i*s-r*c,this._onChangeCallback(),this},slerp:function(t,e){if(0===e)return this;if(1===e)return this.copy(t);var n=this._x,i=this._y,r=this._z,a=this._w,o=a*t._w+n*t._x+i*t._y+r*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),o>=1)return this._w=a,this._x=n,this._y=i,this._z=r,this;var s=1-o*o;if(s<=Number.EPSILON){var c=1-e;return this._w=c*a+e*this._w,this._x=c*n+e*this._x,this._y=c*i+e*this._y,this._z=c*r+e*this._z,this.normalize(),this._onChangeCallback(),this}var h=Math.sqrt(s),l=Math.atan2(h,o),u=Math.sin((1-e)*l)/h,d=Math.sin(e*l)/h;return this._w=a*u+this._w*d,this._x=n*u+this._x*d,this._y=i*u+this._y*d,this._z=r*u+this._z*d,this._onChangeCallback(),this},equals:function(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w},fromArray:function(t,e){return void 0===e&&(e=0),this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t},fromBufferAttribute:function(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this},_onChange:function(t){return this._onChangeCallback=t,this},_onChangeCallback:function(){}});var X=new Z,Y=new q;function Z(t,e,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),this.x=t,this.y=e,this.z=n}Object.assign(Z.prototype,{isVector3:!0,set:function(t,e,n){return void 0===n&&(n=this.z),this.x=t,this.y=e,this.z=n,this},setScalar:function(t){return this.x=t,this.y=t,this.z=t,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setZ:function(t){return this.z=t,this},setComponent:function(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this},getComponent:function(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}},clone:function(){return new this.constructor(this.x,this.y,this.z)},copy:function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},add:function(t,e){return void 0!==e?(console.warn("THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(t,e)):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this)},addScalar:function(t){return this.x+=t,this.y+=t,this.z+=t,this},addVectors:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this},addScaledVector:function(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this},sub:function(t,e){return void 0!==e?(console.warn("THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(t,e)):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this)},subScalar:function(t){return this.x-=t,this.y-=t,this.z-=t,this},subVectors:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this},multiply:function(t,e){return void 0!==e?(console.warn("THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead."),this.multiplyVectors(t,e)):(this.x*=t.x,this.y*=t.y,this.z*=t.z,this)},multiplyScalar:function(t){return this.x*=t,this.y*=t,this.z*=t,this},multiplyVectors:function(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this},applyEuler:function(t){return t&&t.isEuler||console.error("THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order."),this.applyQuaternion(Y.setFromEuler(t))},applyAxisAngle:function(t,e){return this.applyQuaternion(Y.setFromAxisAngle(t,e))},applyMatrix3:function(t){var e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*i,this.y=r[1]*e+r[4]*n+r[7]*i,this.z=r[2]*e+r[5]*n+r[8]*i,this},applyNormalMatrix:function(t){return this.applyMatrix3(t).normalize()},applyMatrix4:function(t){var e=this.x,n=this.y,i=this.z,r=t.elements,a=1/(r[3]*e+r[7]*n+r[11]*i+r[15]);return this.x=(r[0]*e+r[4]*n+r[8]*i+r[12])*a,this.y=(r[1]*e+r[5]*n+r[9]*i+r[13])*a,this.z=(r[2]*e+r[6]*n+r[10]*i+r[14])*a,this},applyQuaternion:function(t){var e=this.x,n=this.y,i=this.z,r=t.x,a=t.y,o=t.z,s=t.w,c=s*e+a*i-o*n,h=s*n+o*e-r*i,l=s*i+r*n-a*e,u=-r*e-a*n-o*i;return this.x=c*s+u*-r+h*-o-l*-a,this.y=h*s+u*-a+l*-r-c*-o,this.z=l*s+u*-o+c*-a-h*-r,this},project:function(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)},unproject:function(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)},transformDirection:function(t){var e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i,this.y=r[1]*e+r[5]*n+r[9]*i,this.z=r[2]*e+r[6]*n+r[10]*i,this.normalize()},divide:function(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this},divideScalar:function(t){return this.multiplyScalar(1/t)},min:function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this},max:function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this},clamp:function(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this},clampScalar:function(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this},clampLength:function(t,e){var n=this.length();return this.divideScalar(n||1).multiplyScalar(Math.max(t,Math.min(e,n)))},floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this},negate:function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},dot:function(t){return this.x*t.x+this.y*t.y+this.z*t.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},manhattanLength:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length()||1)},setLength:function(t){return this.normalize().multiplyScalar(t)},lerp:function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this},lerpVectors:function(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this.z=t.z+(e.z-t.z)*n,this},cross:function(t,e){return void 0!==e?(console.warn("THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead."),this.crossVectors(t,e)):this.crossVectors(this,t)},crossVectors:function(t,e){var n=t.x,i=t.y,r=t.z,a=e.x,o=e.y,s=e.z;return this.x=i*s-r*o,this.y=r*a-n*s,this.z=n*o-i*a,this},projectOnVector:function(t){var e=t.lengthSq();if(0===e)return this.set(0,0,0);var n=t.dot(this)/e;return this.copy(t).multiplyScalar(n)},projectOnPlane:function(t){return X.copy(this).projectOnVector(t),this.sub(X)},reflect:function(t){return this.sub(X.copy(t).multiplyScalar(2*this.dot(t)))},angleTo:function(t){var e=Math.sqrt(this.lengthSq()*t.lengthSq());if(0===e)return Math.PI/2;var n=this.dot(t)/e;return Math.acos(B.clamp(n,-1,1))},distanceTo:function(t){return Math.sqrt(this.distanceToSquared(t))},distanceToSquared:function(t){var e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i},manhattanDistanceTo:function(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)},setFromSpherical:function(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)},setFromSphericalCoords:function(t,e,n){var i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this},setFromCylindrical:function(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)},setFromCylindricalCoords:function(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this},setFromMatrixPosition:function(t){var e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this},setFromMatrixScale:function(t){var e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=i,this},setFromMatrixColumn:function(t,e){return this.fromArray(t.elements,4*e)},setFromMatrix3Column:function(t,e){return this.fromArray(t.elements,3*e)},equals:function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z},fromArray:function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this.z=t[e+2],this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t},fromBufferAttribute:function(t,e,n){return void 0!==n&&console.warn("THREE.Vector3: offset has been removed from .fromBufferAttribute()."),this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this},random:function(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}});var J=new Z,Q=new it,K=new Z(0,0,0),$=new Z(1,1,1),tt=new Z,et=new Z,nt=new Z;function it(){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],arguments.length>0&&console.error("THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.")}Object.assign(it.prototype,{isMatrix4:!0,set:function(t,e,n,i,r,a,o,s,c,h,l,u,d,p,f,m){var v=this.elements;return v[0]=t,v[4]=e,v[8]=n,v[12]=i,v[1]=r,v[5]=a,v[9]=o,v[13]=s,v[2]=c,v[6]=h,v[10]=l,v[14]=u,v[3]=d,v[7]=p,v[11]=f,v[15]=m,this},identity:function(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this},clone:function(){return(new it).fromArray(this.elements)},copy:function(t){var e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],e[9]=n[9],e[10]=n[10],e[11]=n[11],e[12]=n[12],e[13]=n[13],e[14]=n[14],e[15]=n[15],this},copyPosition:function(t){var e=this.elements,n=t.elements;return e[12]=n[12],e[13]=n[13],e[14]=n[14],this},extractBasis:function(t,e,n){return t.setFromMatrixColumn(this,0),e.setFromMatrixColumn(this,1),n.setFromMatrixColumn(this,2),this},makeBasis:function(t,e,n){return this.set(t.x,e.x,n.x,0,t.y,e.y,n.y,0,t.z,e.z,n.z,0,0,0,0,1),this},extractRotation:function(t){var e=this.elements,n=t.elements,i=1/J.setFromMatrixColumn(t,0).length(),r=1/J.setFromMatrixColumn(t,1).length(),a=1/J.setFromMatrixColumn(t,2).length();return e[0]=n[0]*i,e[1]=n[1]*i,e[2]=n[2]*i,e[3]=0,e[4]=n[4]*r,e[5]=n[5]*r,e[6]=n[6]*r,e[7]=0,e[8]=n[8]*a,e[9]=n[9]*a,e[10]=n[10]*a,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this},makeRotationFromEuler:function(t){t&&t.isEuler||console.error("THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.");var e=this.elements,n=t.x,i=t.y,r=t.z,a=Math.cos(n),o=Math.sin(n),s=Math.cos(i),c=Math.sin(i),h=Math.cos(r),l=Math.sin(r);if("XYZ"===t.order){var u=a*h,d=a*l,p=o*h,f=o*l;e[0]=s*h,e[4]=-s*l,e[8]=c,e[1]=d+p*c,e[5]=u-f*c,e[9]=-o*s,e[2]=f-u*c,e[6]=p+d*c,e[10]=a*s}else if("YXZ"===t.order){var m=s*h,v=s*l,g=c*h,y=c*l;e[0]=m+y*o,e[4]=g*o-v,e[8]=a*c,e[1]=a*l,e[5]=a*h,e[9]=-o,e[2]=v*o-g,e[6]=y+m*o,e[10]=a*s}else if("ZXY"===t.order){var x=s*h,_=s*l,b=c*h,w=c*l;e[0]=x-w*o,e[4]=-a*l,e[8]=b+_*o,e[1]=_+b*o,e[5]=a*h,e[9]=w-x*o,e[2]=-a*c,e[6]=o,e[10]=a*s}else if("ZYX"===t.order){var M=a*h,S=a*l,E=o*h,T=o*l;e[0]=s*h,e[4]=E*c-S,e[8]=M*c+T,e[1]=s*l,e[5]=T*c+M,e[9]=S*c-E,e[2]=-c,e[6]=o*s,e[10]=a*s}else if("YZX"===t.order){var A=a*s,L=a*c,P=o*s,R=o*c;e[0]=s*h,e[4]=R-A*l,e[8]=P*l+L,e[1]=l,e[5]=a*h,e[9]=-o*h,e[2]=-c*h,e[6]=L*l+P,e[10]=A-R*l}else if("XZY"===t.order){var C=a*s,O=a*c,N=o*s,D=o*c;e[0]=s*h,e[4]=-l,e[8]=c*h,e[1]=C*l+D,e[5]=a*h,e[9]=O*l-N,e[2]=N*l-O,e[6]=o*h,e[10]=D*l+C}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this},makeRotationFromQuaternion:function(t){return this.compose(K,t,$)},lookAt:function(t,e,n){var i=this.elements;return nt.subVectors(t,e),0===nt.lengthSq()&&(nt.z=1),nt.normalize(),tt.crossVectors(n,nt),0===tt.lengthSq()&&(1===Math.abs(n.z)?nt.x+=1e-4:nt.z+=1e-4,nt.normalize(),tt.crossVectors(n,nt)),tt.normalize(),et.crossVectors(nt,tt),i[0]=tt.x,i[4]=et.x,i[8]=nt.x,i[1]=tt.y,i[5]=et.y,i[9]=nt.y,i[2]=tt.z,i[6]=et.z,i[10]=nt.z,this},multiply:function(t,e){return void 0!==e?(console.warn("THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead."),this.multiplyMatrices(t,e)):this.multiplyMatrices(this,t)},premultiply:function(t){return this.multiplyMatrices(t,this)},multiplyMatrices:function(t,e){var n=t.elements,i=e.elements,r=this.elements,a=n[0],o=n[4],s=n[8],c=n[12],h=n[1],l=n[5],u=n[9],d=n[13],p=n[2],f=n[6],m=n[10],v=n[14],g=n[3],y=n[7],x=n[11],_=n[15],b=i[0],w=i[4],M=i[8],S=i[12],E=i[1],T=i[5],A=i[9],L=i[13],P=i[2],R=i[6],C=i[10],O=i[14],N=i[3],D=i[7],I=i[11],z=i[15];return r[0]=a*b+o*E+s*P+c*N,r[4]=a*w+o*T+s*R+c*D,r[8]=a*M+o*A+s*C+c*I,r[12]=a*S+o*L+s*O+c*z,r[1]=h*b+l*E+u*P+d*N,r[5]=h*w+l*T+u*R+d*D,r[9]=h*M+l*A+u*C+d*I,r[13]=h*S+l*L+u*O+d*z,r[2]=p*b+f*E+m*P+v*N,r[6]=p*w+f*T+m*R+v*D,r[10]=p*M+f*A+m*C+v*I,r[14]=p*S+f*L+m*O+v*z,r[3]=g*b+y*E+x*P+_*N,r[7]=g*w+y*T+x*R+_*D,r[11]=g*M+y*A+x*C+_*I,r[15]=g*S+y*L+x*O+_*z,this},multiplyScalar:function(t){var e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this},determinant:function(){var t=this.elements,e=t[0],n=t[4],i=t[8],r=t[12],a=t[1],o=t[5],s=t[9],c=t[13],h=t[2],l=t[6],u=t[10],d=t[14];return t[3]*(+r*s*l-i*c*l-r*o*u+n*c*u+i*o*d-n*s*d)+t[7]*(+e*s*d-e*c*u+r*a*u-i*a*d+i*c*h-r*s*h)+t[11]*(+e*c*l-e*o*d-r*a*l+n*a*d+r*o*h-n*c*h)+t[15]*(-i*o*h-e*s*l+e*o*u+i*a*l-n*a*u+n*s*h)},transpose:function(){var t,e=this.elements;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this},setPosition:function(t,e,n){var i=this.elements;return t.isVector3?(i[12]=t.x,i[13]=t.y,i[14]=t.z):(i[12]=t,i[13]=e,i[14]=n),this},getInverse:function(t,e){void 0!==e&&console.warn("THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate.");var n=this.elements,i=t.elements,r=i[0],a=i[1],o=i[2],s=i[3],c=i[4],h=i[5],l=i[6],u=i[7],d=i[8],p=i[9],f=i[10],m=i[11],v=i[12],g=i[13],y=i[14],x=i[15],_=p*y*u-g*f*u+g*l*m-h*y*m-p*l*x+h*f*x,b=v*f*u-d*y*u-v*l*m+c*y*m+d*l*x-c*f*x,w=d*g*u-v*p*u+v*h*m-c*g*m-d*h*x+c*p*x,M=v*p*l-d*g*l-v*h*f+c*g*f+d*h*y-c*p*y,S=r*_+a*b+o*w+s*M;if(0===S)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);var E=1/S;return n[0]=_*E,n[1]=(g*f*s-p*y*s-g*o*m+a*y*m+p*o*x-a*f*x)*E,n[2]=(h*y*s-g*l*s+g*o*u-a*y*u-h*o*x+a*l*x)*E,n[3]=(p*l*s-h*f*s-p*o*u+a*f*u+h*o*m-a*l*m)*E,n[4]=b*E,n[5]=(d*y*s-v*f*s+v*o*m-r*y*m-d*o*x+r*f*x)*E,n[6]=(v*l*s-c*y*s-v*o*u+r*y*u+c*o*x-r*l*x)*E,n[7]=(c*f*s-d*l*s+d*o*u-r*f*u-c*o*m+r*l*m)*E,n[8]=w*E,n[9]=(v*p*s-d*g*s-v*a*m+r*g*m+d*a*x-r*p*x)*E,n[10]=(c*g*s-v*h*s+v*a*u-r*g*u-c*a*x+r*h*x)*E,n[11]=(d*h*s-c*p*s-d*a*u+r*p*u+c*a*m-r*h*m)*E,n[12]=M*E,n[13]=(d*g*o-v*p*o+v*a*f-r*g*f-d*a*y+r*p*y)*E,n[14]=(v*h*o-c*g*o-v*a*l+r*g*l+c*a*y-r*h*y)*E,n[15]=(c*p*o-d*h*o+d*a*l-r*p*l-c*a*f+r*h*f)*E,this},scale:function(t){var e=this.elements,n=t.x,i=t.y,r=t.z;return e[0]*=n,e[4]*=i,e[8]*=r,e[1]*=n,e[5]*=i,e[9]*=r,e[2]*=n,e[6]*=i,e[10]*=r,e[3]*=n,e[7]*=i,e[11]*=r,this},getMaxScaleOnAxis:function(){var t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],n=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,n,i))},makeTranslation:function(t,e,n){return this.set(1,0,0,t,0,1,0,e,0,0,1,n,0,0,0,1),this},makeRotationX:function(t){var e=Math.cos(t),n=Math.sin(t);return this.set(1,0,0,0,0,e,-n,0,0,n,e,0,0,0,0,1),this},makeRotationY:function(t){var e=Math.cos(t),n=Math.sin(t);return this.set(e,0,n,0,0,1,0,0,-n,0,e,0,0,0,0,1),this},makeRotationZ:function(t){var e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,0,n,e,0,0,0,0,1,0,0,0,0,1),this},makeRotationAxis:function(t,e){var n=Math.cos(e),i=Math.sin(e),r=1-n,a=t.x,o=t.y,s=t.z,c=r*a,h=r*o;return this.set(c*a+n,c*o-i*s,c*s+i*o,0,c*o+i*s,h*o+n,h*s-i*a,0,c*s-i*o,h*s+i*a,r*s*s+n,0,0,0,0,1),this},makeScale:function(t,e,n){return this.set(t,0,0,0,0,e,0,0,0,0,n,0,0,0,0,1),this},makeShear:function(t,e,n){return this.set(1,e,n,0,t,1,n,0,t,e,1,0,0,0,0,1),this},compose:function(t,e,n){var i=this.elements,r=e._x,a=e._y,o=e._z,s=e._w,c=r+r,h=a+a,l=o+o,u=r*c,d=r*h,p=r*l,f=a*h,m=a*l,v=o*l,g=s*c,y=s*h,x=s*l,_=n.x,b=n.y,w=n.z;return i[0]=(1-(f+v))*_,i[1]=(d+x)*_,i[2]=(p-y)*_,i[3]=0,i[4]=(d-x)*b,i[5]=(1-(u+v))*b,i[6]=(m+g)*b,i[7]=0,i[8]=(p+y)*w,i[9]=(m-g)*w,i[10]=(1-(u+f))*w,i[11]=0,i[12]=t.x,i[13]=t.y,i[14]=t.z,i[15]=1,this},decompose:function(t,e,n){var i=this.elements,r=J.set(i[0],i[1],i[2]).length(),a=J.set(i[4],i[5],i[6]).length(),o=J.set(i[8],i[9],i[10]).length();this.determinant()<0&&(r=-r),t.x=i[12],t.y=i[13],t.z=i[14],Q.copy(this);var s=1/r,c=1/a,h=1/o;return Q.elements[0]*=s,Q.elements[1]*=s,Q.elements[2]*=s,Q.elements[4]*=c,Q.elements[5]*=c,Q.elements[6]*=c,Q.elements[8]*=h,Q.elements[9]*=h,Q.elements[10]*=h,e.setFromRotationMatrix(Q),n.x=r,n.y=a,n.z=o,this},makePerspective:function(t,e,n,i,r,a){void 0===a&&console.warn("THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.");var o=this.elements,s=2*r/(e-t),c=2*r/(n-i),h=(e+t)/(e-t),l=(n+i)/(n-i),u=-(a+r)/(a-r),d=-2*a*r/(a-r);return o[0]=s,o[4]=0,o[8]=h,o[12]=0,o[1]=0,o[5]=c,o[9]=l,o[13]=0,o[2]=0,o[6]=0,o[10]=u,o[14]=d,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this},makeOrthographic:function(t,e,n,i,r,a){var o=this.elements,s=1/(e-t),c=1/(n-i),h=1/(a-r),l=(e+t)*s,u=(n+i)*c,d=(a+r)*h;return o[0]=2*s,o[4]=0,o[8]=0,o[12]=-l,o[1]=0,o[5]=2*c,o[9]=0,o[13]=-u,o[2]=0,o[6]=0,o[10]=-2*h,o[14]=-d,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this},equals:function(t){for(var e=this.elements,n=t.elements,i=0;i<16;i++)if(e[i]!==n[i])return!1;return!0},fromArray:function(t,e){void 0===e&&(e=0);for(var n=0;n<16;n++)this.elements[n]=t[n+e];return this},toArray:function(t,e){void 0===t&&(t=[]),void 0===e&&(e=0);var n=this.elements;return t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+3]=n[3],t[e+4]=n[4],t[e+5]=n[5],t[e+6]=n[6],t[e+7]=n[7],t[e+8]=n[8],t[e+9]=n[9],t[e+10]=n[10],t[e+11]=n[11],t[e+12]=n[12],t[e+13]=n[13],t[e+14]=n[14],t[e+15]=n[15],t}});var rt=new it,at=new q;function ot(t,e,n,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=ot.DefaultOrder),this._x=t,this._y=e,this._z=n,this._order=i}function st(){this.mask=1}ot.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"],ot.DefaultOrder="XYZ",Object.defineProperties(ot.prototype,{x:{get:function(){return this._x},set:function(t){this._x=t,this._onChangeCallback()}},y:{get:function(){return this._y},set:function(t){this._y=t,this._onChangeCallback()}},z:{get:function(){return this._z},set:function(t){this._z=t,this._onChangeCallback()}},order:{get:function(){return this._order},set:function(t){this._order=t,this._onChangeCallback()}}}),Object.assign(ot.prototype,{isEuler:!0,set:function(t,e,n,i){return this._x=t,this._y=e,this._z=n,this._order=i||this._order,this._onChangeCallback(),this},clone:function(){return new this.constructor(this._x,this._y,this._z,this._order)},copy:function(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this._onChangeCallback(),this},setFromRotationMatrix:function(t,e,n){var i=B.clamp,r=t.elements,a=r[0],o=r[4],s=r[8],c=r[1],h=r[5],l=r[9],u=r[2],d=r[6],p=r[10];switch(e=e||this._order){case"XYZ":this._y=Math.asin(i(s,-1,1)),Math.abs(s)<.9999999?(this._x=Math.atan2(-l,p),this._z=Math.atan2(-o,a)):(this._x=Math.atan2(d,h),this._z=0);break;case"YXZ":this._x=Math.asin(-i(l,-1,1)),Math.abs(l)<.9999999?(this._y=Math.atan2(s,p),this._z=Math.atan2(c,h)):(this._y=Math.atan2(-u,a),this._z=0);break;case"ZXY":this._x=Math.asin(i(d,-1,1)),Math.abs(d)<.9999999?(this._y=Math.atan2(-u,p),this._z=Math.atan2(-o,h)):(this._y=0,this._z=Math.atan2(c,a));break;case"ZYX":this._y=Math.asin(-i(u,-1,1)),Math.abs(u)<.9999999?(this._x=Math.atan2(d,p),this._z=Math.atan2(c,a)):(this._x=0,this._z=Math.atan2(-o,h));break;case"YZX":this._z=Math.asin(i(c,-1,1)),Math.abs(c)<.9999999?(this._x=Math.atan2(-l,h),this._y=Math.atan2(-u,a)):(this._x=0,this._y=Math.atan2(s,p));break;case"XZY":this._z=Math.asin(-i(o,-1,1)),Math.abs(o)<.9999999?(this._x=Math.atan2(d,h),this._y=Math.atan2(s,a)):(this._x=Math.atan2(-l,p),this._y=0);break;default:console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: "+e)}return this._order=e,!1!==n&&this._onChangeCallback(),this},setFromQuaternion:function(t,e,n){return rt.makeRotationFromQuaternion(t),this.setFromRotationMatrix(rt,e,n)},setFromVector3:function(t,e){return this.set(t.x,t.y,t.z,e||this._order)},reorder:function(t){return at.setFromEuler(this),this.setFromQuaternion(at,t)},equals:function(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order},fromArray:function(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this._onChangeCallback(),this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._order,t},toVector3:function(t){return t?t.set(this._x,this._y,this._z):new Z(this._x,this._y,this._z)},_onChange:function(t){return this._onChangeCallback=t,this},_onChangeCallback:function(){}}),Object.assign(st.prototype,{set:function(t){this.mask=1<1){for(var n=0;n1){for(var n=0;n0){i.children=[];for(var p=0;p0&&(n.geometries=f),m.length>0&&(n.materials=m),v.length>0&&(n.textures=v),g.length>0&&(n.images=g),y.length>0&&(n.shapes=y)}return n.object=i,n;function x(t){var e=[];for(var n in t){var i=t[n];delete i.metadata,e.push(i)}return e}},clone:function(t){return(new this.constructor).copy(this,t)},copy:function(t,e){if(void 0===e&&(e=!0),this.name=t.name,this.up.copy(t.up),this.position.copy(t.position),this.rotation.order=t.rotation.order,this.quaternion.copy(t.quaternion),this.scale.copy(t.scale),this.matrix.copy(t.matrix),this.matrixWorld.copy(t.matrixWorld),this.matrixAutoUpdate=t.matrixAutoUpdate,this.matrixWorldNeedsUpdate=t.matrixWorldNeedsUpdate,this.layers.mask=t.layers.mask,this.visible=t.visible,this.castShadow=t.castShadow,this.receiveShadow=t.receiveShadow,this.frustumCulled=t.frustumCulled,this.renderOrder=t.renderOrder,this.userData=JSON.parse(JSON.stringify(t.userData)),!0===e)for(var n=0;ns)return!1}return!0}Object.assign(zt.prototype,{isBox3:!0,set:function(t,e){return this.min.copy(t),this.max.copy(e),this},setFromArray:function(t){for(var e=1/0,n=1/0,i=1/0,r=-1/0,a=-1/0,o=-1/0,s=0,c=t.length;sr&&(r=h),l>a&&(a=l),u>o&&(o=u)}return this.min.set(e,n,i),this.max.set(r,a,o),this},setFromBufferAttribute:function(t){for(var e=1/0,n=1/0,i=1/0,r=-1/0,a=-1/0,o=-1/0,s=0,c=t.count;sr&&(r=h),l>a&&(a=l),u>o&&(o=u)}return this.min.set(e,n,i),this.max.set(r,a,o),this},setFromPoints:function(t){this.makeEmpty();for(var e=0,n=t.length;ethis.max.x||t.ythis.max.y||t.zthis.max.z)},containsBox:function(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z},getParameter:function(t,e){return void 0===e&&(console.warn("THREE.Box3: .getParameter() target is now required"),e=new Z),e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))},intersectsBox:function(t){return!(t.max.xthis.max.x||t.max.ythis.max.y||t.max.zthis.max.z)},intersectsSphere:function(t){return this.clampPoint(t.center,St),St.distanceToSquared(t.center)<=t.radius*t.radius},intersectsPlane:function(t){var e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant},intersectsTriangle:function(t){if(this.isEmpty())return!1;this.getCenter(Ot),Nt.subVectors(this.max,Ot),Tt.subVectors(t.a,Ot),At.subVectors(t.b,Ot),Lt.subVectors(t.c,Ot),Pt.subVectors(At,Tt),Rt.subVectors(Lt,At),Ct.subVectors(Tt,Lt);var e=[0,-Pt.z,Pt.y,0,-Rt.z,Rt.y,0,-Ct.z,Ct.y,Pt.z,0,-Pt.x,Rt.z,0,-Rt.x,Ct.z,0,-Ct.x,-Pt.y,Pt.x,0,-Rt.y,Rt.x,0,-Ct.y,Ct.x,0];return!!Bt(e,Tt,At,Lt,Nt)&&(!!Bt(e=[1,0,0,0,1,0,0,0,1],Tt,At,Lt,Nt)&&(Dt.crossVectors(Pt,Rt),Bt(e=[Dt.x,Dt.y,Dt.z],Tt,At,Lt,Nt)))},clampPoint:function(t,e){return void 0===e&&(console.warn("THREE.Box3: .clampPoint() target is now required"),e=new Z),e.copy(t).clamp(this.min,this.max)},distanceToPoint:function(t){return St.copy(t).clamp(this.min,this.max).sub(t).length()},getBoundingSphere:function(t){return void 0===t&&console.error("THREE.Box3: .getBoundingSphere() target is now required"),this.getCenter(t.center),t.radius=.5*this.getSize(St).length(),t},intersect:function(t){return this.min.max(t.min),this.max.min(t.max),this.isEmpty()&&this.makeEmpty(),this},union:function(t){return this.min.min(t.min),this.max.max(t.max),this},applyMatrix4:function(t){return this.isEmpty()||(Mt[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),Mt[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),Mt[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),Mt[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),Mt[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),Mt[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),Mt[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),Mt[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.setFromPoints(Mt)),this},translate:function(t){return this.min.add(t),this.max.add(t),this},equals:function(t){return t.min.equals(this.min)&&t.max.equals(this.max)}});var Ut=new zt;function Ft(t,e){this.center=void 0!==t?t:new Z,this.radius=void 0!==e?e:-1}Object.assign(Ft.prototype,{set:function(t,e){return this.center.copy(t),this.radius=e,this},setFromPoints:function(t,e){var n=this.center;void 0!==e?n.copy(e):Ut.setFromPoints(t).getCenter(n);for(var i=0,r=0,a=t.length;rthis.radius*this.radius&&(e.sub(this.center).normalize(),e.multiplyScalar(this.radius).add(this.center)),e},getBoundingBox:function(t){return void 0===t&&(console.warn("THREE.Sphere: .getBoundingBox() target is now required"),t=new zt),this.isEmpty()?(t.makeEmpty(),t):(t.set(this.center,this.center),t.expandByScalar(this.radius),t)},applyMatrix4:function(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this},translate:function(t){return this.center.add(t),this},equals:function(t){return t.center.equals(this.center)&&t.radius===this.radius}});var kt=new Z,Ht=new Z,Gt=new Z,Vt=new Z,jt=new Z,Wt=new Z,qt=new Z;function Xt(t,e){this.origin=void 0!==t?t:new Z,this.direction=void 0!==e?e:new Z(0,0,-1)}Object.assign(Xt.prototype,{set:function(t,e){return this.origin.copy(t),this.direction.copy(e),this},clone:function(){return(new this.constructor).copy(this)},copy:function(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this},at:function(t,e){return void 0===e&&(console.warn("THREE.Ray: .at() target is now required"),e=new Z),e.copy(this.direction).multiplyScalar(t).add(this.origin)},lookAt:function(t){return this.direction.copy(t).sub(this.origin).normalize(),this},recast:function(t){return this.origin.copy(this.at(t,kt)),this},closestPointToPoint:function(t,e){void 0===e&&(console.warn("THREE.Ray: .closestPointToPoint() target is now required"),e=new Z),e.subVectors(t,this.origin);var n=e.dot(this.direction);return n<0?e.copy(this.origin):e.copy(this.direction).multiplyScalar(n).add(this.origin)},distanceToPoint:function(t){return Math.sqrt(this.distanceSqToPoint(t))},distanceSqToPoint:function(t){var e=kt.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):(kt.copy(this.direction).multiplyScalar(e).add(this.origin),kt.distanceToSquared(t))},distanceSqToSegment:function(t,e,n,i){Ht.copy(t).add(e).multiplyScalar(.5),Gt.copy(e).sub(t).normalize(),Vt.copy(this.origin).sub(Ht);var r,a,o,s,c=.5*t.distanceTo(e),h=-this.direction.dot(Gt),l=Vt.dot(this.direction),u=-Vt.dot(Gt),d=Vt.lengthSq(),p=Math.abs(1-h*h);if(p>0)if(a=h*l-u,s=c*p,(r=h*u-l)>=0)if(a>=-s)if(a<=s){var f=1/p;o=(r*=f)*(r+h*(a*=f)+2*l)+a*(h*r+a+2*u)+d}else a=c,o=-(r=Math.max(0,-(h*a+l)))*r+a*(a+2*u)+d;else a=-c,o=-(r=Math.max(0,-(h*a+l)))*r+a*(a+2*u)+d;else a<=-s?o=-(r=Math.max(0,-(-h*c+l)))*r+(a=r>0?-c:Math.min(Math.max(-c,-u),c))*(a+2*u)+d:a<=s?(r=0,o=(a=Math.min(Math.max(-c,-u),c))*(a+2*u)+d):o=-(r=Math.max(0,-(h*c+l)))*r+(a=r>0?c:Math.min(Math.max(-c,-u),c))*(a+2*u)+d;else a=h>0?-c:c,o=-(r=Math.max(0,-(h*a+l)))*r+a*(a+2*u)+d;return n&&n.copy(this.direction).multiplyScalar(r).add(this.origin),i&&i.copy(Gt).multiplyScalar(a).add(Ht),o},intersectSphere:function(t,e){kt.subVectors(t.center,this.origin);var n=kt.dot(this.direction),i=kt.dot(kt)-n*n,r=t.radius*t.radius;if(i>r)return null;var a=Math.sqrt(r-i),o=n-a,s=n+a;return o<0&&s<0?null:o<0?this.at(s,e):this.at(o,e)},intersectsSphere:function(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius},distanceToPlane:function(t){var e=t.normal.dot(this.direction);if(0===e)return 0===t.distanceToPoint(this.origin)?0:null;var n=-(this.origin.dot(t.normal)+t.constant)/e;return n>=0?n:null},intersectPlane:function(t,e){var n=this.distanceToPlane(t);return null===n?null:this.at(n,e)},intersectsPlane:function(t){var e=t.distanceToPoint(this.origin);return 0===e||t.normal.dot(this.direction)*e<0},intersectBox:function(t,e){var n,i,r,a,o,s,c=1/this.direction.x,h=1/this.direction.y,l=1/this.direction.z,u=this.origin;return c>=0?(n=(t.min.x-u.x)*c,i=(t.max.x-u.x)*c):(n=(t.max.x-u.x)*c,i=(t.min.x-u.x)*c),h>=0?(r=(t.min.y-u.y)*h,a=(t.max.y-u.y)*h):(r=(t.max.y-u.y)*h,a=(t.min.y-u.y)*h),n>a||r>i?null:((r>n||n!=n)&&(n=r),(a=0?(o=(t.min.z-u.z)*l,s=(t.max.z-u.z)*l):(o=(t.max.z-u.z)*l,s=(t.min.z-u.z)*l),n>s||o>i?null:((o>n||n!=n)&&(n=o),(s=0?n:i,e)))},intersectsBox:function(t){return null!==this.intersectBox(t,kt)},intersectTriangle:function(t,e,n,i,r){jt.subVectors(e,t),Wt.subVectors(n,t),qt.crossVectors(jt,Wt);var a,o=this.direction.dot(qt);if(o>0){if(i)return null;a=1}else{if(!(o<0))return null;a=-1,o=-o}Vt.subVectors(this.origin,t);var s=a*this.direction.dot(Wt.crossVectors(Vt,Wt));if(s<0)return null;var c=a*this.direction.dot(jt.cross(Vt));if(c<0)return null;if(s+c>o)return null;var h=-a*Vt.dot(qt);return h<0?null:this.at(h/o,r)},applyMatrix4:function(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this},equals:function(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)}});var Yt=new Z,Zt=new Z,Jt=new F;function Qt(t,e){this.normal=void 0!==t?t:new Z(1,0,0),this.constant=void 0!==e?e:0}Object.assign(Qt.prototype,{isPlane:!0,set:function(t,e){return this.normal.copy(t),this.constant=e,this},setComponents:function(t,e,n,i){return this.normal.set(t,e,n),this.constant=i,this},setFromNormalAndCoplanarPoint:function(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this},setFromCoplanarPoints:function(t,e,n){var i=Yt.subVectors(n,e).cross(Zt.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(i,t),this},clone:function(){return(new this.constructor).copy(this)},copy:function(t){return this.normal.copy(t.normal),this.constant=t.constant,this},normalize:function(){var t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this},negate:function(){return this.constant*=-1,this.normal.negate(),this},distanceToPoint:function(t){return this.normal.dot(t)+this.constant},distanceToSphere:function(t){return this.distanceToPoint(t.center)-t.radius},projectPoint:function(t,e){return void 0===e&&(console.warn("THREE.Plane: .projectPoint() target is now required"),e=new Z),e.copy(this.normal).multiplyScalar(-this.distanceToPoint(t)).add(t)},intersectLine:function(t,e){void 0===e&&(console.warn("THREE.Plane: .intersectLine() target is now required"),e=new Z);var n=t.delta(Yt),i=this.normal.dot(n);if(0===i)return 0===this.distanceToPoint(t.start)?e.copy(t.start):void 0;var r=-(t.start.dot(this.normal)+this.constant)/i;return r<0||r>1?void 0:e.copy(n).multiplyScalar(r).add(t.start)},intersectsLine:function(t){var e=this.distanceToPoint(t.start),n=this.distanceToPoint(t.end);return e<0&&n>0||n<0&&e>0},intersectsBox:function(t){return t.intersectsPlane(this)},intersectsSphere:function(t){return t.intersectsPlane(this)},coplanarPoint:function(t){return void 0===t&&(console.warn("THREE.Plane: .coplanarPoint() target is now required"),t=new Z),t.copy(this.normal).multiplyScalar(-this.constant)},applyMatrix4:function(t,e){var n=e||Jt.getNormalMatrix(t),i=this.coplanarPoint(Yt).applyMatrix4(t),r=this.normal.applyMatrix3(n).normalize();return this.constant=-i.dot(r),this},translate:function(t){return this.constant-=t.dot(this.normal),this},equals:function(t){return t.normal.equals(this.normal)&&t.constant===this.constant}});var Kt=new Z,$t=new Z,te=new Z,ee=new Z,ne=new Z,ie=new Z,re=new Z,ae=new Z,oe=new Z,se=new Z;function ce(t,e,n){this.a=void 0!==t?t:new Z,this.b=void 0!==e?e:new Z,this.c=void 0!==n?n:new Z}Object.assign(ce,{getNormal:function(t,e,n,i){void 0===i&&(console.warn("THREE.Triangle: .getNormal() target is now required"),i=new Z),i.subVectors(n,e),Kt.subVectors(t,e),i.cross(Kt);var r=i.lengthSq();return r>0?i.multiplyScalar(1/Math.sqrt(r)):i.set(0,0,0)},getBarycoord:function(t,e,n,i,r){Kt.subVectors(i,e),$t.subVectors(n,e),te.subVectors(t,e);var a=Kt.dot(Kt),o=Kt.dot($t),s=Kt.dot(te),c=$t.dot($t),h=$t.dot(te),l=a*c-o*o;if(void 0===r&&(console.warn("THREE.Triangle: .getBarycoord() target is now required"),r=new Z),0===l)return r.set(-2,-1,-1);var u=1/l,d=(c*s-o*h)*u,p=(a*h-o*s)*u;return r.set(1-d-p,p,d)},containsPoint:function(t,e,n,i){return ce.getBarycoord(t,e,n,i,ee),ee.x>=0&&ee.y>=0&&ee.x+ee.y<=1},getUV:function(t,e,n,i,r,a,o,s){return this.getBarycoord(t,e,n,i,ee),s.set(0,0),s.addScaledVector(r,ee.x),s.addScaledVector(a,ee.y),s.addScaledVector(o,ee.z),s},isFrontFacing:function(t,e,n,i){return Kt.subVectors(n,e),$t.subVectors(t,e),Kt.cross($t).dot(i)<0}}),Object.assign(ce.prototype,{set:function(t,e,n){return this.a.copy(t),this.b.copy(e),this.c.copy(n),this},setFromPointsAndIndices:function(t,e,n,i){return this.a.copy(t[e]),this.b.copy(t[n]),this.c.copy(t[i]),this},clone:function(){return(new this.constructor).copy(this)},copy:function(t){return this.a.copy(t.a),this.b.copy(t.b),this.c.copy(t.c),this},getArea:function(){return Kt.subVectors(this.c,this.b),$t.subVectors(this.a,this.b),.5*Kt.cross($t).length()},getMidpoint:function(t){return void 0===t&&(console.warn("THREE.Triangle: .getMidpoint() target is now required"),t=new Z),t.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3)},getNormal:function(t){return ce.getNormal(this.a,this.b,this.c,t)},getPlane:function(t){return void 0===t&&(console.warn("THREE.Triangle: .getPlane() target is now required"),t=new Qt),t.setFromCoplanarPoints(this.a,this.b,this.c)},getBarycoord:function(t,e){return ce.getBarycoord(t,this.a,this.b,this.c,e)},getUV:function(t,e,n,i,r){return ce.getUV(t,this.a,this.b,this.c,e,n,i,r)},containsPoint:function(t){return ce.containsPoint(t,this.a,this.b,this.c)},isFrontFacing:function(t){return ce.isFrontFacing(this.a,this.b,this.c,t)},intersectsBox:function(t){return t.intersectsTriangle(this)},closestPointToPoint:function(t,e){void 0===e&&(console.warn("THREE.Triangle: .closestPointToPoint() target is now required"),e=new Z);var n,i,r=this.a,a=this.b,o=this.c;ne.subVectors(a,r),ie.subVectors(o,r),ae.subVectors(t,r);var s=ne.dot(ae),c=ie.dot(ae);if(s<=0&&c<=0)return e.copy(r);oe.subVectors(t,a);var h=ne.dot(oe),l=ie.dot(oe);if(h>=0&&l<=h)return e.copy(a);var u=s*l-h*c;if(u<=0&&s>=0&&h<=0)return n=s/(s-h),e.copy(r).addScaledVector(ne,n);se.subVectors(t,o);var d=ne.dot(se),p=ie.dot(se);if(p>=0&&d<=p)return e.copy(o);var f=d*c-s*p;if(f<=0&&c>=0&&p<=0)return i=c/(c-p),e.copy(r).addScaledVector(ie,i);var m=h*p-d*l;if(m<=0&&l-h>=0&&d-p>=0)return re.subVectors(o,a),i=(l-h)/(l-h+(d-p)),e.copy(a).addScaledVector(re,i);var v=1/(m+f+u);return n=f*v,i=u*v,e.copy(r).addScaledVector(ne,n).addScaledVector(ie,i)},equals:function(t){return t.a.equals(this.a)&&t.b.equals(this.b)&&t.c.equals(this.c)}});var he={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},le={h:0,s:0,l:0},ue={h:0,s:0,l:0};function de(t,e,n){return void 0===e&&void 0===n?this.set(t):this.setRGB(t,e,n)}function pe(t,e,n){return n<0&&(n+=1),n>1&&(n-=1),n<1/6?t+6*(e-t)*n:n<.5?e:n<2/3?t+6*(e-t)*(2/3-n):t}function fe(t){return t<.04045?.0773993808*t:Math.pow(.9478672986*t+.0521327014,2.4)}function me(t){return t<.0031308?12.92*t:1.055*Math.pow(t,.41666)-.055}function ve(t,e,n,i,r,a){this.a=t,this.b=e,this.c=n,this.normal=i&&i.isVector3?i:new Z,this.vertexNormals=Array.isArray(i)?i:[],this.color=r&&r.isColor?r:new de,this.vertexColors=Array.isArray(r)?r:[],this.materialIndex=void 0!==a?a:0}Object.assign(de.prototype,{isColor:!0,r:1,g:1,b:1,set:function(t){return t&&t.isColor?this.copy(t):"number"==typeof t?this.setHex(t):"string"==typeof t&&this.setStyle(t),this},setScalar:function(t){return this.r=t,this.g=t,this.b=t,this},setHex:function(t){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,this},setRGB:function(t,e,n){return this.r=t,this.g=e,this.b=n,this},setHSL:function(t,e,n){if(t=B.euclideanModulo(t,1),e=B.clamp(e,0,1),n=B.clamp(n,0,1),0===e)this.r=this.g=this.b=n;else{var i=n<=.5?n*(1+e):n+e-n*e,r=2*n-i;this.r=pe(r,i,t+1/3),this.g=pe(r,i,t),this.b=pe(r,i,t-1/3)}return this},setStyle:function(t){function e(e){void 0!==e&&parseFloat(e)<1&&console.warn("THREE.Color: Alpha component of "+t+" will be ignored.")}var n;if(n=/^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(t)){var i,r=n[1],a=n[2];switch(r){case"rgb":case"rgba":if(i=/^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(a))return this.r=Math.min(255,parseInt(i[1],10))/255,this.g=Math.min(255,parseInt(i[2],10))/255,this.b=Math.min(255,parseInt(i[3],10))/255,e(i[5]),this;if(i=/^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(a))return this.r=Math.min(100,parseInt(i[1],10))/100,this.g=Math.min(100,parseInt(i[2],10))/100,this.b=Math.min(100,parseInt(i[3],10))/100,e(i[5]),this;break;case"hsl":case"hsla":if(i=/^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(a)){var o=parseFloat(i[1])/360,s=parseInt(i[2],10)/100,c=parseInt(i[3],10)/100;return e(i[5]),this.setHSL(o,s,c)}}}else if(n=/^\#([A-Fa-f0-9]+)$/.exec(t)){var h=n[1],l=h.length;if(3===l)return this.r=parseInt(h.charAt(0)+h.charAt(0),16)/255,this.g=parseInt(h.charAt(1)+h.charAt(1),16)/255,this.b=parseInt(h.charAt(2)+h.charAt(2),16)/255,this;if(6===l)return this.r=parseInt(h.charAt(0)+h.charAt(1),16)/255,this.g=parseInt(h.charAt(2)+h.charAt(3),16)/255,this.b=parseInt(h.charAt(4)+h.charAt(5),16)/255,this}return t&&t.length>0?this.setColorName(t):this},setColorName:function(t){var e=he[t];return void 0!==e?this.setHex(e):console.warn("THREE.Color: Unknown color "+t),this},clone:function(){return new this.constructor(this.r,this.g,this.b)},copy:function(t){return this.r=t.r,this.g=t.g,this.b=t.b,this},copyGammaToLinear:function(t,e){return void 0===e&&(e=2),this.r=Math.pow(t.r,e),this.g=Math.pow(t.g,e),this.b=Math.pow(t.b,e),this},copyLinearToGamma:function(t,e){void 0===e&&(e=2);var n=e>0?1/e:1;return this.r=Math.pow(t.r,n),this.g=Math.pow(t.g,n),this.b=Math.pow(t.b,n),this},convertGammaToLinear:function(t){return this.copyGammaToLinear(this,t),this},convertLinearToGamma:function(t){return this.copyLinearToGamma(this,t),this},copySRGBToLinear:function(t){return this.r=fe(t.r),this.g=fe(t.g),this.b=fe(t.b),this},copyLinearToSRGB:function(t){return this.r=me(t.r),this.g=me(t.g),this.b=me(t.b),this},convertSRGBToLinear:function(){return this.copySRGBToLinear(this),this},convertLinearToSRGB:function(){return this.copyLinearToSRGB(this),this},getHex:function(){return 255*this.r<<16^255*this.g<<8^255*this.b<<0},getHexString:function(){return("000000"+this.getHex().toString(16)).slice(-6)},getHSL:function(t){void 0===t&&(console.warn("THREE.Color: .getHSL() target is now required"),t={h:0,s:0,l:0});var e,n,i=this.r,r=this.g,a=this.b,o=Math.max(i,r,a),s=Math.min(i,r,a),c=(s+o)/2;if(s===o)e=0,n=0;else{var h=o-s;switch(n=c<=.5?h/(o+s):h/(2-o-s),o){case i:e=(r-a)/h+(r0&&(n.alphaTest=this.alphaTest),!0===this.premultipliedAlpha&&(n.premultipliedAlpha=this.premultipliedAlpha),!0===this.wireframe&&(n.wireframe=this.wireframe),this.wireframeLinewidth>1&&(n.wireframeLinewidth=this.wireframeLinewidth),"round"!==this.wireframeLinecap&&(n.wireframeLinecap=this.wireframeLinecap),"round"!==this.wireframeLinejoin&&(n.wireframeLinejoin=this.wireframeLinejoin),!0===this.morphTargets&&(n.morphTargets=!0),!0===this.morphNormals&&(n.morphNormals=!0),!0===this.skinning&&(n.skinning=!0),!1===this.visible&&(n.visible=!1),!1===this.toneMapped&&(n.toneMapped=!1),"{}"!==JSON.stringify(this.userData)&&(n.userData=this.userData),e){var r=i(t.textures),a=i(t.images);r.length>0&&(n.textures=r),a.length>0&&(n.images=a)}return n},clone:function(){return(new this.constructor).copy(this)},copy:function(t){this.name=t.name,this.fog=t.fog,this.blending=t.blending,this.side=t.side,this.flatShading=t.flatShading,this.vertexColors=t.vertexColors,this.opacity=t.opacity,this.transparent=t.transparent,this.blendSrc=t.blendSrc,this.blendDst=t.blendDst,this.blendEquation=t.blendEquation,this.blendSrcAlpha=t.blendSrcAlpha,this.blendDstAlpha=t.blendDstAlpha,this.blendEquationAlpha=t.blendEquationAlpha,this.depthFunc=t.depthFunc,this.depthTest=t.depthTest,this.depthWrite=t.depthWrite,this.stencilWriteMask=t.stencilWriteMask,this.stencilFunc=t.stencilFunc,this.stencilRef=t.stencilRef,this.stencilFuncMask=t.stencilFuncMask,this.stencilFail=t.stencilFail,this.stencilZFail=t.stencilZFail,this.stencilZPass=t.stencilZPass,this.stencilWrite=t.stencilWrite;var e=t.clippingPlanes,n=null;if(null!==e){var i=e.length;n=new Array(i);for(var r=0;r!==i;++r)n[r]=e[r].clone()}return this.clippingPlanes=n,this.clipIntersection=t.clipIntersection,this.clipShadows=t.clipShadows,this.shadowSide=t.shadowSide,this.colorWrite=t.colorWrite,this.precision=t.precision,this.polygonOffset=t.polygonOffset,this.polygonOffsetFactor=t.polygonOffsetFactor,this.polygonOffsetUnits=t.polygonOffsetUnits,this.dithering=t.dithering,this.alphaTest=t.alphaTest,this.premultipliedAlpha=t.premultipliedAlpha,this.visible=t.visible,this.toneMapped=t.toneMapped,this.userData=JSON.parse(JSON.stringify(t.userData)),this},dispose:function(){this.dispatchEvent({type:"dispose"})}}),Object.defineProperty(ye.prototype,"needsUpdate",{set:function(t){!0===t&&this.version++}}),xe.prototype=Object.create(ye.prototype),xe.prototype.constructor=xe,xe.prototype.isMeshBasicMaterial=!0,xe.prototype.copy=function(t){return ye.prototype.copy.call(this,t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.skinning=t.skinning,this.morphTargets=t.morphTargets,this};var _e=new Z,be=new U;function we(t,e,n){if(Array.isArray(t))throw new TypeError("THREE.BufferAttribute: array should be a Typed Array.");this.name="",this.array=t,this.itemSize=e,this.count=void 0!==t?t.length/e:0,this.normalized=!0===n,this.usage=R,this.updateRange={offset:0,count:-1},this.version=0}function Me(t,e,n){we.call(this,new Int8Array(t),e,n)}function Se(t,e,n){we.call(this,new Uint8Array(t),e,n)}function Ee(t,e,n){we.call(this,new Uint8ClampedArray(t),e,n)}function Te(t,e,n){we.call(this,new Int16Array(t),e,n)}function Ae(t,e,n){we.call(this,new Uint16Array(t),e,n)}function Le(t,e,n){we.call(this,new Int32Array(t),e,n)}function Pe(t,e,n){we.call(this,new Uint32Array(t),e,n)}function Re(t,e,n){we.call(this,new Float32Array(t),e,n)}function Ce(t,e,n){we.call(this,new Float64Array(t),e,n)}function Oe(){this.vertices=[],this.normals=[],this.colors=[],this.uvs=[],this.uvs2=[],this.groups=[],this.morphTargets={},this.skinWeights=[],this.skinIndices=[],this.boundingBox=null,this.boundingSphere=null,this.verticesNeedUpdate=!1,this.normalsNeedUpdate=!1,this.colorsNeedUpdate=!1,this.uvsNeedUpdate=!1,this.groupsNeedUpdate=!1}function Ne(t){if(0===t.length)return-1/0;for(var e=t[0],n=1,i=t.length;ne&&(e=t[n]);return e}Object.defineProperty(we.prototype,"needsUpdate",{set:function(t){!0===t&&this.version++}}),Object.assign(we.prototype,{isBufferAttribute:!0,onUploadCallback:function(){},setUsage:function(t){return this.usage=t,this},copy:function(t){return this.name=t.name,this.array=new t.array.constructor(t.array),this.itemSize=t.itemSize,this.count=t.count,this.normalized=t.normalized,this.usage=t.usage,this},copyAt:function(t,e,n){t*=this.itemSize,n*=e.itemSize;for(var i=0,r=this.itemSize;i0,o=r[1]&&r[1].length>0,s=t.morphTargets,c=s.length;if(c>0){e=[];for(var h=0;h0){l=[];for(var p=0;p0&&0===n.length&&console.error("THREE.DirectGeometry: Faceless geometries are not supported.");for(var y=0;y65535?Pe:Ae)(t,1):this.index=t},getAttribute:function(t){return this.attributes[t]},setAttribute:function(t,e){return this.attributes[t]=e,this},deleteAttribute:function(t){return delete this.attributes[t],this},addGroup:function(t,e,n){this.groups.push({start:t,count:e,materialIndex:void 0!==n?n:0})},clearGroups:function(){this.groups=[]},setDrawRange:function(t,e){this.drawRange.start=t,this.drawRange.count=e},applyMatrix4:function(t){var e=this.attributes.position;void 0!==e&&(e.applyMatrix4(t),e.needsUpdate=!0);var n=this.attributes.normal;if(void 0!==n){var i=(new F).getNormalMatrix(t);n.applyNormalMatrix(i),n.needsUpdate=!0}var r=this.attributes.tangent;return void 0!==r&&(r.transformDirection(t),r.needsUpdate=!0),null!==this.boundingBox&&this.computeBoundingBox(),null!==this.boundingSphere&&this.computeBoundingSphere(),this},rotateX:function(t){return Ie.makeRotationX(t),this.applyMatrix4(Ie),this},rotateY:function(t){return Ie.makeRotationY(t),this.applyMatrix4(Ie),this},rotateZ:function(t){return Ie.makeRotationZ(t),this.applyMatrix4(Ie),this},translate:function(t,e,n){return Ie.makeTranslation(t,e,n),this.applyMatrix4(Ie),this},scale:function(t,e,n){return Ie.makeScale(t,e,n),this.applyMatrix4(Ie),this},lookAt:function(t){return ze.lookAt(t),ze.updateMatrix(),this.applyMatrix4(ze.matrix),this},center:function(){return this.computeBoundingBox(),this.boundingBox.getCenter(Be).negate(),this.translate(Be.x,Be.y,Be.z),this},setFromObject:function(t){var e=t.geometry;if(t.isPoints||t.isLine){var n=new Re(3*e.vertices.length,3),i=new Re(3*e.colors.length,3);if(this.setAttribute("position",n.copyVector3sArray(e.vertices)),this.setAttribute("color",i.copyColorsArray(e.colors)),e.lineDistances&&e.lineDistances.length===e.vertices.length){var r=new Re(e.lineDistances.length,1);this.setAttribute("lineDistance",r.copyArray(e.lineDistances))}null!==e.boundingSphere&&(this.boundingSphere=e.boundingSphere.clone()),null!==e.boundingBox&&(this.boundingBox=e.boundingBox.clone())}else t.isMesh&&e&&e.isGeometry&&this.fromGeometry(e);return this},setFromPoints:function(t){for(var e=[],n=0,i=t.length;n0){var n=new Float32Array(3*t.normals.length);this.setAttribute("normal",new we(n,3).copyVector3sArray(t.normals))}if(t.colors.length>0){var i=new Float32Array(3*t.colors.length);this.setAttribute("color",new we(i,3).copyColorsArray(t.colors))}if(t.uvs.length>0){var r=new Float32Array(2*t.uvs.length);this.setAttribute("uv",new we(r,2).copyVector2sArray(t.uvs))}if(t.uvs2.length>0){var a=new Float32Array(2*t.uvs2.length);this.setAttribute("uv2",new we(a,2).copyVector2sArray(t.uvs2))}for(var o in this.groups=t.groups,t.morphTargets){for(var s=[],c=t.morphTargets[o],h=0,l=c.length;h0){var p=new Re(4*t.skinIndices.length,4);this.setAttribute("skinIndex",p.copyVector4sArray(t.skinIndices))}if(t.skinWeights.length>0){var f=new Re(4*t.skinWeights.length,4);this.setAttribute("skinWeight",f.copyVector4sArray(t.skinWeights))}return null!==t.boundingSphere&&(this.boundingSphere=t.boundingSphere.clone()),null!==t.boundingBox&&(this.boundingBox=t.boundingBox.clone()),this},computeBoundingBox:function(){null===this.boundingBox&&(this.boundingBox=new zt);var t=this.attributes.position,e=this.morphAttributes.position;if(void 0!==t){if(this.boundingBox.setFromBufferAttribute(t),e)for(var n=0,i=e.length;n0&&(t.userData=this.userData),void 0!==this.parameters){var e=this.parameters;for(var n in e)void 0!==e[n]&&(t[n]=e[n]);return t}t.data={attributes:{}};var i=this.index;null!==i&&(t.data.index={type:i.array.constructor.name,array:Array.prototype.slice.call(i.array)});var r=this.attributes;for(var a in r){var o=r[a],s=o.toJSON(t.data);""!==o.name&&(s.name=o.name),t.data.attributes[a]=s}var c={},h=!1;for(var l in this.morphAttributes){for(var u=this.morphAttributes[l],d=[],p=0,f=u.length;p0&&(c[l]=d,h=!0)}h&&(t.data.morphAttributes=c,t.data.morphTargetsRelative=this.morphTargetsRelative);var g=this.groups;g.length>0&&(t.data.groups=JSON.parse(JSON.stringify(g)));var y=this.boundingSphere;return null!==y&&(t.data.boundingSphere={center:y.center.toArray(),radius:y.radius}),t},clone:function(){return(new He).copy(this)},copy:function(t){this.index=null,this.attributes={},this.morphAttributes={},this.groups=[],this.boundingBox=null,this.boundingSphere=null;var e={};this.name=t.name;var n=t.index;null!==n&&this.setIndex(n.clone(e));var i=t.attributes;for(var r in i){var a=i[r];this.setAttribute(r,a.clone(e))}var o=t.morphAttributes;for(var s in o){for(var c=[],h=o[s],l=0,u=h.length;ln.far?null:{distance:c,point:an.clone(),object:t}}function cn(t,e,n,i,r,a,o,s,c,h,l,u){We.fromBufferAttribute(r,h),qe.fromBufferAttribute(r,l),Xe.fromBufferAttribute(r,u);var d=t.morphTargetInfluences;if(e.morphTargets&&a&&d){Qe.set(0,0,0),Ke.set(0,0,0),$e.set(0,0,0);for(var p=0,f=a.length;p0){var i=e[n[0]];if(void 0!==i){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(var r=0,a=i.length;r0&&console.error("THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.")}},raycast:function(t,e){var n,i=this.geometry,r=this.material,a=this.matrixWorld;if(void 0!==r&&(null===i.boundingSphere&&i.computeBoundingSphere(),je.copy(i.boundingSphere),je.applyMatrix4(a),!1!==t.ray.intersectsSphere(je)&&(Ge.getInverse(a),Ve.copy(t.ray).applyMatrix4(Ge),null===i.boundingBox||!1!==Ve.intersectsBox(i.boundingBox))))if(i.isBufferGeometry){var o=i.index,s=i.attributes.position,c=i.morphAttributes.position,h=i.morphTargetsRelative,l=i.attributes.uv,u=i.attributes.uv2,d=i.groups,p=i.drawRange;if(null!==o)if(Array.isArray(r))for(var f=0,m=d.length;f0&&(z=H);for(var G=0,V=k.length;G0)for(var d=0;d0&&(this.normalsNeedUpdate=!0)},computeFlatVertexNormals:function(){this.computeFaceNormals();for(var t=0,e=this.faces.length;t0&&(this.normalsNeedUpdate=!0)},computeMorphNormals:function(){for(var t=0,e=this.faces.length;t=0;f--){var m=c[f];this.faces.splice(m,1);for(var v=0,g=this.faceVertexUvs.length;v0,g=f.vertexNormals.length>0,y=1!==f.color.r||1!==f.color.g||1!==f.color.b,x=f.vertexColors.length>0,_=0;if(_=S(_,0,0),_=S(_,1,!0),_=S(_,2,!1),_=S(_,3,m),_=S(_,4,v),_=S(_,5,g),_=S(_,6,y),_=S(_,7,x),o.push(_),o.push(f.a,f.b,f.c),o.push(f.materialIndex),m){var b=this.faceVertexUvs[0][p];o.push(A(b[0]),A(b[1]),A(b[2]))}if(v&&o.push(E(f.normal)),g){var w=f.vertexNormals;o.push(E(w[0]),E(w[1]),E(w[2]))}if(y&&o.push(T(f.color)),x){var M=f.vertexColors;o.push(T(M[0]),T(M[1]),T(M[2]))}}function S(t,e,n){return n?t|1<0&&(t.data.colors=h),u.length>0&&(t.data.uvs=[u]),t.data.faces=o,t},clone:function(){return(new pn).copy(this)},copy:function(t){this.vertices=[],this.colors=[],this.faces=[],this.faceVertexUvs=[[]],this.morphTargets=[],this.morphNormals=[],this.skinWeights=[],this.skinIndices=[],this.lineDistances=[],this.boundingBox=null,this.boundingSphere=null,this.name=t.name;for(var e=t.vertices,n=0,i=e.length;n0?1:-1,l.push(A.x,A.y,A.z),u.push(R/m),u.push(1-L/v),E+=1}for(var O=0;O0&&(e.defines=this.defines),e.vertexShader=this.vertexShader,e.fragmentShader=this.fragmentShader;var r={};for(var a in this.extensions)!0===this.extensions[a]&&(r[a]=!0);return Object.keys(r).length>0&&(e.extensions=r),e},_n.prototype=Object.assign(Object.create(bt.prototype),{constructor:_n,isCamera:!0,copy:function(t,e){return bt.prototype.copy.call(this,t,e),this.matrixWorldInverse.copy(t.matrixWorldInverse),this.projectionMatrix.copy(t.projectionMatrix),this.projectionMatrixInverse.copy(t.projectionMatrixInverse),this},getWorldDirection:function(t){void 0===t&&(console.warn("THREE.Camera: .getWorldDirection() target is now required"),t=new Z),this.updateMatrixWorld(!0);var e=this.matrixWorld.elements;return t.set(-e[8],-e[9],-e[10]).normalize()},updateMatrixWorld:function(t){bt.prototype.updateMatrixWorld.call(this,t),this.matrixWorldInverse.getInverse(this.matrixWorld)},updateWorldMatrix:function(t,e){bt.prototype.updateWorldMatrix.call(this,t,e),this.matrixWorldInverse.getInverse(this.matrixWorld)},clone:function(){return(new this.constructor).copy(this)}}),bn.prototype=Object.assign(Object.create(_n.prototype),{constructor:bn,isPerspectiveCamera:!0,copy:function(t,e){return _n.prototype.copy.call(this,t,e),this.fov=t.fov,this.zoom=t.zoom,this.near=t.near,this.far=t.far,this.focus=t.focus,this.aspect=t.aspect,this.view=null===t.view?null:Object.assign({},t.view),this.filmGauge=t.filmGauge,this.filmOffset=t.filmOffset,this},setFocalLength:function(t){var e=.5*this.getFilmHeight()/t;this.fov=2*B.RAD2DEG*Math.atan(e),this.updateProjectionMatrix()},getFocalLength:function(){var t=Math.tan(.5*B.DEG2RAD*this.fov);return.5*this.getFilmHeight()/t},getEffectiveFOV:function(){return 2*B.RAD2DEG*Math.atan(Math.tan(.5*B.DEG2RAD*this.fov)/this.zoom)},getFilmWidth:function(){return this.filmGauge*Math.min(this.aspect,1)},getFilmHeight:function(){return this.filmGauge/Math.max(this.aspect,1)},setViewOffset:function(t,e,n,i,r,a){this.aspect=t/e,null===this.view&&(this.view={enabled:!0,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1}),this.view.enabled=!0,this.view.fullWidth=t,this.view.fullHeight=e,this.view.offsetX=n,this.view.offsetY=i,this.view.width=r,this.view.height=a,this.updateProjectionMatrix()},clearViewOffset:function(){null!==this.view&&(this.view.enabled=!1),this.updateProjectionMatrix()},updateProjectionMatrix:function(){var t=this.near,e=t*Math.tan(.5*B.DEG2RAD*this.fov)/this.zoom,n=2*e,i=this.aspect*n,r=-.5*i,a=this.view;if(null!==this.view&&this.view.enabled){var o=a.fullWidth,s=a.fullHeight;r+=a.offsetX*i/o,e-=a.offsetY*n/s,i*=a.width/o,n*=a.height/s}var c=this.filmOffset;0!==c&&(r+=t*c/this.getFilmWidth()),this.projectionMatrix.makePerspective(r,r+i,e,e-n,t,this.far),this.projectionMatrixInverse.getInverse(this.projectionMatrix)},toJSON:function(t){var e=bt.prototype.toJSON.call(this,t);return e.object.fov=this.fov,e.object.zoom=this.zoom,e.object.near=this.near,e.object.far=this.far,e.object.focus=this.focus,e.object.aspect=this.aspect,null!==this.view&&(e.object.view=Object.assign({},this.view)),e.object.filmGauge=this.filmGauge,e.object.filmOffset=this.filmOffset,e}});var wn=90;function Mn(t,e,n){if(bt.call(this),this.type="CubeCamera",!0===n.isWebGLCubeRenderTarget){this.renderTarget=n;var i=new bn(wn,1,t,e);i.layers=this.layers,i.up.set(0,-1,0),i.lookAt(new Z(1,0,0)),this.add(i);var r=new bn(wn,1,t,e);r.layers=this.layers,r.up.set(0,-1,0),r.lookAt(new Z(-1,0,0)),this.add(r);var a=new bn(wn,1,t,e);a.layers=this.layers,a.up.set(0,0,1),a.lookAt(new Z(0,1,0)),this.add(a);var o=new bn(wn,1,t,e);o.layers=this.layers,o.up.set(0,0,-1),o.lookAt(new Z(0,-1,0)),this.add(o);var s=new bn(wn,1,t,e);s.layers=this.layers,s.up.set(0,-1,0),s.lookAt(new Z(0,0,1)),this.add(s);var c=new bn(wn,1,t,e);c.layers=this.layers,c.up.set(0,-1,0),c.lookAt(new Z(0,0,-1)),this.add(c),this.update=function(t,e){null===this.parent&&this.updateMatrixWorld();var h=t.xr.enabled,l=t.getRenderTarget();t.xr.enabled=!1;var u=n.texture.generateMipmaps;n.texture.generateMipmaps=!1,t.setRenderTarget(n,0),t.render(e,i),t.setRenderTarget(n,1),t.render(e,r),t.setRenderTarget(n,2),t.render(e,a),t.setRenderTarget(n,3),t.render(e,o),t.setRenderTarget(n,4),t.render(e,s),n.texture.generateMipmaps=u,t.setRenderTarget(n,5),t.render(e,c),t.setRenderTarget(l),t.xr.enabled=h},this.clear=function(t,e,i,r){for(var a=t.getRenderTarget(),o=0;o<6;o++)t.setRenderTarget(n,o),t.clear(e,i,r);t.setRenderTarget(a)}}else console.error("THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.")}function Sn(t,e,n){Number.isInteger(e)&&(console.warn("THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )"),e=n),j.call(this,t,t,e)}function En(t,e,n,i,r,a,s,c,h,l,u,d){G.call(this,null,a,s,c,h,l,i,r,u,d),this.image={data:t||null,width:e||1,height:n||1},this.magFilter=void 0!==h?h:o,this.minFilter=void 0!==l?l:o,this.generateMipmaps=!1,this.flipY=!1,this.unpackAlignment=1,this.needsUpdate=!0}Mn.prototype=Object.create(bt.prototype),Mn.prototype.constructor=Mn,Sn.prototype=Object.create(j.prototype),Sn.prototype.constructor=Sn,Sn.prototype.isWebGLCubeRenderTarget=!0,Sn.prototype.fromEquirectangularTexture=function(t,e){this.texture.type=e.type,this.texture.format=y,this.texture.encoding=e.encoding,this.texture.generateMipmaps=e.generateMipmaps,this.texture.minFilter=e.minFilter,this.texture.magFilter=e.magFilter;var n=new wt,i="\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 \n\t\t\t\t#include \n\n\t\t\t}\n\t\t",r="\n\n\t\t\tuniform sampler2D tEquirect;\n\n\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t#include \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",a=new xn({name:"CubemapFromEquirect",uniforms:vn({tEquirect:{value:null}}),vertexShader:i,fragmentShader:r,side:1,blending:0});a.uniforms.tEquirect.value=e;var o=new on(new mn(5,5,5),a);return n.add(o),new Mn(1,10,this).update(t,n),o.geometry.dispose(),o.material.dispose(),this},En.prototype=Object.create(G.prototype),En.prototype.constructor=En,En.prototype.isDataTexture=!0;var Tn=new Ft,An=new Z;function Ln(t,e,n,i,r,a){this.planes=[void 0!==t?t:new Qt,void 0!==e?e:new Qt,void 0!==n?n:new Qt,void 0!==i?i:new Qt,void 0!==r?r:new Qt,void 0!==a?a:new Qt]}Object.assign(Ln.prototype,{set:function(t,e,n,i,r,a){var o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(n),o[3].copy(i),o[4].copy(r),o[5].copy(a),this},clone:function(){return(new this.constructor).copy(this)},copy:function(t){for(var e=this.planes,n=0;n<6;n++)e[n].copy(t.planes[n]);return this},setFromProjectionMatrix:function(t){var e=this.planes,n=t.elements,i=n[0],r=n[1],a=n[2],o=n[3],s=n[4],c=n[5],h=n[6],l=n[7],u=n[8],d=n[9],p=n[10],f=n[11],m=n[12],v=n[13],g=n[14],y=n[15];return e[0].setComponents(o-i,l-s,f-u,y-m).normalize(),e[1].setComponents(o+i,l+s,f+u,y+m).normalize(),e[2].setComponents(o+r,l+c,f+d,y+v).normalize(),e[3].setComponents(o-r,l-c,f-d,y-v).normalize(),e[4].setComponents(o-a,l-h,f-p,y-g).normalize(),e[5].setComponents(o+a,l+h,f+p,y+g).normalize(),this},intersectsObject:function(t){var e=t.geometry;return null===e.boundingSphere&&e.computeBoundingSphere(),Tn.copy(e.boundingSphere).applyMatrix4(t.matrixWorld),this.intersectsSphere(Tn)},intersectsSprite:function(t){return Tn.center.set(0,0,0),Tn.radius=.7071067811865476,Tn.applyMatrix4(t.matrixWorld),this.intersectsSphere(Tn)},intersectsSphere:function(t){for(var e=this.planes,n=t.center,i=-t.radius,r=0;r<6;r++){if(e[r].distanceToPoint(n)0?t.max.x:t.min.x,An.y=i.normal.y>0?t.max.y:t.min.y,An.z=i.normal.z>0?t.max.z:t.min.z,i.distanceToPoint(An)<0)return!1}return!0},containsPoint:function(t){for(var e=this.planes,n=0;n<6;n++)if(e[n].distanceToPoint(t)<0)return!1;return!0}});var Pn={common:{diffuse:{value:new de(15658734)},opacity:{value:1},map:{value:null},uvTransform:{value:new F},uv2Transform:{value:new F},alphaMap:{value:null}},specularmap:{specularMap:{value:null}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1},refractionRatio:{value:.98},maxMipLevel:{value:0}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1}},emissivemap:{emissiveMap:{value:null}},bumpmap:{bumpMap:{value:null},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalScale:{value:new U(1,1)}},displacementmap:{displacementMap:{value:null},displacementScale:{value:1},displacementBias:{value:0}},roughnessmap:{roughnessMap:{value:null}},metalnessmap:{metalnessMap:{value:null}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new de(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotShadowMap:{value:[]},spotShadowMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}}},points:{diffuse:{value:new de(15658734)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},uvTransform:{value:new F}},sprite:{diffuse:{value:new de(15658734)},opacity:{value:1},center:{value:new U(.5,.5)},rotation:{value:0},map:{value:null},alphaMap:{value:null},uvTransform:{value:new F}}};function Rn(){var t=null,e=!1,n=null,i=null;function r(e,a){n(e,a),i=t.requestAnimationFrame(r)}return{start:function(){!0!==e&&null!==n&&(i=t.requestAnimationFrame(r),e=!0)},stop:function(){t.cancelAnimationFrame(i),e=!1},setAnimationLoop:function(t){n=t},setContext:function(e){t=e}}}function Cn(t,e){var n=e.isWebGL2,i=new WeakMap;return{get:function(t){return t.isInterleavedBufferAttribute&&(t=t.data),i.get(t)},remove:function(e){e.isInterleavedBufferAttribute&&(e=e.data);var n=i.get(e);n&&(t.deleteBuffer(n.buffer),i.delete(e))},update:function(e,r){e.isInterleavedBufferAttribute&&(e=e.data);var a=i.get(e);void 0===a?i.set(e,function(e,n){var i=e.array,r=e.usage,a=t.createBuffer();t.bindBuffer(n,a),t.bufferData(n,i,r),e.onUploadCallback();var o=5126;return i instanceof Float32Array?o=5126:i instanceof Float64Array?console.warn("THREE.WebGLAttributes: Unsupported data buffer format: Float64Array."):i instanceof Uint16Array?o=5123:i instanceof Int16Array?o=5122:i instanceof Uint32Array?o=5125:i instanceof Int32Array?o=5124:i instanceof Int8Array?o=5120:i instanceof Uint8Array&&(o=5121),{buffer:a,type:o,bytesPerElement:i.BYTES_PER_ELEMENT,version:e.version}}(e,r)):a.version 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",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",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",clipping_planes_pars_fragment:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif",clipping_planes_pars_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif",clipping_planes_vertex:"#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif",color_fragment:"#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif",color_pars_fragment:"#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif",color_pars_vertex:"#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif",color_vertex:"#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif",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}",cube_uv_reflection_fragment:"#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_maxMipLevel 8.0\n#define cubeUV_minMipLevel 4.0\n#define cubeUV_maxTileSize 256.0\n#define cubeUV_minTileSize 16.0\nfloat getFace(vec3 direction) {\n vec3 absDirection = abs(direction);\n float face = -1.0;\n if (absDirection.x > absDirection.z) {\n if (absDirection.x > absDirection.y)\n face = direction.x > 0.0 ? 0.0 : 3.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n } else {\n if (absDirection.z > absDirection.y)\n face = direction.z > 0.0 ? 2.0 : 5.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n }\n return face;\n}\nvec2 getUV(vec3 direction, float face) {\n vec2 uv;\n if (face == 0.0) {\n uv = vec2(direction.z, direction.y) / abs(direction.x); } else if (face == 1.0) {\n uv = vec2(-direction.x, -direction.z) / abs(direction.y); } else if (face == 2.0) {\n uv = vec2(-direction.x, direction.y) / abs(direction.z); } else if (face == 3.0) {\n uv = vec2(-direction.z, direction.y) / abs(direction.x); } else if (face == 4.0) {\n uv = vec2(-direction.x, direction.z) / abs(direction.y); } else {\n uv = vec2(direction.x, direction.y) / abs(direction.z); }\n return 0.5 * (uv + 1.0);\n}\nvec3 bilinearCubeUV(sampler2D envMap, vec3 direction, float mipInt) {\n float face = getFace(direction);\n float filterInt = max(cubeUV_minMipLevel - mipInt, 0.0);\n mipInt = max(mipInt, cubeUV_minMipLevel);\n float faceSize = exp2(mipInt);\n float texelSize = 1.0 / (3.0 * cubeUV_maxTileSize);\n vec2 uv = getUV(direction, face) * (faceSize - 1.0);\n vec2 f = fract(uv);\n uv += 0.5 - f;\n if (face > 2.0) {\n uv.y += faceSize;\n face -= 3.0;\n }\n uv.x += face * faceSize;\n if(mipInt < cubeUV_maxMipLevel){\n uv.y += 2.0 * cubeUV_maxTileSize;\n }\n uv.y += filterInt * 2.0 * cubeUV_minTileSize;\n uv.x += 3.0 * max(0.0, cubeUV_maxTileSize - 2.0 * faceSize);\n uv *= texelSize;\n vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.x += texelSize;\n vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.y += texelSize;\n vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.x -= texelSize;\n vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n vec3 tm = mix(tl, tr, f.x);\n vec3 bm = mix(bl, br, f.x);\n return mix(tm, bm, f.y);\n}\n#define r0 1.0\n#define v0 0.339\n#define m0 -2.0\n#define r1 0.8\n#define v1 0.276\n#define m1 -1.0\n#define r4 0.4\n#define v4 0.046\n#define m4 2.0\n#define r5 0.305\n#define v5 0.016\n#define m5 3.0\n#define r6 0.21\n#define v6 0.0038\n#define m6 4.0\nfloat roughnessToMip(float roughness) {\n float mip = 0.0;\n if (roughness >= r1) {\n mip = (r0 - roughness) * (m1 - m0) / (r0 - r1) + m0;\n } else if (roughness >= r4) {\n mip = (r1 - roughness) * (m4 - m1) / (r1 - r4) + m1;\n } else if (roughness >= r5) {\n mip = (r4 - roughness) * (m5 - m4) / (r4 - r5) + m4;\n } else if (roughness >= r6) {\n mip = (r5 - roughness) * (m6 - m5) / (r5 - r6) + m5;\n } else {\n mip = -2.0 * log2(1.16 * roughness); }\n return mip;\n}\nvec4 textureCubeUV(sampler2D envMap, vec3 sampleDir, float roughness) {\n float mip = clamp(roughnessToMip(roughness), m0, cubeUV_maxMipLevel);\n float mipF = fract(mip);\n float mipInt = floor(mip);\n vec3 color0 = bilinearCubeUV(envMap, sampleDir, mipInt);\n if (mipF == 0.0) {\n return vec4(color0, 1.0);\n } else {\n vec3 color1 = bilinearCubeUV(envMap, sampleDir, mipInt + 1.0);\n return vec4(mix(color0, color1, mipF), 1.0);\n }\n}\n#endif",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",displacementmap_pars_vertex:"#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif",displacementmap_vertex:"#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif",emissivemap_fragment:"#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif",emissivemap_pars_fragment:"#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif",encodings_fragment:"gl_FragColor = linearToOutputTexel( gl_FragColor );",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}",envmap_fragment:"#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\t\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#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\treflectVec = normalize( reflectVec );\n\t\tvec2 sampleUV = equirectUv( reflectVec );\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\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",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",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",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",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 vec3 reflectVec = reflect( -viewDir, normal );\n\t\t reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t vec3 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#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV = equirectUv( reflectVec );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif",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",fog_vertex:"#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif",fog_pars_vertex:"#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif",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",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",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}",lightmap_fragment:"#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif",lightmap_pars_fragment:"#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif",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",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",lights_toon_fragment:"ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;",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)",lights_phong_fragment:"BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;",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)",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",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}",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",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",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",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",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",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",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",map_fragment:"#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif",map_pars_fragment:"#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif",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",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",metalnessmap_fragment:"float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif",metalnessmap_pars_fragment:"#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif",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",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",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",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;",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",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",clearcoat_normal_fragment_begin:"#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif",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",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",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}",premultiplied_alpha_fragment:"#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif",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;",dithering_fragment:"#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif",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",roughnessmap_fragment:"float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif",roughnessmap_pars_fragment:"#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif",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",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",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",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}",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",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",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",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",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",specularmap_pars_fragment:"#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif",tonemapping_fragment:"#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif",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; }",transmissionmap_fragment:"#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif",transmissionmap_pars_fragment:"#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif",uv_pars_fragment:"#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif",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",uv_vertex:"#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif",uv2_pars_fragment:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif",uv2_pars_vertex:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n\tuniform mat3 uv2Transform;\n#endif",uv2_vertex:"#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif",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",background_frag:"uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include \n\t#include \n}",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}",cube_frag:"#include \nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include \n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include \n\t#include \n}",cube_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n\tgl_Position.z = gl_Position.w;\n}",depth_frag:"#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include \n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \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}",depth_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvHighPrecisionZW = gl_Position.zw;\n}",distanceRGBA_frag:"#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main () {\n\t#include \n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include \n\t#include \n\t#include \n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}",distanceRGBA_vert:"#define DISTANCE\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include \n\t\t#include \n\t\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvWorldPosition = worldPosition.xyz;\n}",equirect_frag:"uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include \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 \n\t#include \n}",equirect_vert:"varying vec3 vWorldDirection;\n#include \nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include \n\t#include \n}",linedashed_frag:"uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n}",linedashed_vert:"uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshbasic_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \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 \n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include \n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshbasic_vert:"#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifdef USE_ENVMAP\n\t#include \n\t#include \n\t#include \n\t#include \n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",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 \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \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 \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 \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include \n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",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 \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",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 \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshmatcap_vert:"#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\n\t#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n}",meshtoon_frag:"#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshtoon_vert:"#define TOON\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n}",meshphong_frag:"#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include \n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",meshphong_vert:"#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n\t#include \n}",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 \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#ifdef TRANSMISSION\n\t\tdiffuseColor.a *= saturate( 1. - totalTransmission + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) );\n\t#endif\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",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 \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\tvViewPosition = - mvPosition.xyz;\n\t#include \n\t#include \n\t#include \n}",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 \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}",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 \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \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 \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}",points_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n\t#include \n}",points_vert:"uniform float size;\nuniform float scale;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \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 \n\t#include \n\t#include \n\t#include \n}",shadow_frag:"uniform vec3 color;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include \n\t#include \n\t#include \n}",shadow_vert:"#include \n#include \n#include \nvoid main() {\n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n\t#include \n}",sprite_frag:"uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include \n\t#include \n\t#include \n\t#include \n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include \n\t#include \n\t#include \n}",sprite_vert:"uniform float rotation;\nuniform vec2 center;\n#include \n#include \n#include \n#include \n#include \nvoid main() {\n\t#include \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 \n\t#include \n\t#include \n}"},In={basic:{uniforms:gn([Pn.common,Pn.specularmap,Pn.envmap,Pn.aomap,Pn.lightmap,Pn.fog]),vertexShader:Dn.meshbasic_vert,fragmentShader:Dn.meshbasic_frag},lambert:{uniforms:gn([Pn.common,Pn.specularmap,Pn.envmap,Pn.aomap,Pn.lightmap,Pn.emissivemap,Pn.fog,Pn.lights,{emissive:{value:new de(0)}}]),vertexShader:Dn.meshlambert_vert,fragmentShader:Dn.meshlambert_frag},phong:{uniforms:gn([Pn.common,Pn.specularmap,Pn.envmap,Pn.aomap,Pn.lightmap,Pn.emissivemap,Pn.bumpmap,Pn.normalmap,Pn.displacementmap,Pn.fog,Pn.lights,{emissive:{value:new de(0)},specular:{value:new de(1118481)},shininess:{value:30}}]),vertexShader:Dn.meshphong_vert,fragmentShader:Dn.meshphong_frag},standard:{uniforms:gn([Pn.common,Pn.envmap,Pn.aomap,Pn.lightmap,Pn.emissivemap,Pn.bumpmap,Pn.normalmap,Pn.displacementmap,Pn.roughnessmap,Pn.metalnessmap,Pn.fog,Pn.lights,{emissive:{value:new de(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Dn.meshphysical_vert,fragmentShader:Dn.meshphysical_frag},toon:{uniforms:gn([Pn.common,Pn.aomap,Pn.lightmap,Pn.emissivemap,Pn.bumpmap,Pn.normalmap,Pn.displacementmap,Pn.gradientmap,Pn.fog,Pn.lights,{emissive:{value:new de(0)}}]),vertexShader:Dn.meshtoon_vert,fragmentShader:Dn.meshtoon_frag},matcap:{uniforms:gn([Pn.common,Pn.bumpmap,Pn.normalmap,Pn.displacementmap,Pn.fog,{matcap:{value:null}}]),vertexShader:Dn.meshmatcap_vert,fragmentShader:Dn.meshmatcap_frag},points:{uniforms:gn([Pn.points,Pn.fog]),vertexShader:Dn.points_vert,fragmentShader:Dn.points_frag},dashed:{uniforms:gn([Pn.common,Pn.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Dn.linedashed_vert,fragmentShader:Dn.linedashed_frag},depth:{uniforms:gn([Pn.common,Pn.displacementmap]),vertexShader:Dn.depth_vert,fragmentShader:Dn.depth_frag},normal:{uniforms:gn([Pn.common,Pn.bumpmap,Pn.normalmap,Pn.displacementmap,{opacity:{value:1}}]),vertexShader:Dn.normal_vert,fragmentShader:Dn.normal_frag},sprite:{uniforms:gn([Pn.sprite,Pn.fog]),vertexShader:Dn.sprite_vert,fragmentShader:Dn.sprite_frag},background:{uniforms:{uvTransform:{value:new F},t2D:{value:null}},vertexShader:Dn.background_vert,fragmentShader:Dn.background_frag},cube:{uniforms:gn([Pn.envmap,{opacity:{value:1}}]),vertexShader:Dn.cube_vert,fragmentShader:Dn.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Dn.equirect_vert,fragmentShader:Dn.equirect_frag},distanceRGBA:{uniforms:gn([Pn.common,Pn.displacementmap,{referencePosition:{value:new Z},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Dn.distanceRGBA_vert,fragmentShader:Dn.distanceRGBA_frag},shadow:{uniforms:gn([Pn.lights,Pn.fog,{color:{value:new de(0)},opacity:{value:1}}]),vertexShader:Dn.shadow_vert,fragmentShader:Dn.shadow_frag}};function zn(t,n,i,r){var a,o,s=new de(0),c=0,h=null,l=0,u=null;function d(t,e){n.buffers.color.setClear(t.r,t.g,t.b,e,r)}return{getClearColor:function(){return s},setClearColor:function(t,e){s.set(t),d(s,c=void 0!==e?e:1)},getClearAlpha:function(){return c},setClearAlpha:function(t){d(s,c=t)},render:function(n,r,p,f){var m=!0===r.isScene?r.background:null,v=t.xr,g=v.getSession&&v.getSession();if(g&&"additive"===g.environmentBlendMode&&(m=null),null===m?d(s,c):m&&m.isColor&&(d(m,1),f=!0),(t.autoClear||f)&&t.clear(t.autoClearColor,t.autoClearDepth,t.autoClearStencil),m&&(m.isCubeTexture||m.isWebGLCubeRenderTarget||m.mapping===e)){void 0===o&&((o=new on(new mn(1,1,1),new xn({name:"BackgroundCubeMaterial",uniforms:vn(In.cube.uniforms),vertexShader:In.cube.vertexShader,fragmentShader:In.cube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1}))).geometry.deleteAttribute("normal"),o.geometry.deleteAttribute("uv"),o.onBeforeRender=function(t,e,n){this.matrixWorld.copyPosition(n.matrixWorld)},Object.defineProperty(o.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),i.update(o));var y=m.isWebGLCubeRenderTarget?m.texture:m;o.material.uniforms.envMap.value=y,o.material.uniforms.flipEnvMap.value=y.isCubeTexture?-1:1,h===m&&l===y.version&&u===t.toneMapping||(o.material.needsUpdate=!0,h=m,l=y.version,u=t.toneMapping),n.unshift(o,o.geometry,o.material,0,0,null)}else m&&m.isTexture&&(void 0===a&&((a=new on(new Nn(2,2),new xn({name:"BackgroundMaterial",uniforms:vn(In.background.uniforms),vertexShader:In.background.vertexShader,fragmentShader:In.background.fragmentShader,side:0,depthTest:!1,depthWrite:!1,fog:!1}))).geometry.deleteAttribute("normal"),Object.defineProperty(a.material,"map",{get:function(){return this.uniforms.t2D.value}}),i.update(a)),a.material.uniforms.t2D.value=m,!0===m.matrixAutoUpdate&&m.updateMatrix(),a.material.uniforms.uvTransform.value.copy(m.matrix),h===m&&l===m.version&&u===t.toneMapping||(a.material.needsUpdate=!0,h=m,l=m.version,u=t.toneMapping),n.unshift(a,a.geometry,a.material,0,0,null))}}}function Bn(t,e,n,i){var r=t.getParameter(34921),a=i.isWebGL2?null:e.get("OES_vertex_array_object"),o=i.isWebGL2||null!==a,s={},c=d(null),h=c;function l(e){return i.isWebGL2?t.bindVertexArray(e):a.bindVertexArrayOES(e)}function u(e){return i.isWebGL2?t.deleteVertexArray(e):a.deleteVertexArrayOES(e)}function d(t){for(var e=[],n=[],i=[],a=0;a=0){var y=c[u];if(void 0!==y){var x=y.normalized,_=y.itemSize,b=n.get(y);if(void 0===b)continue;var w=b.buffer,M=b.type,S=b.bytesPerElement;if(y.isInterleavedBufferAttribute){var E=y.data,T=E.stride,A=y.offset;E&&E.isInstancedInterleavedBuffer?(m(d,E.meshPerAttribute),void 0===s._maxInstanceCount&&(s._maxInstanceCount=E.meshPerAttribute*E.count)):f(d),t.bindBuffer(34962,w),g(d,_,M,x,T*S,A*S)}else y.isInstancedBufferAttribute?(m(d,y.meshPerAttribute),void 0===s._maxInstanceCount&&(s._maxInstanceCount=y.meshPerAttribute*y.count)):f(d),t.bindBuffer(34962,w),g(d,_,M,x,0,0)}else if("instanceMatrix"===u){var L=n.get(r.instanceMatrix);if(void 0===L)continue;var P=L.buffer,R=L.type;m(d+0,1),m(d+1,1),m(d+2,1),m(d+3,1),t.bindBuffer(34962,P),t.vertexAttribPointer(d+0,4,R,!1,64,0),t.vertexAttribPointer(d+1,4,R,!1,64,16),t.vertexAttribPointer(d+2,4,R,!1,64,32),t.vertexAttribPointer(d+3,4,R,!1,64,48)}else if(void 0!==l){var C=l[u];if(void 0!==C)switch(C.length){case 2:t.vertexAttrib2fv(d,C);break;case 3:t.vertexAttrib3fv(d,C);break;case 4:t.vertexAttrib4fv(d,C);break;default:t.vertexAttrib1fv(d,C)}}}}v()}(r,c,u,y),null!==x&&t.bindBuffer(34963,n.get(x).buffer))},reset:y,resetDefaultState:x,dispose:function(){for(var t in y(),s){var e=s[t];for(var n in e){var i=e[n];for(var r in i)u(i[r].object),delete i[r];delete e[n]}delete s[t]}},releaseStatesOfGeometry:function(t){if(void 0!==s[t.id]){var e=s[t.id];for(var n in e){var i=e[n];for(var r in i)u(i[r].object),delete i[r];delete e[n]}delete s[t.id]}},releaseStatesOfProgram:function(t){for(var e in s){var n=s[e];if(void 0!==n[t.id]){var i=n[t.id];for(var r in i)u(i[r].object),delete i[r];delete n[t.id]}}},initAttributes:p,enableAttribute:f,disableUnusedAttributes:v}}function Un(t,e,n,i){var r,a=i.isWebGL2;this.setMode=function(t){r=t},this.render=function(e,i){t.drawArrays(r,e,i),n.update(i,r,1)},this.renderInstances=function(i,o,s){if(0!==s){var c,h;if(a)c=t,h="drawArraysInstanced";else if(h="drawArraysInstancedANGLE",null===(c=e.get("ANGLE_instanced_arrays")))return void console.error("THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.");c[h](r,i,o,s),n.update(o,r,s)}}}function Fn(t,e,n){var i;function r(e){if("highp"===e){if(t.getShaderPrecisionFormat(35633,36338).precision>0&&t.getShaderPrecisionFormat(35632,36338).precision>0)return"highp";e="mediump"}return"mediump"===e&&t.getShaderPrecisionFormat(35633,36337).precision>0&&t.getShaderPrecisionFormat(35632,36337).precision>0?"mediump":"lowp"}var a="undefined"!=typeof WebGL2RenderingContext&&t instanceof WebGL2RenderingContext||"undefined"!=typeof WebGL2ComputeRenderingContext&&t instanceof WebGL2ComputeRenderingContext,o=void 0!==n.precision?n.precision:"highp",s=r(o);s!==o&&(console.warn("THREE.WebGLRenderer:",o,"not supported, using",s,"instead."),o=s);var c=!0===n.logarithmicDepthBuffer,h=t.getParameter(34930),l=t.getParameter(35660),u=t.getParameter(3379),d=t.getParameter(34076),p=t.getParameter(34921),f=t.getParameter(36347),m=t.getParameter(36348),v=t.getParameter(36349),g=l>0,y=a||!!e.get("OES_texture_float");return{isWebGL2:a,getMaxAnisotropy:function(){if(void 0!==i)return i;var n=e.get("EXT_texture_filter_anisotropic");return i=null!==n?t.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0},getMaxPrecision:r,precision:o,logarithmicDepthBuffer:c,maxTextures:h,maxVertexTextures:l,maxTextureSize:u,maxCubemapSize:d,maxAttributes:p,maxVertexUniforms:f,maxVaryings:m,maxFragmentUniforms:v,vertexTextures:g,floatFragmentTextures:y,floatVertexTextures:g&&y,maxSamples:a?t.getParameter(36183):0}}function kn(){var t=this,e=null,n=0,i=!1,r=!1,a=new Qt,o=new F,s={value:null,needsUpdate:!1};function c(){s.value!==e&&(s.value=e,s.needsUpdate=n>0),t.numPlanes=n,t.numIntersection=0}function h(e,n,i,r){var c=null!==e?e.length:0,h=null;if(0!==c){if(h=s.value,!0!==r||null===h){var l=i+4*c,u=n.matrixWorldInverse;o.getNormalMatrix(u),(null===h||h.length65535?Pe:Ae)(n,1);x.version=o;var _=a.get(t);_&&e.remove(_),a.set(t,x)}return{get:function(t,e){var i=r.get(e);return i||(e.addEventListener("dispose",o),e.isBufferGeometry?i=e:e.isGeometry&&(void 0===e._bufferGeometry&&(e._bufferGeometry=(new He).setFromObject(t)),i=e._bufferGeometry),r.set(e,i),n.memory.geometries++,i)},update:function(t){var n=t.attributes;for(var i in n)e.update(n[i],34962);var r=t.morphAttributes;for(var a in r)for(var o=r[a],s=0,c=o.length;s0)return t;var r=e*n,a=ni[r];if(void 0===a&&(a=new Float32Array(r),ni[r]=a),0!==e){i.toArray(a,0);for(var o=1,s=0;o!==e;++o)s+=n,t[o].toArray(a,s)}return a}function ci(t,e){if(t.length!==e.length)return!1;for(var n=0,i=t.length;n/gm;function ir(t){return t.replace(nr,rr)}function rr(t,e){var n=Dn[e];if(void 0===n)throw new Error("Can not resolve #include <"+e+">");return ir(n)}var ar=/#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g,or=/#pragma unroll_loop_start[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}[\s]+?#pragma unroll_loop_end/g;function sr(t){return t.replace(or,hr).replace(ar,cr)}function cr(t,e,n,i){return console.warn("WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead."),hr(t,e,n,i)}function hr(t,e,n,i){for(var r="",a=parseInt(e);a0?t.gammaFactor:1,_=r.isWebGL2?"":function(t){return[t.extensionDerivatives||t.envMapCubeUV||t.bumpMap||t.tangentSpaceNormalMap||t.clearcoatNormalMap||t.flatShading||"physical"===t.shaderID?"#extension GL_OES_standard_derivatives : enable":"",(t.extensionFragDepth||t.logarithmicDepthBuffer)&&t.rendererExtensionFragDepth?"#extension GL_EXT_frag_depth : enable":"",t.extensionDrawBuffers&&t.rendererExtensionDrawBuffers?"#extension GL_EXT_draw_buffers : require":"",(t.extensionShaderTextureLOD||t.envMap)&&t.rendererExtensionShaderTextureLod?"#extension GL_EXT_shader_texture_lod : enable":""].filter($i).join("\n")}(r),b=function(t){var e=[];for(var n in t){var i=t[n];!1!==i&&e.push("#define "+n+" "+i)}return e.join("\n")}(d),w=u.createProgram();r.isRawShaderMaterial?((o=[b].filter($i).join("\n")).length>0&&(o+="\n"),(s=[_,b].filter($i).join("\n")).length>0&&(s+="\n")):(o=[lr(r),"#define SHADER_NAME "+r.shaderName,b,r.instancing?"#define USE_INSTANCING":"",r.supportsVertexTextures?"#define VERTEX_TEXTURES":"","#define GAMMA_FACTOR "+x,"#define MAX_BONES "+r.maxBones,r.useFog&&r.fog?"#define USE_FOG":"",r.useFog&&r.fogExp2?"#define FOG_EXP2":"",r.map?"#define USE_MAP":"",r.envMap?"#define USE_ENVMAP":"",r.envMap?"#define "+g:"",r.lightMap?"#define USE_LIGHTMAP":"",r.aoMap?"#define USE_AOMAP":"",r.emissiveMap?"#define USE_EMISSIVEMAP":"",r.bumpMap?"#define USE_BUMPMAP":"",r.normalMap?"#define USE_NORMALMAP":"",r.normalMap&&r.objectSpaceNormalMap?"#define OBJECTSPACE_NORMALMAP":"",r.normalMap&&r.tangentSpaceNormalMap?"#define TANGENTSPACE_NORMALMAP":"",r.clearcoatMap?"#define USE_CLEARCOATMAP":"",r.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",r.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",r.displacementMap&&r.supportsVertexTextures?"#define USE_DISPLACEMENTMAP":"",r.specularMap?"#define USE_SPECULARMAP":"",r.roughnessMap?"#define USE_ROUGHNESSMAP":"",r.metalnessMap?"#define USE_METALNESSMAP":"",r.alphaMap?"#define USE_ALPHAMAP":"",r.transmissionMap?"#define USE_TRANSMISSIONMAP":"",r.vertexTangents?"#define USE_TANGENT":"",r.vertexColors?"#define USE_COLOR":"",r.vertexUvs?"#define USE_UV":"",r.uvsVertexOnly?"#define UVS_VERTEX_ONLY":"",r.flatShading?"#define FLAT_SHADED":"",r.skinning?"#define USE_SKINNING":"",r.useVertexTexture?"#define BONE_TEXTURE":"",r.morphTargets?"#define USE_MORPHTARGETS":"",r.morphNormals&&!1===r.flatShading?"#define USE_MORPHNORMALS":"",r.doubleSided?"#define DOUBLE_SIDED":"",r.flipSided?"#define FLIP_SIDED":"",r.shadowMapEnabled?"#define USE_SHADOWMAP":"",r.shadowMapEnabled?"#define "+m:"",r.sizeAttenuation?"#define USE_SIZEATTENUATION":"",r.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",r.logarithmicDepthBuffer&&r.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","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","#ifdef USE_TANGENT","\tattribute vec4 tangent;","#endif","#ifdef USE_COLOR","\tattribute vec3 color;","#endif","#ifdef USE_MORPHTARGETS","\tattribute vec3 morphTarget0;","\tattribute vec3 morphTarget1;","\tattribute vec3 morphTarget2;","\tattribute vec3 morphTarget3;","\t#ifdef USE_MORPHNORMALS","\t\tattribute vec3 morphNormal0;","\t\tattribute vec3 morphNormal1;","\t\tattribute vec3 morphNormal2;","\t\tattribute vec3 morphNormal3;","\t#else","\t\tattribute vec3 morphTarget4;","\t\tattribute vec3 morphTarget5;","\t\tattribute vec3 morphTarget6;","\t\tattribute vec3 morphTarget7;","\t#endif","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif","\n"].filter($i).join("\n"),s=[_,lr(r),"#define SHADER_NAME "+r.shaderName,b,r.alphaTest?"#define ALPHATEST "+r.alphaTest+(r.alphaTest%1?"":".0"):"","#define GAMMA_FACTOR "+x,r.useFog&&r.fog?"#define USE_FOG":"",r.useFog&&r.fogExp2?"#define FOG_EXP2":"",r.map?"#define USE_MAP":"",r.matcap?"#define USE_MATCAP":"",r.envMap?"#define USE_ENVMAP":"",r.envMap?"#define "+v:"",r.envMap?"#define "+g:"",r.envMap?"#define "+y:"",r.lightMap?"#define USE_LIGHTMAP":"",r.aoMap?"#define USE_AOMAP":"",r.emissiveMap?"#define USE_EMISSIVEMAP":"",r.bumpMap?"#define USE_BUMPMAP":"",r.normalMap?"#define USE_NORMALMAP":"",r.normalMap&&r.objectSpaceNormalMap?"#define OBJECTSPACE_NORMALMAP":"",r.normalMap&&r.tangentSpaceNormalMap?"#define TANGENTSPACE_NORMALMAP":"",r.clearcoatMap?"#define USE_CLEARCOATMAP":"",r.clearcoatRoughnessMap?"#define USE_CLEARCOAT_ROUGHNESSMAP":"",r.clearcoatNormalMap?"#define USE_CLEARCOAT_NORMALMAP":"",r.specularMap?"#define USE_SPECULARMAP":"",r.roughnessMap?"#define USE_ROUGHNESSMAP":"",r.metalnessMap?"#define USE_METALNESSMAP":"",r.alphaMap?"#define USE_ALPHAMAP":"",r.sheen?"#define USE_SHEEN":"",r.transmissionMap?"#define USE_TRANSMISSIONMAP":"",r.vertexTangents?"#define USE_TANGENT":"",r.vertexColors?"#define USE_COLOR":"",r.vertexUvs?"#define USE_UV":"",r.uvsVertexOnly?"#define UVS_VERTEX_ONLY":"",r.gradientMap?"#define USE_GRADIENTMAP":"",r.flatShading?"#define FLAT_SHADED":"",r.doubleSided?"#define DOUBLE_SIDED":"",r.flipSided?"#define FLIP_SIDED":"",r.shadowMapEnabled?"#define USE_SHADOWMAP":"",r.shadowMapEnabled?"#define "+m:"",r.premultipliedAlpha?"#define PREMULTIPLIED_ALPHA":"",r.physicallyCorrectLights?"#define PHYSICALLY_CORRECT_LIGHTS":"",r.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"",r.logarithmicDepthBuffer&&r.rendererExtensionFragDepth?"#define USE_LOGDEPTHBUF_EXT":"",(r.extensionShaderTextureLOD||r.envMap)&&r.rendererExtensionShaderTextureLod?"#define TEXTURE_LOD_EXT":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;","uniform bool isOrthographic;",0!==r.toneMapping?"#define TONE_MAPPING":"",0!==r.toneMapping?Dn.tonemapping_pars_fragment:"",0!==r.toneMapping?Ki("toneMapping",r.toneMapping):"",r.dithering?"#define DITHERING":"",Dn.encodings_pars_fragment,r.map?Qi("mapTexelToLinear",r.mapEncoding):"",r.matcap?Qi("matcapTexelToLinear",r.matcapEncoding):"",r.envMap?Qi("envMapTexelToLinear",r.envMapEncoding):"",r.emissiveMap?Qi("emissiveMapTexelToLinear",r.emissiveMapEncoding):"",r.lightMap?Qi("lightMapTexelToLinear",r.lightMapEncoding):"",(c="linearToOutputTexel",h=r.outputEncoding,l=Zi(h),"vec4 "+c+"( vec4 value ) { return LinearTo"+l[0]+l[1]+"; }"),r.depthPacking?"#define DEPTH_PACKING "+r.depthPacking:"","\n"].filter($i).join("\n")),p=er(p=tr(p=ir(p),r),r),f=er(f=tr(f=ir(f),r),r),p=sr(p),f=sr(f),r.isWebGL2&&!r.isRawShaderMaterial&&(o=["#version 300 es\n","#define attribute in","#define varying out","#define texture2D texture"].join("\n")+"\n"+o,s=["#version 300 es\n","#define varying in","out highp vec4 pc_fragColor;","#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"+s);var M,S,E=s+f,T=Xi(u,35633,o+p),A=Xi(u,35632,E);if(u.attachShader(w,T),u.attachShader(w,A),void 0!==r.index0AttributeName?u.bindAttribLocation(w,0,r.index0AttributeName):!0===r.morphTargets&&u.bindAttribLocation(w,0,"position"),u.linkProgram(w),t.debug.checkShaderErrors){var L=u.getProgramInfoLog(w).trim(),P=u.getShaderInfoLog(T).trim(),R=u.getShaderInfoLog(A).trim(),C=!0,O=!0;if(!1===u.getProgramParameter(w,35714)){C=!1;var N=Ji(u,T,"vertex"),D=Ji(u,A,"fragment");console.error("THREE.WebGLProgram: shader error: ",u.getError(),"35715",u.getProgramParameter(w,35715),"gl.getProgramInfoLog",L,N,D)}else""!==L?console.warn("THREE.WebGLProgram: gl.getProgramInfoLog()",L):""!==P&&""!==R||(O=!1);O&&(this.diagnostics={runnable:C,programLog:L,vertexShader:{log:P,prefix:o},fragmentShader:{log:R,prefix:s}})}return u.deleteShader(T),u.deleteShader(A),this.getUniforms=function(){return void 0===M&&(M=new qi(u,w)),M},this.getAttributes=function(){return void 0===S&&(S=function(t,e){for(var n={},i=t.getProgramParameter(e,35721),r=0;r0,maxBones:T,useVertexTexture:h,morphTargets:a.morphTargets,morphNormals:a.morphNormals,maxMorphTargets:t.maxMorphTargets,maxMorphNormals:t.maxMorphNormals,numDirLights:o.directional.length,numPointLights:o.point.length,numSpotLights:o.spot.length,numRectAreaLights:o.rectArea.length,numHemiLights:o.hemi.length,numDirLightShadows:o.directionalShadowMap.length,numPointLightShadows:o.pointShadowMap.length,numSpotLightShadows:o.spotShadowMap.length,numClippingPlanes:g,numClipIntersection:y,dithering:a.dithering,shadowMapEnabled:t.shadowMap.enabled&&f.length>0,shadowMapType:t.shadowMap.type,toneMapping:a.toneMapped?t.toneMapping:0,physicallyCorrectLights:t.physicallyCorrectLights,premultipliedAlpha:a.premultipliedAlpha,alphaTest:a.alphaTest,doubleSided:2===a.side,flipSided:1===a.side,depthPacking:void 0!==a.depthPacking&&a.depthPacking,index0AttributeName:a.index0AttributeName,extensionDerivatives:a.extensions&&a.extensions.derivatives,extensionFragDepth:a.extensions&&a.extensions.fragDepth,extensionDrawBuffers:a.extensions&&a.extensions.drawBuffers,extensionShaderTextureLOD:a.extensions&&a.extensions.shaderTextureLOD,rendererExtensionFragDepth:s||null!==i.get("EXT_frag_depth"),rendererExtensionDrawBuffers:s||null!==i.get("WEBGL_draw_buffers"),rendererExtensionShaderTextureLod:s||null!==i.get("EXT_shader_texture_lod"),customProgramCacheKey:a.customProgramCacheKey()}},getProgramCacheKey:function(e){var n=[];if(e.shaderID?n.push(e.shaderID):(n.push(e.fragmentShader),n.push(e.vertexShader)),void 0!==e.defines)for(var i in e.defines)n.push(i),n.push(e.defines[i]);if(void 0===e.isRawShaderMaterial){for(var r=0;r1&&i.sort(t||fr),r.length>1&&r.sort(e||mr)}}}function gr(t){var e=new WeakMap;function n(t){var i=t.target;i.removeEventListener("dispose",n),e.delete(i)}return{get:function(i,r){var a,o=e.get(i);return void 0===o?(a=new vr(t),e.set(i,new WeakMap),e.get(i).set(r,a),i.addEventListener("dispose",n)):void 0===(a=o.get(r))&&(a=new vr(t),o.set(r,a)),a},dispose:function(){e=new WeakMap}}}function yr(){var t={};return{get:function(e){if(void 0!==t[e.id])return t[e.id];var n;switch(e.type){case"DirectionalLight":n={direction:new Z,color:new de};break;case"SpotLight":n={position:new Z,direction:new Z,color:new de,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case"PointLight":n={position:new Z,color:new de,distance:0,decay:0};break;case"HemisphereLight":n={direction:new Z,skyColor:new de,groundColor:new de};break;case"RectAreaLight":n={color:new de,position:new Z,halfWidth:new Z,halfHeight:new Z}}return t[e.id]=n,n}}}var xr=0;function _r(t,e){return(e.castShadow?1:0)-(t.castShadow?1:0)}function br(){for(var t,e=new yr,n=(t={},{get:function(e){if(void 0!==t[e.id])return t[e.id];var n;switch(e.type){case"DirectionalLight":case"SpotLight":n={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new U};break;case"PointLight":n={shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new U,shadowCameraNear:1,shadowCameraFar:1e3}}return t[e.id]=n,n}}),i={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotShadow:[],spotShadowMap:[],spotShadowMatrix:[],rectArea:[],point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[]},r=0;r<9;r++)i.probe.push(new Z);var a=new Z,o=new it,s=new it;return{setup:function(t,r,c){for(var h=0,l=0,u=0,d=0;d<9;d++)i.probe[d].set(0,0,0);var p=0,f=0,m=0,v=0,g=0,y=0,x=0,_=0,b=c.matrixWorldInverse;t.sort(_r);for(var w=0,M=t.length;w\nvoid main() {\n float mean = 0.0;\n float squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n for ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n #ifdef HORIZONAL_PASS\n vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n mean += distribution.x;\n squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n #else\n float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n mean += depth;\n squared_mean += depth * depth;\n #endif\n }\n mean = mean * HALF_SAMPLE_RATE;\n squared_mean = squared_mean * HALF_SAMPLE_RATE;\n float std_dev = sqrt( squared_mean - mean * mean );\n gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}"}),f=p.clone();f.defines.HORIZONAL_PASS=1;var m=new He;m.setAttribute("position",new we(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));var v=new on(m,p),g=this;function x(n,i){var r=e.update(v);p.uniforms.shadow_pass.value=n.map.texture,p.uniforms.resolution.value=n.mapSize,p.uniforms.radius.value=n.radius,t.setRenderTarget(n.mapPass),t.clear(),t.renderBufferDirect(i,null,r,p,v,null),f.uniforms.shadow_pass.value=n.mapPass.texture,f.uniforms.resolution.value=n.mapSize,f.uniforms.radius.value=n.radius,t.setRenderTarget(n.map),t.clear(),t.renderBufferDirect(i,null,r,f,v,null)}function _(t,e,n){var i=t<<0|e<<1|n<<2,r=c[i];return void 0===r&&(r=new Sr({depthPacking:3201,morphTargets:t,skinning:e}),c[i]=r),r}function b(t,e,n){var i=t<<0|e<<1|n<<2,r=l[i];return void 0===r&&(r=new Er({morphTargets:t,skinning:e}),l[i]=r),r}function w(e,n,i,r,a,o,s){var c=null,h=_,l=e.customDepthMaterial;if(!0===r.isPointLight&&(h=b,l=e.customDistanceMaterial),void 0===l){var p=!1;!0===i.morphTargets&&(p=n.morphAttributes&&n.morphAttributes.position&&n.morphAttributes.position.length>0);var f=!1;!0===e.isSkinnedMesh&&(!0===i.skinning?f=!0:console.warn("THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:",e)),c=h(p,f,!0===e.isInstancedMesh)}else c=l;if(t.localClippingEnabled&&!0===i.clipShadows&&0!==i.clippingPlanes.length){var m=c.uuid,v=i.uuid,g=u[m];void 0===g&&(g={},u[m]=g);var y=g[v];void 0===y&&(y=c.clone(),g[v]=y),c=y}return c.visible=i.visible,c.wireframe=i.wireframe,c.side=3===s?null!==i.shadowSide?i.shadowSide:i.side:null!==i.shadowSide?i.shadowSide:d[i.side],c.clipShadows=i.clipShadows,c.clippingPlanes=i.clippingPlanes,c.clipIntersection=i.clipIntersection,c.wireframeLinewidth=i.wireframeLinewidth,c.linewidth=i.linewidth,!0===r.isPointLight&&!0===c.isMeshDistanceMaterial&&(c.referencePosition.setFromMatrixPosition(r.matrixWorld),c.nearDistance=a,c.farDistance=o),c}function M(n,r,a,o,s){if(!1!==n.visible){if(n.layers.test(r.layers)&&(n.isMesh||n.isLine||n.isPoints)&&(n.castShadow||n.receiveShadow&&3===s)&&(!n.frustumCulled||i.intersectsObject(n))){n.modelViewMatrix.multiplyMatrices(a.matrixWorldInverse,n.matrixWorld);var c=e.update(n),h=n.material;if(Array.isArray(h))for(var l=c.groups,u=0,d=l.length;un||r.y>n)&&(r.x>n&&(a.x=Math.floor(n/w.x),r.x=a.x*w.x,b.mapSize.x=a.x),r.y>n&&(a.y=Math.floor(n/w.y),r.y=a.y*w.y,b.mapSize.y=a.y)),null===b.map&&!b.isPointLightShadow&&3===this.type){var S={minFilter:h,magFilter:h,format:y,stencilBuffer:!1};b.map=new j(r.x,r.y,S),b.map.texture.name=_.name+".shadowMap",b.mapPass=new j(r.x,r.y,S),b.camera.updateProjectionMatrix()}if(null===b.map){var E={minFilter:o,magFilter:o,format:y,stencilBuffer:!1};b.map=new j(r.x,r.y,E),b.map.texture.name=_.name+".shadowMap",b.camera.updateProjectionMatrix()}t.setRenderTarget(b.map),t.clear();for(var T=b.getViewportCount(),A=0;A=1):-1!==A.indexOf("OpenGL ES")&&(T=parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(A)[1]),E=T>=2);var L=null,P={},R=new V,C=new V;function O(t,n,i){var r=new Uint8Array(4),a=e.createTexture();e.bindTexture(t,a),e.texParameteri(t,10241,9728),e.texParameteri(t,10240,9728);for(var o=0;oi||t.height>i)&&(r=i/Math.max(t.width,t.height)),r<1||!0===e){if("undefined"!=typeof HTMLImageElement&&t instanceof HTMLImageElement||"undefined"!=typeof HTMLCanvasElement&&t instanceof HTMLCanvasElement||"undefined"!=typeof ImageBitmap&&t instanceof ImageBitmap){var a=e?B.floorPowerOfTwo:Math.floor,o=a(r*t.width),s=a(r*t.height);void 0===b&&(b=P(o,s));var c=n?P(o,s):b;return c.width=o,c.height=s,c.getContext("2d").drawImage(t,0,0,o,s),console.warn("THREE.WebGLRenderer: Texture has been resized from ("+t.width+"x"+t.height+") to ("+o+"x"+s+")."),c}return"data"in t&&console.warn("THREE.WebGLRenderer: Image in DataTexture is too big ("+t.width+"x"+t.height+")."),t}return t}function C(t){return B.isPowerOfTwo(t.width)&&B.isPowerOfTwo(t.height)}function O(t,e){return t.generateMipmaps&&e&&t.minFilter!==o&&t.minFilter!==h}function N(e,n,r,a){t.generateMipmap(e),i.get(n).__maxMipLevel=Math.log(Math.max(r,a))*Math.LOG2E}function D(n,i,r){if(!1===w)return i;if(null!==n){if(void 0!==t[n])return t[n];console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '"+n+"'")}var a=i;return 6403===i&&(5126===r&&(a=33326),5131===r&&(a=33325),5121===r&&(a=33321)),6407===i&&(5126===r&&(a=34837),5131===r&&(a=34843),5121===r&&(a=32849)),6408===i&&(5126===r&&(a=34836),5131===r&&(a=34842),5121===r&&(a=32856)),33325!==a&&33326!==a&&34842!==a&&34836!==a||e.get("EXT_color_buffer_float"),a}function I(t){return t===o||t===s||t===c?9728:9729}function z(e){var n=e.target;n.removeEventListener("dispose",z),function(e){var n=i.get(e);if(void 0===n.__webglInit)return;t.deleteTexture(n.__webglTexture),i.remove(e)}(n),n.isVideoTexture&&A.delete(n),u.memory.textures--}function U(e){var n=e.target;n.removeEventListener("dispose",U),function(e){var n=i.get(e),r=i.get(e.texture);if(!e)return;void 0!==r.__webglTexture&&t.deleteTexture(r.__webglTexture);e.depthTexture&&e.depthTexture.dispose();if(e.isWebGLCubeRenderTarget)for(var a=0;a<6;a++)t.deleteFramebuffer(n.__webglFramebuffer[a]),n.__webglDepthbuffer&&t.deleteRenderbuffer(n.__webglDepthbuffer[a]);else t.deleteFramebuffer(n.__webglFramebuffer),n.__webglDepthbuffer&&t.deleteRenderbuffer(n.__webglDepthbuffer),n.__webglMultisampledFramebuffer&&t.deleteFramebuffer(n.__webglMultisampledFramebuffer),n.__webglColorRenderbuffer&&t.deleteRenderbuffer(n.__webglColorRenderbuffer),n.__webglDepthRenderbuffer&&t.deleteRenderbuffer(n.__webglDepthRenderbuffer);i.remove(e.texture),i.remove(e)}(n),u.memory.textures--}var F=0;function k(t,e){var r=i.get(t);if(t.isVideoTexture&&function(t){var e=u.render.frame;A.get(t)!==e&&(A.set(t,e),t.update())}(t),t.version>0&&r.__version!==t.version){var a=t.image;if(void 0===a)console.warn("THREE.WebGLRenderer: Texture marked for update but image is undefined");else{if(!1!==a.complete)return void X(r,t,e);console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete")}}n.activeTexture(33984+e),n.bindTexture(3553,r.__webglTexture)}function H(e,r){if(6===e.image.length){var a=i.get(e);if(e.version>0&&a.__version!==e.version){q(a,e),n.activeTexture(33984+r),n.bindTexture(34067,a.__webglTexture),t.pixelStorei(37440,e.flipY);for(var o=e&&(e.isCompressedTexture||e.image[0].isCompressedTexture),s=e.image[0]&&e.image[0].isDataTexture,c=[],h=0;h<6;h++)c[h]=o||s?s?e.image[h].image:e.image[h]:R(e.image[h],!1,!0,S);var u,d=c[0],p=C(d)||w,f=l.convert(e.format),m=l.convert(e.type),v=D(e.internalFormat,f,m);if(W(34067,e,p),o){for(var x=0;x<6;x++){u=c[x].mipmaps;for(var _=0;_1||i.get(s).__currentAnisotropy)&&(t.texParameterf(n,l.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(s.anisotropy,a.getMaxAnisotropy())),i.get(s).__currentAnisotropy=s.anisotropy)}}function q(e,n){void 0===e.__webglInit&&(e.__webglInit=!0,n.addEventListener("dispose",z),e.__webglTexture=t.createTexture(),u.memory.textures++)}function X(e,i,a){var s=3553;i.isDataTexture2DArray&&(s=35866),i.isDataTexture3D&&(s=32879),q(e,i),n.activeTexture(33984+a),n.bindTexture(s,e.__webglTexture),t.pixelStorei(37440,i.flipY),t.pixelStorei(37441,i.premultiplyAlpha),t.pixelStorei(3317,i.unpackAlignment);var c,u=function(t){return!w&&(t.wrapS!==r||t.wrapT!==r||t.minFilter!==o&&t.minFilter!==h)}(i)&&!1===C(i.image),m=R(i.image,u,!1,E),b=C(m)||w,M=l.convert(i.format),S=l.convert(i.type),T=D(i.internalFormat,M,S);W(s,i,b);var A=i.mipmaps;if(i.isDepthTexture)T=6402,w?T=i.type===f?36012:i.type===p?33190:i.type===v?35056:33189:i.type===f&&console.error("WebGLRenderer: Floating point depth texture requires WebGL2."),i.format===x&&6402===T&&i.type!==d&&i.type!==p&&(console.warn("THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture."),i.type=d,S=l.convert(i.type)),i.format===_&&6402===T&&(T=34041,i.type!==v&&(console.warn("THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture."),i.type=v,S=l.convert(i.type))),n.texImage2D(3553,0,T,m.width,m.height,0,M,S,null);else if(i.isDataTexture)if(A.length>0&&b){for(var L=0,P=A.length;L0&&b){for(var B=0,U=A.length;B=M&&console.warn("THREE.WebGLTextures: Trying to use "+t+" texture units while this GPU supports only "+M),F+=1,t},this.resetTextureUnits=function(){F=0},this.setTexture2D=k,this.setTexture2DArray=function(t,e){var r=i.get(t);t.version>0&&r.__version!==t.version?X(r,t,e):(n.activeTexture(33984+e),n.bindTexture(35866,r.__webglTexture))},this.setTexture3D=function(t,e){var r=i.get(t);t.version>0&&r.__version!==t.version?X(r,t,e):(n.activeTexture(33984+e),n.bindTexture(32879,r.__webglTexture))},this.setTextureCube=H,this.setTextureCubeDynamic=G,this.setupRenderTarget=function(e){var r=i.get(e),a=i.get(e.texture);e.addEventListener("dispose",U),a.__webglTexture=t.createTexture(),u.memory.textures++;var o=!0===e.isWebGLCubeRenderTarget,s=!0===e.isWebGLMultisampleRenderTarget,c=C(e)||w;if(!w||e.texture.format!==g||e.texture.type!==f&&e.texture.type!==m||(e.texture.format=y,console.warn("THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.")),o){r.__webglFramebuffer=[];for(var h=0;h<6;h++)r.__webglFramebuffer[h]=t.createFramebuffer()}else if(r.__webglFramebuffer=t.createFramebuffer(),s)if(w){r.__webglMultisampledFramebuffer=t.createFramebuffer(),r.__webglColorRenderbuffer=t.createRenderbuffer(),t.bindRenderbuffer(36161,r.__webglColorRenderbuffer);var d=l.convert(e.texture.format),p=l.convert(e.texture.type),v=D(e.texture.internalFormat,d,p),x=Q(e);t.renderbufferStorageMultisample(36161,x,v,e.width,e.height),t.bindFramebuffer(36160,r.__webglMultisampledFramebuffer),t.framebufferRenderbuffer(36160,36064,36161,r.__webglColorRenderbuffer),t.bindRenderbuffer(36161,null),e.depthBuffer&&(r.__webglDepthRenderbuffer=t.createRenderbuffer(),Z(r.__webglDepthRenderbuffer,e,!0)),t.bindFramebuffer(36160,null)}else console.warn("THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.");if(o){n.bindTexture(34067,a.__webglTexture),W(34067,e.texture,c);for(var _=0;_<6;_++)Y(r.__webglFramebuffer[_],e,36064,34069+_);O(e.texture,c)&&N(34067,e.texture,e.width,e.height),n.bindTexture(34067,null)}else n.bindTexture(3553,a.__webglTexture),W(3553,e.texture,c),Y(r.__webglFramebuffer,e,36064,3553),O(e.texture,c)&&N(3553,e.texture,e.width,e.height),n.bindTexture(3553,null);e.depthBuffer&&J(e)},this.updateRenderTargetMipmap=function(t){var e=t.texture;if(O(e,C(t)||w)){var r=t.isWebGLCubeRenderTarget?34067:3553,a=i.get(e).__webglTexture;n.bindTexture(r,a),N(r,e,t.width,t.height),n.bindTexture(r,null)}},this.updateMultisampleRenderTarget=function(e){if(e.isWebGLMultisampleRenderTarget)if(w){var n=i.get(e);t.bindFramebuffer(36008,n.__webglMultisampledFramebuffer),t.bindFramebuffer(36009,n.__webglFramebuffer);var r=e.width,a=e.height,o=16384;e.depthBuffer&&(o|=256),e.stencilBuffer&&(o|=1024),t.blitFramebuffer(0,0,r,a,0,0,r,a,o,9728),t.bindFramebuffer(36160,n.__webglMultisampledFramebuffer)}else console.warn("THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.")},this.safeSetTexture2D=function(t,e){t&&t.isWebGLRenderTarget&&(!1===K&&(console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead."),K=!0),t=t.texture),k(t,e)},this.safeSetTextureCube=function(t,e){t&&t.isWebGLCubeRenderTarget&&(!1===$&&(console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead."),$=!0),t=t.texture),t&&t.isCubeTexture||Array.isArray(t.image)&&6===t.image.length?H(t,e):G(t,e)}}function Pr(t,e,n){var i=n.isWebGL2;return{convert:function(t){var n;if(t===u)return 5121;if(1017===t)return 32819;if(1018===t)return 32820;if(1019===t)return 33635;if(1010===t)return 5120;if(1011===t)return 5122;if(t===d)return 5123;if(1013===t)return 5124;if(t===p)return 5125;if(t===f)return 5126;if(t===m)return i?5131:null!==(n=e.get("OES_texture_half_float"))?n.HALF_FLOAT_OES:null;if(1021===t)return 6406;if(t===g)return 6407;if(t===y)return 6408;if(1024===t)return 6409;if(1025===t)return 6410;if(t===x)return 6402;if(t===_)return 34041;if(1028===t)return 6403;if(1029===t)return 36244;if(1030===t)return 33319;if(1031===t)return 33320;if(1032===t)return 36248;if(1033===t)return 36249;if(33776===t||33777===t||33778===t||33779===t){if(null===(n=e.get("WEBGL_compressed_texture_s3tc")))return null;if(33776===t)return n.COMPRESSED_RGB_S3TC_DXT1_EXT;if(33777===t)return n.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(33778===t)return n.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(33779===t)return n.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(35840===t||35841===t||35842===t||35843===t){if(null===(n=e.get("WEBGL_compressed_texture_pvrtc")))return null;if(35840===t)return n.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(35841===t)return n.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(35842===t)return n.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(35843===t)return n.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(36196===t)return null!==(n=e.get("WEBGL_compressed_texture_etc1"))?n.COMPRESSED_RGB_ETC1_WEBGL:null;if((37492===t||37496===t)&&null!==(n=e.get("WEBGL_compressed_texture_etc"))){if(37492===t)return n.COMPRESSED_RGB8_ETC2;if(37496===t)return n.COMPRESSED_RGBA8_ETC2_EAC}return 37808===t||37809===t||37810===t||37811===t||37812===t||37813===t||37814===t||37815===t||37816===t||37817===t||37818===t||37819===t||37820===t||37821===t||37840===t||37841===t||37842===t||37843===t||37844===t||37845===t||37846===t||37847===t||37848===t||37849===t||37850===t||37851===t||37852===t||37853===t?null!==(n=e.get("WEBGL_compressed_texture_astc"))?t:null:36492===t?null!==(n=e.get("EXT_texture_compression_bptc"))?t:null:t===v?i?34042:null!==(n=e.get("WEBGL_depth_texture"))?n.UNSIGNED_INT_24_8_WEBGL:null:void 0}}}function Rr(t){bn.call(this),this.cameras=t||[]}function Cr(){bt.call(this),this.type="Group"}function Or(){this._targetRay=null,this._grip=null,this._hand=null}function Nr(t,e){var n=this,i=null,r=1,a=null,o="local-floor",s=null,c=[],h=new Map,l=new bn;l.layers.enable(1),l.viewport=new V;var u=new bn;u.layers.enable(2),u.viewport=new V;var d=[l,u],p=new Rr;p.layers.enable(1),p.layers.enable(2);var f=null,m=null;function v(t){var e=h.get(t.inputSource);e&&e.dispatchEvent({type:t.type})}function g(){h.forEach((function(t,e){t.disconnect(e)})),h.clear(),t.setFramebuffer(null),t.setRenderTarget(t.getRenderTarget()),S.stop(),n.isPresenting=!1,n.dispatchEvent({type:"sessionend"})}function y(t){a=t,S.setContext(i),S.start(),n.isPresenting=!0,n.dispatchEvent({type:"sessionstart"})}function x(t){for(var e=i.inputSources,n=0;n=0&&t.numSupportedMorphTargets++}if(t.morphNormals){t.numSupportedMorphNormals=0;for(var f=0;f=0&&t.numSupportedMorphNormals++}var m=i.uniforms;(t.isShaderMaterial||t.isRawShaderMaterial)&&!0!==t.clipping||(i.numClippingPlanes=G.numPlanes,i.numIntersection=G.numIntersection,m.clippingPlanes=G.uniform),i.environment=t.isMeshStandardMaterial?e.environment:null,i.fog=e.fog,i.needsLights=function(t){return t.isMeshLambertMaterial||t.isMeshToonMaterial||t.isMeshPhongMaterial||t.isMeshStandardMaterial||t.isShadowMaterial||t.isShaderMaterial&&!0===t.lights}(t),i.lightsStateVersion=o,i.needsLights&&(m.ambientLightColor.value=r.state.ambient,m.lightProbe.value=r.state.probe,m.directionalLights.value=r.state.directional,m.directionalLightShadows.value=r.state.directionalShadow,m.spotLights.value=r.state.spot,m.spotLightShadows.value=r.state.spotShadow,m.rectAreaLights.value=r.state.rectArea,m.pointLights.value=r.state.point,m.pointLightShadows.value=r.state.pointShadow,m.hemisphereLights.value=r.state.hemi,m.directionalShadowMap.value=r.state.directionalShadowMap,m.directionalShadowMatrix.value=r.state.directionalShadowMatrix,m.spotShadowMap.value=r.state.spotShadowMap,m.spotShadowMatrix.value=r.state.spotShadowMatrix,m.pointShadowMap.value=r.state.pointShadowMap,m.pointShadowMatrix.value=r.state.pointShadowMatrix);var g=i.program.getUniforms(),y=qi.seqWithValue(g.seq,m);i.uniformsList=y}function Dt(t,e,n,i){!0!==e.isScene&&(e=Y),nt.resetTextureUnits();var r=e.fog,a=n.isMeshStandardMaterial?e.environment:null,o=null===w?v.outputEncoding:w.texture.encoding,s=et.get(n),c=p.state.lights;if(!0===j&&(!0===W||t!==E)){var h=t===E&&n.id===S;G.setState(n.clippingPlanes,n.clipIntersection,n.clipShadows,t,s,h)}n.version===s.__version?void 0===s.program||n.fog&&s.fog!==r||s.environment!==a||s.needsLights&&s.lightsStateVersion!==c.state.version?Nt(n,e,i):void 0===s.numClippingPlanes||s.numClippingPlanes===G.numPlanes&&s.numIntersection===G.numIntersection?s.outputEncoding!==o&&Nt(n,e,i):Nt(n,e,i):(Nt(n,e,i),s.__version=n.version);var l,u,d=!1,m=!1,g=!1,x=s.program,_=x.getUniforms(),b=s.uniforms;if($.useProgram(x.program)&&(d=!0,m=!0,g=!0),n.id!==S&&(S=n.id,m=!0),d||E!==t){if(_.setValue(gt,"projectionMatrix",t.projectionMatrix),K.logarithmicDepthBuffer&&_.setValue(gt,"logDepthBufFC",2/(Math.log(t.far+1)/Math.LN2)),E!==t&&(E=t,m=!0,g=!0),n.isShaderMaterial||n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshStandardMaterial||n.envMap){var M=_.map.cameraPosition;void 0!==M&&M.setValue(gt,X.setFromMatrixPosition(t.matrixWorld))}(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial)&&_.setValue(gt,"isOrthographic",!0===t.isOrthographicCamera),(n.isMeshPhongMaterial||n.isMeshToonMaterial||n.isMeshLambertMaterial||n.isMeshBasicMaterial||n.isMeshStandardMaterial||n.isShaderMaterial||n.isShadowMaterial||n.skinning)&&_.setValue(gt,"viewMatrix",t.matrixWorldInverse)}if(n.skinning){_.setOptional(gt,i,"bindMatrix"),_.setOptional(gt,i,"bindMatrixInverse");var T=i.skeleton;if(T){var A=T.bones;if(K.floatVertexTextures){if(void 0===T.boneTexture){var L=Math.sqrt(4*A.length);L=B.ceilPowerOfTwo(L),L=Math.max(L,4);var P=new Float32Array(L*L*4);P.set(T.boneMatrices);var R=new En(P,L,L,y,f);T.boneMatrices=P,T.boneTexture=R,T.boneTextureSize=L}_.setValue(gt,"boneTexture",T.boneTexture,nt),_.setValue(gt,"boneTextureSize",T.boneTextureSize)}else _.setOptional(gt,T,"boneMatrices")}}return(m||s.receiveShadow!==i.receiveShadow)&&(s.receiveShadow=i.receiveShadow,_.setValue(gt,"receiveShadow",i.receiveShadow)),m&&(_.setValue(gt,"toneMappingExposure",v.toneMappingExposure),s.needsLights&&(u=g,(l=b).ambientLightColor.needsUpdate=u,l.lightProbe.needsUpdate=u,l.directionalLights.needsUpdate=u,l.directionalLightShadows.needsUpdate=u,l.pointLights.needsUpdate=u,l.pointLightShadows.needsUpdate=u,l.spotLights.needsUpdate=u,l.spotLightShadows.needsUpdate=u,l.rectAreaLights.needsUpdate=u,l.hemisphereLights.needsUpdate=u),r&&n.fog&&ct.refreshFogUniforms(b,r),ct.refreshMaterialUniforms(b,n,a,N,O),void 0!==b.ltc_1&&(b.ltc_1.value=Pn.LTC_1),void 0!==b.ltc_2&&(b.ltc_2.value=Pn.LTC_2),qi.upload(gt,s.uniformsList,b,nt)),n.isShaderMaterial&&!0===n.uniformsNeedUpdate&&(qi.upload(gt,s.uniformsList,b,nt),n.uniformsNeedUpdate=!1),n.isSpriteMaterial&&_.setValue(gt,"center",i.center),_.setValue(gt,"modelViewMatrix",i.modelViewMatrix),_.setValue(gt,"normalMatrix",i.normalMatrix),_.setValue(gt,"modelMatrix",i.matrixWorld),x}Pt.setAnimationLoop((function(t){wt.isPresenting||Lt&&Lt(t)})),"undefined"!=typeof window&&Pt.setContext(window),this.setAnimationLoop=function(t){Lt=t,wt.setAnimationLoop(t),null===t?Pt.stop():Pt.start()},this.render=function(t,e){var n,i;if(void 0!==arguments[2]&&(console.warn("THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead."),n=arguments[2]),void 0!==arguments[3]&&(console.warn("THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead."),i=arguments[3]),void 0===e||!0===e.isCamera){if(!0!==g){vt.resetDefaultState(),S=-1,E=null,!0===t.autoUpdate&&t.updateMatrixWorld(),null===e.parent&&e.updateMatrixWorld(),!0===wt.enabled&&!0===wt.isPresenting&&(e=wt.getCamera(e)),!0===t.isScene&&t.onBeforeRender(v,t,e,n||w),(p=lt.get(t,e)).init(),q.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),H.setFromProjectionMatrix(q),W=this.localClippingEnabled,j=G.init(this.clippingPlanes,W,e),(d=ht.get(t,e)).init(),Rt(t,e,0,v.sortObjects),d.finish(),!0===v.sortObjects&&d.sort(D,I),!0===j&&G.beginShadows();var r=p.state.shadowsArray;Mt.render(r,t,e),p.setupLights(e),!0===j&&G.endShadows(),!0===this.info.autoReset&&this.info.reset(),void 0!==n&&this.setRenderTarget(n),ut.render(d,t,e,i);var a=d.opaque,o=d.transparent;a.length>0&&Ct(a,t,e),o.length>0&&Ct(o,t,e),!0===t.isScene&&t.onAfterRender(v,t,e),null!==w&&(nt.updateRenderTargetMipmap(w),nt.updateMultisampleRenderTarget(w)),$.buffers.depth.setTest(!0),$.buffers.depth.setMask(!0),$.buffers.color.setMask(!0),$.setPolygonOffset(!1),d=null,p=null}}else console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.")},this.setFramebuffer=function(t){x!==t&&null===w&>.bindFramebuffer(36160,t),x=t},this.getActiveCubeFace=function(){return _},this.getActiveMipmapLevel=function(){return b},this.getRenderTarget=function(){return w},this.setRenderTarget=function(t,e,n){w=t,_=e,b=n,t&&void 0===et.get(t).__webglFramebuffer&&nt.setupRenderTarget(t);var i=x,r=!1;if(t){var a=et.get(t).__webglFramebuffer;t.isWebGLCubeRenderTarget?(i=a[e||0],r=!0):i=t.isWebGLMultisampleRenderTarget?et.get(t).__webglMultisampledFramebuffer:a,A.copy(t.viewport),P.copy(t.scissor),R=t.scissorTest}else A.copy(z).multiplyScalar(N).floor(),P.copy(F).multiplyScalar(N).floor(),R=k;if(M!==i&&(gt.bindFramebuffer(36160,i),M=i),$.viewport(A),$.scissor(P),$.setScissorTest(R),r){var o=et.get(t.texture);gt.framebufferTexture2D(36160,36064,34069+(e||0),o.__webglTexture,n||0)}},this.readRenderTargetPixels=function(t,e,n,i,r,a,o){if(t&&t.isWebGLRenderTarget){var s=et.get(t).__webglFramebuffer;if(t.isWebGLCubeRenderTarget&&void 0!==o&&(s=s[o]),s){var c=!1;s!==M&&(gt.bindFramebuffer(36160,s),c=!0);try{var h=t.texture,l=h.format,d=h.type;if(l!==y&&mt.convert(l)!==gt.getParameter(35739))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.");if(!(d===u||mt.convert(d)===gt.getParameter(35738)||d===f&&(K.isWebGL2||Q.get("OES_texture_float")||Q.get("WEBGL_color_buffer_float"))||d===m&&(K.isWebGL2?Q.get("EXT_color_buffer_float"):Q.get("EXT_color_buffer_half_float"))))return void console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.");36053===gt.checkFramebufferStatus(36160)?e>=0&&e<=t.width-i&&n>=0&&n<=t.height-r&>.readPixels(e,n,i,r,mt.convert(l),mt.convert(d),a):console.error("THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.")}finally{c&>.bindFramebuffer(36160,M)}}}else console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.")},this.copyFramebufferToTexture=function(t,e,n){void 0===n&&(n=0);var i=Math.pow(2,-n),r=Math.floor(e.image.width*i),a=Math.floor(e.image.height*i),o=mt.convert(e.format);nt.setTexture2D(e,0),gt.copyTexImage2D(3553,n,o,t.x,t.y,r,a,0),$.unbindTexture()},this.copyTextureToTexture=function(t,e,n,i){void 0===i&&(i=0);var r=e.image.width,a=e.image.height,o=mt.convert(n.format),s=mt.convert(n.type);nt.setTexture2D(n,0),gt.pixelStorei(37440,n.flipY),gt.pixelStorei(37441,n.premultiplyAlpha),gt.pixelStorei(3317,n.unpackAlignment),e.isDataTexture?gt.texSubImage2D(3553,i,t.x,t.y,r,a,o,s,e.image.data):e.isCompressedTexture?gt.compressedTexSubImage2D(3553,i,t.x,t.y,e.mipmaps[0].width,e.mipmaps[0].height,o,e.mipmaps[0].data):gt.texSubImage2D(3553,i,t.x,t.y,o,s,e.image),0===i&&n.generateMipmaps&>.generateMipmap(3553),$.unbindTexture()},this.initTexture=function(t){nt.setTexture2D(t,0),$.unbindTexture()},"undefined"!=typeof __THREE_DEVTOOLS__&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe",{detail:this}))}function zr(t){Ir.call(this,t)}function Br(t,e){this.name="",this.color=new de(t),this.density=void 0!==e?e:25e-5}function Ur(t,e,n){this.name="",this.color=new de(t),this.near=void 0!==e?e:1,this.far=void 0!==n?n:1e3}function Fr(t,e){this.array=t,this.stride=e,this.count=void 0!==t?t.length/e:0,this.usage=R,this.updateRange={offset:0,count:-1},this.version=0,this.uuid=B.generateUUID()}Rr.prototype=Object.assign(Object.create(bn.prototype),{constructor:Rr,isArrayCamera:!0}),Cr.prototype=Object.assign(Object.create(bt.prototype),{constructor:Cr,isGroup:!0}),Object.assign(Or.prototype,{constructor:Or,getHandSpace:function(){if(null===this._hand&&(this._hand=new Cr,this._hand.matrixAutoUpdate=!1,this._hand.visible=!1,this._hand.joints=[],this._hand.inputState={pinching:!1},window.XRHand))for(var t=0;t<=window.XRHand.LITTLE_PHALANX_TIP;t++){var e=new Cr;e.matrixAutoUpdate=!1,e.visible=!1,this._hand.joints.push(e),this._hand.add(e)}return this._hand},getTargetRaySpace:function(){return null===this._targetRay&&(this._targetRay=new Cr,this._targetRay.matrixAutoUpdate=!1,this._targetRay.visible=!1),this._targetRay},getGripSpace:function(){return null===this._grip&&(this._grip=new Cr,this._grip.matrixAutoUpdate=!1,this._grip.visible=!1),this._grip},dispatchEvent:function(t){return null!==this._targetRay&&this._targetRay.dispatchEvent(t),null!==this._grip&&this._grip.dispatchEvent(t),null!==this._hand&&this._hand.dispatchEvent(t),this},disconnect:function(t){return this.dispatchEvent({type:"disconnected",data:t}),null!==this._targetRay&&(this._targetRay.visible=!1),null!==this._grip&&(this._grip.visible=!1),null!==this._hand&&(this._hand.visible=!1),this},update:function(t,e,n){var i=null,r=null,a=null,o=this._targetRay,s=this._grip,c=this._hand;if(t)if(t.hand){a=!0;for(var h=0;h<=window.XRHand.LITTLE_PHALANX_TIP;h++)if(t.hand[h]){var l=e.getJointPose(t.hand[h],n),u=c.joints[h];null!==l&&(u.matrix.fromArray(l.transform.matrix),u.matrix.decompose(u.position,u.rotation,u.scale),u.jointRadius=l.radius),u.visible=null!==l;var d=c.joints[window.XRHand.INDEX_PHALANX_TIP],p=c.joints[window.XRHand.THUMB_PHALANX_TIP],f=d.position.distanceTo(p.position);c.inputState.pinching&&f>.025?(c.inputState.pinching=!1,this.dispatchEvent({type:"pinchend",handedness:t.handedness,target:this})):!c.inputState.pinching&&f<=.015&&(c.inputState.pinching=!0,this.dispatchEvent({type:"pinchstart",handedness:t.handedness,target:this}))}}else null!==o&&null!==(i=e.getPose(t.targetRaySpace,n))&&(o.matrix.fromArray(i.transform.matrix),o.matrix.decompose(o.position,o.rotation,o.scale)),null!==s&&t.gripSpace&&null!==(r=e.getPose(t.gripSpace,n))&&(s.matrix.fromArray(r.transform.matrix),s.matrix.decompose(s.position,s.rotation,s.scale));return null!==o&&(o.visible=null!==i),null!==s&&(s.visible=null!==r),null!==c&&(c.visible=null!==a),this}}),Object.assign(Nr.prototype,O.prototype),zr.prototype=Object.assign(Object.create(Ir.prototype),{constructor:zr,isWebGL1Renderer:!0}),Object.assign(Br.prototype,{isFogExp2:!0,clone:function(){return new Br(this.color,this.density)},toJSON:function(){return{type:"FogExp2",color:this.color.getHex(),density:this.density}}}),Object.assign(Ur.prototype,{isFog:!0,clone:function(){return new Ur(this.color,this.near,this.far)},toJSON:function(){return{type:"Fog",color:this.color.getHex(),near:this.near,far:this.far}}}),Object.defineProperty(Fr.prototype,"needsUpdate",{set:function(t){!0===t&&this.version++}}),Object.assign(Fr.prototype,{isInterleavedBuffer:!0,onUploadCallback:function(){},setUsage:function(t){return this.usage=t,this},copy:function(t){return this.array=new t.array.constructor(t.array),this.count=t.count,this.stride=t.stride,this.usage=t.usage,this},copyAt:function(t,e,n){t*=this.stride,n*=e.stride;for(var i=0,r=this.stride;it.far||e.push({distance:s,point:jr.clone(),uv:ce.getUV(jr,Jr,Qr,Kr,$r,ta,ea,new U),face:null,object:this})}},copy:function(t){return bt.prototype.copy.call(this,t),void 0!==t.center&&this.center.copy(t.center),this.material=t.material,this}});var ra,aa,oa,sa,ca,ha=new Z,la=new Z;function ua(){bt.call(this),this._currentLevel=0,this.type="LOD",Object.defineProperties(this,{levels:{enumerable:!0,value:[]}}),this.autoUpdate=!0}function da(t,e){t&&t.isGeometry&&console.error("THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead."),on.call(this,t,e),this.type="SkinnedMesh",this.bindMode="attached",this.bindMatrix=new it,this.bindMatrixInverse=new it}ua.prototype=Object.assign(Object.create(bt.prototype),{constructor:ua,isLOD:!0,copy:function(t){bt.prototype.copy.call(this,t,!1);for(var e=t.levels,n=0,i=e.length;n0){var n,i;for(n=1,i=e.length;n0){ha.setFromMatrixPosition(this.matrixWorld);var n=t.ray.origin.distanceTo(ha);this.getObjectForDistance(n).raycast(t,e)}},update:function(t){var e=this.levels;if(e.length>1){ha.setFromMatrixPosition(t.matrixWorld),la.setFromMatrixPosition(this.matrixWorld);var n,i,r=ha.distanceTo(la)/t.zoom;for(e[0].object.visible=!0,n=1,i=e.length;n=e[n].distance;n++)e[n-1].object.visible=!1,e[n].object.visible=!0;for(this._currentLevel=n-1;no)){l.applyMatrix4(this.matrixWorld);var x=t.ray.origin.distanceTo(l);xt.far||e.push({distance:x,point:h.clone().applyMatrix4(this.matrixWorld),index:m,face:null,faceIndex:null,object:this})}}else for(var _=0,b=p.length/3-1;_o)){l.applyMatrix4(this.matrixWorld);var w=t.ray.origin.distanceTo(l);wt.far||e.push({distance:w,point:h.clone().applyMatrix4(this.matrixWorld),index:_,face:null,faceIndex:null,object:this})}}}else if(n.isGeometry)for(var M=n.vertices,S=M.length,E=0;Eo)){l.applyMatrix4(this.matrixWorld);var T=t.ray.origin.distanceTo(l);Tt.far||e.push({distance:T,point:h.clone().applyMatrix4(this.matrixWorld),index:E,face:null,faceIndex:null,object:this})}}}},updateMorphTargets:function(){var t=this.geometry;if(t.isBufferGeometry){var e=t.morphAttributes,n=Object.keys(e);if(n.length>0){var i=e[n[0]];if(void 0!==i){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(var r=0,a=i.length;r0&&console.error("THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.")}}});var Pa=new Z,Ra=new Z;function Ca(t,e){La.call(this,t,e),this.type="LineSegments"}function Oa(t,e){La.call(this,t,e),this.type="LineLoop"}function Na(t){ye.call(this),this.type="PointsMaterial",this.color=new de(16777215),this.map=null,this.alphaMap=null,this.size=1,this.sizeAttenuation=!0,this.morphTargets=!1,this.setValues(t)}Ca.prototype=Object.assign(Object.create(La.prototype),{constructor:Ca,isLineSegments:!0,computeLineDistances:function(){var t=this.geometry;if(t.isBufferGeometry)if(null===t.index){for(var e=t.attributes.position,n=[],i=0,r=e.count;ir.far)return;a.push({distance:h,distanceToRay:Math.sqrt(s),point:c,index:e,face:null,object:o})}}function ka(t,e,n,i,r,a,o,s,c){G.call(this,t,e,n,i,r,a,o,s,c),this.format=void 0!==o?o:g,this.minFilter=void 0!==a?a:h,this.magFilter=void 0!==r?r:h,this.generateMipmaps=!1;var l=this;"requestVideoFrameCallback"in t&&t.requestVideoFrameCallback((function e(){l.needsUpdate=!0,t.requestVideoFrameCallback(e)}))}function Ha(t,e,n,i,r,a,o,s,c,h,l,u){G.call(this,null,a,o,s,c,h,i,r,l,u),this.image={width:e,height:n},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1}function Ga(t,e,n,i,r,a,o,s,c){G.call(this,t,e,n,i,r,a,o,s,c),this.needsUpdate=!0}function Va(t,e,n,i,r,a,s,c,h,l){if((l=void 0!==l?l:x)!==x&&l!==_)throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat");void 0===n&&l===x&&(n=d),void 0===n&&l===_&&(n=v),G.call(this,null,i,r,a,s,c,l,n,h),this.image={width:t,height:e},this.magFilter=void 0!==s?s:o,this.minFilter=void 0!==c?c:o,this.flipY=!1,this.generateMipmaps=!1}function ja(t){He.call(this),this.type="WireframeGeometry";var e=[],n=[0,0],i={},r=["a","b","c"];if(t&&t.isGeometry){for(var a=t.faces,o=0,s=a.length;o=0?(t(g-s,m,l),u.subVectors(h,l)):(t(g+s,m,l),u.subVectors(l,h)),m-s>=0?(t(g,m-s,l),d.subVectors(h,l)):(t(g,m+s,l),d.subVectors(l,h)),c.crossVectors(u,d).normalize(),a.push(c.x,c.y,c.z),o.push(g,m)}for(var y=0;y.9&&o<.1&&(e<.2&&(a[t+0]+=1),n<.2&&(a[t+2]+=1),i<.2&&(a[t+4]+=1))}}()}(),this.setAttribute("position",new Re(r,3)),this.setAttribute("normal",new Re(r.slice(),3)),this.setAttribute("uv",new Re(a,2)),0===i?this.computeVertexNormals():this.normalizeNormals()}function Za(t,e){pn.call(this),this.type="TetrahedronGeometry",this.parameters={radius:t,detail:e},this.fromBufferGeometry(new Ja(t,e)),this.mergeVertices()}function Ja(t,e){Ya.call(this,[1,1,1,-1,-1,1,-1,1,-1,1,-1,-1],[2,1,0,0,3,2,1,3,0,2,3,1],t,e),this.type="TetrahedronBufferGeometry",this.parameters={radius:t,detail:e}}function Qa(t,e){pn.call(this),this.type="OctahedronGeometry",this.parameters={radius:t,detail:e},this.fromBufferGeometry(new Ka(t,e)),this.mergeVertices()}function Ka(t,e){Ya.call(this,[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1],[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2],t,e),this.type="OctahedronBufferGeometry",this.parameters={radius:t,detail:e}}function $a(t,e){pn.call(this),this.type="IcosahedronGeometry",this.parameters={radius:t,detail:e},this.fromBufferGeometry(new to(t,e)),this.mergeVertices()}function to(t,e){var n=(1+Math.sqrt(5))/2,i=[-1,n,0,1,n,0,-1,-n,0,1,-n,0,0,-1,n,0,1,n,0,-1,-n,0,1,-n,n,0,-1,n,0,1,-n,0,-1,-n,0,1];Ya.call(this,i,[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],t,e),this.type="IcosahedronBufferGeometry",this.parameters={radius:t,detail:e}}function eo(t,e){pn.call(this),this.type="DodecahedronGeometry",this.parameters={radius:t,detail:e},this.fromBufferGeometry(new no(t,e)),this.mergeVertices()}function no(t,e){var n=(1+Math.sqrt(5))/2,i=1/n,r=[-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,-i,-n,0,-i,n,0,i,-n,0,i,n,-i,-n,0,-i,n,0,i,-n,0,i,n,0,-n,0,-i,n,0,-i,-n,0,i,n,0,i];Ya.call(this,r,[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],t,e),this.type="DodecahedronBufferGeometry",this.parameters={radius:t,detail:e}}function io(t,e,n,i,r,a){pn.call(this),this.type="TubeGeometry",this.parameters={path:t,tubularSegments:e,radius:n,radialSegments:i,closed:r},void 0!==a&&console.warn("THREE.TubeGeometry: taper has been removed.");var o=new ro(t,e,n,i,r);this.tangents=o.tangents,this.normals=o.normals,this.binormals=o.binormals,this.fromBufferGeometry(o),this.mergeVertices()}function ro(t,e,n,i,r){He.call(this),this.type="TubeBufferGeometry",this.parameters={path:t,tubularSegments:e,radius:n,radialSegments:i,closed:r},e=e||64,n=n||1,i=i||8,r=r||!1;var a=t.computeFrenetFrames(e,r);this.tangents=a.tangents,this.normals=a.normals,this.binormals=a.binormals;var o=new Z,s=new Z,c=new U,h=new Z,l=[],u=[],d=[],p=[];function f(r){h=t.getPointAt(r/e,h);for(var c=a.normals[r],d=a.binormals[r],p=0;p<=i;p++){var f=p/i*Math.PI*2,m=Math.sin(f),v=-Math.cos(f);s.x=v*c.x+m*d.x,s.y=v*c.y+m*d.y,s.z=v*c.z+m*d.z,s.normalize(),u.push(s.x,s.y,s.z),o.x=h.x+n*s.x,o.y=h.y+n*s.y,o.z=h.z+n*s.z,l.push(o.x,o.y,o.z)}}!function(){for(var t=0;t0){var i=e[n[0]];if(void 0!==i){this.morphTargetInfluences=[],this.morphTargetDictionary={};for(var r=0,a=i.length;r0&&console.error("THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.")}}}),ka.prototype=Object.assign(Object.create(G.prototype),{constructor:ka,isVideoTexture:!0,update:function(){var t=this.image;!1==="requestVideoFrameCallback"in t&&t.readyState>=t.HAVE_CURRENT_DATA&&(this.needsUpdate=!0)}}),Ha.prototype=Object.create(G.prototype),Ha.prototype.constructor=Ha,Ha.prototype.isCompressedTexture=!0,Ga.prototype=Object.create(G.prototype),Ga.prototype.constructor=Ga,Ga.prototype.isCanvasTexture=!0,Va.prototype=Object.create(G.prototype),Va.prototype.constructor=Va,Va.prototype.isDepthTexture=!0,ja.prototype=Object.create(He.prototype),ja.prototype.constructor=ja,Wa.prototype=Object.create(pn.prototype),Wa.prototype.constructor=Wa,qa.prototype=Object.create(He.prototype),qa.prototype.constructor=qa,Xa.prototype=Object.create(pn.prototype),Xa.prototype.constructor=Xa,Ya.prototype=Object.create(He.prototype),Ya.prototype.constructor=Ya,Za.prototype=Object.create(pn.prototype),Za.prototype.constructor=Za,Ja.prototype=Object.create(Ya.prototype),Ja.prototype.constructor=Ja,Qa.prototype=Object.create(pn.prototype),Qa.prototype.constructor=Qa,Ka.prototype=Object.create(Ya.prototype),Ka.prototype.constructor=Ka,$a.prototype=Object.create(pn.prototype),$a.prototype.constructor=$a,to.prototype=Object.create(Ya.prototype),to.prototype.constructor=to,eo.prototype=Object.create(pn.prototype),eo.prototype.constructor=eo,no.prototype=Object.create(Ya.prototype),no.prototype.constructor=no,io.prototype=Object.create(pn.prototype),io.prototype.constructor=io,ro.prototype=Object.create(He.prototype),ro.prototype.constructor=ro,ro.prototype.toJSON=function(){var t=He.prototype.toJSON.call(this);return t.path=this.parameters.path.toJSON(),t},ao.prototype=Object.create(pn.prototype),ao.prototype.constructor=ao,oo.prototype=Object.create(He.prototype),oo.prototype.constructor=oo,so.prototype=Object.create(pn.prototype),so.prototype.constructor=so,co.prototype=Object.create(He.prototype),co.prototype.constructor=co;var ho=function(t,e,n){n=n||2;var i,r,a,o,s,c,h,l=e&&e.length,u=l?e[0]*n:t.length,d=lo(t,0,u,n,!0),p=[];if(!d||d.next===d.prev)return p;if(l&&(d=function(t,e,n,i){var r,a,o,s=[];for(r=0,a=e.length;r80*n){i=a=t[0],r=o=t[1];for(var f=n;fa&&(a=s),c>o&&(o=c);h=0!==(h=Math.max(a-i,o-r))?1/h:0}return po(d,p,n,i,r,h),p};function lo(t,e,n,i,r){var a,o;if(r===function(t,e,n,i){for(var r=0,a=e,o=n-i;a0)for(a=e;a=e;a-=i)o=Oo(a,t[a],t[a+1],o);return o&&To(o,o.next)&&(No(o),o=o.next),o}function uo(t,e){if(!t)return t;e||(e=t);var n,i=t;do{if(n=!1,i.steiner||!To(i,i.next)&&0!==Eo(i.prev,i,i.next))i=i.next;else{if(No(i),(i=e=i.prev)===i.next)break;n=!0}}while(n||i!==e);return e}function po(t,e,n,i,r,a,o){if(t){!o&&a&&function(t,e,n,i){var r=t;do{null===r.z&&(r.z=bo(r.x,r.y,e,n,i)),r.prevZ=r.prev,r.nextZ=r.next,r=r.next}while(r!==t);r.prevZ.nextZ=null,r.prevZ=null,function(t){var e,n,i,r,a,o,s,c,h=1;do{for(n=t,t=null,a=null,o=0;n;){for(o++,i=n,s=0,e=0;e0||c>0&&i;)0!==s&&(0===c||!i||n.z<=i.z)?(r=n,n=n.nextZ,s--):(r=i,i=i.nextZ,c--),a?a.nextZ=r:t=r,r.prevZ=a,a=r;n=i}a.nextZ=null,h*=2}while(o>1)}(r)}(t,i,r,a);for(var s,c,h=t;t.prev!==t.next;)if(s=t.prev,c=t.next,a?mo(t,i,r,a):fo(t))e.push(s.i/n),e.push(t.i/n),e.push(c.i/n),No(t),t=c.next,h=c.next;else if((t=c)===h){o?1===o?po(t=vo(uo(t),e,n),e,n,i,r,a,2):2===o&&go(t,e,n,i,r,a):po(uo(t),e,n,i,r,a,1);break}}}function fo(t){var e=t.prev,n=t,i=t.next;if(Eo(e,n,i)>=0)return!1;for(var r=t.next.next;r!==t.prev;){if(Mo(e.x,e.y,n.x,n.y,i.x,i.y,r.x,r.y)&&Eo(r.prev,r,r.next)>=0)return!1;r=r.next}return!0}function mo(t,e,n,i){var r=t.prev,a=t,o=t.next;if(Eo(r,a,o)>=0)return!1;for(var s=r.xa.x?r.x>o.x?r.x:o.x:a.x>o.x?a.x:o.x,l=r.y>a.y?r.y>o.y?r.y:o.y:a.y>o.y?a.y:o.y,u=bo(s,c,e,n,i),d=bo(h,l,e,n,i),p=t.prevZ,f=t.nextZ;p&&p.z>=u&&f&&f.z<=d;){if(p!==t.prev&&p!==t.next&&Mo(r.x,r.y,a.x,a.y,o.x,o.y,p.x,p.y)&&Eo(p.prev,p,p.next)>=0)return!1;if(p=p.prevZ,f!==t.prev&&f!==t.next&&Mo(r.x,r.y,a.x,a.y,o.x,o.y,f.x,f.y)&&Eo(f.prev,f,f.next)>=0)return!1;f=f.nextZ}for(;p&&p.z>=u;){if(p!==t.prev&&p!==t.next&&Mo(r.x,r.y,a.x,a.y,o.x,o.y,p.x,p.y)&&Eo(p.prev,p,p.next)>=0)return!1;p=p.prevZ}for(;f&&f.z<=d;){if(f!==t.prev&&f!==t.next&&Mo(r.x,r.y,a.x,a.y,o.x,o.y,f.x,f.y)&&Eo(f.prev,f,f.next)>=0)return!1;f=f.nextZ}return!0}function vo(t,e,n){var i=t;do{var r=i.prev,a=i.next.next;!To(r,a)&&Ao(r,i,i.next,a)&&Ro(r,a)&&Ro(a,r)&&(e.push(r.i/n),e.push(i.i/n),e.push(a.i/n),No(i),No(i.next),i=t=a),i=i.next}while(i!==t);return uo(i)}function go(t,e,n,i,r,a){var o=t;do{for(var s=o.next.next;s!==o.prev;){if(o.i!==s.i&&So(o,s)){var c=Co(o,s);return o=uo(o,o.next),c=uo(c,c.next),po(o,e,n,i,r,a),void po(c,e,n,i,r,a)}s=s.next}o=o.next}while(o!==t)}function yo(t,e){return t.x-e.x}function xo(t,e){if(e=function(t,e){var n,i=e,r=t.x,a=t.y,o=-1/0;do{if(a<=i.y&&a>=i.next.y&&i.next.y!==i.y){var s=i.x+(a-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(s<=r&&s>o){if(o=s,s===r){if(a===i.y)return i;if(a===i.next.y)return i.next}n=i.x=i.x&&i.x>=l&&r!==i.x&&Mo(an.x||i.x===n.x&&_o(n,i)))&&(n=i,d=c)),i=i.next}while(i!==h);return n}(t,e)){var n=Co(e,t);uo(e,e.next),uo(n,n.next)}}function _o(t,e){return Eo(t.prev,t,e.prev)<0&&Eo(e.next,t,t.next)<0}function bo(t,e,n,i,r){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-n)*r)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)*r)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function wo(t){var e=t,n=t;do{(e.x=0&&(t-o)*(i-s)-(n-o)*(e-s)>=0&&(n-o)*(a-s)-(r-o)*(i-s)>=0}function So(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var n=t;do{if(n.i!==t.i&&n.next.i!==t.i&&n.i!==e.i&&n.next.i!==e.i&&Ao(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(t,e)&&(Ro(t,e)&&Ro(e,t)&&function(t,e){var n=t,i=!1,r=(t.x+e.x)/2,a=(t.y+e.y)/2;do{n.y>a!=n.next.y>a&&n.next.y!==n.y&&r<(n.next.x-n.x)*(a-n.y)/(n.next.y-n.y)+n.x&&(i=!i),n=n.next}while(n!==t);return i}(t,e)&&(Eo(t.prev,t,e.prev)||Eo(t,e.prev,e))||To(t,e)&&Eo(t.prev,t,t.next)>0&&Eo(e.prev,e,e.next)>0)}function Eo(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function To(t,e){return t.x===e.x&&t.y===e.y}function Ao(t,e,n,i){var r=Po(Eo(t,e,n)),a=Po(Eo(t,e,i)),o=Po(Eo(n,i,t)),s=Po(Eo(n,i,e));return r!==a&&o!==s||(!(0!==r||!Lo(t,n,e))||(!(0!==a||!Lo(t,i,e))||(!(0!==o||!Lo(n,t,i))||!(0!==s||!Lo(n,e,i)))))}function Lo(t,e,n){return e.x<=Math.max(t.x,n.x)&&e.x>=Math.min(t.x,n.x)&&e.y<=Math.max(t.y,n.y)&&e.y>=Math.min(t.y,n.y)}function Po(t){return t>0?1:t<0?-1:0}function Ro(t,e){return Eo(t.prev,t,t.next)<0?Eo(t,e,t.next)>=0&&Eo(t,t.prev,e)>=0:Eo(t,e,t.prev)<0||Eo(t,t.next,e)<0}function Co(t,e){var n=new Do(t.i,t.x,t.y),i=new Do(e.i,e.x,e.y),r=t.next,a=e.prev;return t.next=e,e.prev=t,n.next=r,r.prev=n,i.next=n,n.prev=i,a.next=i,i.prev=a,i}function Oo(t,e,n,i){var r=new Do(t,e,n);return i?(r.next=i.next,r.prev=i,i.next.prev=r,i.next=r):(r.prev=r,r.next=r),r}function No(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function Do(t,e,n){this.i=t,this.x=e,this.y=n,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}var Io={area:function(t){for(var e=t.length,n=0,i=e-1,r=0;r2&&t[e-1].equals(t[0])&&t.pop()}function Bo(t,e){for(var n=0;nNumber.EPSILON){var d=Math.sqrt(l),p=Math.sqrt(c*c+h*h),f=e.x-s/d,m=e.y+o/d,v=((n.x-h/p-f)*h-(n.y+c/p-m)*c)/(o*h-s*c),g=(i=f+o*v-t.x)*i+(r=m+s*v-t.y)*r;if(g<=2)return new U(i,r);a=Math.sqrt(g/2)}else{var y=!1;o>Number.EPSILON?c>Number.EPSILON&&(y=!0):o<-Number.EPSILON?c<-Number.EPSILON&&(y=!0):Math.sign(s)===Math.sign(h)&&(y=!0),y?(i=-s,r=o,a=Math.sqrt(l)):(i=o,r=s,a=Math.sqrt(l/2))}return new U(i/a,r/a)}for(var B=[],F=0,k=P.length,H=k-1,G=F+1;F=0;xt--){for(var _t=xt/p,bt=l*Math.cos(_t*Math.PI/2),wt=u*Math.sin(_t*Math.PI/2)+d,Mt=0,St=P.length;Mt=0;){var i=n,r=n-1;r<0&&(r=t.length-1);for(var a=0,o=s+2*p;a0)&&d.push(S,E,A),(w!==n-1||s0&&g(!0),e>0&&g(!1)),this.setIndex(h),this.setAttribute("position",new Re(l,3)),this.setAttribute("normal",new Re(u,3)),this.setAttribute("uv",new Re(d,2))}function ns(t,e,n,i,r,a,o){ts.call(this,0,t,e,n,i,r,a,o),this.type="ConeGeometry",this.parameters={radius:t,height:e,radialSegments:n,heightSegments:i,openEnded:r,thetaStart:a,thetaLength:o}}function is(t,e,n,i,r,a,o){es.call(this,0,t,e,n,i,r,a,o),this.type="ConeBufferGeometry",this.parameters={radius:t,height:e,radialSegments:n,heightSegments:i,openEnded:r,thetaStart:a,thetaLength:o}}function rs(t,e,n,i){pn.call(this),this.type="CircleGeometry",this.parameters={radius:t,segments:e,thetaStart:n,thetaLength:i},this.fromBufferGeometry(new as(t,e,n,i)),this.mergeVertices()}function as(t,e,n,i){He.call(this),this.type="CircleBufferGeometry",this.parameters={radius:t,segments:e,thetaStart:n,thetaLength:i},t=t||1,e=void 0!==e?Math.max(3,e):8,n=void 0!==n?n:0,i=void 0!==i?i:2*Math.PI;var r=[],a=[],o=[],s=[],c=new Z,h=new U;a.push(0,0,0),o.push(0,0,1),s.push(.5,.5);for(var l=0,u=3;l<=e;l++,u+=3){var d=n+l/e*i;c.x=t*Math.cos(d),c.y=t*Math.sin(d),a.push(c.x,c.y,c.z),o.push(0,0,1),h.x=(a[u]/t+1)/2,h.y=(a[u+1]/t+1)/2,s.push(h.x,h.y)}for(var p=1;p<=e;p++)r.push(p,p+1,0);this.setIndex(r),this.setAttribute("position",new Re(a,3)),this.setAttribute("normal",new Re(o,3)),this.setAttribute("uv",new Re(s,2))}Go.prototype=Object.create(pn.prototype),Go.prototype.constructor=Go,Vo.prototype=Object.create(Fo.prototype),Vo.prototype.constructor=Vo,jo.prototype=Object.create(pn.prototype),jo.prototype.constructor=jo,Wo.prototype=Object.create(He.prototype),Wo.prototype.constructor=Wo,qo.prototype=Object.create(pn.prototype),qo.prototype.constructor=qo,Xo.prototype=Object.create(He.prototype),Xo.prototype.constructor=Xo,Yo.prototype=Object.create(pn.prototype),Yo.prototype.constructor=Yo,Zo.prototype=Object.create(He.prototype),Zo.prototype.constructor=Zo,Jo.prototype=Object.create(pn.prototype),Jo.prototype.constructor=Jo,Jo.prototype.toJSON=function(){var t=pn.prototype.toJSON.call(this);return Ko(this.parameters.shapes,t)},Qo.prototype=Object.create(He.prototype),Qo.prototype.constructor=Qo,Qo.prototype.toJSON=function(){var t=He.prototype.toJSON.call(this);return Ko(this.parameters.shapes,t)},$o.prototype=Object.create(He.prototype),$o.prototype.constructor=$o,ts.prototype=Object.create(pn.prototype),ts.prototype.constructor=ts,es.prototype=Object.create(He.prototype),es.prototype.constructor=es,ns.prototype=Object.create(ts.prototype),ns.prototype.constructor=ns,is.prototype=Object.create(es.prototype),is.prototype.constructor=is,rs.prototype=Object.create(pn.prototype),rs.prototype.constructor=rs,as.prototype=Object.create(He.prototype),as.prototype.constructor=as;var os=Object.freeze({__proto__:null,WireframeGeometry:ja,ParametricGeometry:Wa,ParametricBufferGeometry:qa,TetrahedronGeometry:Za,TetrahedronBufferGeometry:Ja,OctahedronGeometry:Qa,OctahedronBufferGeometry:Ka,IcosahedronGeometry:$a,IcosahedronBufferGeometry:to,DodecahedronGeometry:eo,DodecahedronBufferGeometry:no,PolyhedronGeometry:Xa,PolyhedronBufferGeometry:Ya,TubeGeometry:io,TubeBufferGeometry:ro,TorusKnotGeometry:ao,TorusKnotBufferGeometry:oo,TorusGeometry:so,TorusBufferGeometry:co,TextGeometry:Go,TextBufferGeometry:Vo,SphereGeometry:jo,SphereBufferGeometry:Wo,RingGeometry:qo,RingBufferGeometry:Xo,PlaneGeometry:On,PlaneBufferGeometry:Nn,LatheGeometry:Yo,LatheBufferGeometry:Zo,ShapeGeometry:Jo,ShapeBufferGeometry:Qo,ExtrudeGeometry:Uo,ExtrudeBufferGeometry:Fo,EdgesGeometry:$o,ConeGeometry:ns,ConeBufferGeometry:is,CylinderGeometry:ts,CylinderBufferGeometry:es,CircleGeometry:rs,CircleBufferGeometry:as,BoxGeometry:fn,BoxBufferGeometry:mn});function ss(t){ye.call(this),this.type="ShadowMaterial",this.color=new de(0),this.transparent=!0,this.setValues(t)}function cs(t){xn.call(this,t),this.type="RawShaderMaterial"}function hs(t){ye.call(this),this.defines={STANDARD:""},this.type="MeshStandardMaterial",this.color=new de(16777215),this.roughness=1,this.metalness=0,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new de(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new U(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.roughnessMap=null,this.metalnessMap=null,this.alphaMap=null,this.envMap=null,this.envMapIntensity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.vertexTangents=!1,this.setValues(t)}function ls(t){hs.call(this),this.defines={STANDARD:"",PHYSICAL:""},this.type="MeshPhysicalMaterial",this.clearcoat=0,this.clearcoatMap=null,this.clearcoatRoughness=0,this.clearcoatRoughnessMap=null,this.clearcoatNormalScale=new U(1,1),this.clearcoatNormalMap=null,this.reflectivity=.5,this.sheen=null,this.transmission=0,this.transmissionMap=null,this.setValues(t)}function us(t){ye.call(this),this.type="MeshPhongMaterial",this.color=new de(16777215),this.specular=new de(1118481),this.shininess=30,this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new de(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new U(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)}function ds(t){ye.call(this),this.defines={TOON:""},this.type="MeshToonMaterial",this.color=new de(16777215),this.map=null,this.gradientMap=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new de(0),this.emissiveIntensity=1,this.emissiveMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new U(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)}function ps(t){ye.call(this),this.type="MeshNormalMaterial",this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new U(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)}function fs(t){ye.call(this),this.type="MeshLambertMaterial",this.color=new de(16777215),this.map=null,this.lightMap=null,this.lightMapIntensity=1,this.aoMap=null,this.aoMapIntensity=1,this.emissive=new de(0),this.emissiveIntensity=1,this.emissiveMap=null,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=0,this.reflectivity=1,this.refractionRatio=.98,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)}function ms(t){ye.call(this),this.defines={MATCAP:""},this.type="MeshMatcapMaterial",this.color=new de(16777215),this.matcap=null,this.map=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalMapType=0,this.normalScale=new U(1,1),this.displacementMap=null,this.displacementScale=1,this.displacementBias=0,this.alphaMap=null,this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)}function vs(t){wa.call(this),this.type="LineDashedMaterial",this.scale=1,this.dashSize=3,this.gapSize=1,this.setValues(t)}ss.prototype=Object.create(ye.prototype),ss.prototype.constructor=ss,ss.prototype.isShadowMaterial=!0,ss.prototype.copy=function(t){return ye.prototype.copy.call(this,t),this.color.copy(t.color),this},cs.prototype=Object.create(xn.prototype),cs.prototype.constructor=cs,cs.prototype.isRawShaderMaterial=!0,hs.prototype=Object.create(ye.prototype),hs.prototype.constructor=hs,hs.prototype.isMeshStandardMaterial=!0,hs.prototype.copy=function(t){return ye.prototype.copy.call(this,t),this.defines={STANDARD:""},this.color.copy(t.color),this.roughness=t.roughness,this.metalness=t.metalness,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.roughnessMap=t.roughnessMap,this.metalnessMap=t.metalnessMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.envMapIntensity=t.envMapIntensity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.skinning=t.skinning,this.morphTargets=t.morphTargets,this.morphNormals=t.morphNormals,this.vertexTangents=t.vertexTangents,this},ls.prototype=Object.create(hs.prototype),ls.prototype.constructor=ls,ls.prototype.isMeshPhysicalMaterial=!0,ls.prototype.copy=function(t){return hs.prototype.copy.call(this,t),this.defines={STANDARD:"",PHYSICAL:""},this.clearcoat=t.clearcoat,this.clearcoatMap=t.clearcoatMap,this.clearcoatRoughness=t.clearcoatRoughness,this.clearcoatRoughnessMap=t.clearcoatRoughnessMap,this.clearcoatNormalMap=t.clearcoatNormalMap,this.clearcoatNormalScale.copy(t.clearcoatNormalScale),this.reflectivity=t.reflectivity,t.sheen?this.sheen=(this.sheen||new de).copy(t.sheen):this.sheen=null,this.transmission=t.transmission,this.transmissionMap=t.transmissionMap,this},us.prototype=Object.create(ye.prototype),us.prototype.constructor=us,us.prototype.isMeshPhongMaterial=!0,us.prototype.copy=function(t){return ye.prototype.copy.call(this,t),this.color.copy(t.color),this.specular.copy(t.specular),this.shininess=t.shininess,this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.skinning=t.skinning,this.morphTargets=t.morphTargets,this.morphNormals=t.morphNormals,this},ds.prototype=Object.create(ye.prototype),ds.prototype.constructor=ds,ds.prototype.isMeshToonMaterial=!0,ds.prototype.copy=function(t){return ye.prototype.copy.call(this,t),this.color.copy(t.color),this.map=t.map,this.gradientMap=t.gradientMap,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.skinning=t.skinning,this.morphTargets=t.morphTargets,this.morphNormals=t.morphNormals,this},ps.prototype=Object.create(ye.prototype),ps.prototype.constructor=ps,ps.prototype.isMeshNormalMaterial=!0,ps.prototype.copy=function(t){return ye.prototype.copy.call(this,t),this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.skinning=t.skinning,this.morphTargets=t.morphTargets,this.morphNormals=t.morphNormals,this},fs.prototype=Object.create(ye.prototype),fs.prototype.constructor=fs,fs.prototype.isMeshLambertMaterial=!0,fs.prototype.copy=function(t){return ye.prototype.copy.call(this,t),this.color.copy(t.color),this.map=t.map,this.lightMap=t.lightMap,this.lightMapIntensity=t.lightMapIntensity,this.aoMap=t.aoMap,this.aoMapIntensity=t.aoMapIntensity,this.emissive.copy(t.emissive),this.emissiveMap=t.emissiveMap,this.emissiveIntensity=t.emissiveIntensity,this.specularMap=t.specularMap,this.alphaMap=t.alphaMap,this.envMap=t.envMap,this.combine=t.combine,this.reflectivity=t.reflectivity,this.refractionRatio=t.refractionRatio,this.wireframe=t.wireframe,this.wireframeLinewidth=t.wireframeLinewidth,this.wireframeLinecap=t.wireframeLinecap,this.wireframeLinejoin=t.wireframeLinejoin,this.skinning=t.skinning,this.morphTargets=t.morphTargets,this.morphNormals=t.morphNormals,this},ms.prototype=Object.create(ye.prototype),ms.prototype.constructor=ms,ms.prototype.isMeshMatcapMaterial=!0,ms.prototype.copy=function(t){return ye.prototype.copy.call(this,t),this.defines={MATCAP:""},this.color.copy(t.color),this.matcap=t.matcap,this.map=t.map,this.bumpMap=t.bumpMap,this.bumpScale=t.bumpScale,this.normalMap=t.normalMap,this.normalMapType=t.normalMapType,this.normalScale.copy(t.normalScale),this.displacementMap=t.displacementMap,this.displacementScale=t.displacementScale,this.displacementBias=t.displacementBias,this.alphaMap=t.alphaMap,this.skinning=t.skinning,this.morphTargets=t.morphTargets,this.morphNormals=t.morphNormals,this},vs.prototype=Object.create(wa.prototype),vs.prototype.constructor=vs,vs.prototype.isLineDashedMaterial=!0,vs.prototype.copy=function(t){return wa.prototype.copy.call(this,t),this.scale=t.scale,this.dashSize=t.dashSize,this.gapSize=t.gapSize,this};var gs=Object.freeze({__proto__:null,ShadowMaterial:ss,SpriteMaterial:Vr,RawShaderMaterial:cs,ShaderMaterial:xn,PointsMaterial:Na,MeshPhysicalMaterial:ls,MeshStandardMaterial:hs,MeshPhongMaterial:us,MeshToonMaterial:ds,MeshNormalMaterial:ps,MeshLambertMaterial:fs,MeshDepthMaterial:Sr,MeshDistanceMaterial:Er,MeshBasicMaterial:xe,MeshMatcapMaterial:ms,LineDashedMaterial:vs,LineBasicMaterial:wa,Material:ye}),ys={arraySlice:function(t,e,n){return ys.isTypedArray(t)?new t.constructor(t.subarray(e,void 0!==n?n:t.length)):t.slice(e,n)},convertArray:function(t,e,n){return!t||!n&&t.constructor===e?t:"number"==typeof e.BYTES_PER_ELEMENT?new e(t):Array.prototype.slice.call(t)},isTypedArray:function(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)},getKeyframeOrder:function(t){for(var e=t.length,n=new Array(e),i=0;i!==e;++i)n[i]=i;return n.sort((function(e,n){return t[e]-t[n]})),n},sortedArray:function(t,e,n){for(var i=t.length,r=new t.constructor(i),a=0,o=0;o!==i;++a)for(var s=n[a]*e,c=0;c!==e;++c)r[o++]=t[s+c];return r},flattenJSON:function(t,e,n,i){for(var r=1,a=t[0];void 0!==a&&void 0===a[i];)a=t[r++];if(void 0!==a){var o=a[i];if(void 0!==o)if(Array.isArray(o))do{void 0!==(o=a[i])&&(e.push(a.time),n.push.apply(n,o)),a=t[r++]}while(void 0!==a);else if(void 0!==o.toArray)do{void 0!==(o=a[i])&&(e.push(a.time),o.toArray(n,n.length)),a=t[r++]}while(void 0!==a);else do{void 0!==(o=a[i])&&(e.push(a.time),n.push(o)),a=t[r++]}while(void 0!==a)}},subclip:function(t,e,n,i,r){r=r||30;var a=t.clone();a.name=e;for(var o=[],s=0;s=i)){l.push(c.times[d]);for(var f=0;fa.tracks[v].times[0]&&(m=a.tracks[v].times[0]);for(var g=0;g=i.times[c]){var l=c*s;h=ys.arraySlice(i.values,l)}else{var u=i.createInterpolant();u.evaluate(a),h=u.resultBuffer}if("quaternion"===r)new q(h[0],h[1],h[2],h[3]).normalize().conjugate().toArray(h);for(var d=o.times.length,p=0;p=r)break t;var s=e[1];t=(r=e[--n-1]))break e}a=n,n=0}for(;n>>1;te;)--a;if(++a,0!==r||a!==i){r>=a&&(r=(a=Math.max(a,1))-1);var o=this.getValueSize();this.times=ys.arraySlice(n,r,a),this.values=ys.arraySlice(this.values,r*o,a*o)}return this},validate:function(){var t=!0,e=this.getValueSize();e-Math.floor(e)!=0&&(console.error("THREE.KeyframeTrack: Invalid value size in track.",this),t=!1);var n=this.times,i=this.values,r=n.length;0===r&&(console.error("THREE.KeyframeTrack: Track is empty.",this),t=!1);for(var a=null,o=0;o!==r;o++){var s=n[o];if("number"==typeof s&&isNaN(s)){console.error("THREE.KeyframeTrack: Time is not a valid number.",this,o,s),t=!1;break}if(null!==a&&a>s){console.error("THREE.KeyframeTrack: Out of order keys.",this,o,s,a),t=!1;break}a=s}if(void 0!==i&&ys.isTypedArray(i))for(var c=0,h=i.length;c!==h;++c){var l=i[c];if(isNaN(l)){console.error("THREE.KeyframeTrack: Value is not a valid number.",this,c,l),t=!1;break}}return t},optimize:function(){for(var t=ys.arraySlice(this.times),e=ys.arraySlice(this.values),n=this.getValueSize(),i=this.getInterpolation()===M,r=t.length-1,a=1,o=1;o0){t[a]=t[r];for(var g=r*n,y=a*n,x=0;x!==n;++x)e[y+x]=e[g+x];++a}return a!==t.length?(this.times=ys.arraySlice(t,0,a),this.values=ys.arraySlice(e,0,a*n)):(this.times=t,this.values=e),this},clone:function(){var t=ys.arraySlice(this.times,0),e=ys.arraySlice(this.values,0),n=new(0,this.constructor)(this.name,t,e);return n.createInterpolant=this.createInterpolant,n}}),Ss.prototype=Object.assign(Object.create(Ms.prototype),{constructor:Ss,ValueTypeName:"bool",ValueBufferType:Array,DefaultInterpolation:b,InterpolantFactoryMethodLinear:void 0,InterpolantFactoryMethodSmooth:void 0}),Es.prototype=Object.assign(Object.create(Ms.prototype),{constructor:Es,ValueTypeName:"color"}),Ts.prototype=Object.assign(Object.create(Ms.prototype),{constructor:Ts,ValueTypeName:"number"}),As.prototype=Object.assign(Object.create(xs.prototype),{constructor:As,interpolate_:function(t,e,n,i){for(var r=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=(n-e)/(i-e),c=t*o,h=c+o;c!==h;c+=4)q.slerpFlat(r,0,a,c-o,a,c,s);return r}}),Ls.prototype=Object.assign(Object.create(Ms.prototype),{constructor:Ls,ValueTypeName:"quaternion",DefaultInterpolation:w,InterpolantFactoryMethodLinear:function(t){return new As(this.times,this.values,this.getValueSize(),t)},InterpolantFactoryMethodSmooth:void 0}),Ps.prototype=Object.assign(Object.create(Ms.prototype),{constructor:Ps,ValueTypeName:"string",ValueBufferType:Array,DefaultInterpolation:b,InterpolantFactoryMethodLinear:void 0,InterpolantFactoryMethodSmooth:void 0}),Rs.prototype=Object.assign(Object.create(Ms.prototype),{constructor:Rs,ValueTypeName:"vector"}),Object.assign(Cs,{parse:function(t){for(var e=[],n=t.tracks,i=1/(t.fps||1),r=0,a=n.length;r!==a;++r)e.push(Os(n[r]).scale(i));return new Cs(t.name,t.duration,e,t.blendMode)},toJSON:function(t){for(var e=[],n=t.tracks,i={name:t.name,duration:t.duration,tracks:e,uuid:t.uuid,blendMode:t.blendMode},r=0,a=n.length;r!==a;++r)e.push(Ms.toJSON(n[r]));return i},CreateFromMorphTargetSequence:function(t,e,n,i){for(var r=e.length,a=[],o=0;o1){var h=c[1],l=i[h];l||(i[h]=l=[]),l.push(s)}}var u=[];for(var d in i)u.push(Cs.CreateFromMorphTargetSequence(d,i[d],e,n));return u},parseAnimation:function(t,e){if(!t)return console.error("THREE.AnimationClip: No animation in JSONLoader data."),null;for(var n=function(t,e,n,i,r){if(0!==n.length){var a=[],o=[];ys.flattenJSON(n,a,o,i),0!==a.length&&r.push(new t(e,a,o))}},i=[],r=t.name||"default",a=t.fps||30,o=t.blendMode,s=t.length||-1,c=t.hierarchy||[],h=0;h0||0===t.search(/^data\:image\/jpeg/);r.format=i?g:y,r.needsUpdate=!0,void 0!==e&&e(r)}),n,i),r}}),Object.assign(Ws.prototype,{getPoint:function(){return console.warn("THREE.Curve: .getPoint() not implemented."),null},getPointAt:function(t,e){var n=this.getUtoTmapping(t);return this.getPoint(n,e)},getPoints:function(t){void 0===t&&(t=5);for(var e=[],n=0;n<=t;n++)e.push(this.getPoint(n/t));return e},getSpacedPoints:function(t){void 0===t&&(t=5);for(var e=[],n=0;n<=t;n++)e.push(this.getPointAt(n/t));return e},getLength:function(){var t=this.getLengths();return t[t.length-1]},getLengths:function(t){if(void 0===t&&(t=this.arcLengthDivisions),this.cacheArcLengths&&this.cacheArcLengths.length===t+1&&!this.needsUpdate)return this.cacheArcLengths;this.needsUpdate=!1;var e,n=[],i=this.getPoint(0),r=0;n.push(0);for(var a=1;a<=t;a++)r+=(e=this.getPoint(a/t)).distanceTo(i),n.push(r),i=e;return this.cacheArcLengths=n,n},updateArcLengths:function(){this.needsUpdate=!0,this.getLengths()},getUtoTmapping:function(t,e){var n,i=this.getLengths(),r=0,a=i.length;n=e||t*i[a-1];for(var o,s=0,c=a-1;s<=c;)if((o=i[r=Math.floor(s+(c-s)/2)]-n)<0)s=r+1;else{if(!(o>0)){c=r;break}c=r-1}if(i[r=c]===n)return r/(a-1);var h=i[r];return(r+(n-h)/(i[r+1]-h))/(a-1)},getTangent:function(t,e){var n=1e-4,i=t-n,r=t+n;i<0&&(i=0),r>1&&(r=1);var a=this.getPoint(i),o=this.getPoint(r),s=e||(a.isVector2?new U:new Z);return s.copy(o).sub(a).normalize(),s},getTangentAt:function(t,e){var n=this.getUtoTmapping(t);return this.getTangent(n,e)},computeFrenetFrames:function(t,e){for(var n=new Z,i=[],r=[],a=[],o=new Z,s=new it,c=0;c<=t;c++){var h=c/t;i[c]=this.getTangentAt(h,new Z),i[c].normalize()}r[0]=new Z,a[0]=new Z;var l=Number.MAX_VALUE,u=Math.abs(i[0].x),d=Math.abs(i[0].y),p=Math.abs(i[0].z);u<=l&&(l=u,n.set(1,0,0)),d<=l&&(l=d,n.set(0,1,0)),p<=l&&n.set(0,0,1),o.crossVectors(i[0],n).normalize(),r[0].crossVectors(i[0],o),a[0].crossVectors(i[0],r[0]);for(var f=1;f<=t;f++){if(r[f]=r[f-1].clone(),a[f]=a[f-1].clone(),o.crossVectors(i[f-1],i[f]),o.length()>Number.EPSILON){o.normalize();var m=Math.acos(B.clamp(i[f-1].dot(i[f]),-1,1));r[f].applyMatrix4(s.makeRotationAxis(o,m))}a[f].crossVectors(i[f],r[f])}if(!0===e){var v=Math.acos(B.clamp(r[0].dot(r[t]),-1,1));v/=t,i[0].dot(o.crossVectors(r[0],r[t]))>0&&(v=-v);for(var g=1;g<=t;g++)r[g].applyMatrix4(s.makeRotationAxis(i[g],v*g)),a[g].crossVectors(i[g],r[g])}return{tangents:i,normals:r,binormals:a}},clone:function(){return(new this.constructor).copy(this)},copy:function(t){return this.arcLengthDivisions=t.arcLengthDivisions,this},toJSON:function(){var t={metadata:{version:4.5,type:"Curve",generator:"Curve.toJSON"}};return t.arcLengthDivisions=this.arcLengthDivisions,t.type=this.type,t},fromJSON:function(t){return this.arcLengthDivisions=t.arcLengthDivisions,this}}),qs.prototype=Object.create(Ws.prototype),qs.prototype.constructor=qs,qs.prototype.isEllipseCurve=!0,qs.prototype.getPoint=function(t,e){for(var n=e||new U,i=2*Math.PI,r=this.aEndAngle-this.aStartAngle,a=Math.abs(r)i;)r-=i;r0?0:(Math.floor(Math.abs(l)/c)+1)*c:0===u&&l===c-1&&(l=c-2,u=1),this.closed||l>0?n=s[(l-1)%c]:(Zs.subVectors(s[0],s[1]).add(s[0]),n=Zs),i=s[l%c],r=s[(l+1)%c],this.closed||l+2i.length-2?i.length-1:a+1],l=i[a>i.length-3?i.length-1:a+2];return n.set(tc(o,s.x,c.x,h.x,l.x),tc(o,s.y,c.y,h.y,l.y)),n},hc.prototype.copy=function(t){Ws.prototype.copy.call(this,t),this.points=[];for(var e=0,n=t.points.length;e=e){var r=n[i]-e,a=this.curves[i],o=a.getLength(),s=0===o?0:1-r/o;return a.getPointAt(s)}i++}return null},getLength:function(){var t=this.getCurveLengths();return t[t.length-1]},updateArcLengths:function(){this.needsUpdate=!0,this.cacheLengths=null,this.getCurveLengths()},getCurveLengths:function(){if(this.cacheLengths&&this.cacheLengths.length===this.curves.length)return this.cacheLengths;for(var t=[],e=0,n=0,i=this.curves.length;n1&&!n[n.length-1].equals(n[0])&&n.push(n[0]),n},copy:function(t){Ws.prototype.copy.call(this,t),this.curves=[];for(var e=0,n=t.curves.length;e0){var h=c.getPoint(0);h.equals(this.currentPoint)||this.lineTo(h.x,h.y)}this.curves.push(c);var l=c.getPoint(1);return this.currentPoint.copy(l),this},copy:function(t){return uc.prototype.copy.call(this,t),this.currentPoint.copy(t.currentPoint),this},toJSON:function(){var t=uc.prototype.toJSON.call(this);return t.currentPoint=this.currentPoint.toArray(),t},fromJSON:function(t){return uc.prototype.fromJSON.call(this,t),this.currentPoint.fromArray(t.currentPoint),this}}),pc.prototype=Object.assign(Object.create(dc.prototype),{constructor:pc,getPointsHoles:function(t){for(var e=[],n=0,i=this.holes.length;n0:i.vertexColors=t.vertexColors),void 0!==t.uniforms)for(var r in t.uniforms){var a=t.uniforms[r];switch(i.uniforms[r]={},a.type){case"t":i.uniforms[r].value=n(a.value);break;case"c":i.uniforms[r].value=(new de).setHex(a.value);break;case"v2":i.uniforms[r].value=(new U).fromArray(a.value);break;case"v3":i.uniforms[r].value=(new Z).fromArray(a.value);break;case"v4":i.uniforms[r].value=(new V).fromArray(a.value);break;case"m3":i.uniforms[r].value=(new F).fromArray(a.value);case"m4":i.uniforms[r].value=(new it).fromArray(a.value);break;default:i.uniforms[r].value=a.value}}if(void 0!==t.defines&&(i.defines=t.defines),void 0!==t.vertexShader&&(i.vertexShader=t.vertexShader),void 0!==t.fragmentShader&&(i.fragmentShader=t.fragmentShader),void 0!==t.extensions)for(var o in t.extensions)i.extensions[o]=t.extensions[o];if(void 0!==t.shading&&(i.flatShading=1===t.shading),void 0!==t.size&&(i.size=t.size),void 0!==t.sizeAttenuation&&(i.sizeAttenuation=t.sizeAttenuation),void 0!==t.map&&(i.map=n(t.map)),void 0!==t.matcap&&(i.matcap=n(t.matcap)),void 0!==t.alphaMap&&(i.alphaMap=n(t.alphaMap)),void 0!==t.bumpMap&&(i.bumpMap=n(t.bumpMap)),void 0!==t.bumpScale&&(i.bumpScale=t.bumpScale),void 0!==t.normalMap&&(i.normalMap=n(t.normalMap)),void 0!==t.normalMapType&&(i.normalMapType=t.normalMapType),void 0!==t.normalScale){var s=t.normalScale;!1===Array.isArray(s)&&(s=[s,s]),i.normalScale=(new U).fromArray(s)}return void 0!==t.displacementMap&&(i.displacementMap=n(t.displacementMap)),void 0!==t.displacementScale&&(i.displacementScale=t.displacementScale),void 0!==t.displacementBias&&(i.displacementBias=t.displacementBias),void 0!==t.roughnessMap&&(i.roughnessMap=n(t.roughnessMap)),void 0!==t.metalnessMap&&(i.metalnessMap=n(t.metalnessMap)),void 0!==t.emissiveMap&&(i.emissiveMap=n(t.emissiveMap)),void 0!==t.emissiveIntensity&&(i.emissiveIntensity=t.emissiveIntensity),void 0!==t.specularMap&&(i.specularMap=n(t.specularMap)),void 0!==t.envMap&&(i.envMap=n(t.envMap)),void 0!==t.envMapIntensity&&(i.envMapIntensity=t.envMapIntensity),void 0!==t.reflectivity&&(i.reflectivity=t.reflectivity),void 0!==t.refractionRatio&&(i.refractionRatio=t.refractionRatio),void 0!==t.lightMap&&(i.lightMap=n(t.lightMap)),void 0!==t.lightMapIntensity&&(i.lightMapIntensity=t.lightMapIntensity),void 0!==t.aoMap&&(i.aoMap=n(t.aoMap)),void 0!==t.aoMapIntensity&&(i.aoMapIntensity=t.aoMapIntensity),void 0!==t.gradientMap&&(i.gradientMap=n(t.gradientMap)),void 0!==t.clearcoatMap&&(i.clearcoatMap=n(t.clearcoatMap)),void 0!==t.clearcoatRoughnessMap&&(i.clearcoatRoughnessMap=n(t.clearcoatRoughnessMap)),void 0!==t.clearcoatNormalMap&&(i.clearcoatNormalMap=n(t.clearcoatNormalMap)),void 0!==t.clearcoatNormalScale&&(i.clearcoatNormalScale=(new U).fromArray(t.clearcoatNormalScale)),void 0!==t.transmission&&(i.transmission=t.transmission),void 0!==t.transmissionMap&&(i.transmissionMap=n(t.transmissionMap)),i},setTextures:function(t){return this.textures=t,this}});var Pc=function(t){var e=t.lastIndexOf("/");return-1===e?"./":t.substr(0,e+1)};function Rc(){He.call(this),this.type="InstancedBufferGeometry",this.instanceCount=1/0}function Cc(t,e,n,i){"number"==typeof n&&(i=n,n=!1,console.error("THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.")),we.call(this,t,e,n),this.meshPerAttribute=i||1}function Oc(t){zs.call(this,t)}Rc.prototype=Object.assign(Object.create(He.prototype),{constructor:Rc,isInstancedBufferGeometry:!0,copy:function(t){return He.prototype.copy.call(this,t),this.instanceCount=t.instanceCount,this},clone:function(){return(new this.constructor).copy(this)},toJSON:function(){var t=He.prototype.toJSON.call(this);return t.instanceCount=this.instanceCount,t.isInstancedBufferGeometry=!0,t}}),Cc.prototype=Object.assign(Object.create(we.prototype),{constructor:Cc,isInstancedBufferAttribute:!0,copy:function(t){return we.prototype.copy.call(this,t),this.meshPerAttribute=t.meshPerAttribute,this},toJSON:function(){var t=we.prototype.toJSON.call(this);return t.meshPerAttribute=this.meshPerAttribute,t.isInstancedBufferAttribute=!0,t}}),Oc.prototype=Object.assign(Object.create(zs.prototype),{constructor:Oc,load:function(t,e,n,i){var r=this,a=new Us(r.manager);a.setPath(r.path),a.setRequestHeader(r.requestHeader),a.load(t,(function(n){try{e(r.parse(JSON.parse(n)))}catch(e){i?i(e):console.error(e),r.manager.itemError(t)}}),n,i)},parse:function(t){var e={},n={};function i(t,i){if(void 0!==e[i])return e[i];var r=t.interleavedBuffers[i],a=function(t,e){if(void 0!==n[e])return n[e];var i=t.arrayBuffers[e],r=new Uint32Array(i).buffer;return n[e]=r,r}(t,r.buffer),o=new Fr(new Nc[r.type](a),r.stride);return o.uuid=r.uuid,e[i]=o,o}var r=t.isInstancedBufferGeometry?new Rc:new He,a=t.data.index;if(void 0!==a){var o=new Nc[a.type](a.array);r.setIndex(new we(o,1))}var s=t.data.attributes;for(var c in s){var h=s[c],l=void 0;if(h.isInterleavedBufferAttribute){l=new Gr(i(t.data,h.data),h.itemSize,h.offset,h.normalized)}else{var u=new Nc[h.type](h.array);l=new(h.isInstancedBufferAttribute?Cc:we)(u,h.itemSize,h.normalized)}void 0!==h.name&&(l.name=h.name),r.setAttribute(c,l)}var d=t.data.morphAttributes;if(d)for(var p in d){for(var f=d[p],m=[],v=0,g=f.length;v0){var o=new Ds(e);(n=new Gs(o)).setCrossOrigin(this.crossOrigin);for(var s=0,c=t.length;sNumber.EPSILON){if(h<0&&(o=e[a],c=-c,s=e[r],h=-h),t.ys.y)continue;if(t.y===o.y){if(t.x===o.x)return!0}else{var l=h*(t.x-o.x)-c*(t.y-o.y);if(0===l)return!0;if(l<0)continue;i=!i}}else{if(t.y!==o.y)continue;if(s.x<=t.x&&t.x<=o.x||o.x<=t.x&&t.x<=s.x)return!0}}return i}var r=Io.isClockWise,a=this.subPaths;if(0===a.length)return[];if(!0===e)return n(a);var o,s,c,h=[];if(1===a.length)return s=a[0],(c=new pc).curves=s.curves,h.push(c),h;var l=!r(a[0].getPoints());l=t?!l:l;var u,d,p=[],f=[],m=[],v=0;f[v]=void 0,m[v]=[];for(var g=0,y=a.length;g1){for(var x=!1,_=[],b=0,w=f.length;b0&&(x||(m=p))}for(var R=0,C=f.length;R0){this.source.connect(this.filters[0]);for(var t=1,e=this.filters.length;t0){this.source.disconnect(this.filters[0]);for(var t=1,e=this.filters.length;t0&&this._mixBufferRegionAdditive(n,i,this._addIndex*e,1,e);for(var c=e,h=e+e;c!==h;++c)if(n[c]!==n[c+e]){o.setValue(n,i);break}},saveOriginalState:function(){var t=this.binding,e=this.buffer,n=this.valueSize,i=n*this._origIndex;t.getValue(e,i);for(var r=n,a=i;r!==a;++r)e[r]=e[i+r%n];this._setIdentity(),this.cumulativeWeight=0,this.cumulativeWeightAdditive=0},restoreOriginalState:function(){var t=3*this.valueSize;this.binding.setValue(this.buffer,t)},_setAdditiveIdentityNumeric:function(){for(var t=this._addIndex*this.valueSize,e=t+this.valueSize,n=t;n=.5)for(var a=0;a!==r;++a)t[e+a]=t[n+a]},_slerp:function(t,e,n,i){q.slerpFlat(t,e,t,e,t,n,i)},_slerpAdditive:function(t,e,n,i,r){var a=this._workIndex*r;q.multiplyQuaternionsFlat(t,a,t,e,t,n),q.slerpFlat(t,e,t,e,t,a,i)},_lerp:function(t,e,n,i,r){for(var a=1-i,o=0;o!==r;++o){var s=e+o;t[s]=t[s]*a+t[n+o]*i}},_lerpAdditive:function(t,e,n,i,r){for(var a=0;a!==r;++a){var o=e+a;t[o]=t[o]+t[n+a]*i}}});var lh="\\[\\]\\.:\\/",uh=new RegExp("[\\[\\]\\.:\\/]","g"),dh="[^\\[\\]\\.:\\/]",ph="[^"+lh.replace("\\.","")+"]",fh=/((?:WC+[\/:])*)/.source.replace("WC",dh),mh=/(WCOD+)?/.source.replace("WCOD",ph),vh=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC",dh),gh=/\.(WC+)(?:\[(.+)\])?/.source.replace("WC",dh),yh=new RegExp("^"+fh+mh+vh+gh+"$"),xh=["material","materials","bones"];function _h(t,e,n){var i=n||bh.parseTrackName(e);this._targetGroup=t,this._bindings=t.subscribe_(e,i)}function bh(t,e,n){this.path=e,this.parsedPath=n||bh.parseTrackName(e),this.node=bh.findNode(t,this.parsedPath.nodeName)||t,this.rootNode=t}function wh(t,e,n,i){this._mixer=t,this._clip=e,this._localRoot=n||null,this.blendMode=i||e.blendMode;for(var r=e.tracks,a=r.length,o=new Array(a),s={endingStart:S,endingEnd:S},c=0;c!==a;++c){var h=r[c].createInterpolant(null);o[c]=h,h.settings=s}this._interpolantSettings=s,this._interpolants=o,this._propertyBindings=new Array(a),this._cacheIndex=null,this._byClipCacheIndex=null,this._timeScaleInterpolant=null,this._weightInterpolant=null,this.loop=2201,this._loopCount=-1,this._startTime=null,this.time=0,this.timeScale=1,this._effectiveTimeScale=1,this.weight=1,this._effectiveWeight=1,this.repetitions=1/0,this.paused=!1,this.enabled=!0,this.clampWhenFinished=!1,this.zeroSlopeAtStart=!0,this.zeroSlopeAtEnd=!0}function Mh(t){this._root=t,this._initMemoryManager(),this._accuIndex=0,this.time=0,this.timeScale=1}function Sh(t){"string"==typeof t&&(console.warn("THREE.Uniform: Type parameter is no longer needed."),t=arguments[1]),this.value=t}function Eh(t,e,n){Fr.call(this,t,e),this.meshPerAttribute=n||1}function Th(t,e,n,i){this.ray=new Xt(t,e),this.near=n||0,this.far=i||1/0,this.camera=null,this.layers=new st,this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}},Object.defineProperties(this.params,{PointCloud:{get:function(){return console.warn("THREE.Raycaster: params.PointCloud has been renamed to params.Points."),this.Points}}})}function Ah(t,e){return t.distance-e.distance}function Lh(t,e,n,i){if(t.layers.test(e.layers)&&t.raycast(e,n),!0===i)for(var r=t.children,a=0,o=r.length;a=a){var u=a++,d=e[u];n[d.uuid]=l,e[l]=d,n[h]=u,e[u]=c;for(var p=0,f=r;p!==f;++p){var m=i[p],v=m[u],g=m[l];m[l]=v,m[u]=g}}}this.nCachedObjects_=a},uncache:function(){for(var t=arguments,e=this._objects,n=this._indicesByUUID,i=this._bindings,r=i.length,a=this.nCachedObjects_,o=e.length,s=0,c=arguments.length;s!==c;++s){var h=t[s],l=h.uuid,u=n[l];if(void 0!==u)if(delete n[l],u0){var c=this._interpolants,h=this._propertyBindings;switch(this.blendMode){case 2501:for(var l=0,u=c.length;l!==u;++l)c[l].evaluate(o),h[l].accumulateAdditive(s);break;case A:default:for(var d=0,p=c.length;d!==p;++d)c[d].evaluate(o),h[d].accumulate(i,s)}}}else this._updateWeight(t)},_updateWeight:function(t){var e=0;if(this.enabled){e=this.weight;var n=this._weightInterpolant;if(null!==n){var i=n.evaluate(t)[0];e*=i,t>n.parameterPositions[1]&&(this.stopFading(),0===i&&(this.enabled=!1))}}return this._effectiveWeight=e,e},_updateTimeScale:function(t){var e=0;if(!this.paused){e=this.timeScale;var n=this._timeScaleInterpolant;if(null!==n)e*=n.evaluate(t)[0],t>n.parameterPositions[1]&&(this.stopWarping(),0===e?this.paused=!0:this.timeScale=e)}return this._effectiveTimeScale=e,e},_updateTime:function(t){var e=this._clip.duration,n=this.loop,i=this.time+t,r=this._loopCount,a=2202===n;if(0===t)return-1===r?i:a&&1==(1&r)?e-i:i;if(2200===n){-1===r&&(this._loopCount=0,this._setEndings(!0,!0,!1));t:{if(i>=e)i=e;else{if(!(i<0)){this.time=i;break t}i=0}this.clampWhenFinished?this.paused=!0:this.enabled=!1,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t<0?-1:1})}}else{if(-1===r&&(t>=0?(r=0,this._setEndings(!0,0===this.repetitions,a)):this._setEndings(0===this.repetitions,!0,a)),i>=e||i<0){var o=Math.floor(i/e);i-=e*o,r+=Math.abs(o);var s=this.repetitions-r;if(s<=0)this.clampWhenFinished?this.paused=!0:this.enabled=!1,i=t>0?e:0,this.time=i,this._mixer.dispatchEvent({type:"finished",action:this,direction:t>0?1:-1});else{if(1===s){var c=t<0;this._setEndings(c,!c,a)}else this._setEndings(!1,!1,a);this._loopCount=r,this.time=i,this._mixer.dispatchEvent({type:"loop",action:this,loopDelta:o})}}else this.time=i;if(a&&1==(1&r))return e-i}return i},_setEndings:function(t,e,n){var i=this._interpolantSettings;n?(i.endingStart=E,i.endingEnd=E):(i.endingStart=t?this.zeroSlopeAtStart?E:S:T,i.endingEnd=e?this.zeroSlopeAtEnd?E:S:T)},_scheduleFading:function(t,e,n){var i=this._mixer,r=i.time,a=this._weightInterpolant;null===a&&(a=i._lendControlInterpolant(),this._weightInterpolant=a);var o=a.parameterPositions,s=a.sampleValues;return o[0]=r,s[0]=e,o[1]=r+t,s[1]=n,this}}),Mh.prototype=Object.assign(Object.create(O.prototype),{constructor:Mh,_bindAction:function(t,e){var n=t._localRoot||this._root,i=t._clip.tracks,r=i.length,a=t._propertyBindings,o=t._interpolants,s=n.uuid,c=this._bindingsByRootAndName,h=c[s];void 0===h&&(h={},c[s]=h);for(var l=0;l!==r;++l){var u=i[l],d=u.name,p=h[d];if(void 0!==p)a[l]=p;else{if(void 0!==(p=a[l])){null===p._cacheIndex&&(++p.referenceCount,this._addInactiveBinding(p,s,d));continue}var f=e&&e._propertyBindings[l].binding.parsedPath;++(p=new hh(bh.create(n,d,f),u.ValueTypeName,u.getValueSize())).referenceCount,this._addInactiveBinding(p,s,d),a[l]=p}o[l].resultBuffer=p.buffer}},_activateAction:function(t){if(!this._isActiveAction(t)){if(null===t._cacheIndex){var e=(t._localRoot||this._root).uuid,n=t._clip.uuid,i=this._actionsByClip[n];this._bindAction(t,i&&i.knownActions[0]),this._addInactiveAction(t,n,e)}for(var r=t._propertyBindings,a=0,o=r.length;a!==o;++a){var s=r[a];0==s.useCount++&&(this._lendBinding(s),s.saveOriginalState())}this._lendAction(t)}},_deactivateAction:function(t){if(this._isActiveAction(t)){for(var e=t._propertyBindings,n=0,i=e.length;n!==i;++n){var r=e[n];0==--r.useCount&&(r.restoreOriginalState(),this._takeBackBinding(r))}this._takeBackAction(t)}},_initMemoryManager:function(){this._actions=[],this._nActiveActions=0,this._actionsByClip={},this._bindings=[],this._nActiveBindings=0,this._bindingsByRootAndName={},this._controlInterpolants=[],this._nActiveControlInterpolants=0;var t=this;this.stats={actions:{get total(){return t._actions.length},get inUse(){return t._nActiveActions}},bindings:{get total(){return t._bindings.length},get inUse(){return t._nActiveBindings}},controlInterpolants:{get total(){return t._controlInterpolants.length},get inUse(){return t._nActiveControlInterpolants}}}},_isActiveAction:function(t){var e=t._cacheIndex;return null!==e&&e=0;--e)t[e].stop();return this},update:function(t){t*=this.timeScale;for(var e=this._actions,n=this._nActiveActions,i=this.time+=t,r=Math.sign(t),a=this._accuIndex^=1,o=0;o!==n;++o){e[o]._update(i,t,r,a)}for(var s=this._bindings,c=this._nActiveBindings,h=0;h!==c;++h)s[h].apply(a);return this},setTime:function(t){this.time=0;for(var e=0;ethis.max.x||t.ythis.max.y)},containsBox:function(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y},getParameter:function(t,e){return void 0===e&&(console.warn("THREE.Box2: .getParameter() target is now required"),e=new U),e.set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y))},intersectsBox:function(t){return!(t.max.xthis.max.x||t.max.ythis.max.y)},clampPoint:function(t,e){return void 0===e&&(console.warn("THREE.Box2: .clampPoint() target is now required"),e=new U),e.copy(t).clamp(this.min,this.max)},distanceToPoint:function(t){return Rh.copy(t).clamp(this.min,this.max).sub(t).length()},intersect:function(t){return this.min.max(t.min),this.max.min(t.max),this},union:function(t){return this.min.min(t.min),this.max.max(t.max),this},translate:function(t){return this.min.add(t),this.max.add(t),this},equals:function(t){return t.min.equals(this.min)&&t.max.equals(this.max)}});var Oh=new Z,Nh=new Z;function Dh(t,e){this.start=void 0!==t?t:new Z,this.end=void 0!==e?e:new Z}function Ih(t){bt.call(this),this.material=t,this.render=function(){},this.hasPositions=!1,this.hasNormals=!1,this.hasColors=!1,this.hasUvs=!1,this.positionArray=null,this.normalArray=null,this.colorArray=null,this.uvArray=null,this.count=0}Object.assign(Dh.prototype,{set:function(t,e){return this.start.copy(t),this.end.copy(e),this},clone:function(){return(new this.constructor).copy(this)},copy:function(t){return this.start.copy(t.start),this.end.copy(t.end),this},getCenter:function(t){return void 0===t&&(console.warn("THREE.Line3: .getCenter() target is now required"),t=new Z),t.addVectors(this.start,this.end).multiplyScalar(.5)},delta:function(t){return void 0===t&&(console.warn("THREE.Line3: .delta() target is now required"),t=new Z),t.subVectors(this.end,this.start)},distanceSq:function(){return this.start.distanceToSquared(this.end)},distance:function(){return this.start.distanceTo(this.end)},at:function(t,e){return void 0===e&&(console.warn("THREE.Line3: .at() target is now required"),e=new Z),this.delta(e).multiplyScalar(t).add(this.start)},closestPointToPointParameter:function(t,e){Oh.subVectors(t,this.start),Nh.subVectors(this.end,this.start);var n=Nh.dot(Nh),i=Nh.dot(Oh)/n;return e&&(i=B.clamp(i,0,1)),i},closestPointToPoint:function(t,e,n){var i=this.closestPointToPointParameter(t,e);return void 0===n&&(console.warn("THREE.Line3: .closestPointToPoint() target is now required"),n=new Z),this.delta(n).multiplyScalar(i).add(this.start)},applyMatrix4:function(t){return this.start.applyMatrix4(t),this.end.applyMatrix4(t),this},equals:function(t){return t.start.equals(this.start)&&t.end.equals(this.end)}}),Ih.prototype=Object.create(bt.prototype),Ih.prototype.constructor=Ih,Ih.prototype.isImmediateRenderObject=!0;var zh=new Z;function Bh(t,e){bt.call(this),this.light=t,this.light.updateMatrixWorld(),this.matrix=t.matrixWorld,this.matrixAutoUpdate=!1,this.color=e;for(var n=new He,i=[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],r=0,a=1;r<32;r++,a++){var o=r/32*Math.PI*2,s=a/32*Math.PI*2;i.push(Math.cos(o),Math.sin(o),1,Math.cos(s),Math.sin(s),1)}n.setAttribute("position",new Re(i,3));var c=new wa({fog:!1,toneMapped:!1});this.cone=new Ca(n,c),this.add(this.cone),this.update()}Bh.prototype=Object.create(bt.prototype),Bh.prototype.constructor=Bh,Bh.prototype.dispose=function(){this.cone.geometry.dispose(),this.cone.material.dispose()},Bh.prototype.update=function(){this.light.updateMatrixWorld();var t=this.light.distance?this.light.distance:1e3,e=t*Math.tan(this.light.angle);this.cone.scale.set(e,e,t),zh.setFromMatrixPosition(this.light.target.matrixWorld),this.cone.lookAt(zh),void 0!==this.color?this.cone.material.color.set(this.color):this.cone.material.color.copy(this.light.color)};var Uh=new Z,Fh=new it,kh=new it;function Hh(t){for(var e=function t(e){var n=[];e&&e.isBone&&n.push(e);for(var i=0;i.99999)this.quaternion.set(0,0,0,1);else if(t.y<-.99999)this.quaternion.set(1,0,0,0);else{hl.set(t.z,0,-t.x).normalize();var e=Math.acos(t.y);this.quaternion.setFromAxisAngle(hl,e)}},ll.prototype.setLength=function(t,e,n){void 0===e&&(e=.2*t),void 0===n&&(n=.2*e),this.line.scale.set(1,Math.max(1e-4,t-e),1),this.line.updateMatrix(),this.cone.scale.set(n,e,n),this.cone.position.y=t,this.cone.updateMatrix()},ll.prototype.setColor=function(t){this.line.material.color.set(t),this.cone.material.color.set(t)},ll.prototype.copy=function(t){return bt.prototype.copy.call(this,t,!1),this.line.copy(t.line),this.cone.copy(t.cone),this},ul.prototype=Object.create(Ca.prototype),ul.prototype.constructor=ul;var dl=[.125,.215,.35,.446,.526,.582],pl=5+dl.length,fl=(new bc,function(){for(var t=[],e=[],n=[],i=8,r=0;r4?o=dl[r-8+4-1]:0==r&&(o=0),n.push(o);for(var s=1/(a-1),c=-s/2,h=1+s/2,l=[c,c,h,c,h,h,c,c,h,h,c,h],u=new Float32Array(108),d=new Float32Array(72),p=new Float32Array(36),f=0;f<6;f++){var m=f%3*2/3-1,v=f>2?0:-1,g=[m,v,0,m+2/3,v,0,m+2/3,v+1,0,m,v,0,m+2/3,v+1,0,m,v+1,0];u.set(g,18*f),d.set(l,12*f);var y=[f,f,f,f,f,f];p.set(y,6*f)}var x=new He;x.setAttribute("position",new we(u,3)),x.setAttribute("uv",new we(d,2)),x.setAttribute("faceIndex",new we(p,1)),t.push(x),i>4&&i--}}(),(1+Math.sqrt(5))/2),ml=1/fl;new Z(1,1,1),new Z(-1,1,1),new Z(1,1,-1),new Z(-1,1,-1),new Z(0,fl,ml),new Z(0,fl,-ml),new Z(ml,0,fl),new Z(-ml,0,fl),new Z(fl,ml,0),new Z(-fl,ml,0);function vl(t){console.warn("THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead."),$s.call(this,t),this.type="catmullrom"}function gl(t,e){var n=t.__state.conversionName.toString(),i=Math.round(t.r),r=Math.round(t.g),a=Math.round(t.b),o=t.a,s=Math.round(t.h),c=t.s.toFixed(1),h=t.v.toFixed(1);if(e||"THREE_CHAR_HEX"===n||"SIX_CHAR_HEX"===n){for(var l=t.hex.toString(16);l.length<6;)l="0"+l;return"#"+l}return"CSS_RGB"===n?"rgb("+i+","+r+","+a+")":"CSS_RGBA"===n?"rgba("+i+","+r+","+a+","+o+")":"HEX"===n?"0x"+t.hex.toString(16):"RGB_ARRAY"===n?"["+i+","+r+","+a+"]":"RGBA_ARRAY"===n?"["+i+","+r+","+a+","+o+"]":"RGB_OBJ"===n?"{r:"+i+",g:"+r+",b:"+a+"}":"RGBA_OBJ"===n?"{r:"+i+",g:"+r+",b:"+a+",a:"+o+"}":"HSV_OBJ"===n?"{h:"+s+",s:"+c+",v:"+h+"}":"HSVA_OBJ"===n?"{h:"+s+",s:"+c+",v:"+h+",a:"+o+"}":"unknown format"}Ws.create=function(t,e){return console.log("THREE.Curve.create() has been deprecated"),t.prototype=Object.create(Ws.prototype),t.prototype.constructor=t,t.prototype.getPoint=e,t},Object.assign(uc.prototype,{createPointsGeometry:function(t){console.warn("THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.");var e=this.getPoints(t);return this.createGeometry(e)},createSpacedPointsGeometry:function(t){console.warn("THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.");var e=this.getSpacedPoints(t);return this.createGeometry(e)},createGeometry:function(t){console.warn("THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.");for(var e=new pn,n=0,i=t.length;n=0;n--)e=[t[n].apply(this,e)];return e[0]}},each:function(t,e,n){if(t)if(yl&&t.forEach&&t.forEach===yl)t.forEach(e,n);else if(t.length===t.length+0){var i,r=void 0;for(r=0,i=t.length;r1?_l.toArray(arguments):arguments[0];return _l.each(bl,(function(e){if(e.litmus(t))return _l.each(e.conversions,(function(e,n){if(wl=e.read(t),!1===Ml&&!1!==wl)return Ml=wl,wl.conversionName=n,wl.conversion=e,_l.BREAK})),_l.BREAK})),Ml},El=void 0,Tl={hsv_to_rgb:function(t,e,n){var i=Math.floor(t/60)%6,r=t/60-Math.floor(t/60),a=n*(1-e),o=n*(1-r*e),s=n*(1-(1-r)*e),c=[[n,s,a],[o,n,a],[a,n,s],[a,o,n],[s,a,n],[n,a,o]][i];return{r:255*c[0],g:255*c[1],b:255*c[2]}},rgb_to_hsv:function(t,e,n){var i=Math.min(t,e,n),r=Math.max(t,e,n),a=r-i,o=void 0;return 0===r?{h:NaN,s:0,v:0}:(o=t===r?(e-n)/a:e===r?2+(n-t)/a:4+(t-e)/a,(o/=6)<0&&(o+=1),{h:360*o,s:a/r,v:r/255})},rgb_to_hex:function(t,e,n){var i=this.hex_with_component(0,2,t);return i=this.hex_with_component(i,1,e),i=this.hex_with_component(i,0,n)},component_from_hex:function(t,e){return t>>8*e&255},hex_with_component:function(t,e,n){return n<<(El=8*e)|t&~(255<-1?e.length-e.indexOf(".")-1:0}var Wl=function(t){function e(t,n,i){Ll(this,e);var r=Ol(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n)),a=i||{};return r.__min=a.min,r.__max=a.max,r.__step=a.step,_l.isUndefined(r.__step)?0===r.initialValue?r.__impliedStep=1:r.__impliedStep=Math.pow(10,Math.floor(Math.log(Math.abs(r.initialValue))/Math.LN10))/10:r.__impliedStep=r.__step,r.__precision=jl(r.__impliedStep),r}return Cl(e,t),Pl(e,[{key:"setValue",value:function(t){var n=t;return void 0!==this.__min&&nthis.__max&&(n=this.__max),void 0!==this.__step&&n%this.__step!=0&&(n=Math.round(n/this.__step)*this.__step),Rl(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"setValue",this).call(this,n)}},{key:"min",value:function(t){return this.__min=t,this}},{key:"max",value:function(t){return this.__max=t,this}},{key:"step",value:function(t){return this.__step=t,this.__impliedStep=t,this.__precision=jl(t),this}}]),e}(zl);var ql=function(t){function e(t,n,i){Ll(this,e);var r=Ol(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n,i));r.__truncationSuspended=!1;var a=r,o=void 0;function s(){a.__onFinishChange&&a.__onFinishChange.call(a,a.getValue())}function c(t){var e=o-t.clientY;a.setValue(a.getValue()+e*a.__impliedStep),o=t.clientY}function h(){kl.unbind(window,"mousemove",c),kl.unbind(window,"mouseup",h),s()}return r.__input=document.createElement("input"),r.__input.setAttribute("type","text"),kl.bind(r.__input,"change",(function(){var t=parseFloat(a.__input.value);_l.isNaN(t)||a.setValue(t)})),kl.bind(r.__input,"blur",(function(){s()})),kl.bind(r.__input,"mousedown",(function(t){kl.bind(window,"mousemove",c),kl.bind(window,"mouseup",h),o=t.clientY})),kl.bind(r.__input,"keydown",(function(t){13===t.keyCode&&(a.__truncationSuspended=!0,this.blur(),a.__truncationSuspended=!1,s())})),r.updateDisplay(),r.domElement.appendChild(r.__input),r}return Cl(e,t),Pl(e,[{key:"updateDisplay",value:function(){var t,n,i;return this.__input.value=this.__truncationSuspended?this.getValue():(t=this.getValue(),n=this.__precision,i=Math.pow(10,n),Math.round(t*i)/i),Rl(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"updateDisplay",this).call(this)}}]),e}(Wl);function Xl(t,e,n,i,r){return i+(t-e)/(n-e)*(r-i)}var Yl=function(t){function e(t,n,i,r,a){Ll(this,e);var o=Ol(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n,{min:i,max:r,step:a})),s=o;function c(t){t.preventDefault();var e=s.__background.getBoundingClientRect();return s.setValue(Xl(t.clientX,e.left,e.right,s.__min,s.__max)),!1}function h(){kl.unbind(window,"mousemove",c),kl.unbind(window,"mouseup",h),s.__onFinishChange&&s.__onFinishChange.call(s,s.getValue())}function l(t){var e=t.touches[0].clientX,n=s.__background.getBoundingClientRect();s.setValue(Xl(e,n.left,n.right,s.__min,s.__max))}function u(){kl.unbind(window,"touchmove",l),kl.unbind(window,"touchend",u),s.__onFinishChange&&s.__onFinishChange.call(s,s.getValue())}return o.__background=document.createElement("div"),o.__foreground=document.createElement("div"),kl.bind(o.__background,"mousedown",(function(t){document.activeElement.blur(),kl.bind(window,"mousemove",c),kl.bind(window,"mouseup",h),c(t)})),kl.bind(o.__background,"touchstart",(function(t){if(1!==t.touches.length)return;kl.bind(window,"touchmove",l),kl.bind(window,"touchend",u),l(t)})),kl.addClass(o.__background,"slider"),kl.addClass(o.__foreground,"slider-fg"),o.updateDisplay(),o.__background.appendChild(o.__foreground),o.domElement.appendChild(o.__background),o}return Cl(e,t),Pl(e,[{key:"updateDisplay",value:function(){var t=(this.getValue()-this.__min)/(this.__max-this.__min);return this.__foreground.style.width=100*t+"%",Rl(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"updateDisplay",this).call(this)}}]),e}(Wl),Zl=function(t){function e(t,n,i){Ll(this,e);var r=Ol(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n)),a=r;return r.__button=document.createElement("div"),r.__button.innerHTML=void 0===i?"Fire":i,kl.bind(r.__button,"click",(function(t){return t.preventDefault(),a.fire(),!1})),kl.addClass(r.__button,"button"),r.domElement.appendChild(r.__button),r}return Cl(e,t),Pl(e,[{key:"fire",value:function(){this.__onChange&&this.__onChange.call(this),this.getValue().call(this.object),this.__onFinishChange&&this.__onFinishChange.call(this,this.getValue())}}]),e}(zl),Jl=function(t){function e(t,n){Ll(this,e);var i=Ol(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,n));i.__color=new Nl(i.getValue()),i.__temp=new Nl(0);var r=i;i.domElement=document.createElement("div"),kl.makeSelectable(i.domElement,!1),i.__selector=document.createElement("div"),i.__selector.className="selector",i.__saturation_field=document.createElement("div"),i.__saturation_field.className="saturation-field",i.__field_knob=document.createElement("div"),i.__field_knob.className="field-knob",i.__field_knob_border="2px solid ",i.__hue_knob=document.createElement("div"),i.__hue_knob.className="hue-knob",i.__hue_field=document.createElement("div"),i.__hue_field.className="hue-field",i.__input=document.createElement("input"),i.__input.type="text",i.__input_textShadow="0 1px 1px ",kl.bind(i.__input,"keydown",(function(t){13===t.keyCode&&u.call(this)})),kl.bind(i.__input,"blur",u),kl.bind(i.__selector,"mousedown",(function(){kl.addClass(this,"drag").bind(window,"mouseup",(function(){kl.removeClass(r.__selector,"drag")}))})),kl.bind(i.__selector,"touchstart",(function(){kl.addClass(this,"drag").bind(window,"touchend",(function(){kl.removeClass(r.__selector,"drag")}))}));var a,o=document.createElement("div");function s(t){p(t),kl.bind(window,"mousemove",p),kl.bind(window,"touchmove",p),kl.bind(window,"mouseup",h),kl.bind(window,"touchend",h)}function c(t){f(t),kl.bind(window,"mousemove",f),kl.bind(window,"touchmove",f),kl.bind(window,"mouseup",l),kl.bind(window,"touchend",l)}function h(){kl.unbind(window,"mousemove",p),kl.unbind(window,"touchmove",p),kl.unbind(window,"mouseup",h),kl.unbind(window,"touchend",h),d()}function l(){kl.unbind(window,"mousemove",f),kl.unbind(window,"touchmove",f),kl.unbind(window,"mouseup",l),kl.unbind(window,"touchend",l),d()}function u(){var t=Sl(this.value);!1!==t?(r.__color.__state=t,r.setValue(r.__color.toOriginal())):this.value=r.__color.toString()}function d(){r.__onFinishChange&&r.__onFinishChange.call(r,r.__color.toOriginal())}function p(t){-1===t.type.indexOf("touch")&&t.preventDefault();var e=r.__saturation_field.getBoundingClientRect(),n=t.touches&&t.touches[0]||t,i=n.clientX,a=n.clientY,o=(i-e.left)/(e.right-e.left),s=1-(a-e.top)/(e.bottom-e.top);return s>1?s=1:s<0&&(s=0),o>1?o=1:o<0&&(o=0),r.__color.v=s,r.__color.s=o,r.setValue(r.__color.toOriginal()),!1}function f(t){-1===t.type.indexOf("touch")&&t.preventDefault();var e=r.__hue_field.getBoundingClientRect(),n=1-((t.touches&&t.touches[0]||t).clientY-e.top)/(e.bottom-e.top);return n>1?n=1:n<0&&(n=0),r.__color.h=360*n,r.setValue(r.__color.toOriginal()),!1}return _l.extend(i.__selector.style,{width:"122px",height:"102px",padding:"3px",backgroundColor:"#222",boxShadow:"0px 1px 3px rgba(0,0,0,0.3)"}),_l.extend(i.__field_knob.style,{position:"absolute",width:"12px",height:"12px",border:i.__field_knob_border+(i.__color.v<.5?"#fff":"#000"),boxShadow:"0px 1px 3px rgba(0,0,0,0.5)",borderRadius:"12px",zIndex:1}),_l.extend(i.__hue_knob.style,{position:"absolute",width:"15px",height:"2px",borderRight:"4px solid #fff",zIndex:1}),_l.extend(i.__saturation_field.style,{width:"100px",height:"100px",border:"1px solid #555",marginRight:"3px",display:"inline-block",cursor:"pointer"}),_l.extend(o.style,{width:"100%",height:"100%",background:"none"}),Kl(o,"top","rgba(0,0,0,0)","#000"),_l.extend(i.__hue_field.style,{width:"15px",height:"100px",border:"1px solid #555",cursor:"ns-resize",position:"absolute",top:"3px",right:"3px"}),(a=i.__hue_field).style.background="",a.style.cssText+="background: -moz-linear-gradient(top, #ff0000 0%, #ff00ff 17%, #0000ff 34%, #00ffff 50%, #00ff00 67%, #ffff00 84%, #ff0000 100%);",a.style.cssText+="background: -webkit-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);",a.style.cssText+="background: -o-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);",a.style.cssText+="background: -ms-linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);",a.style.cssText+="background: linear-gradient(top, #ff0000 0%,#ff00ff 17%,#0000ff 34%,#00ffff 50%,#00ff00 67%,#ffff00 84%,#ff0000 100%);",_l.extend(i.__input.style,{outline:"none",textAlign:"center",color:"#fff",border:0,fontWeight:"bold",textShadow:i.__input_textShadow+"rgba(0,0,0,0.7)"}),kl.bind(i.__saturation_field,"mousedown",s),kl.bind(i.__saturation_field,"touchstart",s),kl.bind(i.__field_knob,"mousedown",s),kl.bind(i.__field_knob,"touchstart",s),kl.bind(i.__hue_field,"mousedown",c),kl.bind(i.__hue_field,"touchstart",c),i.__saturation_field.appendChild(o),i.__selector.appendChild(i.__field_knob),i.__selector.appendChild(i.__saturation_field),i.__selector.appendChild(i.__hue_field),i.__hue_field.appendChild(i.__hue_knob),i.domElement.appendChild(i.__input),i.domElement.appendChild(i.__selector),i.updateDisplay(),i}return Cl(e,t),Pl(e,[{key:"updateDisplay",value:function(){var t=Sl(this.getValue());if(!1!==t){var e=!1;_l.each(Nl.COMPONENTS,(function(n){if(!_l.isUndefined(t[n])&&!_l.isUndefined(this.__color.__state[n])&&t[n]!==this.__color.__state[n])return e=!0,{}}),this),e&&_l.extend(this.__color.__state,t)}_l.extend(this.__temp.__state,this.__color.__state),this.__temp.a=1;var n=this.__color.v<.5||this.__color.s>.5?255:0,i=255-n;_l.extend(this.__field_knob.style,{marginLeft:100*this.__color.s-7+"px",marginTop:100*(1-this.__color.v)-7+"px",backgroundColor:this.__temp.toHexString(),border:this.__field_knob_border+"rgb("+n+","+n+","+n+")"}),this.__hue_knob.style.marginTop=100*(1-this.__color.h/360)+"px",this.__temp.s=1,this.__temp.v=1,Kl(this.__saturation_field,"left","#fff",this.__temp.toHexString()),this.__input.value=this.__color.toString(),_l.extend(this.__input.style,{backgroundColor:this.__color.toHexString(),color:"rgb("+n+","+n+","+n+")",textShadow:this.__input_textShadow+"rgba("+i+","+i+","+i+",.7)"})}}]),e}(zl),Ql=["-moz-","-o-","-webkit-","-ms-",""];function Kl(t,e,n,i){t.style.background="",_l.each(Ql,(function(r){t.style.cssText+="background: "+r+"linear-gradient("+e+", "+n+" 0%, "+i+" 100%); "}))}var $l=function(t,e){var n=e||document,i=document.createElement("style");i.type="text/css",i.innerHTML=t;var r=n.getElementsByTagName("head")[0];try{r.appendChild(i)}catch(t){}},tu='
\n\n Here\'s the new load parameter for your GUI\'s constructor:\n\n \n\n
\n\n Automatically save\n values to localStorage on exit.\n\n
The values saved to localStorage will\n override those passed to dat.GUI\'s constructor. This makes it\n easier to work incrementally, but localStorage is fragile,\n and your friends may not see the same values you do.\n\n
\n\n
\n\n
',eu=function(t,e){var n=t[e];return _l.isArray(arguments[2])||_l.isObject(arguments[2])?new Gl(t,e,arguments[2]):_l.isNumber(n)?_l.isNumber(arguments[2])&&_l.isNumber(arguments[3])?_l.isNumber(arguments[4])?new Yl(t,e,arguments[2],arguments[3],arguments[4]):new Yl(t,e,arguments[2],arguments[3]):_l.isNumber(arguments[4])?new ql(t,e,{min:arguments[2],max:arguments[3],step:arguments[4]}):new ql(t,e,{min:arguments[2],max:arguments[3]}):_l.isString(n)?new Vl(t,e):_l.isFunction(n)?new Zl(t,e,""):_l.isBoolean(n)?new Hl(t,e):null};var nu=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(t){setTimeout(t,1e3/60)},iu=function(){function t(){Ll(this,t),this.backgroundElement=document.createElement("div"),_l.extend(this.backgroundElement.style,{backgroundColor:"rgba(0,0,0,0.8)",top:0,left:0,display:"none",zIndex:"1000",opacity:0,WebkitTransition:"opacity 0.2s linear",transition:"opacity 0.2s linear"}),kl.makeFullscreen(this.backgroundElement),this.backgroundElement.style.position="fixed",this.domElement=document.createElement("div"),_l.extend(this.domElement.style,{position:"fixed",display:"none",zIndex:"1001",opacity:0,WebkitTransition:"-webkit-transform 0.2s ease-out, opacity 0.2s linear",transition:"transform 0.2s ease-out, opacity 0.2s linear"}),document.body.appendChild(this.backgroundElement),document.body.appendChild(this.domElement);var e=this;kl.bind(this.backgroundElement,"click",(function(){e.hide()}))}return Pl(t,[{key:"show",value:function(){var t=this;this.backgroundElement.style.display="block",this.domElement.style.display="block",this.domElement.style.opacity=0,this.domElement.style.webkitTransform="scale(1.1)",this.layout(),_l.defer((function(){t.backgroundElement.style.opacity=1,t.domElement.style.opacity=1,t.domElement.style.webkitTransform="scale(1)"}))}},{key:"hide",value:function(){var t=this,e=function e(){t.domElement.style.display="none",t.backgroundElement.style.display="none",kl.unbind(t.domElement,"webkitTransitionEnd",e),kl.unbind(t.domElement,"transitionend",e),kl.unbind(t.domElement,"oTransitionEnd",e)};kl.bind(this.domElement,"webkitTransitionEnd",e),kl.bind(this.domElement,"transitionend",e),kl.bind(this.domElement,"oTransitionEnd",e),this.backgroundElement.style.opacity=0,this.domElement.style.opacity=0,this.domElement.style.webkitTransform="scale(1.1)"}},{key:"layout",value:function(){this.domElement.style.left=window.innerWidth/2-kl.getWidth(this.domElement)/2+"px",this.domElement.style.top=window.innerHeight/2-kl.getHeight(this.domElement)/2+"px"}}]),t}();$l(function(t){if(t&&"undefined"!=typeof window){var e=document.createElement("style");return e.setAttribute("type","text/css"),e.innerHTML=t,document.head.appendChild(e),t}}(".dg ul{list-style:none;margin:0;padding:0;width:100%;clear:both}.dg.ac{position:fixed;top:0;left:0;right:0;height:0;z-index:0}.dg:not(.ac) .main{overflow:hidden}.dg.main{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear}.dg.main.taller-than-window{overflow-y:auto}.dg.main.taller-than-window .close-button{opacity:1;margin-top:-1px;border-top:1px solid #2c2c2c}.dg.main ul.closed .close-button{opacity:1 !important}.dg.main:hover .close-button,.dg.main .close-button.drag{opacity:1}.dg.main .close-button{-webkit-transition:opacity .1s linear;-o-transition:opacity .1s linear;-moz-transition:opacity .1s linear;transition:opacity .1s linear;border:0;line-height:19px;height:20px;cursor:pointer;text-align:center;background-color:#000}.dg.main .close-button.close-top{position:relative}.dg.main .close-button.close-bottom{position:absolute}.dg.main .close-button:hover{background-color:#111}.dg.a{float:right;margin-right:15px;overflow-y:visible}.dg.a.has-save>ul.close-top{margin-top:0}.dg.a.has-save>ul.close-bottom{margin-top:27px}.dg.a.has-save>ul.closed{margin-top:0}.dg.a .save-row{top:0;z-index:1002}.dg.a .save-row.close-top{position:relative}.dg.a .save-row.close-bottom{position:fixed}.dg li{-webkit-transition:height .1s ease-out;-o-transition:height .1s ease-out;-moz-transition:height .1s ease-out;transition:height .1s ease-out;-webkit-transition:overflow .1s linear;-o-transition:overflow .1s linear;-moz-transition:overflow .1s linear;transition:overflow .1s linear}.dg li:not(.folder){cursor:auto;height:27px;line-height:27px;padding:0 4px 0 5px}.dg li.folder{padding:0;border-left:4px solid rgba(0,0,0,0)}.dg li.title{cursor:pointer;margin-left:-4px}.dg .closed li:not(.title),.dg .closed ul li,.dg .closed ul li>*{height:0;overflow:hidden;border:0}.dg .cr{clear:both;padding-left:3px;height:27px;overflow:hidden}.dg .property-name{cursor:default;float:left;clear:left;width:40%;overflow:hidden;text-overflow:ellipsis}.dg .c{float:left;width:60%;position:relative}.dg .c input[type=text]{border:0;margin-top:4px;padding:3px;width:100%;float:right}.dg .has-slider input[type=text]{width:30%;margin-left:0}.dg .slider{float:left;width:66%;margin-left:-5px;margin-right:0;height:19px;margin-top:4px}.dg .slider-fg{height:100%}.dg .c input[type=checkbox]{margin-top:7px}.dg .c select{margin-top:5px}.dg .cr.function,.dg .cr.function .property-name,.dg .cr.function *,.dg .cr.boolean,.dg .cr.boolean *{cursor:pointer}.dg .cr.color{overflow:visible}.dg .selector{display:none;position:absolute;margin-left:-9px;margin-top:23px;z-index:10}.dg .c:hover .selector,.dg .selector.drag{display:block}.dg li.save-row{padding:0}.dg li.save-row .button{display:inline-block;padding:0px 6px}.dg.dialogue{background-color:#222;width:460px;padding:15px;font-size:13px;line-height:15px}#dg-new-constructor{padding:10px;color:#222;font-family:Monaco, monospace;font-size:10px;border:0;resize:none;box-shadow:inset 1px 1px 1px #888;word-wrap:break-word;margin:12px 0;display:block;width:440px;overflow-y:scroll;height:100px;position:relative}#dg-local-explain{display:none;font-size:11px;line-height:17px;border-radius:3px;background-color:#333;padding:8px;margin-top:10px}#dg-local-explain code{font-size:10px}#dat-gui-save-locally{display:none}.dg{color:#eee;font:11px 'Lucida Grande', sans-serif;text-shadow:0 -1px 0 #111}.dg.main::-webkit-scrollbar{width:5px;background:#1a1a1a}.dg.main::-webkit-scrollbar-corner{height:0;display:none}.dg.main::-webkit-scrollbar-thumb{border-radius:5px;background:#676767}.dg li:not(.folder){background:#1a1a1a;border-bottom:1px solid #2c2c2c}.dg li.save-row{line-height:25px;background:#dad5cb;border:0}.dg li.save-row select{margin-left:5px;width:108px}.dg li.save-row .button{margin-left:5px;margin-top:1px;border-radius:2px;font-size:9px;line-height:7px;padding:4px 4px 5px 4px;background:#c5bdad;color:#fff;text-shadow:0 1px 0 #b0a58f;box-shadow:0 -1px 0 #b0a58f;cursor:pointer}.dg li.save-row .button.gears{background:#c5bdad url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAANCAYAAAB/9ZQ7AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAQJJREFUeNpiYKAU/P//PwGIC/ApCABiBSAW+I8AClAcgKxQ4T9hoMAEUrxx2QSGN6+egDX+/vWT4e7N82AMYoPAx/evwWoYoSYbACX2s7KxCxzcsezDh3evFoDEBYTEEqycggWAzA9AuUSQQgeYPa9fPv6/YWm/Acx5IPb7ty/fw+QZblw67vDs8R0YHyQhgObx+yAJkBqmG5dPPDh1aPOGR/eugW0G4vlIoTIfyFcA+QekhhHJhPdQxbiAIguMBTQZrPD7108M6roWYDFQiIAAv6Aow/1bFwXgis+f2LUAynwoIaNcz8XNx3Dl7MEJUDGQpx9gtQ8YCueB+D26OECAAQDadt7e46D42QAAAABJRU5ErkJggg==) 2px 1px no-repeat;height:7px;width:8px}.dg li.save-row .button:hover{background-color:#bab19e;box-shadow:0 -1px 0 #b0a58f}.dg li.folder{border-bottom:0}.dg li.title{padding-left:16px;background:#000 url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlI+hKgFxoCgAOw==) 6px 10px no-repeat;cursor:pointer;border-bottom:1px solid rgba(255,255,255,0.2)}.dg .closed li.title{background-image:url(data:image/gif;base64,R0lGODlhBQAFAJEAAP////Pz8////////yH5BAEAAAIALAAAAAAFAAUAAAIIlGIWqMCbWAEAOw==)}.dg .cr.boolean{border-left:3px solid #806787}.dg .cr.color{border-left:3px solid}.dg .cr.function{border-left:3px solid #e61d5f}.dg .cr.number{border-left:3px solid #2FA1D6}.dg .cr.number input[type=text]{color:#2FA1D6}.dg .cr.string{border-left:3px solid #1ed36f}.dg .cr.string input[type=text]{color:#1ed36f}.dg .cr.function:hover,.dg .cr.boolean:hover{background:#111}.dg .c input[type=text]{background:#303030;outline:none}.dg .c input[type=text]:hover{background:#3c3c3c}.dg .c input[type=text]:focus{background:#494949;color:#fff}.dg .c .slider{background:#303030;cursor:ew-resize}.dg .c .slider-fg{background:#2FA1D6;max-width:100%}.dg .c .slider:hover{background:#3c3c3c}.dg .c .slider:hover .slider-fg{background:#44abda}\n"));var ru="Default",au=function(){try{return!!window.localStorage}catch(t){return!1}}(),ou=void 0,su=!0,cu=void 0,hu=!1,lu=[],uu=function t(e){var n=this,i=e||{};this.domElement=document.createElement("div"),this.__ul=document.createElement("ul"),this.domElement.appendChild(this.__ul),kl.addClass(this.domElement,"dg"),this.__folders={},this.__controllers=[],this.__rememberedObjects=[],this.__rememberedObjectIndecesToControllers=[],this.__listening=[],i=_l.defaults(i,{closeOnTop:!1,autoPlace:!0,width:t.DEFAULT_WIDTH}),i=_l.defaults(i,{resizable:i.autoPlace,hideable:i.autoPlace}),_l.isUndefined(i.load)?i.load={preset:ru}:i.preset&&(i.load.preset=i.preset),_l.isUndefined(i.parent)&&i.hideable&&lu.push(this),i.resizable=_l.isUndefined(i.parent)&&i.resizable,i.autoPlace&&_l.isUndefined(i.scrollable)&&(i.scrollable=!0);var r,a=au&&"true"===localStorage.getItem(gu(this,"isLocal")),o=void 0,s=void 0;if(Object.defineProperties(this,{parent:{get:function(){return i.parent}},scrollable:{get:function(){return i.scrollable}},autoPlace:{get:function(){return i.autoPlace}},closeOnTop:{get:function(){return i.closeOnTop}},preset:{get:function(){return n.parent?n.getRoot().preset:i.load.preset},set:function(t){n.parent?n.getRoot().preset=t:i.load.preset=t,function(t){for(var e=0;e1){var i=n.__li.nextElementSibling;return n.remove(),vu(t,n.object,n.property,{before:i,factoryArgs:[_l.toArray(arguments)]})}if(_l.isArray(e)||_l.isObject(e)){var r=n.__li.nextElementSibling;return n.remove(),vu(t,n.object,n.property,{before:r,factoryArgs:[e]})}},name:function(t){return n.__li.firstElementChild.firstElementChild.innerHTML=t,n},listen:function(){return n.__gui.listen(n),n},remove:function(){return n.__gui.remove(n),n}}),n instanceof Yl){var i=new ql(n.object,n.property,{min:n.__min,max:n.__max,step:n.__step});_l.each(["updateDisplay","onChange","onFinishChange","step","min","max"],(function(t){var e=n[t],r=i[t];n[t]=i[t]=function(){var t=Array.prototype.slice.call(arguments);return r.apply(i,t),e.apply(n,t)}})),kl.addClass(e,"has-slider"),n.domElement.insertBefore(i.domElement,n.domElement.firstElementChild)}else if(n instanceof ql){var r=function(e){if(_l.isNumber(n.__min)&&_l.isNumber(n.__max)){var i=n.__li.firstElementChild.firstElementChild.innerHTML,r=n.__gui.__listening.indexOf(n)>-1;n.remove();var a=vu(t,n.object,n.property,{before:n.__li.nextElementSibling,factoryArgs:[n.__min,n.__max,n.__step]});return a.name(i),r&&a.listen(),a}return e};n.min=_l.compose(r,n.min),n.max=_l.compose(r,n.max)}else n instanceof Hl?(kl.bind(e,"click",(function(){kl.fakeEvent(n.__checkbox,"click")})),kl.bind(n.__checkbox,"click",(function(t){t.stopPropagation()}))):n instanceof Zl?(kl.bind(e,"click",(function(){kl.fakeEvent(n.__button,"click")})),kl.bind(e,"mouseover",(function(){kl.addClass(n.__button,"hover")})),kl.bind(e,"mouseout",(function(){kl.removeClass(n.__button,"hover")}))):n instanceof Jl&&(kl.addClass(e,"color"),n.updateDisplay=_l.compose((function(t){return e.style.borderLeftColor=n.__color.toString(),t}),n.updateDisplay),n.updateDisplay());n.setValue=_l.compose((function(e){return t.getRoot().__preset_select&&n.isModified()&&fu(t.getRoot(),!0),e}),n.setValue)}(t,c,r),t.__controllers.push(r),r}function gu(t,e){return document.location.href+"."+e}function yu(t,e,n){var i=document.createElement("option");i.innerHTML=e,i.value=e,t.__preset_select.appendChild(i),n&&(t.__preset_select.selectedIndex=t.__preset_select.length-1)}function xu(t,e){e.style.display=t.useLocalStorage?"block":"none"}function _u(t){var e=t.__save_row=document.createElement("li");kl.addClass(t.domElement,"has-save"),t.__ul.insertBefore(e,t.__ul.firstChild),kl.addClass(e,"save-row");var n=document.createElement("span");n.innerHTML=" ",kl.addClass(n,"button gears");var i=document.createElement("span");i.innerHTML="Save",kl.addClass(i,"button"),kl.addClass(i,"save");var r=document.createElement("span");r.innerHTML="New",kl.addClass(r,"button"),kl.addClass(r,"save-as");var a=document.createElement("span");a.innerHTML="Revert",kl.addClass(a,"button"),kl.addClass(a,"revert");var o=t.__preset_select=document.createElement("select");if(t.load&&t.load.remembered?_l.each(t.load.remembered,(function(e,n){yu(t,n,n===t.preset)})):yu(t,ru,!1),kl.bind(o,"change",(function(){for(var e=0;e0&&(t.preset=this.preset,t.remembered||(t.remembered={}),t.remembered[this.preset]=Mu(this)),t.folders={},_l.each(this.__folders,(function(e,n){t.folders[n]=e.getSaveObject()})),t},save:function(){this.load.remembered||(this.load.remembered={}),this.load.remembered[this.preset]=Mu(this),fu(this,!1),this.saveToLocalStorageIfPossible()},saveAs:function(t){this.load.remembered||(this.load.remembered={},this.load.remembered.Default=Mu(this,!0)),this.load.remembered[t]=Mu(this),this.preset=t,yu(this,t,!0),this.saveToLocalStorageIfPossible()},revert:function(t){_l.each(this.__controllers,(function(e){this.getRoot().load.remembered?mu(t||this.getRoot(),e):e.setValue(e.initialValue),e.__onFinishChange&&e.__onFinishChange.call(e,e.getValue())}),this),_l.each(this.__folders,(function(t){t.revert(t)})),t||fu(this.getRoot(),!1)},listen:function(t){var e=0===this.__listening.length;this.__listening.push(t),e&&function t(e){0!==e.length&&nu.call(window,(function(){t(e)}));_l.each(e,(function(t){t.updateDisplay()}))}(this.__listening)},updateDisplay:function(){_l.each(this.__controllers,(function(t){t.updateDisplay()})),_l.each(this.__folders,(function(t){t.updateDisplay()}))}});var Su=uu,Eu=function(t){void 0===t&&(t="demo"),this.scene=new wt,this.id=t,this.renderer=null,this.loadingManager=new Ds,this.assets=new Map,this.scene=new wt,this.camera=null,this.ready=!1}; +/** + * three-demo v4.0.1 build Mon Aug 17 2020 + * https://github.com/vanruesc/three-demo + * Copyright 2020 Raoul van Rüschen + * @license Zlib + */Eu.prototype.setRenderer=function(t){return this.renderer=t,this},Eu.prototype.getCamera=function(){return this.camera},Eu.prototype.load=function(){return Promise.resolve()},Eu.prototype.initialize=function(){},Eu.prototype.render=function(t){this.renderer.render(this.scene,this.camera)},Eu.prototype.registerOptions=function(t){},Eu.prototype.reset=function(){return this.scene=new wt,this.camera=null,this.ready=!1,this};var Tu,Au,Lu=function(t){this.type=t,this.previousDemo=null,this.demo=null},Pu=new Lu("change"),Ru=new Lu("load"),Cu=function(t){function e(e,n){var i=n.aside;void 0===i&&(i=e);var r=n.renderer;if(t.call(this),this.renderer=r,void 0===this.renderer){var a=new Ir;a.setSize(e.clientWidth,e.clientHeight),a.setPixelRatio(window.devicePixelRatio),this.renderer=a}this.timestamp=0,this.menu=new Su({autoPlace:!1}),this.demos=new Map,this.demo=null,this.currentDemo=null,e.appendChild(this.renderer.domElement),i.appendChild(this.menu.domElement)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.resetMenu=function(){var t=this,e=this.menu.domElement.parentNode,n=new Su({autoPlace:!1});this.demos.size>1&&n.add(this,"demo",Array.from(this.demos.keys())).onChange((function(){return t.loadDemo()}));return e.removeChild(this.menu.domElement),e.appendChild(n.domElement),this.menu.destroy(),this.menu=n,n},e.prototype.startDemo=function(t){t.id===this.demo&&(t.initialize(),t.registerOptions(this.resetMenu()),t.ready=!0,Ru.demo=t,this.dispatchEvent(Ru))},e.prototype.loadDemo=function(){var t=this,e=this.demos.get(this.demo),n=this.currentDemo,i=this.renderer;window.location.hash=e.id,null!==n&&n.reset(),this.menu.domElement.style.display="none",Pu.previousDemo=n,Pu.demo=e,this.currentDemo=e,this.dispatchEvent(Pu),i.clear(),e.load().then((function(){return t.startDemo(e)})).catch(console.error)},e.prototype.addDemo=function(t){var e=window.location.hash.slice(1),n=this.currentDemo;return this.demos.set(t.id,t.setRenderer(this.renderer)),(null===this.demo&&0===e.length||t.id===e)&&(this.demo=t.id,this.loadDemo()),this.resetMenu(),null!==n&&n.ready&&n.registerOptions(this.menu),this},e.prototype.removeDemo=function(t){var e=this.demos;if(e.has(t))if(e.delete(t),this.demo===t&&e.size>0){var n=Array.from(e.entries())[0];this.demo=n[0],this.currentDemo=n[1],this.loadDemo()}else this.demo=null,this.currentDemo=null,this.renderer.clear();return this},e.prototype.setSize=function(t,e,n){void 0===n&&(n=!0);var i=this.currentDemo,r=i.getCamera();this.renderer.setSize(t,e,n),null!==i&&null!==r&&(r instanceof bc?(r.left=t/-2,r.right=t/2,r.top=e/2,r.bottom=e/-2,r.updateProjectionMatrix()):r instanceof bn&&(r.aspect=t/e,r.updateProjectionMatrix()))},e.prototype.render=function(t){var e=.001*(t-this.timestamp);this.timestamp=t;var n=this.currentDemo;null!==n&&n.ready&&n.render(e)},e}(O);!function(t){t[t.MOVE_FORWARD=0]="MOVE_FORWARD",t[t.MOVE_LEFT=1]="MOVE_LEFT",t[t.MOVE_BACKWARD=2]="MOVE_BACKWARD",t[t.MOVE_RIGHT=3]="MOVE_RIGHT",t[t.MOVE_DOWN=4]="MOVE_DOWN",t[t.MOVE_UP=5]="MOVE_UP",t[t.ZOOM_OUT=6]="ZOOM_OUT",t[t.ZOOM_IN=7]="ZOOM_IN"}(Tu||(Tu={})),function(t){t[t.MAIN=0]="MAIN",t[t.AUXILIARY=1]="AUXILIARY",t[t.SECONDARY=2]="SECONDARY"}(Au||(Au={}));var Ou=function(){this.reset()};Ou.prototype.reset=function(){return this.left=!1,this.right=!1,this.forward=!1,this.backward=!1,this.up=!1,this.down=!1,this};var Nu=2*Math.PI,Du=new Z,Iu=new it,zu=function(t,e,n,i){this.position=t,this.quaternion=e,this.target=n,this.settings=i,this.spherical=new Ph};zu.prototype.setPosition=function(t){return this.position=t,this},zu.prototype.setQuaternion=function(t){return this.quaternion=t,this},zu.prototype.setTarget=function(t){return this.target=t,this},zu.prototype.updateQuaternion=function(){var t=this.settings,e=t.rotation;return t.general.orbit?Iu.lookAt(Du.subVectors(this.position,this.target),e.pivotOffset,e.up):Iu.lookAt(Du.set(0,0,0),this.target.setFromSpherical(this.spherical),e.up),this.quaternion.setFromRotationMatrix(Iu),this},zu.prototype.adjustSpherical=function(t,e){var n=this.settings,i=n.general.orbit,r=n.rotation,a=this.spherical;return a.theta=r.invertX?a.theta+t:a.theta-t,a.phi=!i&&!r.invertY||i&&r.invertY?a.phi+e:a.phi-e,a.theta=Math.min(Math.max(a.theta,r.minAzimuthalAngle),r.maxAzimuthalAngle),a.phi=Math.min(Math.max(a.phi,r.minPolarAngle),r.maxPolarAngle),a.theta%=Nu,a.makeSafe(),i&&this.position.setFromSpherical(a).add(this.target),this},zu.prototype.zoom=function(t){var e=this.settings,n=e.general,i=e.sensitivity,r=e.zoom,a=this.spherical;if(n.orbit&&r.enabled){var o=t*i.zoom;r.invert&&(o=-o);var s=Math.max(r.minDistance,1e-6),c=Math.min(r.maxDistance,Number.POSITIVE_INFINITY);a.radius=Math.min(Math.max(a.radius+o,s),c),this.position.setFromSpherical(a).add(this.target)}return this},zu.prototype.update=function(t){},zu.prototype.lookAt=function(t){var e=this.spherical,n=this.position,i=this.target;return i.copy(t),this.settings.general.orbit?Du.subVectors(n,i):Du.subVectors(i,n).normalize(),e.setFromVector3(Du),e.radius=Math.max(e.radius,1e-6),this.updateQuaternion(),this},zu.prototype.getViewDirection=function(t){return t.setFromSpherical(this.spherical).normalize(),this.settings.general.orbit&&t.negate(),t};var Bu,Uu=new Z(1,0,0),Fu=new Z(0,1,0),ku=new Z(0,0,1),Hu=new Z,Gu=function(t,e,n,i){this.position=t,this.quaternion=e,this.target=n,this.settings=i,this.movementState=new Ou};Gu.prototype.setPosition=function(t){return this.position=t,this},Gu.prototype.setQuaternion=function(t){return this.quaternion=t,this},Gu.prototype.setTarget=function(t){return this.target=t,this},Gu.prototype.translateOnAxis=function(t,e){Hu.copy(t).applyQuaternion(this.quaternion).multiplyScalar(e),this.position.add(Hu),this.settings.general.orbit&&this.target.add(Hu)},Gu.prototype.translate=function(t){var e=this.settings.sensitivity,n=this.movementState,i=t*e.translation;n.backward?this.translateOnAxis(ku,i):n.forward&&this.translateOnAxis(ku,-i),n.right?this.translateOnAxis(Uu,i):n.left&&this.translateOnAxis(Uu,-i),n.up?this.translateOnAxis(Fu,i):n.down&&this.translateOnAxis(Fu,-i)},Gu.prototype.update=function(t){this.settings.translation.enabled&&this.translate(t)},Gu.prototype.moveTo=function(t){return this.settings.general.orbit?this.target.copy(t):this.position.copy(t),this},function(t){t[t.BACKSPACE=8]="BACKSPACE",t[t.TAB=9]="TAB",t[t.ENTER=13]="ENTER",t[t.SHIFT=16]="SHIFT",t[t.CTRL=17]="CTRL",t[t.ALT=18]="ALT",t[t.PAUSE=19]="PAUSE",t[t.CAPS_LOCK=20]="CAPS_LOCK",t[t.ESCAPE=27]="ESCAPE",t[t.SPACE=32]="SPACE",t[t.PAGE_UP=33]="PAGE_UP",t[t.PAGE_DOWN=34]="PAGE_DOWN",t[t.END=35]="END",t[t.HOME=36]="HOME",t[t.LEFT=37]="LEFT",t[t.UP=38]="UP",t[t.RIGHT=39]="RIGHT",t[t.DOWN=40]="DOWN",t[t.INSERT=45]="INSERT",t[t.DELETE=46]="DELETE",t[t.DIGIT_0=48]="DIGIT_0",t[t.DIGIT_1=49]="DIGIT_1",t[t.DIGIT_2=50]="DIGIT_2",t[t.DIGIT_3=51]="DIGIT_3",t[t.DIGIT_4=52]="DIGIT_4",t[t.DIGIT_5=53]="DIGIT_5",t[t.DIGIT_6=54]="DIGIT_6",t[t.DIGIT_7=55]="DIGIT_7",t[t.DIGIT_8=56]="DIGIT_8",t[t.DIGIT_9=57]="DIGIT_9",t[t.A=65]="A",t[t.B=66]="B",t[t.C=67]="C",t[t.D=68]="D",t[t.E=69]="E",t[t.F=70]="F",t[t.G=71]="G",t[t.H=72]="H",t[t.I=73]="I",t[t.J=74]="J",t[t.K=75]="K",t[t.L=76]="L",t[t.M=77]="M",t[t.N=78]="N",t[t.O=79]="O",t[t.P=80]="P",t[t.Q=81]="Q",t[t.R=82]="R",t[t.S=83]="S",t[t.T=84]="T",t[t.U=85]="U",t[t.V=86]="V",t[t.W=87]="W",t[t.X=88]="X",t[t.Y=89]="Y",t[t.Z=90]="Z",t[t.META_LEFT=91]="META_LEFT",t[t.META_RIGHT=92]="META_RIGHT",t[t.SELECT=93]="SELECT",t[t.NUMPAD_0=96]="NUMPAD_0",t[t.NUMPAD_1=97]="NUMPAD_1",t[t.NUMPAD_2=98]="NUMPAD_2",t[t.NUMPAD_3=99]="NUMPAD_3",t[t.NUMPAD_4=100]="NUMPAD_4",t[t.NUMPAD_5=101]="NUMPAD_5",t[t.NUMPAD_6=102]="NUMPAD_6",t[t.NUMPAD_7=103]="NUMPAD_7",t[t.NUMPAD_8=104]="NUMPAD_8",t[t.NUMPAD_9=105]="NUMPAD_9",t[t.MULTIPLY=106]="MULTIPLY",t[t.ADD=107]="ADD",t[t.SUBTRACT=109]="SUBTRACT",t[t.DECIMAL_POINT=110]="DECIMAL_POINT",t[t.DIVIDE=111]="DIVIDE",t[t.F1=112]="F1",t[t.F2=113]="F2",t[t.F3=114]="F3",t[t.F4=115]="F4",t[t.F5=116]="F5",t[t.F6=117]="F6",t[t.F7=118]="F7",t[t.F8=119]="F8",t[t.F9=120]="F9",t[t.F10=121]="F10",t[t.F11=122]="F11",t[t.F12=123]="F12",t[t.NUM_LOCK=144]="NUM_LOCK",t[t.SCROLL_LOCK=145]="SCROLL_LOCK",t[t.SEMICOLON=186]="SEMICOLON",t[t.EQUAL_SIGN=187]="EQUAL_SIGN",t[t.COMMA=188]="COMMA",t[t.DASH=189]="DASH",t[t.PERIOD=190]="PERIOD",t[t.FORWARD_SLASH=191]="FORWARD_SLASH",t[t.GRAVE_ACCENT=192]="GRAVE_ACCENT",t[t.OPEN_BRACKET=219]="OPEN_BRACKET",t[t.BACK_SLASH=220]="BACK_SLASH",t[t.CLOSE_BRACKET=221]="CLOSE_BRACKET",t[t.SINGLE_QUOTE=222]="SINGLE_QUOTE"}(Bu||(Bu={}));var Vu=function(){this.orbit=!0};Vu.prototype.copy=function(t){return this.orbit=t.orbit,this},Vu.prototype.clone=function(){var t=new Vu;return t.copy(this)};var ju=function(){this.defaultActions=new Map,this.actions=new Map};ju.prototype.reset=function(){return this.actions=new Map(this.defaultActions),this},ju.prototype.setDefault=function(t){return this.defaultActions=t,this.reset()},ju.prototype.copy=function(t){return this.defaultActions=new Map(t.defaultActions),this.actions=new Map(t.actions),this},ju.prototype.clearDefault=function(){return this.defaultActions.clear(),this},ju.prototype.clear=function(){return this.actions.clear(),this},ju.prototype.clone=function(){var t=new ju;return t.copy(this)},ju.prototype.has=function(t){return this.actions.has(t)},ju.prototype.get=function(t){return this.actions.get(t)},ju.prototype.set=function(t,e){return this.actions.set(t,e),this},ju.prototype.delete=function(t){return this.actions.delete(t)},ju.prototype.toJSON=function(){return{defaultActions:[].concat(this.defaultActions),actions:[].concat(this.actions)}};var Wu=function(){this.hold=!1,this.lock=!0};Wu.prototype.copy=function(t){return this.hold=t.hold,this.lock=t.lock,this},Wu.prototype.clone=function(){var t=new Wu;return t.copy(this)};var qu=function(){this.up=new Z,this.up.copy(Fu),this.pivotOffset=new Z,this.minAzimuthalAngle=Number.NEGATIVE_INFINITY,this.maxAzimuthalAngle=Number.POSITIVE_INFINITY,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.invertX=!1,this.invertY=!1};qu.prototype.copy=function(t){return this.up.copy(t.up),this.pivotOffset.copy(t.pivotOffset),this.minAzimuthalAngle=t.minAzimuthalAngle,this.maxAzimuthalAngle=t.maxAzimuthalAngle,this.minPolarAngle=t.minPolarAngle,this.maxPolarAngle=t.maxPolarAngle,this.invertX=t.invertX,this.invertY=t.invertY,this},qu.prototype.clone=function(){var t=new qu;return t.copy(this)};var Xu=function(){this.rotationX=1,this.rotationY=1,this.translation=1,this.zoom=1},Yu={rotation:{configurable:!0}};Yu.rotation.set=function(t){this.rotationX=this.rotationY=t},Xu.prototype.copy=function(t){return this.rotationX=t.rotationX,this.rotationY=t.rotationY,this.translation=t.translation,this.zoom=t.zoom,this},Xu.prototype.clone=function(){var t=new Xu;return t.copy(this)},Object.defineProperties(Xu.prototype,Yu);var Zu=function(){this.enabled=!0};Zu.prototype.copy=function(t){return this.enabled=t.enabled,this},Zu.prototype.clone=function(){var t=new Zu;return t.copy(this)};var Ju=function(){this.enabled=!0,this.invert=!1,this.minDistance=1e-6,this.maxDistance=1/0};Ju.prototype.copy=function(t){return this.enabled=t.enabled,this.invert=t.invert,this.minDistance=t.minDistance,this.maxDistance=t.maxDistance,this},Ju.prototype.clone=function(){var t=new Ju;return t.copy(this)};var Qu=function(){this.general=new Vu,this.keyBindings=new ju,this.keyBindings.setDefault(new Map([[Bu.W,Tu.MOVE_FORWARD],[Bu.UP,Tu.MOVE_FORWARD],[Bu.A,Tu.MOVE_LEFT],[Bu.LEFT,Tu.MOVE_LEFT],[Bu.S,Tu.MOVE_BACKWARD],[Bu.DOWN,Tu.MOVE_BACKWARD],[Bu.D,Tu.MOVE_RIGHT],[Bu.RIGHT,Tu.MOVE_RIGHT],[Bu.X,Tu.MOVE_DOWN],[Bu.SPACE,Tu.MOVE_UP],[Bu.PAGE_DOWN,Tu.ZOOM_OUT],[Bu.PAGE_UP,Tu.ZOOM_IN]])),this.pointer=new Wu,this.rotation=new qu,this.sensitivity=new Xu,this.translation=new Zu,this.zoom=new Ju};Qu.prototype.copy=function(t){return this.general.copy(t.general),this.keyBindings.copy(t.keyBindings),this.pointer.copy(t.pointer),this.rotation.copy(t.rotation),this.sensitivity.copy(t.sensitivity),this.translation.copy(t.translation),this.zoom.copy(t.zoom),this},Qu.prototype.clone=function(){var t=new Qu;return t.copy(this)},Qu.prototype.toDataURL=function(){return URL.createObjectURL(new Blob([JSON.stringify(this)],{type:"text/json"}))};var Ku,$u=function(t,e){this.movementState=t,this.direction=e};$u.prototype.execute=function(t){var e=this.movementState;switch(this.direction){case Ku.FORWARD:e.forward=t;break;case Ku.LEFT:e.left=t;break;case Ku.BACKWARD:e.backward=t;break;case Ku.RIGHT:e.right=t;break;case Ku.DOWN:e.down=t;break;case Ku.UP:e.up=t}},function(t){t[t.FORWARD=0]="FORWARD",t[t.LEFT=1]="LEFT",t[t.BACKWARD=2]="BACKWARD",t[t.RIGHT=3]="RIGHT",t[t.DOWN=4]="DOWN",t[t.UP=5]="UP"}(Ku||(Ku={}));var td=function(t,e){this.rotationManager=t,this.zoomIn=e};td.prototype.execute=function(t){t&&this.rotationManager.zoom(this.zoomIn?-1:1)};var ed=function(t,e,n){void 0===t&&(t=null),void 0===e&&(e=null),void 0===n&&(n=document.body),this.domElement=n,this.position=t,this.quaternion=e,this.target=new Z,this.settings=new Qu,this.rotationManager=new zu(t,e,this.target,this.settings),this.translationManager=new Gu(t,e,this.target,this.settings);var i=this.translationManager.movementState;this.strategies=new Map([[Tu.MOVE_FORWARD,new $u(i,Ku.FORWARD)],[Tu.MOVE_LEFT,new $u(i,Ku.LEFT)],[Tu.MOVE_BACKWARD,new $u(i,Ku.BACKWARD)],[Tu.MOVE_RIGHT,new $u(i,Ku.RIGHT)],[Tu.MOVE_DOWN,new $u(i,Ku.DOWN)],[Tu.MOVE_UP,new $u(i,Ku.UP)],[Tu.ZOOM_OUT,new td(this.rotationManager,!1)],[Tu.ZOOM_IN,new td(this.rotationManager,!0)]]),this.lastScreenPosition=new U,this.dragging=!1,this.enabled=!1,null!==t&&null!==e&&(this.lookAt(this.target),null!==n&&this.setEnabled())};ed.prototype.getDomElement=function(){return this.domElement},ed.prototype.setDomElement=function(t){var e=this.enabled;return null!==t&&(e&&this.setEnabled(!1),this.domElement=t,this.setEnabled(e)),this},ed.prototype.getPosition=function(){return this.position},ed.prototype.setPosition=function(t){return this.position=t,this.rotationManager.setPosition(t),this.translationManager.setPosition(t),this.lookAt(this.target)},ed.prototype.getQuaternion=function(){return this.quaternion},ed.prototype.setQuaternion=function(t){return this.quaternion=t,this.rotationManager.setQuaternion(t),this.translationManager.setQuaternion(t),this.lookAt(this.target)},ed.prototype.getTarget=function(t){return t.copy(this.target),this.settings.general.orbit||t.add(this.position),t},ed.prototype.setTarget=function(t){return this.target=t,this.rotationManager.setTarget(t),this.translationManager.setTarget(t),this.lookAt(this.target)},ed.prototype.getViewDirection=function(t){return this.rotationManager.getViewDirection(t)},ed.prototype.setOrbitEnabled=function(t){var e=this.settings.general;return e.orbit!==t&&(this.getTarget(this.target),e.orbit=t,this.lookAt(this.target)),this},ed.prototype.copy=function(t){return this.domElement=t.getDomElement(),this.position=t.getPosition(),this.quaternion=t.getQuaternion(),this.target=t.getTarget(new Z),this.settings.copy(t.settings),this.rotationManager.setPosition(this.position).setQuaternion(this.quaternion).setTarget(this.target),this.translationManager.setPosition(this.position).setQuaternion(this.quaternion).setTarget(this.target),this.lookAt(this.target)},ed.prototype.clone=function(){var t=new ed;return t.copy(this)},ed.prototype.handlePointerMoveEvent=function(t){var e=this.settings,n=e.pointer,i=e.sensitivity,r=this.rotationManager,a=this.lastScreenPosition;if(document.pointerLockElement===this.domElement)n.hold&&!this.dragging||r.adjustSpherical(.001*t.movementX*i.rotationX,.001*t.movementY*i.rotationY).updateQuaternion();else{var o=t.screenX-a.x,s=t.screenY-a.y;a.set(t.screenX,t.screenY),r.adjustSpherical(.001*o*i.rotationX,.001*s*i.rotationY).updateQuaternion()}},ed.prototype.handleTouchMoveEvent=function(t){var e=this.settings.sensitivity,n=this.rotationManager,i=this.lastScreenPosition,r=t.touches[0],a=r.screenX-i.x,o=r.screenY-i.y;i.set(r.screenX,r.screenY),t.preventDefault(),n.adjustSpherical(.001*a*e.rotationX,.001*o*e.rotationY).updateQuaternion()},ed.prototype.handleMainPointerButton=function(t,e){this.dragging=e,this.settings.pointer.lock?this.setPointerLocked():e?(this.lastScreenPosition.set(t.screenX,t.screenY),this.domElement.addEventListener("mousemove",this)):this.domElement.removeEventListener("mousemove",this)},ed.prototype.handleAuxiliaryPointerButton=function(t,e){},ed.prototype.handleSecondaryPointerButton=function(t,e){},ed.prototype.handlePointerButtonEvent=function(t,e){switch(t.preventDefault(),t.button){case Au.MAIN:this.handleMainPointerButton(t,e);break;case Au.AUXILIARY:this.handleAuxiliaryPointerButton(t,e);break;case Au.SECONDARY:this.handleSecondaryPointerButton(t,e)}},ed.prototype.handleTouchEvent=function(t,e){var n=t.touches[0];t.preventDefault(),e?(this.lastScreenPosition.set(n.screenX,n.screenY),this.domElement.addEventListener("touchmove",this)):this.domElement.removeEventListener("touchmove",this)},ed.prototype.handleKeyboardEvent=function(t,e){var n=this.settings.keyBindings;n.has(t.keyCode)&&(t.preventDefault(),this.strategies.get(n.get(t.keyCode)).execute(e))},ed.prototype.handleWheelEvent=function(t){this.rotationManager.zoom(Math.sign(t.deltaY))},ed.prototype.handlePointerLockEvent=function(){document.pointerLockElement===this.domElement?this.domElement.addEventListener("mousemove",this):this.domElement.removeEventListener("mousemove",this)},ed.prototype.handleEvent=function(t){switch(t.type){case"mousemove":this.handlePointerMoveEvent(t);break;case"touchmove":this.handleTouchMoveEvent(t);break;case"mousedown":this.handlePointerButtonEvent(t,!0);break;case"mouseup":this.handlePointerButtonEvent(t,!1);break;case"touchstart":this.handleTouchEvent(t,!0);break;case"touchend":this.handleTouchEvent(t,!1);break;case"keydown":this.handleKeyboardEvent(t,!0);break;case"keyup":this.handleKeyboardEvent(t,!1);break;case"wheel":this.handleWheelEvent(t);break;case"pointerlockchange":this.handlePointerLockEvent()}},ed.prototype.update=function(t){this.rotationManager.update(t),this.translationManager.update(t)},ed.prototype.moveTo=function(t){return this.translationManager.moveTo(t),this},ed.prototype.lookAt=function(t){return this.rotationManager.lookAt(t),this},ed.prototype.setPointerLocked=function(t){void 0===t&&(t=!0),t?document.pointerLockElement!==this.domElement&&void 0!==this.domElement.requestPointerLock&&this.domElement.requestPointerLock():void 0!==document.exitPointerLock&&document.exitPointerLock()},ed.prototype.setEnabled=function(t){void 0===t&&(t=!0);var e=this.domElement;return this.translationManager.movementState.reset(),t&&!this.enabled?(document.addEventListener("pointerlockchange",this),document.body.addEventListener("keyup",this),document.body.addEventListener("keydown",this),e.addEventListener("mousedown",this),e.addEventListener("mouseup",this),e.addEventListener("touchstart",this),e.addEventListener("touchend",this),e.addEventListener("wheel",this)):!t&&this.enabled&&(document.removeEventListener("pointerlockchange",this),document.body.removeEventListener("keyup",this),document.body.removeEventListener("keydown",this),e.removeEventListener("mousedown",this),e.removeEventListener("mouseup",this),e.removeEventListener("touchstart",this),e.removeEventListener("touchend",this),e.removeEventListener("wheel",this),e.removeEventListener("mousemove",this),e.removeEventListener("touchmove",this)),this.setPointerLocked(!1),this.enabled=t,this},ed.prototype.dispose=function(){this.setEnabled(!1)}; +/** + * octree-helper v1.1.6 build Sun Jun 28 2020 + * https://github.com/vanruesc/octree-helper + * Copyright 2020 Raoul van Rüschen + * @license Zlib + */ +/** + * sparse-octree v6.0.2 build Sat Jan 18 2020 + * https://github.com/vanruesc/sparse-octree + * Copyright 2020 Raoul van Rüschen + * @license Zlib + */ +var nd=[new Uint8Array([0,4]),new Uint8Array([1,5]),new Uint8Array([2,6]),new Uint8Array([3,7]),new Uint8Array([0,2]),new Uint8Array([1,3]),new Uint8Array([4,6]),new Uint8Array([5,7]),new Uint8Array([0,1]),new Uint8Array([2,3]),new Uint8Array([4,5]),new Uint8Array([6,7])],id=[new Uint8Array([0,0,0]),new Uint8Array([0,0,1]),new Uint8Array([0,1,0]),new Uint8Array([0,1,1]),new Uint8Array([1,0,0]),new Uint8Array([1,0,1]),new Uint8Array([1,1,0]),new Uint8Array([1,1,1])],rd=function(t){function e(e){void 0===e&&(e=null),t.call(this),this.name="OctreeHelper",this.octree=e,this.update()}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.createLineSegments=function(e,n){var i,r,a,o,s,c,h,l,u,d,p,f,m,v,g,y,x=Math.pow(2,16)/8-1,_=new t,b=new wa({color:16777215*Math.random()});for(d=0,a=0,v=Math.ceil(n/x);v>0;--v){for(a+=n0;)t.remove(e[0])}for(;o.length>0;)this.remove(o[0])},e}(Cr),ad=[new Uint8Array([0,0,0]),new Uint8Array([0,0,1]),new Uint8Array([0,1,0]),new Uint8Array([0,1,1]),new Uint8Array([1,0,0]),new Uint8Array([1,0,1]),new Uint8Array([1,1,0]),new Uint8Array([1,1,1])],od=function(t,e,n){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),this.x=t,this.y=e,this.z=n};od.prototype.set=function(t,e,n){return this.x=t,this.y=e,this.z=n,this},od.prototype.random=function(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this},od.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},od.prototype.clone=function(){return new this.constructor(this.x,this.y,this.z)},od.prototype.fromArray=function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this.z=t[e+2],this},od.prototype.toArray=function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t},od.prototype.setFromSpherical=function(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)},od.prototype.setFromSphericalCoords=function(t,e,n){var i=Math.sin(e)*t;return this.x=i*Math.sin(n),this.y=Math.cos(e)*t,this.z=i*Math.cos(n),this},od.prototype.setFromCylindrical=function(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)},od.prototype.setFromCylindricalCoords=function(t,e,n){return this.x=t*Math.sin(e),this.y=n,this.z=t*Math.cos(e),this},od.prototype.setFromMatrix3Column=function(t,e){return this.fromArray(t.elements,3*e)},od.prototype.setFromMatrixColumn=function(t,e){return this.fromArray(t.elements,4*e)},od.prototype.setFromMatrixPosition=function(t){var e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this},od.prototype.setFromMatrixScale=function(t){var e=this.setFromMatrixColumn(t,0).length(),n=this.setFromMatrixColumn(t,1).length(),i=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=n,this.z=i,this},od.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this},od.prototype.addScalar=function(t){return this.x+=t,this.y+=t,this.z+=t,this},od.prototype.addVectors=function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this},od.prototype.addScaledVector=function(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this},od.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this},od.prototype.subScalar=function(t){return this.x-=t,this.y-=t,this.z-=t,this},od.prototype.subVectors=function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this},od.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this},od.prototype.multiplyScalar=function(t){return this.x*=t,this.y*=t,this.z*=t,this},od.prototype.multiplyVectors=function(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this},od.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this},od.prototype.divideScalar=function(t){return this.x/=t,this.y/=t,this.z/=t,this},od.prototype.crossVectors=function(t,e){var n=t.x,i=t.y,r=t.z,a=e.x,o=e.y,s=e.z;return this.x=i*s-r*o,this.y=r*a-n*s,this.z=n*o-i*a,this},od.prototype.cross=function(t){return this.crossVectors(this,t)},od.prototype.transformDirection=function(t){var e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i,this.y=r[1]*e+r[5]*n+r[9]*i,this.z=r[2]*e+r[6]*n+r[10]*i,this.normalize()},od.prototype.applyMatrix3=function(t){var e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[3]*n+r[6]*i,this.y=r[1]*e+r[4]*n+r[7]*i,this.z=r[2]*e+r[5]*n+r[8]*i,this},od.prototype.applyNormalMatrix=function(t){return this.applyMatrix3(t).normalize()},od.prototype.applyMatrix4=function(t){var e=this.x,n=this.y,i=this.z,r=t.elements;return this.x=r[0]*e+r[4]*n+r[8]*i+r[12],this.y=r[1]*e+r[5]*n+r[9]*i+r[13],this.z=r[2]*e+r[6]*n+r[10]*i+r[14],this},od.prototype.applyQuaternion=function(t){var e=this.x,n=this.y,i=this.z,r=t.x,a=t.y,o=t.z,s=t.w,c=s*e+a*i-o*n,h=s*n+o*e-r*i,l=s*i+r*n-a*e,u=-r*e-a*n-o*i;return this.x=c*s+u*-r+h*-o-l*-a,this.y=h*s+u*-a+l*-r-c*-o,this.z=l*s+u*-o+c*-a-h*-r,this},od.prototype.negate=function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},od.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z},od.prototype.reflect=function(t){var e=t.x,n=t.y,i=t.z;return this.sub(t.multiplyScalar(2*this.dot(t))),t.set(e,n,i),this},od.prototype.angleTo=function(t){var e=Math.sqrt(this.lengthSquared()*t.lengthSquared());return 0===e?.5*Math.PI:Math.acos(Math.min(Math.max(this.dot(t)/e,-1),1))},od.prototype.manhattanLength=function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},od.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z},od.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},od.prototype.manhattanDistanceTo=function(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)},od.prototype.distanceToSquared=function(t){var e=this.x-t.x,n=this.y-t.y,i=this.z-t.z;return e*e+n*n+i*i},od.prototype.distanceTo=function(t){return Math.sqrt(this.distanceToSquared(t))},od.prototype.normalize=function(){return this.divideScalar(this.length())},od.prototype.setLength=function(t){return this.normalize().multiplyScalar(t)},od.prototype.min=function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this},od.prototype.max=function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this},od.prototype.clamp=function(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this},od.prototype.floor=function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this},od.prototype.ceil=function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this},od.prototype.round=function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this},od.prototype.lerp=function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this},od.prototype.lerpVectors=function(t,e,n){return this.subVectors(e,t).multiplyScalar(n).add(t)},od.prototype.equals=function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z};var sd=new od,cd=[new od,new od,new od,new od,new od,new od,new od,new od],hd=function(t,e){void 0===t&&(t=new od(1/0,1/0,1/0)),void 0===e&&(e=new od(-1/0,-1/0,-1/0)),this.min=t,this.max=e};hd.prototype.set=function(t,e){return this.min.copy(t),this.max.copy(e),this},hd.prototype.copy=function(t){return this.min.copy(t.min),this.max.copy(t.max),this},hd.prototype.clone=function(){return(new this.constructor).copy(this)},hd.prototype.makeEmpty=function(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this},hd.prototype.isEmpty=function(){return this.max.x=e.x&&t.y>=e.y&&t.z>=e.z&&t.x<=n.x&&t.y<=n.y&&t.z<=n.z},hd.prototype.containsBox=function(t){var e=this.min,n=this.max,i=t.min,r=t.max;return e.x<=i.x&&r.x<=n.x&&e.y<=i.y&&r.y<=n.y&&e.z<=i.z&&r.z<=n.z},hd.prototype.intersectsBox=function(t){var e=this.min,n=this.max,i=t.min,r=t.max;return r.x>=e.x&&r.y>=e.y&&r.z>=e.z&&i.x<=n.x&&i.y<=n.y&&i.z<=n.z},hd.prototype.intersectsSphere=function(t){return this.clampPoint(t.center,sd).distanceToSquared(t.center)<=t.radius*t.radius},hd.prototype.intersectsPlane=function(t){var e,n;return t.normal.x>0?(e=t.normal.x*this.min.x,n=t.normal.x*this.max.x):(e=t.normal.x*this.max.x,n=t.normal.x*this.min.x),t.normal.y>0?(e+=t.normal.y*this.min.y,n+=t.normal.y*this.max.y):(e+=t.normal.y*this.max.y,n+=t.normal.y*this.min.y),t.normal.z>0?(e+=t.normal.z*this.min.z,n+=t.normal.z*this.max.z):(e+=t.normal.z*this.max.z,n+=t.normal.z*this.min.z),e<=-t.constant&&n>=-t.constant},hd.prototype.equals=function(t){return t.min.equals(this.min)&&t.max.equals(this.max)};new hd,new od;var ld=function(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.x=t,this.y=e},ud={width:{configurable:!0},height:{configurable:!0}};ud.width.get=function(){return this.x},ud.width.set=function(t){return this.x=t},ud.height.get=function(){return this.y},ud.height.set=function(t){return this.y=t},ld.prototype.set=function(t,e){return this.x=t,this.y=e,this},ld.prototype.random=function(){return this.x=Math.random(),this.y=Math.random(),this},ld.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this},ld.prototype.clone=function(){return new this.constructor(this.x,this.y)},ld.prototype.fromArray=function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this},ld.prototype.toArray=function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t},ld.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},ld.prototype.addScalar=function(t){return this.x+=t,this.y+=t,this},ld.prototype.addVectors=function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this},ld.prototype.addScaledVector=function(t,e){return this.x+=t.x*e,this.y+=t.y*e,this},ld.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this},ld.prototype.subScalar=function(t){return this.x-=t,this.y-=t,this},ld.prototype.subVectors=function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this},ld.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},ld.prototype.multiplyScalar=function(t){return this.x*=t,this.y*=t,this},ld.prototype.divide=function(t){return this.x/=t.x,this.y/=t.y,this},ld.prototype.divideScalar=function(t){return this.x/=t,this.y/=t,this},ld.prototype.applyMatrix3=function(t){var e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this},ld.prototype.dot=function(t){return this.x*t.x+this.y*t.y},ld.prototype.cross=function(t){return this.x*t.y-this.y*t.x},ld.prototype.manhattanLength=function(){return Math.abs(this.x)+Math.abs(this.y)},ld.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y},ld.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},ld.prototype.manhattanDistanceTo=function(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)},ld.prototype.distanceToSquared=function(t){var e=this.x-t.x,n=this.y-t.y;return e*e+n*n},ld.prototype.distanceTo=function(t){return Math.sqrt(this.distanceToSquared(t))},ld.prototype.normalize=function(){return this.divideScalar(this.length())},ld.prototype.setLength=function(t){return this.normalize().multiplyScalar(t)},ld.prototype.min=function(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this},ld.prototype.max=function(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this},ld.prototype.clamp=function(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this},ld.prototype.floor=function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ld.prototype.ceil=function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},ld.prototype.round=function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},ld.prototype.negate=function(){return this.x=-this.x,this.y=-this.y,this},ld.prototype.angle=function(){return Math.atan2(-this.y,-this.x)+Math.PI},ld.prototype.lerp=function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this},ld.prototype.lerpVectors=function(t,e,n){return this.subVectors(e,t).multiplyScalar(n).add(t)},ld.prototype.rotateAround=function(t,e){var n=Math.cos(e),i=Math.sin(e),r=this.x-t.x,a=this.y-t.y;return this.x=r*n-a*i+t.x,this.y=r*i+a*n+t.y,this},ld.prototype.equals=function(t){return t.x===this.x&&t.y===this.y},Object.defineProperties(ld.prototype,ud);new ld;var dd=function(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1])};dd.prototype.set=function(t,e,n,i,r,a,o,s,c){var h=this.elements;return h[0]=t,h[3]=e,h[6]=n,h[1]=i,h[4]=r,h[7]=a,h[2]=o,h[5]=s,h[8]=c,this},dd.prototype.identity=function(){return this.set(1,0,0,0,1,0,0,0,1),this},dd.prototype.copy=function(t){var e=t.elements,n=this.elements;return n[0]=e[0],n[1]=e[1],n[2]=e[2],n[3]=e[3],n[4]=e[4],n[5]=e[5],n[6]=e[6],n[7]=e[7],n[8]=e[8],this},dd.prototype.clone=function(){return(new this.constructor).fromArray(this.elements)},dd.prototype.fromArray=function(t,e){void 0===e&&(e=0);var n,i=this.elements;for(n=0;n<9;++n)i[n]=t[n+e];return this},dd.prototype.toArray=function(t,e){void 0===t&&(t=[]),void 0===e&&(e=0);var n,i=this.elements;for(n=0;n<9;++n)t[n+e]=i[n];return t},dd.prototype.multiplyMatrices=function(t,e){var n=t.elements,i=e.elements,r=this.elements,a=n[0],o=n[3],s=n[6],c=n[1],h=n[4],l=n[7],u=n[2],d=n[5],p=n[8],f=i[0],m=i[3],v=i[6],g=i[1],y=i[4],x=i[7],_=i[2],b=i[5],w=i[8];return r[0]=a*f+o*g+s*_,r[3]=a*m+o*y+s*b,r[6]=a*v+o*x+s*w,r[1]=c*f+h*g+l*_,r[4]=c*m+h*y+l*b,r[7]=c*v+h*x+l*w,r[2]=u*f+d*g+p*_,r[5]=u*m+d*y+p*b,r[8]=u*v+d*x+p*w,this},dd.prototype.multiply=function(t){return this.multiplyMatrices(this,t)},dd.prototype.premultiply=function(t){return this.multiplyMatrices(t,this)},dd.prototype.multiplyScalar=function(t){var e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this},dd.prototype.determinant=function(){var t=this.elements,e=t[0],n=t[1],i=t[2],r=t[3],a=t[4],o=t[5],s=t[6],c=t[7],h=t[8];return e*a*h-e*o*c-n*r*h+n*o*s+i*r*c-i*a*s},dd.prototype.getInverse=function(t){var e,n=t.elements,i=this.elements,r=n[0],a=n[1],o=n[2],s=n[3],c=n[4],h=n[5],l=n[6],u=n[7],d=n[8],p=d*c-h*u,f=h*l-d*s,m=u*s-c*l,v=r*p+a*f+o*m;return 0!==v?(e=1/v,i[0]=p*e,i[1]=(o*u-d*a)*e,i[2]=(h*a-o*c)*e,i[3]=f*e,i[4]=(d*r-o*l)*e,i[5]=(o*s-h*r)*e,i[6]=m*e,i[7]=(a*l-u*r)*e,i[8]=(c*r-a*s)*e):this.set(0,0,0,0,0,0,0,0,0),this},dd.prototype.transpose=function(){var t,e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this},dd.prototype.scale=function(t,e){var n=this.elements;return n[0]*=t,n[3]*=t,n[6]*=t,n[1]*=e,n[4]*=e,n[7]*=e,this},dd.prototype.rotate=function(t){var e=Math.cos(t),n=Math.sin(t),i=this.elements,r=i[0],a=i[3],o=i[6],s=i[1],c=i[4],h=i[7];return i[0]=e*r+n*s,i[3]=e*a+n*c,i[6]=e*o+n*h,i[1]=-n*r+e*s,i[4]=-n*a+e*c,i[7]=-n*o+e*h,this},dd.prototype.translate=function(t,e){var n=this.elements;return n[0]+=t*n[2],n[3]+=t*n[5],n[6]+=t*n[8],n[1]+=e*n[2],n[4]+=e*n[5],n[7]+=e*n[8],this},dd.prototype.equals=function(t){var e,n=this.elements,i=t.elements,r=!0;for(e=0;r&&e<9;++e)n[e]!==i[e]&&(r=!1);return r};var pd="XYZ",fd="YZX",md="ZXY",vd="XZY",gd="YXZ",yd="ZYX",xd=function(t,e,n,i){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),this.x=t,this.y=e,this.z=n,this.w=i};function _d(t,e,n){return Math.max(Math.min(t,n),e)}xd.prototype.set=function(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.w=i,this},xd.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},xd.prototype.clone=function(){return new this.constructor(this.x,this.y,this.z,this.w)},xd.prototype.fromArray=function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this},xd.prototype.toArray=function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t},xd.prototype.setFromEuler=function(t){var e=t.x,n=t.y,i=t.z,r=Math.cos,a=Math.sin,o=r(e/2),s=r(n/2),c=r(i/2),h=a(e/2),l=a(n/2),u=a(i/2);switch(t.order){case pd:this.x=h*s*c+o*l*u,this.y=o*l*c-h*s*u,this.z=o*s*u+h*l*c,this.w=o*s*c-h*l*u;break;case gd:this.x=h*s*c+o*l*u,this.y=o*l*c-h*s*u,this.z=o*s*u-h*l*c,this.w=o*s*c+h*l*u;break;case md:this.x=h*s*c-o*l*u,this.y=o*l*c+h*s*u,this.z=o*s*u+h*l*c,this.w=o*s*c-h*l*u;break;case yd:this.x=h*s*c-o*l*u,this.y=o*l*c+h*s*u,this.z=o*s*u-h*l*c,this.w=o*s*c+h*l*u;break;case fd:this.x=h*s*c+o*l*u,this.y=o*l*c+h*s*u,this.z=o*s*u-h*l*c,this.w=o*s*c-h*l*u;break;case vd:this.x=h*s*c-o*l*u,this.y=o*l*c-h*s*u,this.z=o*s*u+h*l*c,this.w=o*s*c+h*l*u}return this},xd.prototype.setFromAxisAngle=function(t,e){var n=e/2,i=Math.sin(n);return this.x=t.x*i,this.y=t.y*i,this.z=t.z*i,this.w=Math.cos(n),this},xd.prototype.setFromRotationMatrix=function(t){var e,n=t.elements,i=n[0],r=n[4],a=n[8],o=n[1],s=n[5],c=n[9],h=n[2],l=n[6],u=n[10],d=i+s+u;return d>0?(e=.5/Math.sqrt(d+1),this.w=.25/e,this.x=(l-c)*e,this.y=(a-h)*e,this.z=(o-r)*e):i>s&&i>u?(e=2*Math.sqrt(1+i-s-u),this.w=(l-c)/e,this.x=.25*e,this.y=(r+o)/e,this.z=(a+h)/e):s>u?(e=2*Math.sqrt(1+s-i-u),this.w=(a-h)/e,this.x=(r+o)/e,this.y=.25*e,this.z=(c+l)/e):(e=2*Math.sqrt(1+u-i-s),this.w=(o-r)/e,this.x=(a+h)/e,this.y=(c+l)/e,this.z=.25*e),this},xd.prototype.setFromUnitVectors=function(t,e){var n=t.dot(e)+1;return n<1e-6?(n=0,Math.abs(t.x)>Math.abs(t.z)?(this.x=-t.y,this.y=t.x,this.z=0,this.w=n):(this.x=0,this.y=-t.z,this.z=t.y,this.w=n)):(this.x=t.y*e.z-t.z*e.y,this.y=t.z*e.x-t.x*e.z,this.z=t.x*e.y-t.y*e.x,this.w=n),this.normalize()},xd.prototype.angleTo=function(t){return 2*Math.acos(Math.abs(Math.min(Math.max(this.dot(t),-1),1)))},xd.prototype.rotateTowards=function(t,e){var n=this.angleTo(t);return 0!==n&&this.slerp(t,Math.min(1,e/n)),this},xd.prototype.invert=function(){return this.conjugate()},xd.prototype.conjugate=function(){return this.x*=-1,this.y*=-1,this.z*=-1,this},xd.prototype.lengthSquared=function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},xd.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},xd.prototype.normalize=function(){var t,e=this.length();return 0===e?(this.x=0,this.y=0,this.z=0,this.w=1):(t=1/e,this.x=this.x*t,this.y=this.y*t,this.z=this.z*t,this.w=this.w*t),this},xd.prototype.dot=function(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w},xd.prototype.multiplyQuaternions=function(t,e){var n=t.x,i=t.y,r=t.z,a=t.w,o=e.x,s=e.y,c=e.z,h=e.w;return this.x=n*h+a*o+i*c-r*s,this.y=i*h+a*s+r*o-n*c,this.z=r*h+a*c+n*s-i*o,this.w=a*h-n*o-i*s-r*c,this},xd.prototype.multiply=function(t){return this.multiplyQuaternions(this,t)},xd.prototype.premultiply=function(t){return this.multiplyQuaternions(t,this)},xd.prototype.slerp=function(t,e){var n,i,r,a,o,s,c,h=this.x,l=this.y,u=this.z,d=this.w;return 1===e?this.copy(t):e>0&&((n=d*t.w+h*t.x+l*t.y+u*t.z)<0?(this.w=-t.w,this.x=-t.x,this.y=-t.y,this.z=-t.z,n=-n):this.copy(t),n>=1?(this.w=d,this.x=h,this.y=l,this.z=u):(o=1-e,(i=1-n*n)<=Number.EPSILON?(this.w=o*d+e*this.w,this.x=o*h+e*this.x,this.y=o*l+e*this.y,this.z=o*u+e*this.z,this.normalize()):(r=Math.sqrt(i),a=Math.atan2(r,n),s=Math.sin(o*a)/r,c=Math.sin(e*a)/r,this.w=d*s+this.w*c,this.x=h*s+this.x*c,this.y=l*s+this.y*c,this.z=u*s+this.z*c))),this},xd.prototype.equals=function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w},xd.slerp=function(t,e,n,i){return n.copy(t).slerp(e,i)},xd.slerpFlat=function(t,e,n,i,r,a,o){var s,c,h,l,u,d,p,f,m=r[a],v=r[a+1],g=r[a+2],y=r[a+3],x=n[i],_=n[i+1],b=n[i+2],w=n[i+3];w===y&&x===m&&_===v&&b===g||(s=1-o,d=(l=x*m+_*v+b*g+w*y)>=0?1:-1,(u=1-l*l)>Number.EPSILON&&(h=Math.sqrt(u),p=Math.atan2(h,l*d),s=Math.sin(s*p)/h,o=Math.sin(o*p)/h),x=x*s+m*(f=o*d),_=_*s+v*f,b=b*s+g*f,w=w*s+y*f,s===1-o&&(x*=c=1/Math.sqrt(x*x+_*_+b*b+w*w),_*=c,b*=c,w*=c)),t[e]=x,t[e+1]=_,t[e+2]=b,t[e+3]=w};var bd=new dd,wd=new xd,Md=function t(e,n,i){void 0===e&&(e=0),void 0===n&&(n=0),void 0===i&&(i=0),this.x=e,this.y=n,this.z=i,this.order=t.defaultOrder},Sd={defaultOrder:{configurable:!0}};Md.prototype.set=function(t,e,n,i){return this.x=t,this.y=e,this.z=n,this.order=i,this},Md.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.order=t.order,this},Md.prototype.clone=function(){return new this.constructor(this.x,this.y,this.z,this.order)},Md.prototype.fromArray=function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.order=t[e+3],this},Md.prototype.toArray=function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.order,t},Md.prototype.toVector3=function(t){return void 0===t&&(t=new od),t.set(this.x,this.y,this.z)},Md.prototype.setFromRotationMatrix=function(t,e){void 0===e&&(e=this.order);var n=t.elements,i=n[0],r=n[4],a=n[8],o=n[1],s=n[5],c=n[9],h=n[2],l=n[6],u=n[10],d=1-1e-7;switch(e){case pd:this.y=Math.asin(_d(a,-1,1)),Math.abs(a)=0?e.copy(this.direction).multiplyScalar(n).add(this.origin):e.copy(this.origin)},Td.prototype.distanceSquaredToPoint=function(t){var e=Ed[0].subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceToSquared(t):Ed[0].copy(this.direction).multiplyScalar(e).add(this.origin).distanceToSquared(t)},Td.prototype.distanceToPoint=function(t){return Math.sqrt(this.distanceSquaredToPoint(t))},Td.prototype.distanceToPlane=function(t){var e=t.normal.dot(this.direction),n=0!==e?-(this.origin.dot(t.normal)+t.constant)/e:0===t.distanceToPoint(this.origin)?0:-1;return n>=0?n:null},Td.prototype.distanceSquaredToSegment=function(t,e,n,i){var r,a,o,s,c,h=Ed[0].copy(t).add(e).multiplyScalar(.5),l=Ed[1].copy(e).sub(t).normalize(),u=Ed[2].copy(this.origin).sub(h),d=.5*t.distanceTo(e),p=-this.direction.dot(l),f=u.dot(this.direction),m=-u.dot(l),v=u.lengthSq(),g=Math.abs(1-p*p);return g>0?(a=p*f-m,o=d*g,(r=p*m-f)>=0?a>=-o?a<=o?c=(r*=s=1/g)*(r+p*(a*=s)+2*f)+a*(p*r+a+2*m)+v:(a=d,c=-(r=Math.max(0,-(p*a+f)))*r+a*(a+2*m)+v):(a=-d,c=-(r=Math.max(0,-(p*a+f)))*r+a*(a+2*m)+v):a<=-o?c=-(r=Math.max(0,-(-p*d+f)))*r+(a=r>0?-d:Math.min(Math.max(-d,-m),d))*(a+2*m)+v:a<=o?(r=0,c=(a=Math.min(Math.max(-d,-m),d))*(a+2*m)+v):c=-(r=Math.max(0,-(p*d+f)))*r+(a=r>0?d:Math.min(Math.max(-d,-m),d))*(a+2*m)+v):(a=p>0?-d:d,c=-(r=Math.max(0,-(p*a+f)))*r+a*(a+2*m)+v),void 0!==n&&n.copy(this.direction).multiplyScalar(r).add(this.origin),void 0!==i&&i.copy(l).multiplyScalar(a).add(h),c},Td.prototype.intersectSphere=function(t,e){void 0===e&&(e=new od);var n,i,r,a=Ed[0].subVectors(t.center,this.origin),o=a.dot(this.direction),s=a.dot(a)-o*o,c=t.radius*t.radius,h=null;return s<=c&&(r=o+(n=Math.sqrt(c-s)),((i=o-n)>=0||r>=0)&&(h=i<0?this.at(r,e):this.at(i,e))),h},Td.prototype.intersectsSphere=function(t){return this.distanceSqToPoint(t.center)<=t.radius*t.radius},Td.prototype.intersectPlane=function(t,e){void 0===e&&(e=new od);var n=this.distanceToPlane(t);return null===n?null:this.at(n,e)},Td.prototype.intersectsPlane=function(t){var e=t.distanceToPoint(this.origin);return 0===e||t.normal.dot(this.direction)*e<0},Td.prototype.intersectBox=function(t,e){void 0===e&&(e=new od);var n,i,r,a,o,s,c=this.origin,h=this.direction,l=t.min,u=t.max,d=1/h.x,p=1/h.y,f=1/h.z,m=null;return d>=0?(n=(l.x-c.x)*d,i=(u.x-c.x)*d):(n=(u.x-c.x)*d,i=(l.x-c.x)*d),p>=0?(r=(l.y-c.y)*p,a=(u.y-c.y)*p):(r=(u.y-c.y)*p,a=(l.y-c.y)*p),n<=a&&r<=i&&((r>n||n!=n)&&(n=r),(a=0?(o=(l.z-c.z)*f,s=(u.z-c.z)*f):(o=(u.z-c.z)*f,s=(l.z-c.z)*f),n<=s&&o<=i&&((o>n||n!=n)&&(n=o),(s=0&&(m=this.at(n>=0?n:i,e)))),m},Td.prototype.intersectsBox=function(t){return null!==this.intersectBox(t,Ed[0])},Td.prototype.intersectTriangle=function(t,e,n,i,r){var a,o,s,c,h,l=this.direction,u=Ed[0],d=Ed[1],p=Ed[2],f=Ed[3],m=null;return d.subVectors(e,t),p.subVectors(n,t),f.crossVectors(d,p),0===(a=l.dot(f))||i&&a>0||(a>0?o=1:(o=-1,a=-a),u.subVectors(this.origin,t),(s=o*l.dot(p.crossVectors(u,p)))>=0&&(c=o*l.dot(d.cross(u)))>=0&&s+c<=a&&(h=-o*u.dot(f))>=0&&(m=this.at(h/a,r))),m},Td.prototype.applyMatrix4=function(t){return this.origin.applyMatrix4(t),this.direction.transformDirection(t),this},Td.prototype.equals=function(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)};var Ad=new od,Ld=function(t,e){void 0===t&&(t=new od),void 0===e&&(e=new od),this.min=t,this.max=e,this.children=null};Ld.prototype.getCenter=function(t){return t.addVectors(this.min,this.max).multiplyScalar(.5)},Ld.prototype.getDimensions=function(t){return t.subVectors(this.max,this.min)},Ld.prototype.split=function(){var t,e,n=this.min,i=this.max,r=this.getCenter(Ad),a=this.children=[null,null,null,null,null,null,null,null];for(t=0;t<8;++t)e=ad[t],a[t]=new this.constructor(new od(0===e[0]?n.x:r.x,0===e[1]?n.y:r.y,0===e[2]?n.z:r.z),new od(0===e[0]?r.x:i.x,0===e[1]?r.y:i.y,0===e[2]?r.z:i.z))};var Pd=function(t,e,n,i){void 0===i&&(i=null),this.distance=t,this.distanceToRay=e,this.point=n,this.object=i};var Rd=[new Uint8Array([4,2,1]),new Uint8Array([5,3,8]),new Uint8Array([6,8,3]),new Uint8Array([7,8,8]),new Uint8Array([8,6,5]),new Uint8Array([8,7,8]),new Uint8Array([8,8,7]),new Uint8Array([8,8,8])];function Cd(t,e,n,i){var r,a=0;return e=0&&a>=0&&o>=0){var c=t.children;if(null===c)s.push(t);else{var h=.5*(e+r),l=.5*(n+a),u=.5*(i+o),d=zd.value,p=function(t,e,n,i,r,a){var o=0;return t>e&&t>n?(rn?(i=0;)if(t=a[c]++,e=o[c].children,t<8)if(null!==e){if(n=e[t],i&&(kd.min=n.min,kd.max=n.max,!r.intersectsBox(kd)))continue;o.push(n),a.push(0),++c}else s=o.pop(),a.pop();else o.pop(),a.pop(),--c;return this.result.value=s,this.result.done=null===s,this.result},Hd.prototype.return=function(t){return this.result.value=t,this.result.done=!0,this.result},Hd.prototype[Symbol.iterator]=function(){return this};var Gd=new hd;var Vd=function(t){this.root=t},jd={min:{configurable:!0},max:{configurable:!0},children:{configurable:!0}};jd.min.get=function(){return this.root.min},jd.max.get=function(){return this.root.max},jd.children.get=function(){return this.root.children},Vd.prototype.getCenter=function(t){return this.root.getCenter(t)},Vd.prototype.getDimensions=function(t){return this.root.getDimensions(t)},Vd.prototype.cull=function(t){var e=[];return function t(e,n,i){var r,a,o=e.children;if(Gd.min=e.min,Gd.max=e.max,n.intersectsBox(Gd))if(null!==o)for(r=0,a=o.length;ro&&(o=r);return o}(this.root)},Vd.prototype.findNodesByLevel=function(t){var e=[];return function t(e,n,i,r){var a,o,s=e.children;if(i===n)r.push(e);else if(null!==s)for(++i,a=0,o=s.length;a=n.x-e&&t.y>=n.y-e&&t.z>=n.z-e&&t.x<=i.x+e&&t.y<=i.y+e&&t.z<=i.z+e},e.prototype.redistribute=function(t){var e,n,i,r,a,o,s,c=this.children,h=this.points,l=this.data;if(null!==c&&null!==h){for(e=0,i=h.length;e=0&&(s={point:p[f],data:r.data[f],distance:c})}return s}(t,e,n,this.root);return null!==i&&(i.point=i.point.clone()),i},e.prototype.findPoints=function(t,e,n){void 0===n&&(n=!1);var i=[];return function t(e,n,i,r,a){var o,s,c,h=r.children;if(null!==h)for(o=0,s=h.length;o0&&function(t,e,n){var i,r,a,o,s,c,h,l,u,d,p,f=e.params.Points.threshold,m=f*f;for(s=0,h=t.length;s=e.near&&r<=e.far&&(a=Math.sqrt(o),n.push(new Pd(r,a,i,u.data[c]))))}(i,e,n),n},e}(Vd),Qd=new U,Kd=function(t){function e(e,n,i){t.call(this),this.params.Points.threshold=.1,this.octree=e,this.camera=n,this.object=i,this.enabled=!0,this.delta="",this.selectedObject=null,this.selectedPoint=new on(new Wo(.2,16,16),new xe({transparent:!0,color:52479,opacity:.75})),this.selectedPoint.visible=!1}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.handleEvent=function(t){switch(t.type){case"mousemove":this.raycast(t)}},e.prototype.raycast=function(t){var e,n,i,r;Qd.x=t.clientX/window.innerWidth*2-1,Qd.y=-t.clientY/window.innerHeight*2+1,this.setFromCamera(Qd,this.camera),this.enabled?(n=performance.now(),e=this.octree.raycast(this),i=performance.now()):(n=performance.now(),e=this.intersectObjects(this.object.children),i=performance.now()),this.delta=(i-n).toFixed(2)+" ms",null!==this.selectedObject&&(this.selectedObject.material.color.setHex(12582912),this.selectedObject=null,this.selectedPoint.visible=!1),e.length>0&&(void 0!==(r=e[0]).object?(this.selectedObject=r.object,this.selectedObject.material.color.setHex(13434624),this.selectedPoint.visible=r.object.parent.visible,this.selectedPoint.position.copy(r.point)):console.warn(e))},e.prototype.registerOptions=function(t){var e=t.addFolder("Raycasting");e.add(this,"enabled"),e.add(this,"delta").listen(),e.open()},e}(Th),$d=new it,tp=new Ln,ep=function(t,e){this.octree=t,this.scene=e,this.enabled=!1,this.cullCamera=new bn(20,1.77,.5,5),this.s=new Ph(5,Math.PI/3,1.75*Math.PI),this.delta="",this.culledOctants=new Ua(new He,new Na({color:13434624,sizeAttenuation:!1,size:2})),this.culledOctants.visible=!1,this.cameraHelper=new el(this.cullCamera),this.cameraHelper.visible=!1};ep.prototype.updateCamera=function(){var t=this.cullCamera;t.position.setFromSpherical(this.s),t.lookAt(this.scene.position),t.updateMatrixWorld(!0),tp.setFromProjectionMatrix($d.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse))},ep.prototype.cull=function(){var t,e,n,i,r,a,o,s=this.culledOctants;if(this.enabled)if(this.updateCamera(),t=performance.now(),a=this.octree.cull(tp),this.delta=(performance.now()-t).toFixed(2)+" ms",a.length>0){for(o=new Float32Array(3*a.length*2),e=0,n=0,i=a.length;e0;)e=new Ua(t(65536,6,a,.25),o),o=o.clone(),a+=r,n.add(e);return n}();this.points=r,t.add(r);var a=function(e){var n=new Z,i=new zt;i.setFromObject(t);for(var r=performance.now(),a=new Jd(i.min,i.max,0,8,5),o=e.children.length-1;o>=0;--o)for(var s=e.children[o],c=s.geometry.getAttribute("position").array,h=0,l=c.length;hPeer dependencies

A sparse, pointer-based octree data structure. For a linear implementation see linear-octree.

Demo · Sandbox · Documentation

-

Installation

This library requires the peer dependencies iterator-result and math-ds.

-
npm install iterator-result math-ds
-
-
npm install sparse-octree
+

Installation

This library requires the peer dependencies math-ds.

+
npm install math-ds sparse-octree
 

Usage

Points
import { Vector3 } from "math-ds";
 import { PointOctree } from "sparse-octree";
diff --git a/public/docs/index.json b/public/docs/index.json
index 1055aaa..3204f6b 100644
--- a/public/docs/index.json
+++ b/public/docs/index.json
@@ -4396,7 +4396,7 @@
   },
   {
     "kind": "index",
-    "content": "# Sparse Octree\r\n\r\n[![Build status](https://travis-ci.org/vanruesc/sparse-octree.svg?branch=master)](https://travis-ci.org/vanruesc/sparse-octree)\r\n[![npm version](https://badgen.net/npm/v/sparse-octree?color=green)](https://www.npmjs.com/package/sparse-octree)\r\n[![Peer dependencies](https://david-dm.org/vanruesc/sparse-octree/peer-status.svg)](https://david-dm.org/vanruesc/sparse-octree?type=peer)\r\n\r\nA sparse, pointer-based octree data structure. For a linear implementation see [linear-octree](https://github.com/vanruesc/linear-octree).\r\n\r\n*[Demo](https://vanruesc.github.io/sparse-octree/public/demo) · [Sandbox](https://codesandbox.io/s/sparse-octree-3yn8o) · [Documentation](https://vanruesc.github.io/sparse-octree/public/docs)*\r\n\r\n\r\n## Installation\r\n\r\nThis library requires the peer dependencies [iterator-result](https://github.com/vanruesc/iterator-result) and [math-ds](https://github.com/vanruesc/math-ds).\r\n\r\n```sh\r\nnpm install iterator-result math-ds\r\n``` \r\n\r\n```sh\r\nnpm install sparse-octree\r\n``` \r\n\r\n\r\n## Usage\r\n\r\n##### Points\r\n\r\n```js\r\nimport { Vector3 } from \"math-ds\";\r\nimport { PointOctree } from \"sparse-octree\";\r\n\r\nconst min = new Vector3(-1, -1, -1);\r\nconst max = new Vector3(1, 1, 1);\r\n\r\nconst octree = new PointOctree(min, max);\r\n\r\nconst myData = {};\r\nconst p1 = new Vector3(0, 0, 0);\r\nconst p2 = new Vector3(0, 0, 0.5);\r\n\r\noctree.insert(p1, myData);\r\noctree.move(p1, p2);\r\noctree.get(p2); // => myData\r\n\r\noctree.remove(p2);\r\noctree.get(p2); // => null\r\n```\r\n\r\n##### Custom Octrees\r\n\r\n```js\r\nimport { Octree, CubicOctant } from \"sparse-octree\";\r\n\r\nexport class CubicOctree extends Octree {\r\n\r\n\tconstructor(min, size) {\r\n\r\n\t\tthis.root = new CubicOctant(min, size);\r\n\r\n\t}\r\n\r\n}\r\n```\r\n\r\n\r\n## Features\r\n\r\n- Pointer-based structure\r\n  - Handles octant splitting\r\n  - Supports cubic octrees for reduced memory usage\r\n  - Dynamic depth\r\n- Adheres to a [common octant layout](https://vanruesc.github.io/sparse-octree/public/docs/variable/index.html#static-variable-layout)\r\n- Supports raycasting\r\n- Supports culling\r\n- Can be extended to manage any data\r\n- Provides a point management implementation\r\n\r\n\r\n## Octree Helper\r\n\r\nThe [octree-helper](https://github.com/vanruesc/octree-helper) module provides an octree visualization tool for [three.js](https://threejs.org/).\r\n\r\n\r\n## Contributing\r\n\r\nMaintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.\r\n",
+    "content": "# Sparse Octree\r\n\r\n[![Build status](https://travis-ci.org/vanruesc/sparse-octree.svg?branch=master)](https://travis-ci.org/vanruesc/sparse-octree)\r\n[![npm version](https://badgen.net/npm/v/sparse-octree?color=green)](https://www.npmjs.com/package/sparse-octree)\r\n[![Peer dependencies](https://david-dm.org/vanruesc/sparse-octree/peer-status.svg)](https://david-dm.org/vanruesc/sparse-octree?type=peer)\r\n\r\nA sparse, pointer-based octree data structure. For a linear implementation see [linear-octree](https://github.com/vanruesc/linear-octree).\r\n\r\n*[Demo](https://vanruesc.github.io/sparse-octree/public/demo) · [Sandbox](https://codesandbox.io/s/sparse-octree-3yn8o) · [Documentation](https://vanruesc.github.io/sparse-octree/public/docs)*\r\n\r\n\r\n## Installation\r\n\r\nThis library requires the peer dependencies [math-ds](https://github.com/vanruesc/math-ds).\r\n\r\n```sh\r\nnpm install math-ds sparse-octree\r\n``` \r\n\r\n\r\n## Usage\r\n\r\n##### Points\r\n\r\n```js\r\nimport { Vector3 } from \"math-ds\";\r\nimport { PointOctree } from \"sparse-octree\";\r\n\r\nconst min = new Vector3(-1, -1, -1);\r\nconst max = new Vector3(1, 1, 1);\r\n\r\nconst octree = new PointOctree(min, max);\r\n\r\nconst myData = {};\r\nconst p1 = new Vector3(0, 0, 0);\r\nconst p2 = new Vector3(0, 0, 0.5);\r\n\r\noctree.insert(p1, myData);\r\noctree.move(p1, p2);\r\noctree.get(p2); // => myData\r\n\r\noctree.remove(p2);\r\noctree.get(p2); // => null\r\n```\r\n\r\n##### Custom Octrees\r\n\r\n```js\r\nimport { Octree, CubicOctant } from \"sparse-octree\";\r\n\r\nexport class CubicOctree extends Octree {\r\n\r\n\tconstructor(min, size) {\r\n\r\n\t\tthis.root = new CubicOctant(min, size);\r\n\r\n\t}\r\n\r\n}\r\n```\r\n\r\n\r\n## Features\r\n\r\n- Pointer-based structure\r\n  - Handles octant splitting\r\n  - Supports cubic octrees for reduced memory usage\r\n  - Dynamic depth\r\n- Adheres to a [common octant layout](https://vanruesc.github.io/sparse-octree/public/docs/variable/index.html#static-variable-layout)\r\n- Supports raycasting\r\n- Supports culling\r\n- Can be extended to manage any data\r\n- Provides a point management implementation\r\n\r\n\r\n## Octree Helper\r\n\r\nThe [octree-helper](https://github.com/vanruesc/octree-helper) module provides an octree visualization tool for [three.js](https://threejs.org/).\r\n\r\n\r\n## Contributing\r\n\r\nMaintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.\r\n",
     "longname": "D:\\Sourcecode\\JavaScript\\sparse-octree\\README.md",
     "name": "./README.md",
     "static": true,
@@ -4404,7 +4404,7 @@
   },
   {
     "kind": "packageJSON",
-    "content": "{\r\n\t\"name\": \"sparse-octree\",\r\n\t\"version\": \"6.0.2\",\r\n\t\"description\": \"A sparse octree data structure.\",\r\n\t\"homepage\": \"https://github.com/vanruesc/sparse-octree\",\r\n\t\"main\": \"build/sparse-octree.js\",\r\n\t\"module\": \"build/sparse-octree.esm.js\",\r\n\t\"sideEffects\": false,\r\n\t\"license\": \"Zlib\",\r\n\r\n\t\"keywords\": [\r\n\t\t\"partition\",\r\n\t\t\"hierarchy\",\r\n\t\t\"subdivision\",\r\n\t\t\"raycasting\",\r\n\t\t\"3d\",\r\n\t\t\"spatial\",\r\n\t\t\"voxel\",\r\n\t\t\"points\",\r\n\t\t\"frustum\",\r\n\t\t\"culling\",\r\n\t\t\"pointer\"\r\n\t],\r\n\r\n\t\"author\": {\r\n\t\t\"name\": \"Raoul van Rüschen\",\r\n\t\t\"email\": \"vanruesc@outlook.de\"\r\n\t},\r\n\r\n\t\"repository\": {\r\n\t\t\"type\": \"git\",\r\n\t\t\"url\": \"https://github.com/vanruesc/sparse-octree.git\"\r\n\t},\r\n\r\n\t\"bugs\": {\r\n\t\t\"url\": \"https://github.com/vanruesc/sparse-octree/issues\"\r\n\t},\r\n\r\n\t\"files\": [\"build\"],\r\n\r\n\t\"scripts\": {\r\n\t\t\"ava\": \"ava\",\r\n\t\t\"lint\": \"npm run lint:lib && npm run lint:demo && npm run lint:test\",\r\n\t\t\"lint:config\": \"eslint *.js\",\r\n\t\t\"lint:lib\": \"eslint src\",\r\n\t\t\"lint:demo\": \"eslint demo/src\",\r\n\t\t\"lint:test\": \"eslint test\",\r\n\t\t\"build\": \"rollup -c\",\r\n\t\t\"build:production\": \"cross-env NODE_ENV=production npm run build\",\r\n\t\t\"watch\": \"rollup -c --watch\",\r\n\t\t\"doc\": \"rimraf public/docs && esdoc\",\r\n\t\t\"pretest\": \"npm run lint && npm run build:production\",\r\n\t\t\"test\": \"npm run ava\",\r\n\t\t\"prepack\": \"npm test && npm run doc\"\r\n\t},\r\n\r\n\t\"ava\": {\r\n\t\t\"failFast\": true,\r\n\t\t\"files\": [\"test/**/*.js\"]\r\n\t},\r\n\r\n\t\"eslintConfig\": {\r\n\t\t\"extends\": \"delta\"\r\n\t},\r\n\r\n\t\"peerDependencies\": {\r\n\t\t\"iterator-result\": \">= 0.0.0 < 2.0.0\",\r\n\t\t\"math-ds\": \">= 1.0.0 < 2.0.0\"\r\n\t},\r\n\r\n\t\"devDependencies\": {\r\n\t\t\"@babel/core\": \"7.x.x\",\r\n\t\t\"@babel/preset-env\": \"7.x.x\",\r\n\t\t\"@rollup/plugin-node-resolve\": \"7.x.x\",\r\n\t\t\"ava\": \"2.x.x\",\r\n\t\t\"cross-env\": \"6.x.x\",\r\n\t\t\"dat.gui\": \"0.x.x\",\r\n\t\t\"delta-controls\": \"2.x.x\",\r\n\t\t\"esdoc\": \"1.x.x\",\r\n\t\t\"esdoc-importpath-plugin\": \"1.x.x\",\r\n\t\t\"esdoc-standard-plugin\": \"1.x.x\",\r\n\t\t\"eslint\": \"6.x.x\",\r\n\t\t\"eslint-config-delta\": \"1.x.x\",\r\n\t\t\"iterator-result\": \"1.x.x\",\r\n\t\t\"math-ds\": \"1.x.x\",\r\n\t\t\"rimraf\": \"3.x.x\",\r\n\t\t\"octree-helper\": \"1.x.x\",\r\n\t\t\"rollup\": \"1.x.x\",\r\n\t\t\"rollup-plugin-babel\": \"4.x.x\",\r\n\t\t\"rollup-plugin-terser\": \"5.x.x\",\r\n\t\t\"synthetic-event\": \"1.x.x\",\r\n\t\t\"three\": \"0.x.x\",\r\n\t\t\"three-demo\": \"3.x.x\"\r\n\t}\r\n}\r\n",
+    "content": "{\r\n\t\"name\": \"sparse-octree\",\r\n\t\"version\": \"6.1.0\",\r\n\t\"description\": \"A sparse octree data structure.\",\r\n\t\"homepage\": \"https://github.com/vanruesc/sparse-octree\",\r\n\t\"main\": \"build/sparse-octree.js\",\r\n\t\"module\": \"build/sparse-octree.esm.js\",\r\n\t\"exports\": {\r\n\t\t\".\": \"./build/sparse-octree.esm.js\"\r\n\t},\r\n\t\"sideEffects\": false,\r\n\t\"license\": \"Zlib\",\r\n\t\"keywords\": [\r\n\t\t\"partition\",\r\n\t\t\"hierarchy\",\r\n\t\t\"subdivision\",\r\n\t\t\"raycasting\",\r\n\t\t\"3d\",\r\n\t\t\"spatial\",\r\n\t\t\"voxel\",\r\n\t\t\"points\",\r\n\t\t\"frustum\",\r\n\t\t\"culling\",\r\n\t\t\"pointer\"\r\n\t],\r\n\t\"author\": {\r\n\t\t\"name\": \"Raoul van Rüschen\",\r\n\t\t\"email\": \"vanruesc@outlook.de\"\r\n\t},\r\n\t\"repository\": {\r\n\t\t\"type\": \"git\",\r\n\t\t\"url\": \"https://github.com/vanruesc/sparse-octree.git\"\r\n\t},\r\n\t\"bugs\": {\r\n\t\t\"url\": \"https://github.com/vanruesc/sparse-octree/issues\"\r\n\t},\r\n\t\"files\": [\r\n\t\t\"build\"\r\n\t],\r\n\t\"scripts\": {\r\n\t\t\"ava\": \"ava\",\r\n\t\t\"build\": \"rollup -c\",\r\n\t\t\"build:production\": \"cross-env NODE_ENV=production rollup -c\",\r\n\t\t\"watch\": \"rollup -c -w\",\r\n\t\t\"dev\": \"concurrently -k -n server,rollup,eslint \\\"hs -s\\\" \\\"rollup -c -w\\\" \\\"esw -w src demo/src\\\"\",\r\n\t\t\"doc\": \"rimraf public/docs && esdoc\",\r\n\t\t\"lint\": \"eslint src demo/src\",\r\n\t\t\"prepack\": \"npm test && npm run doc\",\r\n\t\t\"pretest\": \"rimraf build && npm run build:production\",\r\n\t\t\"test\": \"ava\"\r\n\t},\r\n\t\"ava\": {\r\n\t\t\"failFast\": true,\r\n\t\t\"files\": [\r\n\t\t\t\"test/**/*.js\"\r\n\t\t],\r\n\t\t\"require\": [\r\n\t\t\t\"esm\"\r\n\t\t]\r\n\t},\r\n\t\"eslintConfig\": {\r\n\t\t\"extends\": \"aether\"\r\n\t},\r\n\t\"dependencies\": {\r\n\t\t\"iterator-result\": \"1.x.x\"\r\n\t},\r\n\t\"peerDependencies\": {\r\n\t\t\"math-ds\": \">= 1.0.0 < 2.0.0\"\r\n\t},\r\n\t\"devDependencies\": {\r\n\t\t\"@rollup/plugin-buble\": \"0.x.x\",\r\n\t\t\"@rollup/plugin-node-resolve\": \"9.x.x\",\r\n\t\t\"ava\": \"3.x.x\",\r\n\t\t\"concurrently\": \"5.x.x\",\r\n\t\t\"cross-env\": \"7.x.x\",\r\n\t\t\"dat.gui\": \"0.x.x\",\r\n\t\t\"esdoc\": \"1.x.x\",\r\n\t\t\"esdoc-importpath-plugin\": \"1.x.x\",\r\n\t\t\"esdoc-standard-plugin\": \"1.x.x\",\r\n\t\t\"eslint\": \"7.x.x\",\r\n\t\t\"eslint-config-aether\": \"1.x.x\",\r\n\t\t\"eslint-watch\": \"7.x.x\",\r\n\t\t\"esm\": \"3.x.x\",\r\n\t\t\"http-server\": \"0.x.x\",\r\n\t\t\"math-ds\": \"1.x.x\",\r\n\t\t\"octree-helper\": \"1.x.x\",\r\n\t\t\"rimraf\": \"3.x.x\",\r\n\t\t\"rollup\": \"2.x.x\",\r\n\t\t\"rollup-plugin-terser\": \"7.x.x\",\r\n\t\t\"spatial-controls\": \"3.x.x\",\r\n\t\t\"three\": \"0.x.x\",\r\n\t\t\"three-demo\": \"4.x.x\"\r\n\t}\r\n}\r\n",
     "longname": "D:\\Sourcecode\\JavaScript\\sparse-octree\\package.json",
     "name": "package.json",
     "static": true,