diff --git a/.gitignore b/.gitignore index b4800aa..f422166 100644 --- a/.gitignore +++ b/.gitignore @@ -103,7 +103,7 @@ typings/ ## Custom ### .DS_Store -lib/ +# lib/ docs/ demo/release demo/_data/version.yml diff --git a/lib/CSSCamera.js b/lib/CSSCamera.js new file mode 100644 index 0000000..0f9fe14 --- /dev/null +++ b/lib/CSSCamera.js @@ -0,0 +1,264 @@ +import * as tslib_1 from "tslib"; +import { mat4, vec3, quat } from 'gl-matrix'; +import { getElement, applyCSS, getTransformMatrix, findIndex, getOffsetFromParent, getRotateOffset, assign } from './utils/helper'; +import { quatToEuler } from './utils/math'; +import * as DEFAULT from './constants/default'; +var CSSCamera = (function () { + function CSSCamera(el, options) { + if (options === void 0) { options = {}; } + this._element = getElement(el); + var op = assign(assign({}, DEFAULT.OPTIONS), options); + this._position = vec3.fromValues(op.position[0], op.position[1], op.position[2]); + this._scale = vec3.fromValues(op.scale[0], op.scale[1], op.scale[2]); + this._rotation = vec3.fromValues(op.rotation[0], op.rotation[1], op.rotation[2]); + this._perspective = op.perspective; + this._rotateOffset = op.rotateOffset; + this._updateTimer = -1; + var element = this._element; + var viewport = document.createElement('div'); + var camera = viewport.cloneNode(); + var world = viewport.cloneNode(); + viewport.className = DEFAULT.CLASS.VIEWPORT; + camera.className = DEFAULT.CLASS.CAMERA; + world.className = DEFAULT.CLASS.WORLD; + applyCSS(viewport, DEFAULT.STYLE.VIEWPORT); + applyCSS(camera, DEFAULT.STYLE.CAMERA); + applyCSS(world, DEFAULT.STYLE.WORLD); + camera.appendChild(world); + viewport.appendChild(camera); + this._viewportEl = viewport; + this._cameraEl = camera; + this._worldEl = world; + element.parentElement.insertBefore(viewport, element); + world.appendChild(element); + this.update(0); + } + Object.defineProperty(CSSCamera, "VERSION", { + get: function () { return '#__VERSION__#'; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "element", { + get: function () { return this._element; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "viewportEl", { + get: function () { return this._viewportEl; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "cameraEl", { + get: function () { return this._cameraEl; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "worldEl", { + get: function () { return this._worldEl; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "position", { + get: function () { return tslib_1.__spread(this._position); }, + set: function (val) { this._position = vec3.fromValues(val[0], val[1], val[2]); }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "scale", { + get: function () { return tslib_1.__spread(this._scale); }, + set: function (val) { this._scale = vec3.fromValues(val[0], val[1], val[2]); }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "rotation", { + get: function () { return tslib_1.__spread(this._rotation); }, + set: function (val) { this._rotation = vec3.fromValues(val[0], val[1], val[2]); }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "quaternion", { + get: function () { + var r = this._rotation; + var quaternion = quat.fromEuler(quat.create(), r[0], r[1], r[2]); + return tslib_1.__spread(quaternion); + }, + set: function (val) { this._rotation = quatToEuler(quat.fromValues(val[0], val[1], val[2], val[3])); }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "perspective", { + get: function () { return this._perspective; }, + set: function (val) { this._perspective = val; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "rotateOffset", { + get: function () { return this._rotateOffset; }, + set: function (val) { this._rotateOffset = val; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "cameraCSS", { + get: function () { + var perspective = this._perspective; + var rotateOffset = this._rotateOffset; + var rotation = this._rotation; + var scale = this._scale; + return "scale3d(" + scale[0] + ", " + scale[1] + ", " + scale[2] + ") translateZ(" + (perspective - rotateOffset) + "px) rotateX(" + rotation[0] + "deg) rotateY(" + rotation[1] + "deg) rotateZ(" + rotation[2] + "deg)"; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(CSSCamera.prototype, "worldCSS", { + get: function () { + var position = this._position; + return "translate3d(" + -position[0] + "px, " + -position[1] + "px, " + -position[2] + "px)"; + }, + enumerable: true, + configurable: true + }); + CSSCamera.prototype.focus = function (el) { + var element = getElement(el); + var focusMatrix = this._getFocusMatrix(element); + var rotation = quat.create(); + var translation = vec3.create(); + mat4.getRotation(rotation, focusMatrix); + mat4.getTranslation(translation, focusMatrix); + var eulerAngle = quatToEuler(rotation); + vec3.negate(eulerAngle, eulerAngle); + this._rotation = eulerAngle; + this._position = translation; + return this; + }; + CSSCamera.prototype.translateLocal = function (x, y, z) { + if (x === void 0) { x = 0; } + if (y === void 0) { y = 0; } + if (z === void 0) { z = 0; } + var position = this._position; + var rotation = this._rotation; + var transVec = vec3.fromValues(x, y, z); + var rotQuat = quat.create(); + quat.fromEuler(rotQuat, -rotation[0], -rotation[1], -rotation[2]); + vec3.transformQuat(transVec, transVec, rotQuat); + vec3.add(position, position, transVec); + return this; + }; + CSSCamera.prototype.translate = function (x, y, z) { + if (x === void 0) { x = 0; } + if (y === void 0) { y = 0; } + if (z === void 0) { z = 0; } + vec3.add(this._position, this._position, vec3.fromValues(x, y, z)); + return this; + }; + CSSCamera.prototype.rotate = function (x, y, z) { + if (x === void 0) { x = 0; } + if (y === void 0) { y = 0; } + if (z === void 0) { z = 0; } + vec3.add(this._rotation, this._rotation, vec3.fromValues(x, y, z)); + return this; + }; + CSSCamera.prototype.update = function (duration, options) { + if (duration === void 0) { duration = 0; } + if (options === void 0) { options = {}; } + return tslib_1.__awaiter(this, void 0, void 0, function () { + var updateOptions, transitionDuration, updateOption, finalOption_1; + var _this = this; + return tslib_1.__generator(this, function (_a) { + applyCSS(this._viewportEl, { perspective: this.perspective + "px" }); + applyCSS(this._cameraEl, { transform: this.cameraCSS }); + applyCSS(this._worldEl, { transform: this.worldCSS }); + updateOptions = assign(assign({}, DEFAULT.UPDATE_OPTIONS), options); + if (duration > 0) { + if (this._updateTimer > 0) { + window.clearTimeout(this._updateTimer); + } + transitionDuration = duration + "ms"; + updateOption = Object.keys(updateOptions).reduce(function (option, key) { + option["transition" + (key.charAt(0).toUpperCase() + key.slice(1))] = updateOptions[key]; + return option; + }, {}); + finalOption_1 = tslib_1.__assign({ transitionDuration: transitionDuration }, updateOption); + [this._viewportEl, this._cameraEl, this._worldEl].forEach(function (el) { + applyCSS(el, finalOption_1); + }); + } + return [2, new Promise(function (resolve) { + if (duration > 0) { + _this._updateTimer = window.setTimeout(function () { + [_this._viewportEl, _this._cameraEl, _this._worldEl].forEach(function (el) { + applyCSS(el, { transition: '' }); + }); + _this._updateTimer = -1; + resolve(); + }, duration); + } + else { + requestAnimationFrame(function () { + resolve(); + }); + } + })]; + }); + }); + }; + CSSCamera.prototype._getFocusMatrix = function (element) { + var elements = []; + while (element) { + elements.push(element); + if (element === this._element) + break; + element = element.parentElement; + } + elements.reverse(); + var elStyles = elements.map(function (el) { return window.getComputedStyle(el); }); + var firstFlatIndex = findIndex(elStyles, function (style) { return style.transformStyle !== 'preserve-3d'; }); + if (firstFlatIndex > 0) { + elStyles.splice(firstFlatIndex + 1); + } + var parentOffset = { + left: 0, + top: 0, + width: this.viewportEl.offsetWidth, + height: this.viewportEl.offsetHeight, + }; + var accRotation = quat.identity(quat.create()); + var centerPos = vec3.fromValues(0, 0, 0); + elStyles.forEach(function (style, idx) { + var el = elements[idx]; + var currentOffset = { + left: el.offsetLeft, + top: el.offsetTop, + width: el.offsetWidth, + height: el.offsetHeight, + }; + var transformMat = getTransformMatrix(style); + var offsetFromParent = getOffsetFromParent(currentOffset, parentOffset); + vec3.transformQuat(offsetFromParent, offsetFromParent, accRotation); + vec3.add(centerPos, centerPos, offsetFromParent); + var rotateOffset = getRotateOffset(style, currentOffset); + vec3.transformQuat(rotateOffset, rotateOffset, accRotation); + var transformOrigin = vec3.clone(centerPos); + vec3.add(transformOrigin, transformOrigin, rotateOffset); + var centerFromOrigin = vec3.create(); + vec3.sub(centerFromOrigin, centerPos, transformOrigin); + var invAccRotation = quat.invert(quat.create(), accRotation); + vec3.transformQuat(centerFromOrigin, centerFromOrigin, invAccRotation); + vec3.transformMat4(centerFromOrigin, centerFromOrigin, transformMat); + vec3.transformQuat(centerFromOrigin, centerFromOrigin, accRotation); + var newCenterPos = vec3.add(vec3.create(), transformOrigin, centerFromOrigin); + var rotation = mat4.getRotation(quat.create(), transformMat); + vec3.copy(centerPos, newCenterPos); + quat.mul(accRotation, accRotation, rotation); + parentOffset = currentOffset; + }); + var perspective = vec3.fromValues(0, 0, this.perspective); + vec3.transformQuat(perspective, perspective, accRotation); + vec3.add(centerPos, centerPos, perspective); + var matrix = mat4.create(); + mat4.fromRotationTranslation(matrix, accRotation, centerPos); + return matrix; + }; + return CSSCamera; +}()); +export default CSSCamera; +//# sourceMappingURL=CSSCamera.js.map \ No newline at end of file diff --git a/lib/CSSCamera.js.map b/lib/CSSCamera.js.map new file mode 100644 index 0000000..a92dc52 --- /dev/null +++ b/lib/CSSCamera.js.map @@ -0,0 +1 @@ +{"version":3,"file":"CSSCamera.js","sourceRoot":"","sources":["../src/CSSCamera.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACnI,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAC;AAG/C;IAsLE,mBAAY,EAAwB,EAAE,OAA8B;QAA9B,wBAAA,EAAA,YAA8B;QAClE,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;QAE/B,IAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO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AI,CAAC,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;YAC7C,YAAY,GAAG,aAAa,CAAC;QAC/B,CAAC,CAAC,CAAC;QAEH,IAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC5D,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;QAC1D,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;QAE5C,IAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7B,IAAI,CAAC,uBAAuB,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;QAE7D,OAAO,MAAM,CAAC;IAChB,CAAC;IACH,gBAAC;AAAD,CAAC,AA/bD,IA+bC;AAED,eAAe,SAAS,CAAC"} \ No newline at end of file diff --git a/lib/constants/default.js b/lib/constants/default.js new file mode 100644 index 0000000..230f386 --- /dev/null +++ b/lib/constants/default.js @@ -0,0 +1,38 @@ +export var STYLE = { + VIEWPORT: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + overflow: 'hidden', + }, + CAMERA: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + 'will-change': 'transform', + }, + WORLD: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + 'will-change': 'transform', + }, +}; +export var CLASS = { + VIEWPORT: 'cc-viewport', + CAMERA: 'cc-camera', + WORLD: 'cc-world', +}; +export var OPTIONS = { + position: [0, 0, 0], + scale: [1, 1, 1], + rotation: [0, 0, 0], + perspective: 0, + rotateOffset: 0, +}; +export var UPDATE_OPTIONS = { + property: 'transform', + timingFunction: 'ease-out', + delay: '0ms', +}; +//# sourceMappingURL=default.js.map \ No newline at end of file diff --git a/lib/constants/default.js.map b/lib/constants/default.js.map new file mode 100644 index 0000000..b542b42 --- /dev/null +++ b/lib/constants/default.js.map @@ -0,0 +1 @@ +{"version":3,"file":"default.js","sourceRoot":"","sources":["../../src/constants/default.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,KAAK,GAAG;IACnB,QAAQ,EAAE;QACR,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;QACd,iBAAiB,EAAE,aAAa;QAChC,QAAQ,EAAE,QAAQ;KACnB;IACD,MAAM,EAAE;QACN,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;QACd,iBAAiB,EAAE,aAAa;QAChC,aAAa,EAAE,WAAW;KAC3B;IACD,KAAK,EAAE;QACL,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;QACd,iBAAiB,EAAE,aAAa;QAChC,aAAa,EAAE,WAAW;KAC3B;CACF,CAAC;AAEF,MAAM,CAAC,IAAM,KAAK,GAAG;IACnB,QAAQ,EAAE,aAAa;IACvB,MAAM,EAAE,WAAW;IACnB,KAAK,EAAE,UAAU;CAClB,CAAC;AAEF,MAAM,CAAC,IAAM,OAAO,GAAG;IACrB,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACnB,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAChB,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACnB,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,IAAM,cAAc,GAAG;IAC5B,QAAQ,EAAE,WAAW;IACrB,cAAc,EAAE,UAAU;IAC1B,KAAK,EAAE,KAAK;CACb,CAAC"} \ No newline at end of file diff --git a/lib/constants/error.js b/lib/constants/error.js new file mode 100644 index 0000000..e366f1e --- /dev/null +++ b/lib/constants/error.js @@ -0,0 +1,3 @@ +export var ELEMENT_NOT_EXIST = function (selector) { return "Element with selector \"" + selector + "\" doesn't exist."; }; +export var MUST_STRING_OR_ELEMENT = function (received) { return "Element should be provided in string or HTMLElement. Received: " + received; }; +//# sourceMappingURL=error.js.map \ No newline at end of file diff --git a/lib/constants/error.js.map b/lib/constants/error.js.map new file mode 100644 index 0000000..087c165 --- /dev/null +++ b/lib/constants/error.js.map @@ -0,0 +1 @@ +{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/constants/error.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,iBAAiB,GAAG,UAAC,QAAgB,IAAK,OAAA,6BAA0B,QAAQ,sBAAkB,EAApD,CAAoD,CAAC;AAC5G,MAAM,CAAC,IAAM,sBAAsB,GAAG,UAAC,QAAa,IAAK,OAAA,oEAAkE,QAAU,EAA5E,CAA4E,CAAC"} \ No newline at end of file diff --git a/lib/css-camera.esm.js b/lib/css-camera.esm.js new file mode 100644 index 0000000..f30f5c5 --- /dev/null +++ b/lib/css-camera.esm.js @@ -0,0 +1,720 @@ +/* +Copyright (c) 2019 WoodNeck +name: css-camera +license: MIT +author: WoodNeck +repository: git+https://github.com/WoodNeck/css-camera.git +version: 1.0.1 +*/ +import { vec3, mat4, quat } from 'gl-matrix'; + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. All rights reserved. +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 + +THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED +WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +MERCHANTABLITY OR NON-INFRINGEMENT. + +See the Apache Version 2.0 License for specific language governing permissions +and limitations under the License. +***************************************************************************** */ +var __assign = function () { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + + return t; + }; + + return __assign.apply(this, arguments); +}; +function __awaiter(thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + + function step(result) { + result.done ? resolve(result.value) : new P(function (resolve) { + resolve(result.value); + }).then(fulfilled, rejected); + } + + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +} +function __generator(thisArg, body) { + var _ = { + label: 0, + sent: function () { + if (t[0] & 1) throw t[1]; + return t[1]; + }, + trys: [], + ops: [] + }, + f, + y, + t, + g; + return g = { + next: verb(0), + "throw": verb(1), + "return": verb(2) + }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { + return this; + }), g; + + function verb(n) { + return function (v) { + return step([n, v]); + }; + } + + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + + switch (op[0]) { + case 0: + case 1: + t = op; + break; + + case 4: + _.label++; + return { + value: op[1], + done: false + }; + + case 5: + _.label++; + y = op[1]; + op = [0]; + continue; + + case 7: + op = _.ops.pop(); + + _.trys.pop(); + + continue; + + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { + _ = 0; + continue; + } + + if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { + _.label = op[1]; + break; + } + + if (op[0] === 6 && _.label < t[1]) { + _.label = t[1]; + t = op; + break; + } + + if (t && _.label < t[2]) { + _.label = t[2]; + + _.ops.push(op); + + break; + } + + if (t[2]) _.ops.pop(); + + _.trys.pop(); + + continue; + } + + op = body.call(thisArg, _); + } catch (e) { + op = [6, e]; + y = 0; + } finally { + f = t = 0; + } + + if (op[0] & 5) throw op[1]; + return { + value: op[0] ? op[1] : void 0, + done: true + }; + } +} +function __read(o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), + r, + ar = [], + e; + + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } catch (error) { + e = { + error: error + }; + } finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } finally { + if (e) throw e.error; + } + } + + return ar; +} +function __spread() { + for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); + + return ar; +} + +var ELEMENT_NOT_EXIST = function (selector) { + return "Element with selector \"" + selector + "\" doesn't exist."; +}; +var MUST_STRING_OR_ELEMENT = function (received) { + return "Element should be provided in string or HTMLElement. Received: " + received; +}; + +var getElement = function (el, baseElement) { + if (typeof el === 'string') { + var queryResult = baseElement ? baseElement.querySelector(el) : document.querySelector(el); + + if (!queryResult) { + throw new Error(ELEMENT_NOT_EXIST(el)); + } + + return queryResult; + } else if (el.nodeName && el.nodeType === 1) { + return el; + } else { + throw new Error(MUST_STRING_OR_ELEMENT(el)); + } +}; +function applyCSS(element, cssObj) { + Object.keys(cssObj).forEach(function (property) { + element.style[property] = cssObj[property]; + }); +} +function getTransformMatrix(elStyle) { + var trVal = elStyle.getPropertyValue('transform'); + var transformStr = /\(((\s|\S)+)\)/.exec(trVal); + var matrixVal = transformStr ? transformStr[1].split(',').map(function (val) { + return parseFloat(val); + }) : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; + + if (matrixVal.length === 16) { + return mat4.fromValues.apply(mat4, __spread(matrixVal)); + } else { + var matrix = mat4.create(); + mat4.identity(matrix); + matrix[0] = matrixVal[0]; + matrix[1] = matrixVal[1]; + matrix[4] = matrixVal[2]; + matrix[5] = matrixVal[3]; + matrix[12] = matrixVal[4]; + matrix[13] = matrixVal[5]; + return matrix; + } +} +function getOffsetFromParent(currentOffset, parentOffset) { + var offsetLeft = currentOffset.left + (currentOffset.width - parentOffset.width) / 2; + var offsetTop = currentOffset.top + (currentOffset.height - parentOffset.height) / 2; + return vec3.fromValues(offsetLeft, offsetTop, 0); +} +function getRotateOffset(elStyle, currentOffset) { + var axis = elStyle.transformOrigin.split(' ').map(function (str) { + return parseFloat(str.substring(0, str.length - 2)); + }); + var ax = axis[0] - currentOffset.width / 2; + var ay = axis[1] - currentOffset.height / 2; + return vec3.fromValues(ax, ay, 0); +} +function findIndex(iterable, callback) { + for (var i = 0; i < iterable.length; i += 1) { + var element = iterable[i]; + + if (element && callback(element)) { + return i; + } + } + + return -1; +} +function clamp(val, min, max) { + return Math.max(Math.min(val, max), min); +} +function assign(target) { + var srcs = []; + + for (var _i = 1; _i < arguments.length; _i++) { + srcs[_i - 1] = arguments[_i]; + } + + srcs.forEach(function (source) { + Object.keys(source).forEach(function (key) { + var value = source[key]; + target[key] = value; + }); + }); + return target; +} + +function radToDeg(rad) { + return 180 * rad / Math.PI; +} +function quatToEuler(q) { + var rotM = mat4.create(); + mat4.fromQuat(rotM, q); + var m11 = rotM[0]; + var m12 = rotM[4]; + var m21 = rotM[1]; + var m22 = rotM[5]; + var m31 = rotM[2]; + var m32 = rotM[6]; + var m33 = rotM[10]; + var euler = vec3.create(); + euler[1] = Math.asin(-clamp(m31, -1, 1)); + + if (Math.abs(m31) < 0.99999) { + euler[0] = Math.atan2(m32, m33); + euler[2] = Math.atan2(m21, m11); + } else { + euler[0] = 0; + euler[2] = Math.atan2(-m12, m22); + } + + return euler.map(function (val) { + return radToDeg(val); + }); +} + +var STYLE = { + VIEWPORT: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + overflow: 'hidden' + }, + CAMERA: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + 'will-change': 'transform' + }, + WORLD: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + 'will-change': 'transform' + } +}; +var CLASS = { + VIEWPORT: 'cc-viewport', + CAMERA: 'cc-camera', + WORLD: 'cc-world' +}; +var OPTIONS = { + position: [0, 0, 0], + scale: [1, 1, 1], + rotation: [0, 0, 0], + perspective: 0, + rotateOffset: 0 +}; +var UPDATE_OPTIONS = { + property: 'transform', + timingFunction: 'ease-out', + delay: '0ms' +}; + +var CSSCamera = function () { + function CSSCamera(el, options) { + if (options === void 0) { + options = {}; + } + + this._element = getElement(el); + var op = assign(assign({}, OPTIONS), options); + this._position = vec3.fromValues(op.position[0], op.position[1], op.position[2]); + this._scale = vec3.fromValues(op.scale[0], op.scale[1], op.scale[2]); + this._rotation = vec3.fromValues(op.rotation[0], op.rotation[1], op.rotation[2]); + this._perspective = op.perspective; + this._rotateOffset = op.rotateOffset; + this._updateTimer = -1; + var element = this._element; + var viewport = document.createElement('div'); + var camera = viewport.cloneNode(); + var world = viewport.cloneNode(); + viewport.className = CLASS.VIEWPORT; + camera.className = CLASS.CAMERA; + world.className = CLASS.WORLD; + applyCSS(viewport, STYLE.VIEWPORT); + applyCSS(camera, STYLE.CAMERA); + applyCSS(world, STYLE.WORLD); + camera.appendChild(world); + viewport.appendChild(camera); + this._viewportEl = viewport; + this._cameraEl = camera; + this._worldEl = world; + element.parentElement.insertBefore(viewport, element); + world.appendChild(element); + this.update(0); + } + + var __proto = CSSCamera.prototype; + Object.defineProperty(CSSCamera, "VERSION", { + get: function () { + return '1.0.1'; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "element", { + get: function () { + return this._element; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "viewportEl", { + get: function () { + return this._viewportEl; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "cameraEl", { + get: function () { + return this._cameraEl; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "worldEl", { + get: function () { + return this._worldEl; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "position", { + get: function () { + return __spread(this._position); + }, + set: function (val) { + this._position = vec3.fromValues(val[0], val[1], val[2]); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "scale", { + get: function () { + return __spread(this._scale); + }, + set: function (val) { + this._scale = vec3.fromValues(val[0], val[1], val[2]); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "rotation", { + get: function () { + return __spread(this._rotation); + }, + set: function (val) { + this._rotation = vec3.fromValues(val[0], val[1], val[2]); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "quaternion", { + get: function () { + var r = this._rotation; + var quaternion = quat.fromEuler(quat.create(), r[0], r[1], r[2]); + return __spread(quaternion); + }, + set: function (val) { + this._rotation = quatToEuler(quat.fromValues(val[0], val[1], val[2], val[3])); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "perspective", { + get: function () { + return this._perspective; + }, + set: function (val) { + this._perspective = val; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "rotateOffset", { + get: function () { + return this._rotateOffset; + }, + set: function (val) { + this._rotateOffset = val; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "cameraCSS", { + get: function () { + var perspective = this._perspective; + var rotateOffset = this._rotateOffset; + var rotation = this._rotation; + var scale = this._scale; + return "scale3d(" + scale[0] + ", " + scale[1] + ", " + scale[2] + ") translateZ(" + (perspective - rotateOffset) + "px) rotateX(" + rotation[0] + "deg) rotateY(" + rotation[1] + "deg) rotateZ(" + rotation[2] + "deg)"; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "worldCSS", { + get: function () { + var position = this._position; + return "translate3d(" + -position[0] + "px, " + -position[1] + "px, " + -position[2] + "px)"; + }, + enumerable: true, + configurable: true + }); + + __proto.focus = function (el) { + var element = getElement(el); + + var focusMatrix = this._getFocusMatrix(element); + + var rotation = quat.create(); + var translation = vec3.create(); + mat4.getRotation(rotation, focusMatrix); + mat4.getTranslation(translation, focusMatrix); + var eulerAngle = quatToEuler(rotation); + vec3.negate(eulerAngle, eulerAngle); + this._rotation = eulerAngle; + this._position = translation; + return this; + }; + + __proto.translateLocal = function (x, y, z) { + if (x === void 0) { + x = 0; + } + + if (y === void 0) { + y = 0; + } + + if (z === void 0) { + z = 0; + } + + var position = this._position; + var rotation = this._rotation; + var transVec = vec3.fromValues(x, y, z); + var rotQuat = quat.create(); + quat.fromEuler(rotQuat, -rotation[0], -rotation[1], -rotation[2]); + vec3.transformQuat(transVec, transVec, rotQuat); + vec3.add(position, position, transVec); + return this; + }; + + __proto.translate = function (x, y, z) { + if (x === void 0) { + x = 0; + } + + if (y === void 0) { + y = 0; + } + + if (z === void 0) { + z = 0; + } + + vec3.add(this._position, this._position, vec3.fromValues(x, y, z)); + return this; + }; + + __proto.rotate = function (x, y, z) { + if (x === void 0) { + x = 0; + } + + if (y === void 0) { + y = 0; + } + + if (z === void 0) { + z = 0; + } + + vec3.add(this._rotation, this._rotation, vec3.fromValues(x, y, z)); + return this; + }; + + __proto.update = function (duration, options) { + if (duration === void 0) { + duration = 0; + } + + if (options === void 0) { + options = {}; + } + + return __awaiter(this, void 0, Promise, function () { + var updateOptions, transitionDuration, updateOption, finalOption_1; + + var _this = this; + + return __generator(this, function (_a) { + applyCSS(this._viewportEl, { + perspective: this.perspective + "px" + }); + applyCSS(this._cameraEl, { + transform: this.cameraCSS + }); + applyCSS(this._worldEl, { + transform: this.worldCSS + }); + updateOptions = assign(assign({}, UPDATE_OPTIONS), options); + + if (duration > 0) { + if (this._updateTimer > 0) { + window.clearTimeout(this._updateTimer); + } + + transitionDuration = duration + "ms"; + updateOption = Object.keys(updateOptions).reduce(function (option, key) { + option["transition" + (key.charAt(0).toUpperCase() + key.slice(1))] = updateOptions[key]; + return option; + }, {}); + finalOption_1 = __assign({ + transitionDuration: transitionDuration + }, updateOption); + [this._viewportEl, this._cameraEl, this._worldEl].forEach(function (el) { + applyCSS(el, finalOption_1); + }); + } + + return [2, new Promise(function (resolve) { + if (duration > 0) { + _this._updateTimer = window.setTimeout(function () { + [_this._viewportEl, _this._cameraEl, _this._worldEl].forEach(function (el) { + applyCSS(el, { + transition: '' + }); + }); + _this._updateTimer = -1; + resolve(); + }, duration); + } else { + requestAnimationFrame(function () { + resolve(); + }); + } + })]; + }); + }); + }; + + __proto._getFocusMatrix = function (element) { + var elements = []; + + while (element) { + elements.push(element); + if (element === this._element) break; + element = element.parentElement; + } + + elements.reverse(); + var elStyles = elements.map(function (el) { + return window.getComputedStyle(el); + }); + var firstFlatIndex = findIndex(elStyles, function (style) { + return style.transformStyle !== 'preserve-3d'; + }); + + if (firstFlatIndex > 0) { + elStyles.splice(firstFlatIndex + 1); + } + + var parentOffset = { + left: 0, + top: 0, + width: this.viewportEl.offsetWidth, + height: this.viewportEl.offsetHeight + }; + var accRotation = quat.identity(quat.create()); + var centerPos = vec3.fromValues(0, 0, 0); + elStyles.forEach(function (style, idx) { + var el = elements[idx]; + var currentOffset = { + left: el.offsetLeft, + top: el.offsetTop, + width: el.offsetWidth, + height: el.offsetHeight + }; + var transformMat = getTransformMatrix(style); + var offsetFromParent = getOffsetFromParent(currentOffset, parentOffset); + vec3.transformQuat(offsetFromParent, offsetFromParent, accRotation); + vec3.add(centerPos, centerPos, offsetFromParent); + var rotateOffset = getRotateOffset(style, currentOffset); + vec3.transformQuat(rotateOffset, rotateOffset, accRotation); + var transformOrigin = vec3.clone(centerPos); + vec3.add(transformOrigin, transformOrigin, rotateOffset); + var centerFromOrigin = vec3.create(); + vec3.sub(centerFromOrigin, centerPos, transformOrigin); + var invAccRotation = quat.invert(quat.create(), accRotation); + vec3.transformQuat(centerFromOrigin, centerFromOrigin, invAccRotation); + vec3.transformMat4(centerFromOrigin, centerFromOrigin, transformMat); + vec3.transformQuat(centerFromOrigin, centerFromOrigin, accRotation); + var newCenterPos = vec3.add(vec3.create(), transformOrigin, centerFromOrigin); + var rotation = mat4.getRotation(quat.create(), transformMat); + vec3.copy(centerPos, newCenterPos); + quat.mul(accRotation, accRotation, rotation); + parentOffset = currentOffset; + }); + var perspective = vec3.fromValues(0, 0, this.perspective); + vec3.transformQuat(perspective, perspective, accRotation); + vec3.add(centerPos, centerPos, perspective); + var matrix = mat4.create(); + mat4.fromRotationTranslation(matrix, accRotation, centerPos); + return matrix; + }; + + return CSSCamera; +}(); + +export default CSSCamera; +//# sourceMappingURL=css-camera.esm.js.map diff --git a/lib/css-camera.esm.js.map b/lib/css-camera.esm.js.map new file mode 100644 index 0000000..2e6770d --- /dev/null +++ b/lib/css-camera.esm.js.map @@ -0,0 +1 @@ +{"version":3,"file":"css-camera.esm.js","sources":["../src/constants/error.ts","../src/utils/helper.ts","../src/utils/math.ts","../src/constants/default.ts","../src/CSSCamera.ts"],"sourcesContent":["export const ELEMENT_NOT_EXIST = (selector: string) => `Element with selector \"${selector}\" doesn't exist.`;\nexport const MUST_STRING_OR_ELEMENT = (received: any) => `Element should be provided in string or HTMLElement. Received: ${received}`;\n","import { mat4, vec3 } from 'gl-matrix';\nimport { ELEMENT_NOT_EXIST, MUST_STRING_OR_ELEMENT } from '../constants/error';\nimport { Matrix4x4, Offset } from '../types';\n\nexport const getElement = (el: string | HTMLElement, baseElement?: HTMLElement): HTMLElement => {\n if (typeof el === 'string') {\n const queryResult = baseElement\n ? baseElement.querySelector(el)\n : document.querySelector(el);\n if (!queryResult) {\n throw new Error(ELEMENT_NOT_EXIST(el));\n }\n return queryResult as HTMLElement;\n } else if (el.nodeName && el.nodeType === 1) {\n return el;\n } else {\n throw new Error(MUST_STRING_OR_ELEMENT(el));\n }\n};\n\nexport function applyCSS(element: HTMLElement, cssObj: { [keys: string]: string }): void {\n Object.keys(cssObj).forEach(property => {\n (element.style as any)[property] = cssObj[property];\n });\n}\n\nexport function getTransformMatrix(elStyle: CSSStyleDeclaration): mat4 {\n const trVal = elStyle.getPropertyValue('transform');\n const transformStr = /\\(((\\s|\\S)+)\\)/.exec(trVal);\n const matrixVal = transformStr\n ? transformStr[1].split(',').map(val => parseFloat(val)) as Matrix4x4\n : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] as Matrix4x4;\n if (matrixVal.length === 16 ) {\n return mat4.fromValues(...matrixVal);\n } else {\n // Convert 2d matrix(length 6) to 3d\n const matrix = mat4.create();\n mat4.identity(matrix);\n\n matrix[0] = matrixVal[0];\n matrix[1] = matrixVal[1];\n matrix[4] = matrixVal[2];\n matrix[5] = matrixVal[3];\n matrix[12] = matrixVal[4];\n matrix[13] = matrixVal[5];\n\n return matrix;\n }\n}\n\nexport function getOffsetFromParent(currentOffset: Offset, parentOffset: Offset): vec3 {\n const offsetLeft = currentOffset.left + (currentOffset.width - parentOffset.width) / 2;\n const offsetTop = currentOffset.top + (currentOffset.height - parentOffset.height) / 2;\n\n return vec3.fromValues(offsetLeft, offsetTop, 0);\n}\n\nexport function getRotateOffset(elStyle: CSSStyleDeclaration, currentOffset: Offset): vec3 {\n const axis = (elStyle.transformOrigin as string)\n .split(' ')\n .map(str => parseFloat(str.substring(0, str.length - 2)));\n const ax = axis[0] - currentOffset.width / 2;\n const ay = axis[1] - currentOffset.height / 2;\n\n return vec3.fromValues(ax, ay, 0);\n}\n\nexport function findIndex(iterable: T[], callback: (el: T) => boolean): number {\n for (let i = 0; i < iterable.length; i += 1) {\n const element = iterable[i];\n if (element && callback(element)) {\n return i;\n }\n }\n\n return -1;\n}\n\n// return [0, 1, ...., max - 1]\nexport function range(max: number): number[] {\n const counterArray: number[] = [];\n for (let i = 0; i < max; i += 1) {\n counterArray[i] = i;\n }\n return counterArray;\n}\n\nexport function clamp(val: number, min: number, max: number): number {\n return Math.max(Math.min(val, max), min);\n}\n\nexport function assign(target: object, ...srcs: object[]): object {\n srcs.forEach(source => {\n Object.keys(source).forEach(key => {\n const value = (source as any)[key];\n (target as any)[key] = value;\n });\n });\n\n return target;\n}\n","import { mat4, quat, vec3 } from 'gl-matrix';\nimport { clamp } from './helper';\n\nexport function degToRad(deg: number): number {\n return Math.PI * deg / 180;\n}\n\nexport function radToDeg(rad: number): number {\n return 180 * rad / Math.PI;\n}\n\n// From Three.js https://github.com/mrdoob/three.js/blob/dev/src/math/Euler.js\nexport function quatToEuler(q: quat): vec3 {\n const rotM = mat4.create();\n mat4.fromQuat(rotM, q);\n\n const m11 = rotM[0];\n const m12 = rotM[4];\n // const m13 = rotM[8];\n const m21 = rotM[1];\n const m22 = rotM[5];\n // const m23 = rotM[9];\n const m31 = rotM[2];\n const m32 = rotM[6];\n const m33 = rotM[10];\n\n const euler = vec3.create();\n\n // ZYX\n euler[1] = Math.asin(-clamp(m31, -1, 1));\n if (Math.abs(m31) < 0.99999) {\n euler[0] = Math.atan2(m32, m33);\n euler[2] = Math.atan2(m21, m11);\n } else {\n euler[0] = 0;\n euler[2] = Math.atan2(-m12, m22);\n }\n\n return euler.map(val => radToDeg(val)) as vec3;\n}\n","export const STYLE = {\n VIEWPORT: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n overflow: 'hidden',\n },\n CAMERA: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n 'will-change': 'transform',\n },\n WORLD: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n 'will-change': 'transform',\n },\n};\n\nexport const CLASS = {\n VIEWPORT: 'cc-viewport',\n CAMERA: 'cc-camera',\n WORLD: 'cc-world',\n};\n\nexport const OPTIONS = {\n position: [0, 0, 0],\n scale: [1, 1, 1],\n rotation: [0, 0, 0],\n perspective: 0,\n rotateOffset: 0,\n};\n\nexport const UPDATE_OPTIONS = {\n property: 'transform',\n timingFunction: 'ease-out',\n delay: '0ms',\n};\n","import { mat4, vec3, quat } from 'gl-matrix';\nimport { getElement, applyCSS, getTransformMatrix, findIndex, getOffsetFromParent, getRotateOffset, assign } from './utils/helper';\nimport { quatToEuler } from './utils/math';\nimport * as DEFAULT from './constants/default';\nimport { Offset, UpdateOption, ValueOf, Options } from './types';\n\nclass CSSCamera {\n private _element: HTMLElement;\n private _viewportEl: HTMLElement;\n private _cameraEl: HTMLElement;\n private _worldEl: HTMLElement;\n\n private _position: vec3;\n private _scale: vec3;\n private _rotation: vec3;\n private _perspective: number;\n private _rotateOffset: number;\n private _updateTimer: number;\n\n /**\n * Current version of CSSCamera.\n * @example\n * console.log(CSSCamera.VERSION); // ex) 1.0.0\n * @type {string}\n */\n static get VERSION() { return '#__VERSION__#'; }\n\n /**\n * The element provided in the constructor.\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.element === el); // true\n * @type {HTMLElement}\n */\n public get element() { return this._element; }\n\n /**\n * The reference of viewport DOM element.\n * @type {HTMLElement}\n */\n public get viewportEl() { return this._viewportEl; }\n\n /**\n * The reference of camera DOM element.\n * @type {HTMLElement}\n */\n public get cameraEl() { return this._cameraEl; }\n\n /**\n * The reference of world DOM element.\n * @type {HTMLElement}\n */\n public get worldEl() { return this._worldEl; }\n\n /**\n * The current position as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.position); // [0, 0, 0];\n * camera.position = [0, 0, 300];\n * console.log(camera.position); // [0, 0, 300];\n * @type {number[]}\n */\n public get position() { return [...this._position]; }\n\n /**\n * The current scale as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.scale); // [1, 1, 1];\n * camera.scale = [5, 1, 1];\n * console.log(camera.scale); // [5, 1, 1];\n * @type {number[]}\n */\n public get scale() { return [...this._scale]; }\n\n /**\n * The current Euler rotation angles in degree as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.rotation); // [0, 0, 0];\n * camera.rotation = [90, 0, 0];\n * console.log(camera.rotation); // [90, 0, 0];\n * @type {number[]}\n */\n public get rotation() { return [...this._rotation]; }\n\n /**\n * The current quaternion rotation as number array([x, y, z, w]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.quaternion); // [0, 0, 0, 1];\n * camera.rotation = [90, 0, 0];\n * console.log(camera.quaternion); // [0.7071067690849304, 0, 0, 0.7071067690849304];\n * camera.quaternion = [0, 0, 0, 1];\n * console.log(camera.rotation); // [0, -0, 0];\n * @type {number[]}\n */\n public get quaternion() {\n const r = this._rotation;\n const quaternion = quat.fromEuler(quat.create(), r[0], r[1], r[2]);\n\n return [...quaternion];\n }\n\n /**\n * The current perspective value that will be applied to viewport element.\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.perspective); // 300\n * @type {number}\n */\n public get perspective() { return this._perspective; }\n\n /**\n * The current rotate offset value that will be applied to camera element.\n * The camera will be as far away from the focal point as this value.\n * |![rot0](https://woodneck.github.io/css-camera/asset/rot0.gif)|![rot150](https://woodneck.github.io/css-camera/asset/rot150.gif)|\n * |:---:|:---:|\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * camera.rotateOffset = 100;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(400px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * @type {number}\n */\n public get rotateOffset() { return this._rotateOffset; }\n\n /**\n * CSS string can be applied to camera element based on current transform.\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * @type {string}\n */\n public get cameraCSS() {\n const perspective = this._perspective;\n const rotateOffset = this._rotateOffset;\n const rotation = this._rotation;\n const scale = this._scale;\n\n // Rotate in order of Z - Y - X\n // tslint:disable-next-line: max-line-length\n return `scale3d(${scale[0]}, ${scale[1]}, ${scale[2]}) translateZ(${perspective - rotateOffset}px) rotateX(${rotation[0]}deg) rotateY(${rotation[1]}deg) rotateZ(${rotation[2]}deg)`;\n }\n\n /**\n * CSS string can be applied to world element based on current transform.\n * ```\n * const camera = new CSSCamera(el);\n * console.log(camera.worldCSS); // \"translate3d(0px, 0px, 0px)\";\n * camera.translate(0, 0, 300);\n * console.log(camera.worldCSS); // \"translate3d(0px, 0px, -300px)\";\n * ```\n * @type {string}\n */\n public get worldCSS() {\n const position = this._position;\n\n return `translate3d(${-position[0]}px, ${-position[1]}px, ${-position[2]}px)`;\n }\n\n public set position(val: number[]) { this._position = vec3.fromValues(val[0], val[1], val[2]); }\n public set scale(val: number[]) { this._scale = vec3.fromValues(val[0], val[1], val[2]); }\n public set rotation(val: number[]) { this._rotation = vec3.fromValues(val[0], val[1], val[2]); }\n public set quaternion(val: number[]) { this._rotation = quatToEuler(quat.fromValues(val[0], val[1], val[2], val[3])); }\n public set perspective(val: number) { this._perspective = val; }\n public set rotateOffset(val: number) { this._rotateOffset = val; }\n\n /**\n * Create new CSSCamera with given element / selector.\n * @param - The element to apply camera. Can be HTMLElement or CSS selector.\n * @param {Partial} [options] Camera options\n * @param {number[]} [options.position=[0, 0, 0]] Initial position of the camera.\n * @param {number[]} [options.scale=[1, 1, 1]] Initial scale of the camera.\n * @param {number[]} [options.rotation=[0, 0, 0]] Initial Euler rotation angles(x, y, z) of the camera in degree.\n * @param {number} [options.perspective=0] Initial perspective of the camera.\n * @param {number} [options.rotateOffset=0] Initial rotate offset of the camera.\n * @example\n * const camera = new CSSCamera(\"#el\", {\n * position: [0, 0, 150], // Initial pos(x, y, z)\n * rotation: [90, 0, 0], // Initial rotation(x, y, z, in degree)\n * perspective: 300 // CSS \"perspective\" value to apply\n * });\n */\n constructor(el: string | HTMLElement, options: Partial = {}) {\n this._element = getElement(el);\n\n const op = assign(assign({}, DEFAULT.OPTIONS), options) as Options;\n\n this._position = vec3.fromValues(op.position[0], op.position[1], op.position[2]);\n this._scale = vec3.fromValues(op.scale[0], op.scale[1], op.scale[2]);\n this._rotation = vec3.fromValues(op.rotation[0], op.rotation[1], op.rotation[2]);\n this._perspective = op.perspective;\n this._rotateOffset = op.rotateOffset;\n this._updateTimer = -1;\n\n const element = this._element;\n const viewport = document.createElement('div');\n const camera = viewport.cloneNode() as HTMLElement;\n const world = viewport.cloneNode() as HTMLElement;\n\n viewport.className = DEFAULT.CLASS.VIEWPORT;\n camera.className = DEFAULT.CLASS.CAMERA;\n world.className = DEFAULT.CLASS.WORLD;\n\n applyCSS(viewport, DEFAULT.STYLE.VIEWPORT);\n applyCSS(camera, DEFAULT.STYLE.CAMERA);\n applyCSS(world, DEFAULT.STYLE.WORLD);\n\n camera.appendChild(world);\n viewport.appendChild(camera);\n\n this._viewportEl = viewport;\n this._cameraEl = camera;\n this._worldEl = world;\n\n // EL's PARENT -> VIEWPORT -> CAMERA -> WORLD -> EL\n element.parentElement!.insertBefore(viewport, element);\n world.appendChild(element);\n\n this.update(0);\n }\n\n /**\n * Focus a camera to given element.\n * After focus, element will be in front of camera with no rotation applied.\n * Also, it will have original width / height if neither [scale](#scale) nor [perspectiveOffset](#perspectiveOffset) is applied.\n * This method won't work if any of element's parent except camera element has scale applied.\n * @param - The element to focus. Can be HTMLElement or CSS selector.\n * @return {CSSCamera} The instance itself\n */\n public focus(el: string | HTMLElement): this {\n const element = getElement(el);\n const focusMatrix = this._getFocusMatrix(element);\n\n const rotation = quat.create();\n const translation = vec3.create();\n mat4.getRotation(rotation, focusMatrix);\n mat4.getTranslation(translation, focusMatrix);\n\n const eulerAngle = quatToEuler(rotation);\n\n vec3.negate(eulerAngle, eulerAngle);\n\n this._rotation = eulerAngle;\n this._position = translation;\n return this;\n }\n\n /**\n * Translate a camera in its local coordinate space.\n * For example, `camera.translateLocal(0, 0, -300)` will always move camera to direction where it's seeing.\n * @param - Amount of horizontal translation, in px.\n * @param - Amount of vertical translation, in px.\n * @param - Amount of translation in view direction, in px.\n * @return {CSSCamera} The instance itself\n */\n public translateLocal(x: number = 0, y: number = 0, z: number = 0): this {\n const position = this._position;\n const rotation = this._rotation;\n\n const transVec = vec3.fromValues(x, y, z);\n const rotQuat = quat.create();\n quat.fromEuler(rotQuat, -rotation[0], -rotation[1], -rotation[2]);\n vec3.transformQuat(transVec, transVec, rotQuat);\n\n vec3.add(position, position, transVec);\n return this;\n }\n\n /**\n * Translate a camera in world(absolute) coordinate space.\n * @param - Amount of translation in x axis, in px.\n * @param - Amount of translation in y axis, in px.\n * @param - Amount of translation in z axis, in px.\n * @return {CSSCamera} The instance itself\n */\n public translate(x: number = 0, y: number = 0, z: number = 0): this {\n vec3.add(this._position, this._position, vec3.fromValues(x, y, z));\n\n return this;\n }\n\n /**\n * Rotate a camera in world(absolute) coordinate space.\n * @param - Amount of rotation in x axis, in degree.\n * @param - Amount of rotation in y axis, in degree.\n * @param - Amount of rotation in z axis, in degree.\n * @return {CSSCamera} The instance itself\n */\n public rotate(x: number = 0, y: number = 0, z: number = 0): this {\n vec3.add(this._rotation, this._rotation, vec3.fromValues(x, y, z));\n\n return this;\n }\n\n /**\n * Updates a camera CSS with given duration.\n * Every other camera transforming properties / methods will be batched until this method is called.\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.cameraEl.style.transform); // ''\n *\n * camera.perspective = 300;\n * camera.translate(0, 0, 300);\n * camera.rotate(0, 90, 0);\n * console.log(camera.cameraEl.style.transform); // '', Not changed!\n *\n * await camera.update(1000); // Camera style is updated.\n * console.log(camera.cameraEl.style.transform); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(90deg) rotateZ(0deg)\n *\n * // When if you want to apply multiple properties\n * camera.update(1000, {\n * property: \"transform, background-color\",\n * timingFunction: \"ease-out, ease-out\", // As same with CSS, you should assign values to each property\n * delay: \"0ms, 100ms\"\n * });\n * @param - Transition duration in ms.\n * @param {Partial} [options] Transition options.\n * @param {string} [options.property=\"transform\"] CSS [transition-property](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-property) to apply.\n * @param {string} [options.timingFunction=\"ease-out\"] CSS [transition-timing-function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function) to apply.\n * @param {string} [options.delay=\"0ms\"] CSS [transition-delay](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-delay) to apply.\n * @return {Promise} A promise resolving instance itself\n */\n public async update(duration: number = 0, options: Partial = {}): Promise {\n applyCSS(this._viewportEl, { perspective: `${this.perspective}px` });\n applyCSS(this._cameraEl, { transform: this.cameraCSS });\n applyCSS(this._worldEl, { transform: this.worldCSS });\n\n const updateOptions = assign(assign({}, DEFAULT.UPDATE_OPTIONS), options) as UpdateOption;\n\n if (duration > 0) {\n if (this._updateTimer > 0) {\n window.clearTimeout(this._updateTimer);\n }\n\n const transitionDuration = `${duration}ms`;\n const updateOption = Object.keys(updateOptions).reduce((option: {[key: string]: ValueOf}, key) => {\n option[`transition${key.charAt(0).toUpperCase() + key.slice(1)}`] = updateOptions[key as keyof UpdateOption]!;\n return option;\n }, {});\n\n const finalOption = {\n transitionDuration,\n ...updateOption,\n };\n\n [this._viewportEl, this._cameraEl, this._worldEl].forEach(el => {\n applyCSS(el, finalOption);\n });\n }\n\n return new Promise(resolve => {\n // Make sure to use requestAnimationFrame even if duration is 0\n // To make sure DOM is updated, for successive update() calls.\n if (duration > 0) {\n this._updateTimer = window.setTimeout(() => {\n // Reset transition values\n [this._viewportEl, this._cameraEl, this._worldEl].forEach(el => {\n applyCSS(el, { transition: '' });\n });\n this._updateTimer = -1;\n resolve();\n }, duration);\n } else {\n requestAnimationFrame(() => {\n resolve();\n });\n }\n });\n }\n\n private _getFocusMatrix(element: HTMLElement): mat4 {\n const elements: HTMLElement[] = [];\n while (element) {\n elements.push(element);\n if (element === this._element) break;\n element = element.parentElement!;\n }\n\n // Order by shallow to deep\n elements.reverse();\n\n const elStyles = elements.map(el => window.getComputedStyle(el));\n\n // Find first element that transform-style is not preserve-3d\n // As all childs of that element is affected by its matrix\n const firstFlatIndex = findIndex(elStyles, style => style.transformStyle !== 'preserve-3d');\n if (firstFlatIndex > 0) { // el doesn't have to be preserve-3d'ed\n elStyles.splice(firstFlatIndex + 1);\n }\n\n let parentOffset: Offset = {\n left: 0,\n top: 0,\n width: this.viewportEl.offsetWidth,\n height: this.viewportEl.offsetHeight,\n };\n\n // Accumulated rotation\n const accRotation = quat.identity(quat.create());\n // Assume center of screen as (0, 0, 0)\n const centerPos = vec3.fromValues(0, 0, 0);\n\n elStyles.forEach((style, idx) => {\n const el = elements[idx];\n const currentOffset = {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n };\n const transformMat = getTransformMatrix(style);\n const offsetFromParent = getOffsetFromParent(currentOffset, parentOffset);\n vec3.transformQuat(offsetFromParent, offsetFromParent, accRotation);\n\n vec3.add(centerPos, centerPos, offsetFromParent);\n\n const rotateOffset = getRotateOffset(style, currentOffset);\n vec3.transformQuat(rotateOffset, rotateOffset, accRotation);\n\n const transformOrigin = vec3.clone(centerPos);\n vec3.add(transformOrigin, transformOrigin, rotateOffset);\n\n const centerFromOrigin = vec3.create();\n vec3.sub(centerFromOrigin, centerPos, transformOrigin);\n\n const invAccRotation = quat.invert(quat.create(), accRotation);\n vec3.transformQuat(centerFromOrigin, centerFromOrigin, invAccRotation);\n vec3.transformMat4(centerFromOrigin, centerFromOrigin, transformMat);\n vec3.transformQuat(centerFromOrigin, centerFromOrigin, accRotation);\n\n const newCenterPos = vec3.add(vec3.create(), transformOrigin, centerFromOrigin);\n const rotation = mat4.getRotation(quat.create(), transformMat);\n\n vec3.copy(centerPos, newCenterPos);\n quat.mul(accRotation, accRotation, rotation);\n parentOffset = currentOffset;\n });\n\n const perspective = vec3.fromValues(0, 0, this.perspective);\n vec3.transformQuat(perspective, perspective, accRotation);\n vec3.add(centerPos, centerPos, perspective);\n\n const matrix = mat4.create();\n mat4.fromRotationTranslation(matrix, accRotation, centerPos);\n\n return matrix;\n }\n}\n\nexport default CSSCamera;\n"],"names":["ELEMENT_NOT_EXIST","selector","MUST_STRING_OR_ELEMENT","received","getElement","el","baseElement","queryResult","querySelector","document","Error","nodeName","nodeType","applyCSS","element","cssObj","Object","keys","forEach","property","style","getTransformMatrix","elStyle","trVal","getPropertyValue","transformStr","exec","matrixVal","split","map","val","parseFloat","length","mat4","fromValues","matrix","create","identity","getOffsetFromParent","currentOffset","parentOffset","offsetLeft","left","width","offsetTop","top","height","vec3","getRotateOffset","axis","transformOrigin","str","substring","ax","ay","findIndex","iterable","callback","i","clamp","min","max","Math","assign","target","_i","srcs","source","key","value","radToDeg","rad","PI","quatToEuler","q","rotM","fromQuat","m11","m12","m21","m22","m31","m32","m33","euler","asin","abs","atan2","STYLE","VIEWPORT","overflow","CAMERA","WORLD","CLASS","OPTIONS","position","scale","rotation","perspective","rotateOffset","UPDATE_OPTIONS","timingFunction","delay","options","_element","op","DEFAULT","_position","_scale","_rotation","_perspective","_rotateOffset","_updateTimer","viewport","createElement","camera","cloneNode","world","className","appendChild","_viewportEl","_cameraEl","_worldEl","parentElement","insertBefore","update","CSSCamera","r","quaternion","quat","fromEuler","focusMatrix","_getFocusMatrix","translation","getRotation","getTranslation","eulerAngle","negate","x","y","z","transVec","rotQuat","transformQuat","add","duration","Promise","transform","cameraCSS","worldCSS","updateOptions","window","clearTimeout","transitionDuration","updateOption","reduce","option","charAt","toUpperCase","slice","finalOption_1","resolve","_this","setTimeout","transition","requestAnimationFrame","elements","push","reverse","elStyles","getComputedStyle","firstFlatIndex","transformStyle","splice","viewportEl","offsetWidth","offsetHeight","accRotation","centerPos","idx","transformMat","offsetFromParent","clone","centerFromOrigin","sub","invAccRotation","invert","transformMat4","newCenterPos","copy","mul","fromRotationTranslation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,IAAMA,iBAAiB,GAAG,UAACC,QAAD;SAAsB,6BAA0BA,QAA1B,sBAAA;CAAhD;AACP,AAAO,IAAMC,sBAAsB,GAAG,UAACC,QAAD;SAAmB,oEAAkEA,QAAlE;CAAlD;;ACGA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GF,IAAI,CAACG,MAAL,EAAf;IACAH,IAAI,CAAC8J,uBAAL,CAA6B5J,MAA7B,EAAqC8I,WAArC,EAAkDC,SAAlD;WAEO/I,MAAP;GA3EM;;kBA6EV;GA/bA;;;;"} \ No newline at end of file diff --git a/lib/css-camera.js b/lib/css-camera.js new file mode 100644 index 0000000..14f42a4 --- /dev/null +++ b/lib/css-camera.js @@ -0,0 +1,726 @@ +/* +Copyright (c) 2019 WoodNeck +name: css-camera +license: MIT +author: WoodNeck +repository: git+https://github.com/WoodNeck/css-camera.git +version: 1.0.1 +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('gl-matrix')) : + typeof define === 'function' && define.amd ? define(['gl-matrix'], factory) : + (global = global || self, global.CSSCamera = factory(global['gl-matrix'])); +}(this, function (glMatrix) { 'use strict'; + + /*! ***************************************************************************** + Copyright (c) Microsoft Corporation. All rights reserved. + 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 + + THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED + WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + MERCHANTABLITY OR NON-INFRINGEMENT. + + See the Apache Version 2.0 License for specific language governing permissions + and limitations under the License. + ***************************************************************************** */ + var __assign = function () { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + + return t; + }; + + return __assign.apply(this, arguments); + }; + function __awaiter(thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + + function step(result) { + result.done ? resolve(result.value) : new P(function (resolve) { + resolve(result.value); + }).then(fulfilled, rejected); + } + + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + } + function __generator(thisArg, body) { + var _ = { + label: 0, + sent: function () { + if (t[0] & 1) throw t[1]; + return t[1]; + }, + trys: [], + ops: [] + }, + f, + y, + t, + g; + return g = { + next: verb(0), + "throw": verb(1), + "return": verb(2) + }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { + return this; + }), g; + + function verb(n) { + return function (v) { + return step([n, v]); + }; + } + + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + + switch (op[0]) { + case 0: + case 1: + t = op; + break; + + case 4: + _.label++; + return { + value: op[1], + done: false + }; + + case 5: + _.label++; + y = op[1]; + op = [0]; + continue; + + case 7: + op = _.ops.pop(); + + _.trys.pop(); + + continue; + + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { + _ = 0; + continue; + } + + if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { + _.label = op[1]; + break; + } + + if (op[0] === 6 && _.label < t[1]) { + _.label = t[1]; + t = op; + break; + } + + if (t && _.label < t[2]) { + _.label = t[2]; + + _.ops.push(op); + + break; + } + + if (t[2]) _.ops.pop(); + + _.trys.pop(); + + continue; + } + + op = body.call(thisArg, _); + } catch (e) { + op = [6, e]; + y = 0; + } finally { + f = t = 0; + } + + if (op[0] & 5) throw op[1]; + return { + value: op[0] ? op[1] : void 0, + done: true + }; + } + } + function __read(o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), + r, + ar = [], + e; + + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } catch (error) { + e = { + error: error + }; + } finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } finally { + if (e) throw e.error; + } + } + + return ar; + } + function __spread() { + for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); + + return ar; + } + + var ELEMENT_NOT_EXIST = function (selector) { + return "Element with selector \"" + selector + "\" doesn't exist."; + }; + var MUST_STRING_OR_ELEMENT = function (received) { + return "Element should be provided in string or HTMLElement. Received: " + received; + }; + + var getElement = function (el, baseElement) { + if (typeof el === 'string') { + var queryResult = baseElement ? baseElement.querySelector(el) : document.querySelector(el); + + if (!queryResult) { + throw new Error(ELEMENT_NOT_EXIST(el)); + } + + return queryResult; + } else if (el.nodeName && el.nodeType === 1) { + return el; + } else { + throw new Error(MUST_STRING_OR_ELEMENT(el)); + } + }; + function applyCSS(element, cssObj) { + Object.keys(cssObj).forEach(function (property) { + element.style[property] = cssObj[property]; + }); + } + function getTransformMatrix(elStyle) { + var trVal = elStyle.getPropertyValue('transform'); + var transformStr = /\(((\s|\S)+)\)/.exec(trVal); + var matrixVal = transformStr ? transformStr[1].split(',').map(function (val) { + return parseFloat(val); + }) : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; + + if (matrixVal.length === 16) { + return glMatrix.mat4.fromValues.apply(glMatrix.mat4, __spread(matrixVal)); + } else { + var matrix = glMatrix.mat4.create(); + glMatrix.mat4.identity(matrix); + matrix[0] = matrixVal[0]; + matrix[1] = matrixVal[1]; + matrix[4] = matrixVal[2]; + matrix[5] = matrixVal[3]; + matrix[12] = matrixVal[4]; + matrix[13] = matrixVal[5]; + return matrix; + } + } + function getOffsetFromParent(currentOffset, parentOffset) { + var offsetLeft = currentOffset.left + (currentOffset.width - parentOffset.width) / 2; + var offsetTop = currentOffset.top + (currentOffset.height - parentOffset.height) / 2; + return glMatrix.vec3.fromValues(offsetLeft, offsetTop, 0); + } + function getRotateOffset(elStyle, currentOffset) { + var axis = elStyle.transformOrigin.split(' ').map(function (str) { + return parseFloat(str.substring(0, str.length - 2)); + }); + var ax = axis[0] - currentOffset.width / 2; + var ay = axis[1] - currentOffset.height / 2; + return glMatrix.vec3.fromValues(ax, ay, 0); + } + function findIndex(iterable, callback) { + for (var i = 0; i < iterable.length; i += 1) { + var element = iterable[i]; + + if (element && callback(element)) { + return i; + } + } + + return -1; + } + function clamp(val, min, max) { + return Math.max(Math.min(val, max), min); + } + function assign(target) { + var srcs = []; + + for (var _i = 1; _i < arguments.length; _i++) { + srcs[_i - 1] = arguments[_i]; + } + + srcs.forEach(function (source) { + Object.keys(source).forEach(function (key) { + var value = source[key]; + target[key] = value; + }); + }); + return target; + } + + function radToDeg(rad) { + return 180 * rad / Math.PI; + } + function quatToEuler(q) { + var rotM = glMatrix.mat4.create(); + glMatrix.mat4.fromQuat(rotM, q); + var m11 = rotM[0]; + var m12 = rotM[4]; + var m21 = rotM[1]; + var m22 = rotM[5]; + var m31 = rotM[2]; + var m32 = rotM[6]; + var m33 = rotM[10]; + var euler = glMatrix.vec3.create(); + euler[1] = Math.asin(-clamp(m31, -1, 1)); + + if (Math.abs(m31) < 0.99999) { + euler[0] = Math.atan2(m32, m33); + euler[2] = Math.atan2(m21, m11); + } else { + euler[0] = 0; + euler[2] = Math.atan2(-m12, m22); + } + + return euler.map(function (val) { + return radToDeg(val); + }); + } + + var STYLE = { + VIEWPORT: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + overflow: 'hidden' + }, + CAMERA: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + 'will-change': 'transform' + }, + WORLD: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + 'will-change': 'transform' + } + }; + var CLASS = { + VIEWPORT: 'cc-viewport', + CAMERA: 'cc-camera', + WORLD: 'cc-world' + }; + var OPTIONS = { + position: [0, 0, 0], + scale: [1, 1, 1], + rotation: [0, 0, 0], + perspective: 0, + rotateOffset: 0 + }; + var UPDATE_OPTIONS = { + property: 'transform', + timingFunction: 'ease-out', + delay: '0ms' + }; + + var CSSCamera = function () { + function CSSCamera(el, options) { + if (options === void 0) { + options = {}; + } + + this._element = getElement(el); + var op = assign(assign({}, OPTIONS), options); + this._position = glMatrix.vec3.fromValues(op.position[0], op.position[1], op.position[2]); + this._scale = glMatrix.vec3.fromValues(op.scale[0], op.scale[1], op.scale[2]); + this._rotation = glMatrix.vec3.fromValues(op.rotation[0], op.rotation[1], op.rotation[2]); + this._perspective = op.perspective; + this._rotateOffset = op.rotateOffset; + this._updateTimer = -1; + var element = this._element; + var viewport = document.createElement('div'); + var camera = viewport.cloneNode(); + var world = viewport.cloneNode(); + viewport.className = CLASS.VIEWPORT; + camera.className = CLASS.CAMERA; + world.className = CLASS.WORLD; + applyCSS(viewport, STYLE.VIEWPORT); + applyCSS(camera, STYLE.CAMERA); + applyCSS(world, STYLE.WORLD); + camera.appendChild(world); + viewport.appendChild(camera); + this._viewportEl = viewport; + this._cameraEl = camera; + this._worldEl = world; + element.parentElement.insertBefore(viewport, element); + world.appendChild(element); + this.update(0); + } + + var __proto = CSSCamera.prototype; + Object.defineProperty(CSSCamera, "VERSION", { + get: function () { + return '1.0.1'; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "element", { + get: function () { + return this._element; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "viewportEl", { + get: function () { + return this._viewportEl; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "cameraEl", { + get: function () { + return this._cameraEl; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "worldEl", { + get: function () { + return this._worldEl; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "position", { + get: function () { + return __spread(this._position); + }, + set: function (val) { + this._position = glMatrix.vec3.fromValues(val[0], val[1], val[2]); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "scale", { + get: function () { + return __spread(this._scale); + }, + set: function (val) { + this._scale = glMatrix.vec3.fromValues(val[0], val[1], val[2]); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "rotation", { + get: function () { + return __spread(this._rotation); + }, + set: function (val) { + this._rotation = glMatrix.vec3.fromValues(val[0], val[1], val[2]); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "quaternion", { + get: function () { + var r = this._rotation; + var quaternion = glMatrix.quat.fromEuler(glMatrix.quat.create(), r[0], r[1], r[2]); + return __spread(quaternion); + }, + set: function (val) { + this._rotation = quatToEuler(glMatrix.quat.fromValues(val[0], val[1], val[2], val[3])); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "perspective", { + get: function () { + return this._perspective; + }, + set: function (val) { + this._perspective = val; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "rotateOffset", { + get: function () { + return this._rotateOffset; + }, + set: function (val) { + this._rotateOffset = val; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "cameraCSS", { + get: function () { + var perspective = this._perspective; + var rotateOffset = this._rotateOffset; + var rotation = this._rotation; + var scale = this._scale; + return "scale3d(" + scale[0] + ", " + scale[1] + ", " + scale[2] + ") translateZ(" + (perspective - rotateOffset) + "px) rotateX(" + rotation[0] + "deg) rotateY(" + rotation[1] + "deg) rotateZ(" + rotation[2] + "deg)"; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "worldCSS", { + get: function () { + var position = this._position; + return "translate3d(" + -position[0] + "px, " + -position[1] + "px, " + -position[2] + "px)"; + }, + enumerable: true, + configurable: true + }); + + __proto.focus = function (el) { + var element = getElement(el); + + var focusMatrix = this._getFocusMatrix(element); + + var rotation = glMatrix.quat.create(); + var translation = glMatrix.vec3.create(); + glMatrix.mat4.getRotation(rotation, focusMatrix); + glMatrix.mat4.getTranslation(translation, focusMatrix); + var eulerAngle = quatToEuler(rotation); + glMatrix.vec3.negate(eulerAngle, eulerAngle); + this._rotation = eulerAngle; + this._position = translation; + return this; + }; + + __proto.translateLocal = function (x, y, z) { + if (x === void 0) { + x = 0; + } + + if (y === void 0) { + y = 0; + } + + if (z === void 0) { + z = 0; + } + + var position = this._position; + var rotation = this._rotation; + var transVec = glMatrix.vec3.fromValues(x, y, z); + var rotQuat = glMatrix.quat.create(); + glMatrix.quat.fromEuler(rotQuat, -rotation[0], -rotation[1], -rotation[2]); + glMatrix.vec3.transformQuat(transVec, transVec, rotQuat); + glMatrix.vec3.add(position, position, transVec); + return this; + }; + + __proto.translate = function (x, y, z) { + if (x === void 0) { + x = 0; + } + + if (y === void 0) { + y = 0; + } + + if (z === void 0) { + z = 0; + } + + glMatrix.vec3.add(this._position, this._position, glMatrix.vec3.fromValues(x, y, z)); + return this; + }; + + __proto.rotate = function (x, y, z) { + if (x === void 0) { + x = 0; + } + + if (y === void 0) { + y = 0; + } + + if (z === void 0) { + z = 0; + } + + glMatrix.vec3.add(this._rotation, this._rotation, glMatrix.vec3.fromValues(x, y, z)); + return this; + }; + + __proto.update = function (duration, options) { + if (duration === void 0) { + duration = 0; + } + + if (options === void 0) { + options = {}; + } + + return __awaiter(this, void 0, Promise, function () { + var updateOptions, transitionDuration, updateOption, finalOption_1; + + var _this = this; + + return __generator(this, function (_a) { + applyCSS(this._viewportEl, { + perspective: this.perspective + "px" + }); + applyCSS(this._cameraEl, { + transform: this.cameraCSS + }); + applyCSS(this._worldEl, { + transform: this.worldCSS + }); + updateOptions = assign(assign({}, UPDATE_OPTIONS), options); + + if (duration > 0) { + if (this._updateTimer > 0) { + window.clearTimeout(this._updateTimer); + } + + transitionDuration = duration + "ms"; + updateOption = Object.keys(updateOptions).reduce(function (option, key) { + option["transition" + (key.charAt(0).toUpperCase() + key.slice(1))] = updateOptions[key]; + return option; + }, {}); + finalOption_1 = __assign({ + transitionDuration: transitionDuration + }, updateOption); + [this._viewportEl, this._cameraEl, this._worldEl].forEach(function (el) { + applyCSS(el, finalOption_1); + }); + } + + return [2, new Promise(function (resolve) { + if (duration > 0) { + _this._updateTimer = window.setTimeout(function () { + [_this._viewportEl, _this._cameraEl, _this._worldEl].forEach(function (el) { + applyCSS(el, { + transition: '' + }); + }); + _this._updateTimer = -1; + resolve(); + }, duration); + } else { + requestAnimationFrame(function () { + resolve(); + }); + } + })]; + }); + }); + }; + + __proto._getFocusMatrix = function (element) { + var elements = []; + + while (element) { + elements.push(element); + if (element === this._element) break; + element = element.parentElement; + } + + elements.reverse(); + var elStyles = elements.map(function (el) { + return window.getComputedStyle(el); + }); + var firstFlatIndex = findIndex(elStyles, function (style) { + return style.transformStyle !== 'preserve-3d'; + }); + + if (firstFlatIndex > 0) { + elStyles.splice(firstFlatIndex + 1); + } + + var parentOffset = { + left: 0, + top: 0, + width: this.viewportEl.offsetWidth, + height: this.viewportEl.offsetHeight + }; + var accRotation = glMatrix.quat.identity(glMatrix.quat.create()); + var centerPos = glMatrix.vec3.fromValues(0, 0, 0); + elStyles.forEach(function (style, idx) { + var el = elements[idx]; + var currentOffset = { + left: el.offsetLeft, + top: el.offsetTop, + width: el.offsetWidth, + height: el.offsetHeight + }; + var transformMat = getTransformMatrix(style); + var offsetFromParent = getOffsetFromParent(currentOffset, parentOffset); + glMatrix.vec3.transformQuat(offsetFromParent, offsetFromParent, accRotation); + glMatrix.vec3.add(centerPos, centerPos, offsetFromParent); + var rotateOffset = getRotateOffset(style, currentOffset); + glMatrix.vec3.transformQuat(rotateOffset, rotateOffset, accRotation); + var transformOrigin = glMatrix.vec3.clone(centerPos); + glMatrix.vec3.add(transformOrigin, transformOrigin, rotateOffset); + var centerFromOrigin = glMatrix.vec3.create(); + glMatrix.vec3.sub(centerFromOrigin, centerPos, transformOrigin); + var invAccRotation = glMatrix.quat.invert(glMatrix.quat.create(), accRotation); + glMatrix.vec3.transformQuat(centerFromOrigin, centerFromOrigin, invAccRotation); + glMatrix.vec3.transformMat4(centerFromOrigin, centerFromOrigin, transformMat); + glMatrix.vec3.transformQuat(centerFromOrigin, centerFromOrigin, accRotation); + var newCenterPos = glMatrix.vec3.add(glMatrix.vec3.create(), transformOrigin, centerFromOrigin); + var rotation = glMatrix.mat4.getRotation(glMatrix.quat.create(), transformMat); + glMatrix.vec3.copy(centerPos, newCenterPos); + glMatrix.quat.mul(accRotation, accRotation, rotation); + parentOffset = currentOffset; + }); + var perspective = glMatrix.vec3.fromValues(0, 0, this.perspective); + glMatrix.vec3.transformQuat(perspective, perspective, accRotation); + glMatrix.vec3.add(centerPos, centerPos, perspective); + var matrix = glMatrix.mat4.create(); + glMatrix.mat4.fromRotationTranslation(matrix, accRotation, centerPos); + return matrix; + }; + + return CSSCamera; + }(); + + return CSSCamera; + +})); +//# sourceMappingURL=css-camera.js.map diff --git a/lib/css-camera.js.map b/lib/css-camera.js.map new file mode 100644 index 0000000..301799f --- /dev/null +++ b/lib/css-camera.js.map @@ -0,0 +1 @@ +{"version":3,"file":"css-camera.js","sources":["../src/constants/error.ts","../src/utils/helper.ts","../src/utils/math.ts","../src/constants/default.ts","../src/CSSCamera.ts"],"sourcesContent":["export const ELEMENT_NOT_EXIST = (selector: string) => `Element with selector \"${selector}\" doesn't exist.`;\nexport const MUST_STRING_OR_ELEMENT = (received: any) => `Element should be provided in string or HTMLElement. Received: ${received}`;\n","import { mat4, vec3 } from 'gl-matrix';\nimport { ELEMENT_NOT_EXIST, MUST_STRING_OR_ELEMENT } from '../constants/error';\nimport { Matrix4x4, Offset } from '../types';\n\nexport const getElement = (el: string | HTMLElement, baseElement?: HTMLElement): HTMLElement => {\n if (typeof el === 'string') {\n const queryResult = baseElement\n ? baseElement.querySelector(el)\n : document.querySelector(el);\n if (!queryResult) {\n throw new Error(ELEMENT_NOT_EXIST(el));\n }\n return queryResult as HTMLElement;\n } else if (el.nodeName && el.nodeType === 1) {\n return el;\n } else {\n throw new Error(MUST_STRING_OR_ELEMENT(el));\n }\n};\n\nexport function applyCSS(element: HTMLElement, cssObj: { [keys: string]: string }): void {\n Object.keys(cssObj).forEach(property => {\n (element.style as any)[property] = cssObj[property];\n });\n}\n\nexport function getTransformMatrix(elStyle: CSSStyleDeclaration): mat4 {\n const trVal = elStyle.getPropertyValue('transform');\n const transformStr = /\\(((\\s|\\S)+)\\)/.exec(trVal);\n const matrixVal = transformStr\n ? transformStr[1].split(',').map(val => parseFloat(val)) as Matrix4x4\n : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] as Matrix4x4;\n if (matrixVal.length === 16 ) {\n return mat4.fromValues(...matrixVal);\n } else {\n // Convert 2d matrix(length 6) to 3d\n const matrix = mat4.create();\n mat4.identity(matrix);\n\n matrix[0] = matrixVal[0];\n matrix[1] = matrixVal[1];\n matrix[4] = matrixVal[2];\n matrix[5] = matrixVal[3];\n matrix[12] = matrixVal[4];\n matrix[13] = matrixVal[5];\n\n return matrix;\n }\n}\n\nexport function getOffsetFromParent(currentOffset: Offset, parentOffset: Offset): vec3 {\n const offsetLeft = currentOffset.left + (currentOffset.width - parentOffset.width) / 2;\n const offsetTop = currentOffset.top + (currentOffset.height - parentOffset.height) / 2;\n\n return vec3.fromValues(offsetLeft, offsetTop, 0);\n}\n\nexport function getRotateOffset(elStyle: CSSStyleDeclaration, currentOffset: Offset): vec3 {\n const axis = (elStyle.transformOrigin as string)\n .split(' ')\n .map(str => parseFloat(str.substring(0, str.length - 2)));\n const ax = axis[0] - currentOffset.width / 2;\n const ay = axis[1] - currentOffset.height / 2;\n\n return vec3.fromValues(ax, ay, 0);\n}\n\nexport function findIndex(iterable: T[], callback: (el: T) => boolean): number {\n for (let i = 0; i < iterable.length; i += 1) {\n const element = iterable[i];\n if (element && callback(element)) {\n return i;\n }\n }\n\n return -1;\n}\n\n// return [0, 1, ...., max - 1]\nexport function range(max: number): number[] {\n const counterArray: number[] = [];\n for (let i = 0; i < max; i += 1) {\n counterArray[i] = i;\n }\n return counterArray;\n}\n\nexport function clamp(val: number, min: number, max: number): number {\n return Math.max(Math.min(val, max), min);\n}\n\nexport function assign(target: object, ...srcs: object[]): object {\n srcs.forEach(source => {\n Object.keys(source).forEach(key => {\n const value = (source as any)[key];\n (target as any)[key] = value;\n });\n });\n\n return target;\n}\n","import { mat4, quat, vec3 } from 'gl-matrix';\nimport { clamp } from './helper';\n\nexport function degToRad(deg: number): number {\n return Math.PI * deg / 180;\n}\n\nexport function radToDeg(rad: number): number {\n return 180 * rad / Math.PI;\n}\n\n// From Three.js https://github.com/mrdoob/three.js/blob/dev/src/math/Euler.js\nexport function quatToEuler(q: quat): vec3 {\n const rotM = mat4.create();\n mat4.fromQuat(rotM, q);\n\n const m11 = rotM[0];\n const m12 = rotM[4];\n // const m13 = rotM[8];\n const m21 = rotM[1];\n const m22 = rotM[5];\n // const m23 = rotM[9];\n const m31 = rotM[2];\n const m32 = rotM[6];\n const m33 = rotM[10];\n\n const euler = vec3.create();\n\n // ZYX\n euler[1] = Math.asin(-clamp(m31, -1, 1));\n if (Math.abs(m31) < 0.99999) {\n euler[0] = Math.atan2(m32, m33);\n euler[2] = Math.atan2(m21, m11);\n } else {\n euler[0] = 0;\n euler[2] = Math.atan2(-m12, m22);\n }\n\n return euler.map(val => radToDeg(val)) as vec3;\n}\n","export const STYLE = {\n VIEWPORT: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n overflow: 'hidden',\n },\n CAMERA: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n 'will-change': 'transform',\n },\n WORLD: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n 'will-change': 'transform',\n },\n};\n\nexport const CLASS = {\n VIEWPORT: 'cc-viewport',\n CAMERA: 'cc-camera',\n WORLD: 'cc-world',\n};\n\nexport const OPTIONS = {\n position: [0, 0, 0],\n scale: [1, 1, 1],\n rotation: [0, 0, 0],\n perspective: 0,\n rotateOffset: 0,\n};\n\nexport const UPDATE_OPTIONS = {\n property: 'transform',\n timingFunction: 'ease-out',\n delay: '0ms',\n};\n","import { mat4, vec3, quat } from 'gl-matrix';\nimport { getElement, applyCSS, getTransformMatrix, findIndex, getOffsetFromParent, getRotateOffset, assign } from './utils/helper';\nimport { quatToEuler } from './utils/math';\nimport * as DEFAULT from './constants/default';\nimport { Offset, UpdateOption, ValueOf, Options } from './types';\n\nclass CSSCamera {\n private _element: HTMLElement;\n private _viewportEl: HTMLElement;\n private _cameraEl: HTMLElement;\n private _worldEl: HTMLElement;\n\n private _position: vec3;\n private _scale: vec3;\n private _rotation: vec3;\n private _perspective: number;\n private _rotateOffset: number;\n private _updateTimer: number;\n\n /**\n * Current version of CSSCamera.\n * @example\n * console.log(CSSCamera.VERSION); // ex) 1.0.0\n * @type {string}\n */\n static get VERSION() { return '#__VERSION__#'; }\n\n /**\n * The element provided in the constructor.\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.element === el); // true\n * @type {HTMLElement}\n */\n public get element() { return this._element; }\n\n /**\n * The reference of viewport DOM element.\n * @type {HTMLElement}\n */\n public get viewportEl() { return this._viewportEl; }\n\n /**\n * The reference of camera DOM element.\n * @type {HTMLElement}\n */\n public get cameraEl() { return this._cameraEl; }\n\n /**\n * The reference of world DOM element.\n * @type {HTMLElement}\n */\n public get worldEl() { return this._worldEl; }\n\n /**\n * The current position as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.position); // [0, 0, 0];\n * camera.position = [0, 0, 300];\n * console.log(camera.position); // [0, 0, 300];\n * @type {number[]}\n */\n public get position() { return [...this._position]; }\n\n /**\n * The current scale as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.scale); // [1, 1, 1];\n * camera.scale = [5, 1, 1];\n * console.log(camera.scale); // [5, 1, 1];\n * @type {number[]}\n */\n public get scale() { return [...this._scale]; }\n\n /**\n * The current Euler rotation angles in degree as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.rotation); // [0, 0, 0];\n * camera.rotation = [90, 0, 0];\n * console.log(camera.rotation); // [90, 0, 0];\n * @type {number[]}\n */\n public get rotation() { return [...this._rotation]; }\n\n /**\n * The current quaternion rotation as number array([x, y, z, w]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.quaternion); // [0, 0, 0, 1];\n * camera.rotation = [90, 0, 0];\n * console.log(camera.quaternion); // [0.7071067690849304, 0, 0, 0.7071067690849304];\n * camera.quaternion = [0, 0, 0, 1];\n * console.log(camera.rotation); // [0, -0, 0];\n * @type {number[]}\n */\n public get quaternion() {\n const r = this._rotation;\n const quaternion = quat.fromEuler(quat.create(), r[0], r[1], r[2]);\n\n return [...quaternion];\n }\n\n /**\n * The current perspective value that will be applied to viewport element.\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.perspective); // 300\n * @type {number}\n */\n public get perspective() { return this._perspective; }\n\n /**\n * The current rotate offset value that will be applied to camera element.\n * The camera will be as far away from the focal point as this value.\n * |![rot0](https://woodneck.github.io/css-camera/asset/rot0.gif)|![rot150](https://woodneck.github.io/css-camera/asset/rot150.gif)|\n * |:---:|:---:|\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * camera.rotateOffset = 100;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(400px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * @type {number}\n */\n public get rotateOffset() { return this._rotateOffset; }\n\n /**\n * CSS string can be applied to camera element based on current transform.\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * @type {string}\n */\n public get cameraCSS() {\n const perspective = this._perspective;\n const rotateOffset = this._rotateOffset;\n const rotation = this._rotation;\n const scale = this._scale;\n\n // Rotate in order of Z - Y - X\n // tslint:disable-next-line: max-line-length\n return `scale3d(${scale[0]}, ${scale[1]}, ${scale[2]}) translateZ(${perspective - rotateOffset}px) rotateX(${rotation[0]}deg) rotateY(${rotation[1]}deg) rotateZ(${rotation[2]}deg)`;\n }\n\n /**\n * CSS string can be applied to world element based on current transform.\n * ```\n * const camera = new CSSCamera(el);\n * console.log(camera.worldCSS); // \"translate3d(0px, 0px, 0px)\";\n * camera.translate(0, 0, 300);\n * console.log(camera.worldCSS); // \"translate3d(0px, 0px, -300px)\";\n * ```\n * @type {string}\n */\n public get worldCSS() {\n const position = this._position;\n\n return `translate3d(${-position[0]}px, ${-position[1]}px, ${-position[2]}px)`;\n }\n\n public set position(val: number[]) { this._position = vec3.fromValues(val[0], val[1], val[2]); }\n public set scale(val: number[]) { this._scale = vec3.fromValues(val[0], val[1], val[2]); }\n public set rotation(val: number[]) { this._rotation = vec3.fromValues(val[0], val[1], val[2]); }\n public set quaternion(val: number[]) { this._rotation = quatToEuler(quat.fromValues(val[0], val[1], val[2], val[3])); }\n public set perspective(val: number) { this._perspective = val; }\n public set rotateOffset(val: number) { this._rotateOffset = val; }\n\n /**\n * Create new CSSCamera with given element / selector.\n * @param - The element to apply camera. Can be HTMLElement or CSS selector.\n * @param {Partial} [options] Camera options\n * @param {number[]} [options.position=[0, 0, 0]] Initial position of the camera.\n * @param {number[]} [options.scale=[1, 1, 1]] Initial scale of the camera.\n * @param {number[]} [options.rotation=[0, 0, 0]] Initial Euler rotation angles(x, y, z) of the camera in degree.\n * @param {number} [options.perspective=0] Initial perspective of the camera.\n * @param {number} [options.rotateOffset=0] Initial rotate offset of the camera.\n * @example\n * const camera = new CSSCamera(\"#el\", {\n * position: [0, 0, 150], // Initial pos(x, y, z)\n * rotation: [90, 0, 0], // Initial rotation(x, y, z, in degree)\n * perspective: 300 // CSS \"perspective\" value to apply\n * });\n */\n constructor(el: string | HTMLElement, options: Partial = {}) {\n this._element = getElement(el);\n\n const op = assign(assign({}, DEFAULT.OPTIONS), options) as Options;\n\n this._position = vec3.fromValues(op.position[0], op.position[1], op.position[2]);\n this._scale = vec3.fromValues(op.scale[0], op.scale[1], op.scale[2]);\n this._rotation = vec3.fromValues(op.rotation[0], op.rotation[1], op.rotation[2]);\n this._perspective = op.perspective;\n this._rotateOffset = op.rotateOffset;\n this._updateTimer = -1;\n\n const element = this._element;\n const viewport = document.createElement('div');\n const camera = viewport.cloneNode() as HTMLElement;\n const world = viewport.cloneNode() as HTMLElement;\n\n viewport.className = DEFAULT.CLASS.VIEWPORT;\n camera.className = DEFAULT.CLASS.CAMERA;\n world.className = DEFAULT.CLASS.WORLD;\n\n applyCSS(viewport, DEFAULT.STYLE.VIEWPORT);\n applyCSS(camera, DEFAULT.STYLE.CAMERA);\n applyCSS(world, DEFAULT.STYLE.WORLD);\n\n camera.appendChild(world);\n viewport.appendChild(camera);\n\n this._viewportEl = viewport;\n this._cameraEl = camera;\n this._worldEl = world;\n\n // EL's PARENT -> VIEWPORT -> CAMERA -> WORLD -> EL\n element.parentElement!.insertBefore(viewport, element);\n world.appendChild(element);\n\n this.update(0);\n }\n\n /**\n * Focus a camera to given element.\n * After focus, element will be in front of camera with no rotation applied.\n * Also, it will have original width / height if neither [scale](#scale) nor [perspectiveOffset](#perspectiveOffset) is applied.\n * This method won't work if any of element's parent except camera element has scale applied.\n * @param - The element to focus. Can be HTMLElement or CSS selector.\n * @return {CSSCamera} The instance itself\n */\n public focus(el: string | HTMLElement): this {\n const element = getElement(el);\n const focusMatrix = this._getFocusMatrix(element);\n\n const rotation = quat.create();\n const translation = vec3.create();\n mat4.getRotation(rotation, focusMatrix);\n mat4.getTranslation(translation, focusMatrix);\n\n const eulerAngle = quatToEuler(rotation);\n\n vec3.negate(eulerAngle, eulerAngle);\n\n this._rotation = eulerAngle;\n this._position = translation;\n return this;\n }\n\n /**\n * Translate a camera in its local coordinate space.\n * For example, `camera.translateLocal(0, 0, -300)` will always move camera to direction where it's seeing.\n * @param - Amount of horizontal translation, in px.\n * @param - Amount of vertical translation, in px.\n * @param - Amount of translation in view direction, in px.\n * @return {CSSCamera} The instance itself\n */\n public translateLocal(x: number = 0, y: number = 0, z: number = 0): this {\n const position = this._position;\n const rotation = this._rotation;\n\n const transVec = vec3.fromValues(x, y, z);\n const rotQuat = quat.create();\n quat.fromEuler(rotQuat, -rotation[0], -rotation[1], -rotation[2]);\n vec3.transformQuat(transVec, transVec, rotQuat);\n\n vec3.add(position, position, transVec);\n return this;\n }\n\n /**\n * Translate a camera in world(absolute) coordinate space.\n * @param - Amount of translation in x axis, in px.\n * @param - Amount of translation in y axis, in px.\n * @param - Amount of translation in z axis, in px.\n * @return {CSSCamera} The instance itself\n */\n public translate(x: number = 0, y: number = 0, z: number = 0): this {\n vec3.add(this._position, this._position, vec3.fromValues(x, y, z));\n\n return this;\n }\n\n /**\n * Rotate a camera in world(absolute) coordinate space.\n * @param - Amount of rotation in x axis, in degree.\n * @param - Amount of rotation in y axis, in degree.\n * @param - Amount of rotation in z axis, in degree.\n * @return {CSSCamera} The instance itself\n */\n public rotate(x: number = 0, y: number = 0, z: number = 0): this {\n vec3.add(this._rotation, this._rotation, vec3.fromValues(x, y, z));\n\n return this;\n }\n\n /**\n * Updates a camera CSS with given duration.\n * Every other camera transforming properties / methods will be batched until this method is called.\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.cameraEl.style.transform); // ''\n *\n * camera.perspective = 300;\n * camera.translate(0, 0, 300);\n * camera.rotate(0, 90, 0);\n * console.log(camera.cameraEl.style.transform); // '', Not changed!\n *\n * await camera.update(1000); // Camera style is updated.\n * console.log(camera.cameraEl.style.transform); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(90deg) rotateZ(0deg)\n *\n * // When if you want to apply multiple properties\n * camera.update(1000, {\n * property: \"transform, background-color\",\n * timingFunction: \"ease-out, ease-out\", // As same with CSS, you should assign values to each property\n * delay: \"0ms, 100ms\"\n * });\n * @param - Transition duration in ms.\n * @param {Partial} [options] Transition options.\n * @param {string} [options.property=\"transform\"] CSS [transition-property](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-property) to apply.\n * @param {string} [options.timingFunction=\"ease-out\"] CSS [transition-timing-function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function) to apply.\n * @param {string} [options.delay=\"0ms\"] CSS [transition-delay](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-delay) to apply.\n * @return {Promise} A promise resolving instance itself\n */\n public async update(duration: number = 0, options: Partial = {}): Promise {\n applyCSS(this._viewportEl, { perspective: `${this.perspective}px` });\n applyCSS(this._cameraEl, { transform: this.cameraCSS });\n applyCSS(this._worldEl, { transform: this.worldCSS });\n\n const updateOptions = assign(assign({}, DEFAULT.UPDATE_OPTIONS), options) as UpdateOption;\n\n if (duration > 0) {\n if (this._updateTimer > 0) {\n window.clearTimeout(this._updateTimer);\n }\n\n const transitionDuration = `${duration}ms`;\n const updateOption = Object.keys(updateOptions).reduce((option: {[key: string]: ValueOf}, key) => {\n option[`transition${key.charAt(0).toUpperCase() + key.slice(1)}`] = updateOptions[key as keyof UpdateOption]!;\n return option;\n }, {});\n\n const finalOption = {\n transitionDuration,\n ...updateOption,\n };\n\n [this._viewportEl, this._cameraEl, this._worldEl].forEach(el => {\n applyCSS(el, finalOption);\n });\n }\n\n return new Promise(resolve => {\n // Make sure to use requestAnimationFrame even if duration is 0\n // To make sure DOM is updated, for successive update() calls.\n if (duration > 0) {\n this._updateTimer = window.setTimeout(() => {\n // Reset transition values\n [this._viewportEl, this._cameraEl, this._worldEl].forEach(el => {\n applyCSS(el, { transition: '' });\n });\n this._updateTimer = -1;\n resolve();\n }, duration);\n } else {\n requestAnimationFrame(() => {\n resolve();\n });\n }\n });\n }\n\n private _getFocusMatrix(element: HTMLElement): mat4 {\n const elements: HTMLElement[] = [];\n while (element) {\n elements.push(element);\n if (element === this._element) break;\n element = element.parentElement!;\n }\n\n // Order by shallow to deep\n elements.reverse();\n\n const elStyles = elements.map(el => window.getComputedStyle(el));\n\n // Find first element that transform-style is not preserve-3d\n // As all childs of that element is affected by its matrix\n const firstFlatIndex = findIndex(elStyles, style => style.transformStyle !== 'preserve-3d');\n if (firstFlatIndex > 0) { // el doesn't have to be preserve-3d'ed\n elStyles.splice(firstFlatIndex + 1);\n }\n\n let parentOffset: Offset = {\n left: 0,\n top: 0,\n width: this.viewportEl.offsetWidth,\n height: this.viewportEl.offsetHeight,\n };\n\n // Accumulated rotation\n const accRotation = quat.identity(quat.create());\n // Assume center of screen as (0, 0, 0)\n const centerPos = vec3.fromValues(0, 0, 0);\n\n elStyles.forEach((style, idx) => {\n const el = elements[idx];\n const currentOffset = {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n };\n const transformMat = getTransformMatrix(style);\n const offsetFromParent = getOffsetFromParent(currentOffset, parentOffset);\n vec3.transformQuat(offsetFromParent, offsetFromParent, accRotation);\n\n vec3.add(centerPos, centerPos, offsetFromParent);\n\n const rotateOffset = getRotateOffset(style, currentOffset);\n vec3.transformQuat(rotateOffset, rotateOffset, accRotation);\n\n const transformOrigin = vec3.clone(centerPos);\n vec3.add(transformOrigin, transformOrigin, rotateOffset);\n\n const centerFromOrigin = vec3.create();\n vec3.sub(centerFromOrigin, centerPos, transformOrigin);\n\n const invAccRotation = quat.invert(quat.create(), accRotation);\n vec3.transformQuat(centerFromOrigin, centerFromOrigin, invAccRotation);\n vec3.transformMat4(centerFromOrigin, centerFromOrigin, transformMat);\n vec3.transformQuat(centerFromOrigin, centerFromOrigin, accRotation);\n\n const newCenterPos = vec3.add(vec3.create(), transformOrigin, centerFromOrigin);\n const rotation = mat4.getRotation(quat.create(), transformMat);\n\n vec3.copy(centerPos, newCenterPos);\n quat.mul(accRotation, accRotation, rotation);\n parentOffset = currentOffset;\n });\n\n const perspective = vec3.fromValues(0, 0, this.perspective);\n vec3.transformQuat(perspective, perspective, accRotation);\n vec3.add(centerPos, centerPos, perspective);\n\n const matrix = mat4.create();\n mat4.fromRotationTranslation(matrix, accRotation, centerPos);\n\n return matrix;\n }\n}\n\nexport default CSSCamera;\n"],"names":["ELEMENT_NOT_EXIST","selector","MUST_STRING_OR_ELEMENT","received","getElement","el","baseElement","queryResult","querySelector","document","Error","nodeName","nodeType","applyCSS","element","cssObj","Object","keys","forEach","property","style","getTransformMatrix","elStyle","trVal","getPropertyValue","transformStr","exec","matrixVal","split","map","val","parseFloat","length","mat4","fromValues","matrix","create","identity","getOffsetFromParent","currentOffset","parentOffset","offsetLeft","left","width","offsetTop","top","height","vec3","getRotateOffset","axis","transformOrigin","str","substring","ax","ay","findIndex","iterable","callback","i","clamp","min","max","Math","assign","target","_i","srcs","source","key","value","radToDeg","rad","PI","quatToEuler","q","rotM","fromQuat","m11","m12","m21","m22","m31","m32","m33","euler","asin","abs","atan2","STYLE","VIEWPORT","overflow","CAMERA","WORLD","CLASS","OPTIONS","position","scale","rotation","perspective","rotateOffset","UPDATE_OPTIONS","timingFunction","delay","options","_element","op","DEFAULT","_position","_scale","_rotation","_perspective","_rotateOffset","_updateTimer","viewport","createElement","camera","cloneNode","world","className","appendChild","_viewportEl","_cameraEl","_worldEl","parentElement","insertBefore","update","CSSCamera","r","quaternion","quat","fromEuler","focusMatrix","_getFocusMatrix","translation","getRotation","getTranslation","eulerAngle","negate","x","y","z","transVec","rotQuat","transformQuat","add","duration","Promise","transform","cameraCSS","worldCSS","updateOptions","window","clearTimeout","transitionDuration","updateOption","reduce","option","charAt","toUpperCase","slice","finalOption_1","resolve","_this","setTimeout","transition","requestAnimationFrame","elements","push","reverse","elStyles","getComputedStyle","firstFlatIndex","transformStyle","splice","viewportEl","offsetWidth","offsetHeight","accRotation","centerPos","idx","transformMat","offsetFromParent","clone","centerFromOrigin","sub","invAccRotation","invert","transformMat4","newCenterPos","copy","mul","fromRotationTranslation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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A/B;IAEA,QAAM/D,MAAM,GAAGF,aAAI,CAACG,MAAL,EAAf;IACAH,IAAAA,aAAI,CAAC8J,uBAAL,CAA6B5J,MAA7B,EAAqC8I,WAArC,EAAkDC,SAAlD;IAEA,WAAO/I,MAAP;IACD,GA5EO;;IA6EV,kBAAA;IAAC,GA/bD;;;;;;;;"} \ No newline at end of file diff --git a/lib/css-camera.min.js b/lib/css-camera.min.js new file mode 100644 index 0000000..c125a15 --- /dev/null +++ b/lib/css-camera.min.js @@ -0,0 +1,10 @@ +/* +Copyright (c) 2019 WoodNeck +name: css-camera +license: MIT +author: WoodNeck +repository: git+https://github.com/WoodNeck/css-camera.git +version: 1.0.1 +*/ +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("gl-matrix")):"function"==typeof define&&define.amd?define(["gl-matrix"],e):(t=t||self).CSSCamera=e(t["gl-matrix"])}(this,function(m){"use strict";var u=function(){return(u=Object.assign||function(t){for(var e,r=1,n=arguments.length;ra[0]&&e[1] {\n if (typeof el === 'string') {\n const queryResult = baseElement\n ? baseElement.querySelector(el)\n : document.querySelector(el);\n if (!queryResult) {\n throw new Error(ELEMENT_NOT_EXIST(el));\n }\n return queryResult as HTMLElement;\n } else if (el.nodeName && el.nodeType === 1) {\n return el;\n } else {\n throw new Error(MUST_STRING_OR_ELEMENT(el));\n }\n};\n\nexport function applyCSS(element: HTMLElement, cssObj: { [keys: string]: string }): void {\n Object.keys(cssObj).forEach(property => {\n (element.style as any)[property] = cssObj[property];\n });\n}\n\nexport function getTransformMatrix(elStyle: CSSStyleDeclaration): mat4 {\n const trVal = elStyle.getPropertyValue('transform');\n const transformStr = /\\(((\\s|\\S)+)\\)/.exec(trVal);\n const matrixVal = transformStr\n ? transformStr[1].split(',').map(val => parseFloat(val)) as Matrix4x4\n : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] as Matrix4x4;\n if (matrixVal.length === 16 ) {\n return mat4.fromValues(...matrixVal);\n } else {\n // Convert 2d matrix(length 6) to 3d\n const matrix = mat4.create();\n mat4.identity(matrix);\n\n matrix[0] = matrixVal[0];\n matrix[1] = matrixVal[1];\n matrix[4] = matrixVal[2];\n matrix[5] = matrixVal[3];\n matrix[12] = matrixVal[4];\n matrix[13] = matrixVal[5];\n\n return matrix;\n }\n}\n\nexport function getOffsetFromParent(currentOffset: Offset, parentOffset: Offset): vec3 {\n const offsetLeft = currentOffset.left + (currentOffset.width - parentOffset.width) / 2;\n const offsetTop = currentOffset.top + (currentOffset.height - parentOffset.height) / 2;\n\n return vec3.fromValues(offsetLeft, offsetTop, 0);\n}\n\nexport function getRotateOffset(elStyle: CSSStyleDeclaration, currentOffset: Offset): vec3 {\n const axis = (elStyle.transformOrigin as string)\n .split(' ')\n .map(str => parseFloat(str.substring(0, str.length - 2)));\n const ax = axis[0] - currentOffset.width / 2;\n const ay = axis[1] - currentOffset.height / 2;\n\n return vec3.fromValues(ax, ay, 0);\n}\n\nexport function findIndex(iterable: T[], callback: (el: T) => boolean): number {\n for (let i = 0; i < iterable.length; i += 1) {\n const element = iterable[i];\n if (element && callback(element)) {\n return i;\n }\n }\n\n return -1;\n}\n\n// return [0, 1, ...., max - 1]\nexport function range(max: number): number[] {\n const counterArray: number[] = [];\n for (let i = 0; i < max; i += 1) {\n counterArray[i] = i;\n }\n return counterArray;\n}\n\nexport function clamp(val: number, min: number, max: number): number {\n return Math.max(Math.min(val, max), min);\n}\n\nexport function assign(target: object, ...srcs: object[]): object {\n srcs.forEach(source => {\n Object.keys(source).forEach(key => {\n const value = (source as any)[key];\n (target as any)[key] = value;\n });\n });\n\n return target;\n}\n","export const ELEMENT_NOT_EXIST = (selector: string) => `Element with selector \"${selector}\" doesn't exist.`;\nexport const MUST_STRING_OR_ELEMENT = (received: any) => `Element should be provided in string or HTMLElement. Received: ${received}`;\n","import { mat4, quat, vec3 } from 'gl-matrix';\nimport { clamp } from './helper';\n\nexport function degToRad(deg: number): number {\n return Math.PI * deg / 180;\n}\n\nexport function radToDeg(rad: number): number {\n return 180 * rad / Math.PI;\n}\n\n// From Three.js https://github.com/mrdoob/three.js/blob/dev/src/math/Euler.js\nexport function quatToEuler(q: quat): vec3 {\n const rotM = mat4.create();\n mat4.fromQuat(rotM, q);\n\n const m11 = rotM[0];\n const m12 = rotM[4];\n // const m13 = rotM[8];\n const m21 = rotM[1];\n const m22 = rotM[5];\n // const m23 = rotM[9];\n const m31 = rotM[2];\n const m32 = rotM[6];\n const m33 = rotM[10];\n\n const euler = vec3.create();\n\n // ZYX\n euler[1] = Math.asin(-clamp(m31, -1, 1));\n if (Math.abs(m31) < 0.99999) {\n euler[0] = Math.atan2(m32, m33);\n euler[2] = Math.atan2(m21, m11);\n } else {\n euler[0] = 0;\n euler[2] = Math.atan2(-m12, m22);\n }\n\n return euler.map(val => radToDeg(val)) as vec3;\n}\n","export const STYLE = {\n VIEWPORT: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n overflow: 'hidden',\n },\n CAMERA: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n 'will-change': 'transform',\n },\n WORLD: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n 'will-change': 'transform',\n },\n};\n\nexport const CLASS = {\n VIEWPORT: 'cc-viewport',\n CAMERA: 'cc-camera',\n WORLD: 'cc-world',\n};\n\nexport const OPTIONS = {\n position: [0, 0, 0],\n scale: [1, 1, 1],\n rotation: [0, 0, 0],\n perspective: 0,\n rotateOffset: 0,\n};\n\nexport const UPDATE_OPTIONS = {\n property: 'transform',\n timingFunction: 'ease-out',\n delay: '0ms',\n};\n","import { mat4, vec3, quat } from 'gl-matrix';\nimport { getElement, applyCSS, getTransformMatrix, findIndex, getOffsetFromParent, getRotateOffset, assign } from './utils/helper';\nimport { quatToEuler } from './utils/math';\nimport * as DEFAULT from './constants/default';\nimport { Offset, UpdateOption, ValueOf, Options } from './types';\n\nclass CSSCamera {\n private _element: HTMLElement;\n private _viewportEl: HTMLElement;\n private _cameraEl: HTMLElement;\n private _worldEl: HTMLElement;\n\n private _position: vec3;\n private _scale: vec3;\n private _rotation: vec3;\n private _perspective: number;\n private _rotateOffset: number;\n private _updateTimer: number;\n\n /**\n * Current version of CSSCamera.\n * @example\n * console.log(CSSCamera.VERSION); // ex) 1.0.0\n * @type {string}\n */\n static get VERSION() { return '#__VERSION__#'; }\n\n /**\n * The element provided in the constructor.\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.element === el); // true\n * @type {HTMLElement}\n */\n public get element() { return this._element; }\n\n /**\n * The reference of viewport DOM element.\n * @type {HTMLElement}\n */\n public get viewportEl() { return this._viewportEl; }\n\n /**\n * The reference of camera DOM element.\n * @type {HTMLElement}\n */\n public get cameraEl() { return this._cameraEl; }\n\n /**\n * The reference of world DOM element.\n * @type {HTMLElement}\n */\n public get worldEl() { return this._worldEl; }\n\n /**\n * The current position as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.position); // [0, 0, 0];\n * camera.position = [0, 0, 300];\n * console.log(camera.position); // [0, 0, 300];\n * @type {number[]}\n */\n public get position() { return [...this._position]; }\n\n /**\n * The current scale as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.scale); // [1, 1, 1];\n * camera.scale = [5, 1, 1];\n * console.log(camera.scale); // [5, 1, 1];\n * @type {number[]}\n */\n public get scale() { return [...this._scale]; }\n\n /**\n * The current Euler rotation angles in degree as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.rotation); // [0, 0, 0];\n * camera.rotation = [90, 0, 0];\n * console.log(camera.rotation); // [90, 0, 0];\n * @type {number[]}\n */\n public get rotation() { return [...this._rotation]; }\n\n /**\n * The current quaternion rotation as number array([x, y, z, w]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.quaternion); // [0, 0, 0, 1];\n * camera.rotation = [90, 0, 0];\n * console.log(camera.quaternion); // [0.7071067690849304, 0, 0, 0.7071067690849304];\n * camera.quaternion = [0, 0, 0, 1];\n * console.log(camera.rotation); // [0, -0, 0];\n * @type {number[]}\n */\n public get quaternion() {\n const r = this._rotation;\n const quaternion = quat.fromEuler(quat.create(), r[0], r[1], r[2]);\n\n return [...quaternion];\n }\n\n /**\n * The current perspective value that will be applied to viewport element.\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.perspective); // 300\n * @type {number}\n */\n public get perspective() { return this._perspective; }\n\n /**\n * The current rotate offset value that will be applied to camera element.\n * The camera will be as far away from the focal point as this value.\n * |![rot0](https://woodneck.github.io/css-camera/asset/rot0.gif)|![rot150](https://woodneck.github.io/css-camera/asset/rot150.gif)|\n * |:---:|:---:|\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * camera.rotateOffset = 100;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(400px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * @type {number}\n */\n public get rotateOffset() { return this._rotateOffset; }\n\n /**\n * CSS string can be applied to camera element based on current transform.\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * @type {string}\n */\n public get cameraCSS() {\n const perspective = this._perspective;\n const rotateOffset = this._rotateOffset;\n const rotation = this._rotation;\n const scale = this._scale;\n\n // Rotate in order of Z - Y - X\n // tslint:disable-next-line: max-line-length\n return `scale3d(${scale[0]}, ${scale[1]}, ${scale[2]}) translateZ(${perspective - rotateOffset}px) rotateX(${rotation[0]}deg) rotateY(${rotation[1]}deg) rotateZ(${rotation[2]}deg)`;\n }\n\n /**\n * CSS string can be applied to world element based on current transform.\n * ```\n * const camera = new CSSCamera(el);\n * console.log(camera.worldCSS); // \"translate3d(0px, 0px, 0px)\";\n * camera.translate(0, 0, 300);\n * console.log(camera.worldCSS); // \"translate3d(0px, 0px, -300px)\";\n * ```\n * @type {string}\n */\n public get worldCSS() {\n const position = this._position;\n\n return `translate3d(${-position[0]}px, ${-position[1]}px, ${-position[2]}px)`;\n }\n\n public set position(val: number[]) { this._position = vec3.fromValues(val[0], val[1], val[2]); }\n public set scale(val: number[]) { this._scale = vec3.fromValues(val[0], val[1], val[2]); }\n public set rotation(val: number[]) { this._rotation = vec3.fromValues(val[0], val[1], val[2]); }\n public set quaternion(val: number[]) { this._rotation = quatToEuler(quat.fromValues(val[0], val[1], val[2], val[3])); }\n public set perspective(val: number) { this._perspective = val; }\n public set rotateOffset(val: number) { this._rotateOffset = val; }\n\n /**\n * Create new CSSCamera with given element / selector.\n * @param - The element to apply camera. Can be HTMLElement or CSS selector.\n * @param {Partial} [options] Camera options\n * @param {number[]} [options.position=[0, 0, 0]] Initial position of the camera.\n * @param {number[]} [options.scale=[1, 1, 1]] Initial scale of the camera.\n * @param {number[]} [options.rotation=[0, 0, 0]] Initial Euler rotation angles(x, y, z) of the camera in degree.\n * @param {number} [options.perspective=0] Initial perspective of the camera.\n * @param {number} [options.rotateOffset=0] Initial rotate offset of the camera.\n * @example\n * const camera = new CSSCamera(\"#el\", {\n * position: [0, 0, 150], // Initial pos(x, y, z)\n * rotation: [90, 0, 0], // Initial rotation(x, y, z, in degree)\n * perspective: 300 // CSS \"perspective\" value to apply\n * });\n */\n constructor(el: string | HTMLElement, options: Partial = {}) {\n this._element = getElement(el);\n\n const op = assign(assign({}, DEFAULT.OPTIONS), options) as Options;\n\n this._position = vec3.fromValues(op.position[0], op.position[1], op.position[2]);\n this._scale = vec3.fromValues(op.scale[0], op.scale[1], op.scale[2]);\n this._rotation = vec3.fromValues(op.rotation[0], op.rotation[1], op.rotation[2]);\n this._perspective = op.perspective;\n this._rotateOffset = op.rotateOffset;\n this._updateTimer = -1;\n\n const element = this._element;\n const viewport = document.createElement('div');\n const camera = viewport.cloneNode() as HTMLElement;\n const world = viewport.cloneNode() as HTMLElement;\n\n viewport.className = DEFAULT.CLASS.VIEWPORT;\n camera.className = DEFAULT.CLASS.CAMERA;\n world.className = DEFAULT.CLASS.WORLD;\n\n applyCSS(viewport, DEFAULT.STYLE.VIEWPORT);\n applyCSS(camera, DEFAULT.STYLE.CAMERA);\n applyCSS(world, DEFAULT.STYLE.WORLD);\n\n camera.appendChild(world);\n viewport.appendChild(camera);\n\n this._viewportEl = viewport;\n this._cameraEl = camera;\n this._worldEl = world;\n\n // EL's PARENT -> VIEWPORT -> CAMERA -> WORLD -> EL\n element.parentElement!.insertBefore(viewport, element);\n world.appendChild(element);\n\n this.update(0);\n }\n\n /**\n * Focus a camera to given element.\n * After focus, element will be in front of camera with no rotation applied.\n * Also, it will have original width / height if neither [scale](#scale) nor [perspectiveOffset](#perspectiveOffset) is applied.\n * This method won't work if any of element's parent except camera element has scale applied.\n * @param - The element to focus. Can be HTMLElement or CSS selector.\n * @return {CSSCamera} The instance itself\n */\n public focus(el: string | HTMLElement): this {\n const element = getElement(el);\n const focusMatrix = this._getFocusMatrix(element);\n\n const rotation = quat.create();\n const translation = vec3.create();\n mat4.getRotation(rotation, focusMatrix);\n mat4.getTranslation(translation, focusMatrix);\n\n const eulerAngle = quatToEuler(rotation);\n\n vec3.negate(eulerAngle, eulerAngle);\n\n this._rotation = eulerAngle;\n this._position = translation;\n return this;\n }\n\n /**\n * Translate a camera in its local coordinate space.\n * For example, `camera.translateLocal(0, 0, -300)` will always move camera to direction where it's seeing.\n * @param - Amount of horizontal translation, in px.\n * @param - Amount of vertical translation, in px.\n * @param - Amount of translation in view direction, in px.\n * @return {CSSCamera} The instance itself\n */\n public translateLocal(x: number = 0, y: number = 0, z: number = 0): this {\n const position = this._position;\n const rotation = this._rotation;\n\n const transVec = vec3.fromValues(x, y, z);\n const rotQuat = quat.create();\n quat.fromEuler(rotQuat, -rotation[0], -rotation[1], -rotation[2]);\n vec3.transformQuat(transVec, transVec, rotQuat);\n\n vec3.add(position, position, transVec);\n return this;\n }\n\n /**\n * Translate a camera in world(absolute) coordinate space.\n * @param - Amount of translation in x axis, in px.\n * @param - Amount of translation in y axis, in px.\n * @param - Amount of translation in z axis, in px.\n * @return {CSSCamera} The instance itself\n */\n public translate(x: number = 0, y: number = 0, z: number = 0): this {\n vec3.add(this._position, this._position, vec3.fromValues(x, y, z));\n\n return this;\n }\n\n /**\n * Rotate a camera in world(absolute) coordinate space.\n * @param - Amount of rotation in x axis, in degree.\n * @param - Amount of rotation in y axis, in degree.\n * @param - Amount of rotation in z axis, in degree.\n * @return {CSSCamera} The instance itself\n */\n public rotate(x: number = 0, y: number = 0, z: number = 0): this {\n vec3.add(this._rotation, this._rotation, vec3.fromValues(x, y, z));\n\n return this;\n }\n\n /**\n * Updates a camera CSS with given duration.\n * Every other camera transforming properties / methods will be batched until this method is called.\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.cameraEl.style.transform); // ''\n *\n * camera.perspective = 300;\n * camera.translate(0, 0, 300);\n * camera.rotate(0, 90, 0);\n * console.log(camera.cameraEl.style.transform); // '', Not changed!\n *\n * await camera.update(1000); // Camera style is updated.\n * console.log(camera.cameraEl.style.transform); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(90deg) rotateZ(0deg)\n *\n * // When if you want to apply multiple properties\n * camera.update(1000, {\n * property: \"transform, background-color\",\n * timingFunction: \"ease-out, ease-out\", // As same with CSS, you should assign values to each property\n * delay: \"0ms, 100ms\"\n * });\n * @param - Transition duration in ms.\n * @param {Partial} [options] Transition options.\n * @param {string} [options.property=\"transform\"] CSS [transition-property](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-property) to apply.\n * @param {string} [options.timingFunction=\"ease-out\"] CSS [transition-timing-function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function) to apply.\n * @param {string} [options.delay=\"0ms\"] CSS [transition-delay](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-delay) to apply.\n * @return {Promise} A promise resolving instance itself\n */\n public async update(duration: number = 0, options: Partial = {}): Promise {\n applyCSS(this._viewportEl, { perspective: `${this.perspective}px` });\n applyCSS(this._cameraEl, { transform: this.cameraCSS });\n applyCSS(this._worldEl, { transform: this.worldCSS });\n\n const updateOptions = assign(assign({}, DEFAULT.UPDATE_OPTIONS), options) as UpdateOption;\n\n if (duration > 0) {\n if (this._updateTimer > 0) {\n window.clearTimeout(this._updateTimer);\n }\n\n const transitionDuration = `${duration}ms`;\n const updateOption = Object.keys(updateOptions).reduce((option: {[key: string]: ValueOf}, key) => {\n option[`transition${key.charAt(0).toUpperCase() + key.slice(1)}`] = updateOptions[key as keyof UpdateOption]!;\n return option;\n }, {});\n\n const finalOption = {\n transitionDuration,\n ...updateOption,\n };\n\n [this._viewportEl, this._cameraEl, this._worldEl].forEach(el => {\n applyCSS(el, finalOption);\n });\n }\n\n return new Promise(resolve => {\n // Make sure to use requestAnimationFrame even if duration is 0\n // To make sure DOM is updated, for successive update() calls.\n if (duration > 0) {\n this._updateTimer = window.setTimeout(() => {\n // Reset transition values\n [this._viewportEl, this._cameraEl, this._worldEl].forEach(el => {\n applyCSS(el, { transition: '' });\n });\n this._updateTimer = -1;\n resolve();\n }, duration);\n } else {\n requestAnimationFrame(() => {\n resolve();\n });\n }\n });\n }\n\n private _getFocusMatrix(element: HTMLElement): mat4 {\n const elements: HTMLElement[] = [];\n while (element) {\n elements.push(element);\n if (element === this._element) break;\n element = element.parentElement!;\n }\n\n // Order by shallow to deep\n elements.reverse();\n\n const elStyles = elements.map(el => window.getComputedStyle(el));\n\n // Find first element that transform-style is not preserve-3d\n // As all childs of that element is affected by its matrix\n const firstFlatIndex = findIndex(elStyles, style => style.transformStyle !== 'preserve-3d');\n if (firstFlatIndex > 0) { // el doesn't have to be preserve-3d'ed\n elStyles.splice(firstFlatIndex + 1);\n }\n\n let parentOffset: Offset = {\n left: 0,\n top: 0,\n width: this.viewportEl.offsetWidth,\n height: this.viewportEl.offsetHeight,\n };\n\n // Accumulated rotation\n const accRotation = quat.identity(quat.create());\n // Assume center of screen as (0, 0, 0)\n const centerPos = vec3.fromValues(0, 0, 0);\n\n elStyles.forEach((style, idx) => {\n const el = elements[idx];\n const currentOffset = {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n };\n const transformMat = getTransformMatrix(style);\n const offsetFromParent = getOffsetFromParent(currentOffset, parentOffset);\n vec3.transformQuat(offsetFromParent, offsetFromParent, accRotation);\n\n vec3.add(centerPos, centerPos, offsetFromParent);\n\n const rotateOffset = getRotateOffset(style, currentOffset);\n vec3.transformQuat(rotateOffset, rotateOffset, accRotation);\n\n const transformOrigin = vec3.clone(centerPos);\n vec3.add(transformOrigin, transformOrigin, rotateOffset);\n\n const centerFromOrigin = vec3.create();\n vec3.sub(centerFromOrigin, centerPos, transformOrigin);\n\n const invAccRotation = quat.invert(quat.create(), accRotation);\n vec3.transformQuat(centerFromOrigin, centerFromOrigin, invAccRotation);\n vec3.transformMat4(centerFromOrigin, centerFromOrigin, transformMat);\n vec3.transformQuat(centerFromOrigin, centerFromOrigin, accRotation);\n\n const newCenterPos = vec3.add(vec3.create(), transformOrigin, centerFromOrigin);\n const rotation = mat4.getRotation(quat.create(), transformMat);\n\n vec3.copy(centerPos, newCenterPos);\n quat.mul(accRotation, accRotation, rotation);\n parentOffset = currentOffset;\n });\n\n const perspective = vec3.fromValues(0, 0, this.perspective);\n vec3.transformQuat(perspective, perspective, accRotation);\n vec3.add(centerPos, centerPos, perspective);\n\n const matrix = mat4.create();\n mat4.fromRotationTranslation(matrix, accRotation, centerPos);\n\n return matrix;\n }\n}\n\nexport default CSSCamera;\n"],"names":["getElement","el","baseElement","queryResult","querySelector","document","Error","selector","ELEMENT_NOT_EXIST","nodeName","nodeType","received","MUST_STRING_OR_ELEMENT","applyCSS","element","cssObj","Object","keys","forEach","property","style","assign","target","_i","srcs","source","key","value","quatToEuler","q","rotM","mat4","create","fromQuat","m11","m12","m21","m22","m31","m32","m33","euler","vec3","Math","asin","val","min","max","clamp","abs","atan2","map","rad","PI","radToDeg","STYLE","width","height","overflow","CLASS","OPTIONS","position","scale","rotation","perspective","rotateOffset","UPDATE_OPTIONS","timingFunction","delay","options","_element","op","DEFAULT","_position","fromValues","_scale","_rotation","_perspective","_rotateOffset","_updateTimer","this","viewport","createElement","camera","cloneNode","world","className","appendChild","_viewportEl","_cameraEl","_worldEl","parentElement","insertBefore","update","CSSCamera","r","quat","fromEuler","focusMatrix","_getFocusMatrix","translation","getRotation","getTranslation","eulerAngle","negate","x","y","z","transVec","rotQuat","transformQuat","add","duration","Promise","transform","cameraCSS","worldCSS","updateOptions","window","clearTimeout","transitionDuration","updateOption","reduce","option","charAt","toUpperCase","slice","finalOption_1","resolve","_this","setTimeout","transition","requestAnimationFrame","elements","push","reverse","elStyles","getComputedStyle","firstFlatIndex","iterable","callback","i","length","findIndex","transformStyle","splice","parentOffset","left","top","viewportEl","offsetWidth","offsetHeight","accRotation","identity","centerPos","idx","currentOffset","offsetLeft","offsetTop","transformMat","elStyle","trVal","getPropertyValue","transformStr","exec","matrixVal","split","parseFloat","matrix","getTransformMatrix","offsetFromParent","getOffsetFromParent","axis","transformOrigin","str","substring","ax","ay","getRotateOffset","clone","centerFromOrigin","sub","invAccRotation","invert","transformMat4","newCenterPos","copy","mul","fromRotationTranslation"],"mappings":";;;;;;;;21DAI0B,SAAbA,EAAcC,EAA0BC,MAC/B,iBAAPD,EAAiB,KAClBE,EAAcD,EAChBA,EAAYE,cAAcH,GAC1BI,SAASD,cAAcH,OACtBE,QACK,IAAIG,MCVW,SAACC,SAAqB,0BAA0BA,sBDUrDC,CAAkBP,WAE/BE,EACJ,GAAIF,EAAGQ,UAA4B,IAAhBR,EAAGS,gBAClBT,QAED,IAAIK,MCfoB,SAACK,SAAkB,kEAAkEA,EDenGC,CAAuBX,aAI/BY,EAASC,EAAsBC,GAC7CC,OAAOC,KAAKF,GAAQG,QAAQ,SAAAC,GACzBL,EAAQM,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AAKqE,IAAIrE,OAAKV,SAAU6I,EAAiBO,GACxDrH,EAAWhC,OAAKsE,YAAYL,OAAKhE,SAAU+H,GAEjDrH,OAAKgJ,KAAKhC,EAAW+B,GACrBzF,OAAK2F,IAAInC,EAAaA,EAAazF,GACnCmF,EAAeU,QAGX5F,EAActB,OAAKgC,WAAW,EAAG,EAAGM,KAAKhB,aAC/CtB,OAAKoE,cAAc9C,EAAaA,EAAawF,GAC7C9G,OAAKqE,IAAI2C,EAAWA,EAAW1F,OAEzBwG,EAASzI,OAAKC,gBACpBD,OAAK6J,wBAAwBpB,EAAQhB,EAAaE,GAE3Cc"} \ No newline at end of file diff --git a/lib/css-camera.pkgd.js b/lib/css-camera.pkgd.js new file mode 100644 index 0000000..d913089 --- /dev/null +++ b/lib/css-camera.pkgd.js @@ -0,0 +1,3951 @@ +/* +Copyright (c) 2019 WoodNeck +name: css-camera +license: MIT +author: WoodNeck +repository: git+https://github.com/WoodNeck/css-camera.git +version: 1.0.1 +*/ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = global || self, global.CSSCamera = factory()); +}(this, function () { 'use strict'; + + /*! ***************************************************************************** + Copyright (c) Microsoft Corporation. All rights reserved. + 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 + + THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED + WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, + MERCHANTABLITY OR NON-INFRINGEMENT. + + See the Apache Version 2.0 License for specific language governing permissions + and limitations under the License. + ***************************************************************************** */ + var __assign = function () { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + + return t; + }; + + return __assign.apply(this, arguments); + }; + function __awaiter(thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + + function step(result) { + result.done ? resolve(result.value) : new P(function (resolve) { + resolve(result.value); + }).then(fulfilled, rejected); + } + + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + } + function __generator(thisArg, body) { + var _ = { + label: 0, + sent: function () { + if (t[0] & 1) throw t[1]; + return t[1]; + }, + trys: [], + ops: [] + }, + f, + y, + t, + g; + return g = { + next: verb(0), + "throw": verb(1), + "return": verb(2) + }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { + return this; + }), g; + + function verb(n) { + return function (v) { + return step([n, v]); + }; + } + + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + + switch (op[0]) { + case 0: + case 1: + t = op; + break; + + case 4: + _.label++; + return { + value: op[1], + done: false + }; + + case 5: + _.label++; + y = op[1]; + op = [0]; + continue; + + case 7: + op = _.ops.pop(); + + _.trys.pop(); + + continue; + + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { + _ = 0; + continue; + } + + if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) { + _.label = op[1]; + break; + } + + if (op[0] === 6 && _.label < t[1]) { + _.label = t[1]; + t = op; + break; + } + + if (t && _.label < t[2]) { + _.label = t[2]; + + _.ops.push(op); + + break; + } + + if (t[2]) _.ops.pop(); + + _.trys.pop(); + + continue; + } + + op = body.call(thisArg, _); + } catch (e) { + op = [6, e]; + y = 0; + } finally { + f = t = 0; + } + + if (op[0] & 5) throw op[1]; + return { + value: op[0] ? op[1] : void 0, + done: true + }; + } + } + function __read(o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), + r, + ar = [], + e; + + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } catch (error) { + e = { + error: error + }; + } finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } finally { + if (e) throw e.error; + } + } + + return ar; + } + function __spread() { + for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); + + return ar; + } + + /** + * Common utilities + * @module glMatrix + */ + // Configuration Constants + var EPSILON = 0.000001; + var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array; + var RANDOM = Math.random; + var degree = Math.PI / 180; + + /** + * 3x3 Matrix + * @module mat3 + */ + + /** + * Creates a new identity mat3 + * + * @returns {mat3} a new 3x3 matrix + */ + + function create() { + var out = new ARRAY_TYPE(9); + + if (ARRAY_TYPE != Float32Array) { + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[5] = 0; + out[6] = 0; + out[7] = 0; + } + + out[0] = 1; + out[4] = 1; + out[8] = 1; + return out; + } + + /** + * 4x4 Matrix
Format: column-major, when typed out it looks like row-major
The matrices are being post multiplied. + * @module mat4 + */ + + /** + * Creates a new identity mat4 + * + * @returns {mat4} a new 4x4 matrix + */ + + function create$1() { + var out = new ARRAY_TYPE(16); + + if (ARRAY_TYPE != Float32Array) { + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + } + + out[0] = 1; + out[5] = 1; + out[10] = 1; + out[15] = 1; + return out; + } + /** + * Creates a new mat4 initialized with values from an existing matrix + * + * @param {mat4} a matrix to clone + * @returns {mat4} a new 4x4 matrix + */ + + function clone(a) { + var out = new ARRAY_TYPE(16); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; + } + /** + * Copy the values from one mat4 to another + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + + function copy(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; + } + /** + * Create a new mat4 with the given values + * + * @param {Number} m00 Component in column 0, row 0 position (index 0) + * @param {Number} m01 Component in column 0, row 1 position (index 1) + * @param {Number} m02 Component in column 0, row 2 position (index 2) + * @param {Number} m03 Component in column 0, row 3 position (index 3) + * @param {Number} m10 Component in column 1, row 0 position (index 4) + * @param {Number} m11 Component in column 1, row 1 position (index 5) + * @param {Number} m12 Component in column 1, row 2 position (index 6) + * @param {Number} m13 Component in column 1, row 3 position (index 7) + * @param {Number} m20 Component in column 2, row 0 position (index 8) + * @param {Number} m21 Component in column 2, row 1 position (index 9) + * @param {Number} m22 Component in column 2, row 2 position (index 10) + * @param {Number} m23 Component in column 2, row 3 position (index 11) + * @param {Number} m30 Component in column 3, row 0 position (index 12) + * @param {Number} m31 Component in column 3, row 1 position (index 13) + * @param {Number} m32 Component in column 3, row 2 position (index 14) + * @param {Number} m33 Component in column 3, row 3 position (index 15) + * @returns {mat4} A new mat4 + */ + + function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) { + var out = new ARRAY_TYPE(16); + out[0] = m00; + out[1] = m01; + out[2] = m02; + out[3] = m03; + out[4] = m10; + out[5] = m11; + out[6] = m12; + out[7] = m13; + out[8] = m20; + out[9] = m21; + out[10] = m22; + out[11] = m23; + out[12] = m30; + out[13] = m31; + out[14] = m32; + out[15] = m33; + return out; + } + /** + * Set the components of a mat4 to the given values + * + * @param {mat4} out the receiving matrix + * @param {Number} m00 Component in column 0, row 0 position (index 0) + * @param {Number} m01 Component in column 0, row 1 position (index 1) + * @param {Number} m02 Component in column 0, row 2 position (index 2) + * @param {Number} m03 Component in column 0, row 3 position (index 3) + * @param {Number} m10 Component in column 1, row 0 position (index 4) + * @param {Number} m11 Component in column 1, row 1 position (index 5) + * @param {Number} m12 Component in column 1, row 2 position (index 6) + * @param {Number} m13 Component in column 1, row 3 position (index 7) + * @param {Number} m20 Component in column 2, row 0 position (index 8) + * @param {Number} m21 Component in column 2, row 1 position (index 9) + * @param {Number} m22 Component in column 2, row 2 position (index 10) + * @param {Number} m23 Component in column 2, row 3 position (index 11) + * @param {Number} m30 Component in column 3, row 0 position (index 12) + * @param {Number} m31 Component in column 3, row 1 position (index 13) + * @param {Number} m32 Component in column 3, row 2 position (index 14) + * @param {Number} m33 Component in column 3, row 3 position (index 15) + * @returns {mat4} out + */ + + function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) { + out[0] = m00; + out[1] = m01; + out[2] = m02; + out[3] = m03; + out[4] = m10; + out[5] = m11; + out[6] = m12; + out[7] = m13; + out[8] = m20; + out[9] = m21; + out[10] = m22; + out[11] = m23; + out[12] = m30; + out[13] = m31; + out[14] = m32; + out[15] = m33; + return out; + } + /** + * Set a mat4 to the identity matrix + * + * @param {mat4} out the receiving matrix + * @returns {mat4} out + */ + + function identity(out) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + /** + * Transpose the values of a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + + function transpose(out, a) { + // If we are transposing ourselves we can skip a few steps but have to cache some values + if (out === a) { + var a01 = a[1], + a02 = a[2], + a03 = a[3]; + var a12 = a[6], + a13 = a[7]; + var a23 = a[11]; + out[1] = a[4]; + out[2] = a[8]; + out[3] = a[12]; + out[4] = a01; + out[6] = a[9]; + out[7] = a[13]; + out[8] = a02; + out[9] = a12; + out[11] = a[14]; + out[12] = a03; + out[13] = a13; + out[14] = a23; + } else { + out[0] = a[0]; + out[1] = a[4]; + out[2] = a[8]; + out[3] = a[12]; + out[4] = a[1]; + out[5] = a[5]; + out[6] = a[9]; + out[7] = a[13]; + out[8] = a[2]; + out[9] = a[6]; + out[10] = a[10]; + out[11] = a[14]; + out[12] = a[3]; + out[13] = a[7]; + out[14] = a[11]; + out[15] = a[15]; + } + + return out; + } + /** + * Inverts a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + + function invert(out, a) { + var a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3]; + var a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7]; + var a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + var a30 = a[12], + a31 = a[13], + a32 = a[14], + a33 = a[15]; + var b00 = a00 * a11 - a01 * a10; + var b01 = a00 * a12 - a02 * a10; + var b02 = a00 * a13 - a03 * a10; + var b03 = a01 * a12 - a02 * a11; + var b04 = a01 * a13 - a03 * a11; + var b05 = a02 * a13 - a03 * a12; + var b06 = a20 * a31 - a21 * a30; + var b07 = a20 * a32 - a22 * a30; + var b08 = a20 * a33 - a23 * a30; + var b09 = a21 * a32 - a22 * a31; + var b10 = a21 * a33 - a23 * a31; + var b11 = a22 * a33 - a23 * a32; // Calculate the determinant + + var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (!det) { + return null; + } + + det = 1.0 / det; + out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; + out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; + out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; + out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; + out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; + out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; + out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; + out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; + out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; + out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; + out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; + out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; + out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; + out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; + out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; + out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; + return out; + } + /** + * Calculates the adjugate of a mat4 + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the source matrix + * @returns {mat4} out + */ + + function adjoint(out, a) { + var a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3]; + var a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7]; + var a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + var a30 = a[12], + a31 = a[13], + a32 = a[14], + a33 = a[15]; + out[0] = a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22); + out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22)); + out[2] = a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12); + out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12)); + out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22)); + out[5] = a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22); + out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12)); + out[7] = a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12); + out[8] = a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21); + out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21)); + out[10] = a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11); + out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11)); + out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21)); + out[13] = a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21); + out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11)); + out[15] = a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11); + return out; + } + /** + * Calculates the determinant of a mat4 + * + * @param {mat4} a the source matrix + * @returns {Number} determinant of a + */ + + function determinant(a) { + var a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3]; + var a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7]; + var a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + var a30 = a[12], + a31 = a[13], + a32 = a[14], + a33 = a[15]; + var b00 = a00 * a11 - a01 * a10; + var b01 = a00 * a12 - a02 * a10; + var b02 = a00 * a13 - a03 * a10; + var b03 = a01 * a12 - a02 * a11; + var b04 = a01 * a13 - a03 * a11; + var b05 = a02 * a13 - a03 * a12; + var b06 = a20 * a31 - a21 * a30; + var b07 = a20 * a32 - a22 * a30; + var b08 = a20 * a33 - a23 * a30; + var b09 = a21 * a32 - a22 * a31; + var b10 = a21 * a33 - a23 * a31; + var b11 = a22 * a33 - a23 * a32; // Calculate the determinant + + return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + } + /** + * Multiplies two mat4s + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @returns {mat4} out + */ + + function multiply(out, a, b) { + var a00 = a[0], + a01 = a[1], + a02 = a[2], + a03 = a[3]; + var a10 = a[4], + a11 = a[5], + a12 = a[6], + a13 = a[7]; + var a20 = a[8], + a21 = a[9], + a22 = a[10], + a23 = a[11]; + var a30 = a[12], + a31 = a[13], + a32 = a[14], + a33 = a[15]; // Cache only the current line of the second matrix + + var b0 = b[0], + b1 = b[1], + b2 = b[2], + b3 = b[3]; + out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30; + out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31; + out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32; + out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33; + b0 = b[4]; + b1 = b[5]; + b2 = b[6]; + b3 = b[7]; + out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30; + out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31; + out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32; + out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33; + b0 = b[8]; + b1 = b[9]; + b2 = b[10]; + b3 = b[11]; + out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30; + out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31; + out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32; + out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33; + b0 = b[12]; + b1 = b[13]; + b2 = b[14]; + b3 = b[15]; + out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30; + out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31; + out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32; + out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33; + return out; + } + /** + * Translate a mat4 by the given vector + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to translate + * @param {vec3} v vector to translate by + * @returns {mat4} out + */ + + function translate(out, a, v) { + var x = v[0], + y = v[1], + z = v[2]; + var a00, a01, a02, a03; + var a10, a11, a12, a13; + var a20, a21, a22, a23; + + if (a === out) { + out[12] = a[0] * x + a[4] * y + a[8] * z + a[12]; + out[13] = a[1] * x + a[5] * y + a[9] * z + a[13]; + out[14] = a[2] * x + a[6] * y + a[10] * z + a[14]; + out[15] = a[3] * x + a[7] * y + a[11] * z + a[15]; + } else { + a00 = a[0]; + a01 = a[1]; + a02 = a[2]; + a03 = a[3]; + a10 = a[4]; + a11 = a[5]; + a12 = a[6]; + a13 = a[7]; + a20 = a[8]; + a21 = a[9]; + a22 = a[10]; + a23 = a[11]; + out[0] = a00; + out[1] = a01; + out[2] = a02; + out[3] = a03; + out[4] = a10; + out[5] = a11; + out[6] = a12; + out[7] = a13; + out[8] = a20; + out[9] = a21; + out[10] = a22; + out[11] = a23; + out[12] = a00 * x + a10 * y + a20 * z + a[12]; + out[13] = a01 * x + a11 * y + a21 * z + a[13]; + out[14] = a02 * x + a12 * y + a22 * z + a[14]; + out[15] = a03 * x + a13 * y + a23 * z + a[15]; + } + + return out; + } + /** + * Scales the mat4 by the dimensions in the given vec3 not using vectorization + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to scale + * @param {vec3} v the vec3 to scale the matrix by + * @returns {mat4} out + **/ + + function scale(out, a, v) { + var x = v[0], + y = v[1], + z = v[2]; + out[0] = a[0] * x; + out[1] = a[1] * x; + out[2] = a[2] * x; + out[3] = a[3] * x; + out[4] = a[4] * y; + out[5] = a[5] * y; + out[6] = a[6] * y; + out[7] = a[7] * y; + out[8] = a[8] * z; + out[9] = a[9] * z; + out[10] = a[10] * z; + out[11] = a[11] * z; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + return out; + } + /** + * Rotates a mat4 by the given angle around the given axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @param {vec3} axis the axis to rotate around + * @returns {mat4} out + */ + + function rotate(out, a, rad, axis) { + var x = axis[0], + y = axis[1], + z = axis[2]; + var len = Math.sqrt(x * x + y * y + z * z); + var s, c, t; + var a00, a01, a02, a03; + var a10, a11, a12, a13; + var a20, a21, a22, a23; + var b00, b01, b02; + var b10, b11, b12; + var b20, b21, b22; + + if (len < EPSILON) { + return null; + } + + len = 1 / len; + x *= len; + y *= len; + z *= len; + s = Math.sin(rad); + c = Math.cos(rad); + t = 1 - c; + a00 = a[0]; + a01 = a[1]; + a02 = a[2]; + a03 = a[3]; + a10 = a[4]; + a11 = a[5]; + a12 = a[6]; + a13 = a[7]; + a20 = a[8]; + a21 = a[9]; + a22 = a[10]; + a23 = a[11]; // Construct the elements of the rotation matrix + + b00 = x * x * t + c; + b01 = y * x * t + z * s; + b02 = z * x * t - y * s; + b10 = x * y * t - z * s; + b11 = y * y * t + c; + b12 = z * y * t + x * s; + b20 = x * z * t + y * s; + b21 = y * z * t - x * s; + b22 = z * z * t + c; // Perform rotation-specific matrix multiplication + + out[0] = a00 * b00 + a10 * b01 + a20 * b02; + out[1] = a01 * b00 + a11 * b01 + a21 * b02; + out[2] = a02 * b00 + a12 * b01 + a22 * b02; + out[3] = a03 * b00 + a13 * b01 + a23 * b02; + out[4] = a00 * b10 + a10 * b11 + a20 * b12; + out[5] = a01 * b10 + a11 * b11 + a21 * b12; + out[6] = a02 * b10 + a12 * b11 + a22 * b12; + out[7] = a03 * b10 + a13 * b11 + a23 * b12; + out[8] = a00 * b20 + a10 * b21 + a20 * b22; + out[9] = a01 * b20 + a11 * b21 + a21 * b22; + out[10] = a02 * b20 + a12 * b21 + a22 * b22; + out[11] = a03 * b20 + a13 * b21 + a23 * b22; + + if (a !== out) { + // If the source and destination differ, copy the unchanged last row + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } + + return out; + } + /** + * Rotates a matrix by the given angle around the X axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + + function rotateX(out, a, rad) { + var s = Math.sin(rad); + var c = Math.cos(rad); + var a10 = a[4]; + var a11 = a[5]; + var a12 = a[6]; + var a13 = a[7]; + var a20 = a[8]; + var a21 = a[9]; + var a22 = a[10]; + var a23 = a[11]; + + if (a !== out) { + // If the source and destination differ, copy the unchanged rows + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } // Perform axis-specific matrix multiplication + + + out[4] = a10 * c + a20 * s; + out[5] = a11 * c + a21 * s; + out[6] = a12 * c + a22 * s; + out[7] = a13 * c + a23 * s; + out[8] = a20 * c - a10 * s; + out[9] = a21 * c - a11 * s; + out[10] = a22 * c - a12 * s; + out[11] = a23 * c - a13 * s; + return out; + } + /** + * Rotates a matrix by the given angle around the Y axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + + function rotateY(out, a, rad) { + var s = Math.sin(rad); + var c = Math.cos(rad); + var a00 = a[0]; + var a01 = a[1]; + var a02 = a[2]; + var a03 = a[3]; + var a20 = a[8]; + var a21 = a[9]; + var a22 = a[10]; + var a23 = a[11]; + + if (a !== out) { + // If the source and destination differ, copy the unchanged rows + out[4] = a[4]; + out[5] = a[5]; + out[6] = a[6]; + out[7] = a[7]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } // Perform axis-specific matrix multiplication + + + out[0] = a00 * c - a20 * s; + out[1] = a01 * c - a21 * s; + out[2] = a02 * c - a22 * s; + out[3] = a03 * c - a23 * s; + out[8] = a00 * s + a20 * c; + out[9] = a01 * s + a21 * c; + out[10] = a02 * s + a22 * c; + out[11] = a03 * s + a23 * c; + return out; + } + /** + * Rotates a matrix by the given angle around the Z axis + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to rotate + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + + function rotateZ(out, a, rad) { + var s = Math.sin(rad); + var c = Math.cos(rad); + var a00 = a[0]; + var a01 = a[1]; + var a02 = a[2]; + var a03 = a[3]; + var a10 = a[4]; + var a11 = a[5]; + var a12 = a[6]; + var a13 = a[7]; + + if (a !== out) { + // If the source and destination differ, copy the unchanged last row + out[8] = a[8]; + out[9] = a[9]; + out[10] = a[10]; + out[11] = a[11]; + out[12] = a[12]; + out[13] = a[13]; + out[14] = a[14]; + out[15] = a[15]; + } // Perform axis-specific matrix multiplication + + + out[0] = a00 * c + a10 * s; + out[1] = a01 * c + a11 * s; + out[2] = a02 * c + a12 * s; + out[3] = a03 * c + a13 * s; + out[4] = a10 * c - a00 * s; + out[5] = a11 * c - a01 * s; + out[6] = a12 * c - a02 * s; + out[7] = a13 * c - a03 * s; + return out; + } + /** + * Creates a matrix from a vector translation + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, dest, vec); + * + * @param {mat4} out mat4 receiving operation result + * @param {vec3} v Translation vector + * @returns {mat4} out + */ + + function fromTranslation(out, v) { + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + return out; + } + /** + * Creates a matrix from a vector scaling + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.scale(dest, dest, vec); + * + * @param {mat4} out mat4 receiving operation result + * @param {vec3} v Scaling vector + * @returns {mat4} out + */ + + function fromScaling(out, v) { + out[0] = v[0]; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = v[1]; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = v[2]; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + /** + * Creates a matrix from a given angle around a given axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotate(dest, dest, rad, axis); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @param {vec3} axis the axis to rotate around + * @returns {mat4} out + */ + + function fromRotation(out, rad, axis) { + var x = axis[0], + y = axis[1], + z = axis[2]; + var len = Math.sqrt(x * x + y * y + z * z); + var s, c, t; + + if (len < EPSILON) { + return null; + } + + len = 1 / len; + x *= len; + y *= len; + z *= len; + s = Math.sin(rad); + c = Math.cos(rad); + t = 1 - c; // Perform rotation-specific matrix multiplication + + out[0] = x * x * t + c; + out[1] = y * x * t + z * s; + out[2] = z * x * t - y * s; + out[3] = 0; + out[4] = x * y * t - z * s; + out[5] = y * y * t + c; + out[6] = z * y * t + x * s; + out[7] = 0; + out[8] = x * z * t + y * s; + out[9] = y * z * t - x * s; + out[10] = z * z * t + c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + /** + * Creates a matrix from the given angle around the X axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateX(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + + function fromXRotation(out, rad) { + var s = Math.sin(rad); + var c = Math.cos(rad); // Perform axis-specific matrix multiplication + + out[0] = 1; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = c; + out[6] = s; + out[7] = 0; + out[8] = 0; + out[9] = -s; + out[10] = c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + /** + * Creates a matrix from the given angle around the Y axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateY(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + + function fromYRotation(out, rad) { + var s = Math.sin(rad); + var c = Math.cos(rad); // Perform axis-specific matrix multiplication + + out[0] = c; + out[1] = 0; + out[2] = -s; + out[3] = 0; + out[4] = 0; + out[5] = 1; + out[6] = 0; + out[7] = 0; + out[8] = s; + out[9] = 0; + out[10] = c; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + /** + * Creates a matrix from the given angle around the Z axis + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.rotateZ(dest, dest, rad); + * + * @param {mat4} out mat4 receiving operation result + * @param {Number} rad the angle to rotate the matrix by + * @returns {mat4} out + */ + + function fromZRotation(out, rad) { + var s = Math.sin(rad); + var c = Math.cos(rad); // Perform axis-specific matrix multiplication + + out[0] = c; + out[1] = s; + out[2] = 0; + out[3] = 0; + out[4] = -s; + out[5] = c; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 1; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + /** + * Creates a matrix from a quaternion rotation and vector translation + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * let quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @returns {mat4} out + */ + + function fromRotationTranslation(out, q, v) { + // Quaternion math + var x = q[0], + y = q[1], + z = q[2], + w = q[3]; + var x2 = x + x; + var y2 = y + y; + var z2 = z + z; + var xx = x * x2; + var xy = x * y2; + var xz = x * z2; + var yy = y * y2; + var yz = y * z2; + var zz = z * z2; + var wx = w * x2; + var wy = w * y2; + var wz = w * z2; + out[0] = 1 - (yy + zz); + out[1] = xy + wz; + out[2] = xz - wy; + out[3] = 0; + out[4] = xy - wz; + out[5] = 1 - (xx + zz); + out[6] = yz + wx; + out[7] = 0; + out[8] = xz + wy; + out[9] = yz - wx; + out[10] = 1 - (xx + yy); + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + return out; + } + /** + * Creates a new mat4 from a dual quat. + * + * @param {mat4} out Matrix + * @param {quat2} a Dual Quaternion + * @returns {mat4} mat4 receiving operation result + */ + + function fromQuat2(out, a) { + var translation = new ARRAY_TYPE(3); + var bx = -a[0], + by = -a[1], + bz = -a[2], + bw = a[3], + ax = a[4], + ay = a[5], + az = a[6], + aw = a[7]; + var magnitude = bx * bx + by * by + bz * bz + bw * bw; //Only scale if it makes sense + + if (magnitude > 0) { + translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude; + translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude; + translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude; + } else { + translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2; + translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2; + translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2; + } + + fromRotationTranslation(out, a, translation); + return out; + } + /** + * Returns the translation vector component of a transformation + * matrix. If a matrix is built with fromRotationTranslation, + * the returned vector will be the same as the translation vector + * originally supplied. + * @param {vec3} out Vector to receive translation component + * @param {mat4} mat Matrix to be decomposed (input) + * @return {vec3} out + */ + + function getTranslation(out, mat) { + out[0] = mat[12]; + out[1] = mat[13]; + out[2] = mat[14]; + return out; + } + /** + * Returns the scaling factor component of a transformation + * matrix. If a matrix is built with fromRotationTranslationScale + * with a normalized Quaternion paramter, the returned vector will be + * the same as the scaling vector + * originally supplied. + * @param {vec3} out Vector to receive scaling factor component + * @param {mat4} mat Matrix to be decomposed (input) + * @return {vec3} out + */ + + function getScaling(out, mat) { + var m11 = mat[0]; + var m12 = mat[1]; + var m13 = mat[2]; + var m21 = mat[4]; + var m22 = mat[5]; + var m23 = mat[6]; + var m31 = mat[8]; + var m32 = mat[9]; + var m33 = mat[10]; + out[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13); + out[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23); + out[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33); + return out; + } + /** + * Returns a quaternion representing the rotational component + * of a transformation matrix. If a matrix is built with + * fromRotationTranslation, the returned quaternion will be the + * same as the quaternion originally supplied. + * @param {quat} out Quaternion to receive the rotation component + * @param {mat4} mat Matrix to be decomposed (input) + * @return {quat} out + */ + + function getRotation(out, mat) { + // Algorithm taken from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm + var trace = mat[0] + mat[5] + mat[10]; + var S = 0; + + if (trace > 0) { + S = Math.sqrt(trace + 1.0) * 2; + out[3] = 0.25 * S; + out[0] = (mat[6] - mat[9]) / S; + out[1] = (mat[8] - mat[2]) / S; + out[2] = (mat[1] - mat[4]) / S; + } else if (mat[0] > mat[5] && mat[0] > mat[10]) { + S = Math.sqrt(1.0 + mat[0] - mat[5] - mat[10]) * 2; + out[3] = (mat[6] - mat[9]) / S; + out[0] = 0.25 * S; + out[1] = (mat[1] + mat[4]) / S; + out[2] = (mat[8] + mat[2]) / S; + } else if (mat[5] > mat[10]) { + S = Math.sqrt(1.0 + mat[5] - mat[0] - mat[10]) * 2; + out[3] = (mat[8] - mat[2]) / S; + out[0] = (mat[1] + mat[4]) / S; + out[1] = 0.25 * S; + out[2] = (mat[6] + mat[9]) / S; + } else { + S = Math.sqrt(1.0 + mat[10] - mat[0] - mat[5]) * 2; + out[3] = (mat[1] - mat[4]) / S; + out[0] = (mat[8] + mat[2]) / S; + out[1] = (mat[6] + mat[9]) / S; + out[2] = 0.25 * S; + } + + return out; + } + /** + * Creates a matrix from a quaternion rotation, vector translation and vector scale + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * let quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * mat4.scale(dest, scale) + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @param {vec3} s Scaling vector + * @returns {mat4} out + */ + + function fromRotationTranslationScale(out, q, v, s) { + // Quaternion math + var x = q[0], + y = q[1], + z = q[2], + w = q[3]; + var x2 = x + x; + var y2 = y + y; + var z2 = z + z; + var xx = x * x2; + var xy = x * y2; + var xz = x * z2; + var yy = y * y2; + var yz = y * z2; + var zz = z * z2; + var wx = w * x2; + var wy = w * y2; + var wz = w * z2; + var sx = s[0]; + var sy = s[1]; + var sz = s[2]; + out[0] = (1 - (yy + zz)) * sx; + out[1] = (xy + wz) * sx; + out[2] = (xz - wy) * sx; + out[3] = 0; + out[4] = (xy - wz) * sy; + out[5] = (1 - (xx + zz)) * sy; + out[6] = (yz + wx) * sy; + out[7] = 0; + out[8] = (xz + wy) * sz; + out[9] = (yz - wx) * sz; + out[10] = (1 - (xx + yy)) * sz; + out[11] = 0; + out[12] = v[0]; + out[13] = v[1]; + out[14] = v[2]; + out[15] = 1; + return out; + } + /** + * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin + * This is equivalent to (but much faster than): + * + * mat4.identity(dest); + * mat4.translate(dest, vec); + * mat4.translate(dest, origin); + * let quatMat = mat4.create(); + * quat4.toMat4(quat, quatMat); + * mat4.multiply(dest, quatMat); + * mat4.scale(dest, scale) + * mat4.translate(dest, negativeOrigin); + * + * @param {mat4} out mat4 receiving operation result + * @param {quat4} q Rotation quaternion + * @param {vec3} v Translation vector + * @param {vec3} s Scaling vector + * @param {vec3} o The origin vector around which to scale and rotate + * @returns {mat4} out + */ + + function fromRotationTranslationScaleOrigin(out, q, v, s, o) { + // Quaternion math + var x = q[0], + y = q[1], + z = q[2], + w = q[3]; + var x2 = x + x; + var y2 = y + y; + var z2 = z + z; + var xx = x * x2; + var xy = x * y2; + var xz = x * z2; + var yy = y * y2; + var yz = y * z2; + var zz = z * z2; + var wx = w * x2; + var wy = w * y2; + var wz = w * z2; + var sx = s[0]; + var sy = s[1]; + var sz = s[2]; + var ox = o[0]; + var oy = o[1]; + var oz = o[2]; + var out0 = (1 - (yy + zz)) * sx; + var out1 = (xy + wz) * sx; + var out2 = (xz - wy) * sx; + var out4 = (xy - wz) * sy; + var out5 = (1 - (xx + zz)) * sy; + var out6 = (yz + wx) * sy; + var out8 = (xz + wy) * sz; + var out9 = (yz - wx) * sz; + var out10 = (1 - (xx + yy)) * sz; + out[0] = out0; + out[1] = out1; + out[2] = out2; + out[3] = 0; + out[4] = out4; + out[5] = out5; + out[6] = out6; + out[7] = 0; + out[8] = out8; + out[9] = out9; + out[10] = out10; + out[11] = 0; + out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz); + out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz); + out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz); + out[15] = 1; + return out; + } + /** + * Calculates a 4x4 matrix from the given quaternion + * + * @param {mat4} out mat4 receiving operation result + * @param {quat} q Quaternion to create matrix from + * + * @returns {mat4} out + */ + + function fromQuat(out, q) { + var x = q[0], + y = q[1], + z = q[2], + w = q[3]; + var x2 = x + x; + var y2 = y + y; + var z2 = z + z; + var xx = x * x2; + var yx = y * x2; + var yy = y * y2; + var zx = z * x2; + var zy = z * y2; + var zz = z * z2; + var wx = w * x2; + var wy = w * y2; + var wz = w * z2; + out[0] = 1 - yy - zz; + out[1] = yx + wz; + out[2] = zx - wy; + out[3] = 0; + out[4] = yx - wz; + out[5] = 1 - xx - zz; + out[6] = zy + wx; + out[7] = 0; + out[8] = zx + wy; + out[9] = zy - wx; + out[10] = 1 - xx - yy; + out[11] = 0; + out[12] = 0; + out[13] = 0; + out[14] = 0; + out[15] = 1; + return out; + } + /** + * Generates a frustum matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {Number} left Left bound of the frustum + * @param {Number} right Right bound of the frustum + * @param {Number} bottom Bottom bound of the frustum + * @param {Number} top Top bound of the frustum + * @param {Number} near Near bound of the frustum + * @param {Number} far Far bound of the frustum + * @returns {mat4} out + */ + + function frustum(out, left, right, bottom, top, near, far) { + var rl = 1 / (right - left); + var tb = 1 / (top - bottom); + var nf = 1 / (near - far); + out[0] = near * 2 * rl; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = near * 2 * tb; + out[6] = 0; + out[7] = 0; + out[8] = (right + left) * rl; + out[9] = (top + bottom) * tb; + out[10] = (far + near) * nf; + out[11] = -1; + out[12] = 0; + out[13] = 0; + out[14] = far * near * 2 * nf; + out[15] = 0; + return out; + } + /** + * Generates a perspective projection matrix with the given bounds. + * Passing null/undefined/no value for far will generate infinite projection matrix. + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} fovy Vertical field of view in radians + * @param {number} aspect Aspect ratio. typically viewport width/height + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum, can be null or Infinity + * @returns {mat4} out + */ + + function perspective(out, fovy, aspect, near, far) { + var f = 1.0 / Math.tan(fovy / 2), + nf; + out[0] = f / aspect; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = f; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[11] = -1; + out[12] = 0; + out[13] = 0; + out[15] = 0; + + if (far != null && far !== Infinity) { + nf = 1 / (near - far); + out[10] = (far + near) * nf; + out[14] = 2 * far * near * nf; + } else { + out[10] = -1; + out[14] = -2 * near; + } + + return out; + } + /** + * Generates a perspective projection matrix with the given field of view. + * This is primarily useful for generating projection matrices to be used + * with the still experiemental WebVR API. + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ + + function perspectiveFromFieldOfView(out, fov, near, far) { + var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0); + var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0); + var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0); + var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0); + var xScale = 2.0 / (leftTan + rightTan); + var yScale = 2.0 / (upTan + downTan); + out[0] = xScale; + out[1] = 0.0; + out[2] = 0.0; + out[3] = 0.0; + out[4] = 0.0; + out[5] = yScale; + out[6] = 0.0; + out[7] = 0.0; + out[8] = -((leftTan - rightTan) * xScale * 0.5); + out[9] = (upTan - downTan) * yScale * 0.5; + out[10] = far / (near - far); + out[11] = -1.0; + out[12] = 0.0; + out[13] = 0.0; + out[14] = far * near / (near - far); + out[15] = 0.0; + return out; + } + /** + * Generates a orthogonal projection matrix with the given bounds + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {number} left Left bound of the frustum + * @param {number} right Right bound of the frustum + * @param {number} bottom Bottom bound of the frustum + * @param {number} top Top bound of the frustum + * @param {number} near Near bound of the frustum + * @param {number} far Far bound of the frustum + * @returns {mat4} out + */ + + function ortho(out, left, right, bottom, top, near, far) { + var lr = 1 / (left - right); + var bt = 1 / (bottom - top); + var nf = 1 / (near - far); + out[0] = -2 * lr; + out[1] = 0; + out[2] = 0; + out[3] = 0; + out[4] = 0; + out[5] = -2 * bt; + out[6] = 0; + out[7] = 0; + out[8] = 0; + out[9] = 0; + out[10] = 2 * nf; + out[11] = 0; + out[12] = (left + right) * lr; + out[13] = (top + bottom) * bt; + out[14] = (far + near) * nf; + out[15] = 1; + return out; + } + /** + * Generates a look-at matrix with the given eye position, focal point, and up axis. + * If you want a matrix that actually makes an object look at another object, you should use targetTo instead. + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {vec3} eye Position of the viewer + * @param {vec3} center Point the viewer is looking at + * @param {vec3} up vec3 pointing up + * @returns {mat4} out + */ + + function lookAt(out, eye, center, up) { + var x0, x1, x2, y0, y1, y2, z0, z1, z2, len; + var eyex = eye[0]; + var eyey = eye[1]; + var eyez = eye[2]; + var upx = up[0]; + var upy = up[1]; + var upz = up[2]; + var centerx = center[0]; + var centery = center[1]; + var centerz = center[2]; + + if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) { + return identity(out); + } + + z0 = eyex - centerx; + z1 = eyey - centery; + z2 = eyez - centerz; + len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); + z0 *= len; + z1 *= len; + z2 *= len; + x0 = upy * z2 - upz * z1; + x1 = upz * z0 - upx * z2; + x2 = upx * z1 - upy * z0; + len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); + + if (!len) { + x0 = 0; + x1 = 0; + x2 = 0; + } else { + len = 1 / len; + x0 *= len; + x1 *= len; + x2 *= len; + } + + y0 = z1 * x2 - z2 * x1; + y1 = z2 * x0 - z0 * x2; + y2 = z0 * x1 - z1 * x0; + len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); + + if (!len) { + y0 = 0; + y1 = 0; + y2 = 0; + } else { + len = 1 / len; + y0 *= len; + y1 *= len; + y2 *= len; + } + + out[0] = x0; + out[1] = y0; + out[2] = z0; + out[3] = 0; + out[4] = x1; + out[5] = y1; + out[6] = z1; + out[7] = 0; + out[8] = x2; + out[9] = y2; + out[10] = z2; + out[11] = 0; + out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez); + out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez); + out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez); + out[15] = 1; + return out; + } + /** + * Generates a matrix that makes something look at something else. + * + * @param {mat4} out mat4 frustum matrix will be written into + * @param {vec3} eye Position of the viewer + * @param {vec3} center Point the viewer is looking at + * @param {vec3} up vec3 pointing up + * @returns {mat4} out + */ + + function targetTo(out, eye, target, up) { + var eyex = eye[0], + eyey = eye[1], + eyez = eye[2], + upx = up[0], + upy = up[1], + upz = up[2]; + var z0 = eyex - target[0], + z1 = eyey - target[1], + z2 = eyez - target[2]; + var len = z0 * z0 + z1 * z1 + z2 * z2; + + if (len > 0) { + len = 1 / Math.sqrt(len); + z0 *= len; + z1 *= len; + z2 *= len; + } + + var x0 = upy * z2 - upz * z1, + x1 = upz * z0 - upx * z2, + x2 = upx * z1 - upy * z0; + len = x0 * x0 + x1 * x1 + x2 * x2; + + if (len > 0) { + len = 1 / Math.sqrt(len); + x0 *= len; + x1 *= len; + x2 *= len; + } + + out[0] = x0; + out[1] = x1; + out[2] = x2; + out[3] = 0; + out[4] = z1 * x2 - z2 * x1; + out[5] = z2 * x0 - z0 * x2; + out[6] = z0 * x1 - z1 * x0; + out[7] = 0; + out[8] = z0; + out[9] = z1; + out[10] = z2; + out[11] = 0; + out[12] = eyex; + out[13] = eyey; + out[14] = eyez; + out[15] = 1; + return out; + } + /** + * Returns a string representation of a mat4 + * + * @param {mat4} a matrix to represent as a string + * @returns {String} string representation of the matrix + */ + + function str(a) { + return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' + a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')'; + } + /** + * Returns Frobenius norm of a mat4 + * + * @param {mat4} a the matrix to calculate Frobenius norm of + * @returns {Number} Frobenius norm + */ + + function frob(a) { + return Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2)); + } + /** + * Adds two mat4's + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @returns {mat4} out + */ + + function add(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + out[3] = a[3] + b[3]; + out[4] = a[4] + b[4]; + out[5] = a[5] + b[5]; + out[6] = a[6] + b[6]; + out[7] = a[7] + b[7]; + out[8] = a[8] + b[8]; + out[9] = a[9] + b[9]; + out[10] = a[10] + b[10]; + out[11] = a[11] + b[11]; + out[12] = a[12] + b[12]; + out[13] = a[13] + b[13]; + out[14] = a[14] + b[14]; + out[15] = a[15] + b[15]; + return out; + } + /** + * Subtracts matrix b from matrix a + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @returns {mat4} out + */ + + function subtract(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + out[3] = a[3] - b[3]; + out[4] = a[4] - b[4]; + out[5] = a[5] - b[5]; + out[6] = a[6] - b[6]; + out[7] = a[7] - b[7]; + out[8] = a[8] - b[8]; + out[9] = a[9] - b[9]; + out[10] = a[10] - b[10]; + out[11] = a[11] - b[11]; + out[12] = a[12] - b[12]; + out[13] = a[13] - b[13]; + out[14] = a[14] - b[14]; + out[15] = a[15] - b[15]; + return out; + } + /** + * Multiply each element of the matrix by a scalar. + * + * @param {mat4} out the receiving matrix + * @param {mat4} a the matrix to scale + * @param {Number} b amount to scale the matrix's elements by + * @returns {mat4} out + */ + + function multiplyScalar(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[3] = a[3] * b; + out[4] = a[4] * b; + out[5] = a[5] * b; + out[6] = a[6] * b; + out[7] = a[7] * b; + out[8] = a[8] * b; + out[9] = a[9] * b; + out[10] = a[10] * b; + out[11] = a[11] * b; + out[12] = a[12] * b; + out[13] = a[13] * b; + out[14] = a[14] * b; + out[15] = a[15] * b; + return out; + } + /** + * Adds two mat4's after multiplying each element of the second operand by a scalar value. + * + * @param {mat4} out the receiving vector + * @param {mat4} a the first operand + * @param {mat4} b the second operand + * @param {Number} scale the amount to scale b's elements by before adding + * @returns {mat4} out + */ + + function multiplyScalarAndAdd(out, a, b, scale) { + out[0] = a[0] + b[0] * scale; + out[1] = a[1] + b[1] * scale; + out[2] = a[2] + b[2] * scale; + out[3] = a[3] + b[3] * scale; + out[4] = a[4] + b[4] * scale; + out[5] = a[5] + b[5] * scale; + out[6] = a[6] + b[6] * scale; + out[7] = a[7] + b[7] * scale; + out[8] = a[8] + b[8] * scale; + out[9] = a[9] + b[9] * scale; + out[10] = a[10] + b[10] * scale; + out[11] = a[11] + b[11] * scale; + out[12] = a[12] + b[12] * scale; + out[13] = a[13] + b[13] * scale; + out[14] = a[14] + b[14] * scale; + out[15] = a[15] + b[15] * scale; + return out; + } + /** + * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===) + * + * @param {mat4} a The first matrix. + * @param {mat4} b The second matrix. + * @returns {Boolean} True if the matrices are equal, false otherwise. + */ + + function exactEquals(a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8] && a[9] === b[9] && a[10] === b[10] && a[11] === b[11] && a[12] === b[12] && a[13] === b[13] && a[14] === b[14] && a[15] === b[15]; + } + /** + * Returns whether or not the matrices have approximately the same elements in the same position. + * + * @param {mat4} a The first matrix. + * @param {mat4} b The second matrix. + * @returns {Boolean} True if the matrices are equal, false otherwise. + */ + + function equals(a, b) { + var a0 = a[0], + a1 = a[1], + a2 = a[2], + a3 = a[3]; + var a4 = a[4], + a5 = a[5], + a6 = a[6], + a7 = a[7]; + var a8 = a[8], + a9 = a[9], + a10 = a[10], + a11 = a[11]; + var a12 = a[12], + a13 = a[13], + a14 = a[14], + a15 = a[15]; + var b0 = b[0], + b1 = b[1], + b2 = b[2], + b3 = b[3]; + var b4 = b[4], + b5 = b[5], + b6 = b[6], + b7 = b[7]; + var b8 = b[8], + b9 = b[9], + b10 = b[10], + b11 = b[11]; + var b12 = b[12], + b13 = b[13], + b14 = b[14], + b15 = b[15]; + return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) && Math.abs(a9 - b9) <= EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) && Math.abs(a10 - b10) <= EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) && Math.abs(a11 - b11) <= EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) && Math.abs(a12 - b12) <= EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) && Math.abs(a13 - b13) <= EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) && Math.abs(a14 - b14) <= EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) && Math.abs(a15 - b15) <= EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15)); + } + /** + * Alias for {@link mat4.multiply} + * @function + */ + + var mul = multiply; + /** + * Alias for {@link mat4.subtract} + * @function + */ + + var sub = subtract; + + var mat4 = ({ + create: create$1, + clone: clone, + copy: copy, + fromValues: fromValues, + set: set, + identity: identity, + transpose: transpose, + invert: invert, + adjoint: adjoint, + determinant: determinant, + multiply: multiply, + translate: translate, + scale: scale, + rotate: rotate, + rotateX: rotateX, + rotateY: rotateY, + rotateZ: rotateZ, + fromTranslation: fromTranslation, + fromScaling: fromScaling, + fromRotation: fromRotation, + fromXRotation: fromXRotation, + fromYRotation: fromYRotation, + fromZRotation: fromZRotation, + fromRotationTranslation: fromRotationTranslation, + fromQuat2: fromQuat2, + getTranslation: getTranslation, + getScaling: getScaling, + getRotation: getRotation, + fromRotationTranslationScale: fromRotationTranslationScale, + fromRotationTranslationScaleOrigin: fromRotationTranslationScaleOrigin, + fromQuat: fromQuat, + frustum: frustum, + perspective: perspective, + perspectiveFromFieldOfView: perspectiveFromFieldOfView, + ortho: ortho, + lookAt: lookAt, + targetTo: targetTo, + str: str, + frob: frob, + add: add, + subtract: subtract, + multiplyScalar: multiplyScalar, + multiplyScalarAndAdd: multiplyScalarAndAdd, + exactEquals: exactEquals, + equals: equals, + mul: mul, + sub: sub + }); + + /** + * 3 Dimensional Vector + * @module vec3 + */ + + /** + * Creates a new, empty vec3 + * + * @returns {vec3} a new 3D vector + */ + + function create$2() { + var out = new ARRAY_TYPE(3); + + if (ARRAY_TYPE != Float32Array) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + } + + return out; + } + /** + * Creates a new vec3 initialized with values from an existing vector + * + * @param {vec3} a vector to clone + * @returns {vec3} a new 3D vector + */ + + function clone$1(a) { + var out = new ARRAY_TYPE(3); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + return out; + } + /** + * Calculates the length of a vec3 + * + * @param {vec3} a vector to calculate length of + * @returns {Number} length of a + */ + + function length(a) { + var x = a[0]; + var y = a[1]; + var z = a[2]; + return Math.sqrt(x * x + y * y + z * z); + } + /** + * Creates a new vec3 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @returns {vec3} a new 3D vector + */ + + function fromValues$1(x, y, z) { + var out = new ARRAY_TYPE(3); + out[0] = x; + out[1] = y; + out[2] = z; + return out; + } + /** + * Copy the values from one vec3 to another + * + * @param {vec3} out the receiving vector + * @param {vec3} a the source vector + * @returns {vec3} out + */ + + function copy$1(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + return out; + } + /** + * Adds two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + + function add$1(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + return out; + } + /** + * Subtracts vector b from vector a + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + + function subtract$1(out, a, b) { + out[0] = a[0] - b[0]; + out[1] = a[1] - b[1]; + out[2] = a[2] - b[2]; + return out; + } + /** + * Negates the components of a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to negate + * @returns {vec3} out + */ + + function negate(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + return out; + } + /** + * Normalize a vec3 + * + * @param {vec3} out the receiving vector + * @param {vec3} a vector to normalize + * @returns {vec3} out + */ + + function normalize(out, a) { + var x = a[0]; + var y = a[1]; + var z = a[2]; + var len = x * x + y * y + z * z; + + if (len > 0) { + //TODO: evaluate use of glm_invsqrt here? + len = 1 / Math.sqrt(len); + } + + out[0] = a[0] * len; + out[1] = a[1] * len; + out[2] = a[2] * len; + return out; + } + /** + * Calculates the dot product of two vec3's + * + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {Number} dot product of a and b + */ + + function dot(a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; + } + /** + * Computes the cross product of two vec3's + * + * @param {vec3} out the receiving vector + * @param {vec3} a the first operand + * @param {vec3} b the second operand + * @returns {vec3} out + */ + + function cross(out, a, b) { + var ax = a[0], + ay = a[1], + az = a[2]; + var bx = b[0], + by = b[1], + bz = b[2]; + out[0] = ay * bz - az * by; + out[1] = az * bx - ax * bz; + out[2] = ax * by - ay * bx; + return out; + } + /** + * Transforms the vec3 with a mat4. + * 4th vector component is implicitly '1' + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {mat4} m matrix to transform with + * @returns {vec3} out + */ + + function transformMat4(out, a, m) { + var x = a[0], + y = a[1], + z = a[2]; + var w = m[3] * x + m[7] * y + m[11] * z + m[15]; + w = w || 1.0; + out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w; + out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w; + out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w; + return out; + } + /** + * Transforms the vec3 with a quat + * Can also be used for dual quaternions. (Multiply it with the real part) + * + * @param {vec3} out the receiving vector + * @param {vec3} a the vector to transform + * @param {quat} q quaternion to transform with + * @returns {vec3} out + */ + + function transformQuat(out, a, q) { + // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed + var qx = q[0], + qy = q[1], + qz = q[2], + qw = q[3]; + var x = a[0], + y = a[1], + z = a[2]; // var qvec = [qx, qy, qz]; + // var uv = vec3.cross([], qvec, a); + + var uvx = qy * z - qz * y, + uvy = qz * x - qx * z, + uvz = qx * y - qy * x; // var uuv = vec3.cross([], qvec, uv); + + var uuvx = qy * uvz - qz * uvy, + uuvy = qz * uvx - qx * uvz, + uuvz = qx * uvy - qy * uvx; // vec3.scale(uv, uv, 2 * w); + + var w2 = qw * 2; + uvx *= w2; + uvy *= w2; + uvz *= w2; // vec3.scale(uuv, uuv, 2); + + uuvx *= 2; + uuvy *= 2; + uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv)); + + out[0] = x + uvx + uuvx; + out[1] = y + uvy + uuvy; + out[2] = z + uvz + uuvz; + return out; + } + /** + * Alias for {@link vec3.subtract} + * @function + */ + + var sub$1 = subtract$1; + /** + * Alias for {@link vec3.length} + * @function + */ + + var len = length; + /** + * Perform some operation over an array of vec3s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ + + var forEach = function () { + var vec = create$2(); + return function (a, stride, offset, count, fn, arg) { + var i, l; + + if (!stride) { + stride = 3; + } + + if (!offset) { + offset = 0; + } + + if (count) { + l = Math.min(count * stride + offset, a.length); + } else { + l = a.length; + } + + for (i = offset; i < l; i += stride) { + vec[0] = a[i]; + vec[1] = a[i + 1]; + vec[2] = a[i + 2]; + fn(vec, vec, arg); + a[i] = vec[0]; + a[i + 1] = vec[1]; + a[i + 2] = vec[2]; + } + + return a; + }; + }(); + + /** + * 4 Dimensional Vector + * @module vec4 + */ + + /** + * Creates a new, empty vec4 + * + * @returns {vec4} a new 4D vector + */ + + function create$3() { + var out = new ARRAY_TYPE(4); + + if (ARRAY_TYPE != Float32Array) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 0; + } + + return out; + } + /** + * Creates a new vec4 initialized with values from an existing vector + * + * @param {vec4} a vector to clone + * @returns {vec4} a new 4D vector + */ + + function clone$2(a) { + var out = new ARRAY_TYPE(4); + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; + } + /** + * Creates a new vec4 initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {vec4} a new 4D vector + */ + + function fromValues$2(x, y, z, w) { + var out = new ARRAY_TYPE(4); + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = w; + return out; + } + /** + * Copy the values from one vec4 to another + * + * @param {vec4} out the receiving vector + * @param {vec4} a the source vector + * @returns {vec4} out + */ + + function copy$2(out, a) { + out[0] = a[0]; + out[1] = a[1]; + out[2] = a[2]; + out[3] = a[3]; + return out; + } + /** + * Set the components of a vec4 to the given values + * + * @param {vec4} out the receiving vector + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {vec4} out + */ + + function set$1(out, x, y, z, w) { + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = w; + return out; + } + /** + * Adds two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {vec4} out + */ + + function add$2(out, a, b) { + out[0] = a[0] + b[0]; + out[1] = a[1] + b[1]; + out[2] = a[2] + b[2]; + out[3] = a[3] + b[3]; + return out; + } + /** + * Scales a vec4 by a scalar number + * + * @param {vec4} out the receiving vector + * @param {vec4} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {vec4} out + */ + + function scale$1(out, a, b) { + out[0] = a[0] * b; + out[1] = a[1] * b; + out[2] = a[2] * b; + out[3] = a[3] * b; + return out; + } + /** + * Calculates the length of a vec4 + * + * @param {vec4} a vector to calculate length of + * @returns {Number} length of a + */ + + function length$1(a) { + var x = a[0]; + var y = a[1]; + var z = a[2]; + var w = a[3]; + return Math.sqrt(x * x + y * y + z * z + w * w); + } + /** + * Calculates the squared length of a vec4 + * + * @param {vec4} a vector to calculate squared length of + * @returns {Number} squared length of a + */ + + function squaredLength(a) { + var x = a[0]; + var y = a[1]; + var z = a[2]; + var w = a[3]; + return x * x + y * y + z * z + w * w; + } + /** + * Normalize a vec4 + * + * @param {vec4} out the receiving vector + * @param {vec4} a vector to normalize + * @returns {vec4} out + */ + + function normalize$1(out, a) { + var x = a[0]; + var y = a[1]; + var z = a[2]; + var w = a[3]; + var len = x * x + y * y + z * z + w * w; + + if (len > 0) { + len = 1 / Math.sqrt(len); + } + + out[0] = x * len; + out[1] = y * len; + out[2] = z * len; + out[3] = w * len; + return out; + } + /** + * Calculates the dot product of two vec4's + * + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @returns {Number} dot product of a and b + */ + + function dot$1(a, b) { + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3]; + } + /** + * Performs a linear interpolation between two vec4's + * + * @param {vec4} out the receiving vector + * @param {vec4} a the first operand + * @param {vec4} b the second operand + * @param {Number} t interpolation amount, in the range [0-1], between the two inputs + * @returns {vec4} out + */ + + function lerp(out, a, b, t) { + var ax = a[0]; + var ay = a[1]; + var az = a[2]; + var aw = a[3]; + out[0] = ax + t * (b[0] - ax); + out[1] = ay + t * (b[1] - ay); + out[2] = az + t * (b[2] - az); + out[3] = aw + t * (b[3] - aw); + return out; + } + /** + * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===) + * + * @param {vec4} a The first vector. + * @param {vec4} b The second vector. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + + function exactEquals$1(a, b) { + return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3]; + } + /** + * Returns whether or not the vectors have approximately the same elements in the same position. + * + * @param {vec4} a The first vector. + * @param {vec4} b The second vector. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + + function equals$1(a, b) { + var a0 = a[0], + a1 = a[1], + a2 = a[2], + a3 = a[3]; + var b0 = b[0], + b1 = b[1], + b2 = b[2], + b3 = b[3]; + return Math.abs(a0 - b0) <= EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)); + } + /** + * Perform some operation over an array of vec4s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ + + var forEach$1 = function () { + var vec = create$3(); + return function (a, stride, offset, count, fn, arg) { + var i, l; + + if (!stride) { + stride = 4; + } + + if (!offset) { + offset = 0; + } + + if (count) { + l = Math.min(count * stride + offset, a.length); + } else { + l = a.length; + } + + for (i = offset; i < l; i += stride) { + vec[0] = a[i]; + vec[1] = a[i + 1]; + vec[2] = a[i + 2]; + vec[3] = a[i + 3]; + fn(vec, vec, arg); + a[i] = vec[0]; + a[i + 1] = vec[1]; + a[i + 2] = vec[2]; + a[i + 3] = vec[3]; + } + + return a; + }; + }(); + + /** + * Quaternion + * @module quat + */ + + /** + * Creates a new identity quat + * + * @returns {quat} a new quaternion + */ + + function create$4() { + var out = new ARRAY_TYPE(4); + + if (ARRAY_TYPE != Float32Array) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + } + + out[3] = 1; + return out; + } + /** + * Set a quat to the identity quaternion + * + * @param {quat} out the receiving quaternion + * @returns {quat} out + */ + + function identity$1(out) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + } + /** + * Sets a quat from the given angle and rotation axis, + * then returns it. + * + * @param {quat} out the receiving quaternion + * @param {vec3} axis the axis around which to rotate + * @param {Number} rad the angle in radians + * @returns {quat} out + **/ + + function setAxisAngle(out, axis, rad) { + rad = rad * 0.5; + var s = Math.sin(rad); + out[0] = s * axis[0]; + out[1] = s * axis[1]; + out[2] = s * axis[2]; + out[3] = Math.cos(rad); + return out; + } + /** + * Gets the rotation axis and angle for a given + * quaternion. If a quaternion is created with + * setAxisAngle, this method will return the same + * values as providied in the original parameter list + * OR functionally equivalent values. + * Example: The quaternion formed by axis [0, 0, 1] and + * angle -90 is the same as the quaternion formed by + * [0, 0, 1] and 270. This method favors the latter. + * @param {vec3} out_axis Vector receiving the axis of rotation + * @param {quat} q Quaternion to be decomposed + * @return {Number} Angle, in radians, of the rotation + */ + + function getAxisAngle(out_axis, q) { + var rad = Math.acos(q[3]) * 2.0; + var s = Math.sin(rad / 2.0); + + if (s > EPSILON) { + out_axis[0] = q[0] / s; + out_axis[1] = q[1] / s; + out_axis[2] = q[2] / s; + } else { + // If s is zero, return any axis (no rotation - axis does not matter) + out_axis[0] = 1; + out_axis[1] = 0; + out_axis[2] = 0; + } + + return rad; + } + /** + * Multiplies two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {quat} out + */ + + function multiply$1(out, a, b) { + var ax = a[0], + ay = a[1], + az = a[2], + aw = a[3]; + var bx = b[0], + by = b[1], + bz = b[2], + bw = b[3]; + out[0] = ax * bw + aw * bx + ay * bz - az * by; + out[1] = ay * bw + aw * by + az * bx - ax * bz; + out[2] = az * bw + aw * bz + ax * by - ay * bx; + out[3] = aw * bw - ax * bx - ay * by - az * bz; + return out; + } + /** + * Rotates a quaternion by the given angle about the X axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ + + function rotateX$1(out, a, rad) { + rad *= 0.5; + var ax = a[0], + ay = a[1], + az = a[2], + aw = a[3]; + var bx = Math.sin(rad), + bw = Math.cos(rad); + out[0] = ax * bw + aw * bx; + out[1] = ay * bw + az * bx; + out[2] = az * bw - ay * bx; + out[3] = aw * bw - ax * bx; + return out; + } + /** + * Rotates a quaternion by the given angle about the Y axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ + + function rotateY$1(out, a, rad) { + rad *= 0.5; + var ax = a[0], + ay = a[1], + az = a[2], + aw = a[3]; + var by = Math.sin(rad), + bw = Math.cos(rad); + out[0] = ax * bw - az * by; + out[1] = ay * bw + aw * by; + out[2] = az * bw + ax * by; + out[3] = aw * bw - ay * by; + return out; + } + /** + * Rotates a quaternion by the given angle about the Z axis + * + * @param {quat} out quat receiving operation result + * @param {quat} a quat to rotate + * @param {number} rad angle (in radians) to rotate + * @returns {quat} out + */ + + function rotateZ$1(out, a, rad) { + rad *= 0.5; + var ax = a[0], + ay = a[1], + az = a[2], + aw = a[3]; + var bz = Math.sin(rad), + bw = Math.cos(rad); + out[0] = ax * bw + ay * bz; + out[1] = ay * bw - ax * bz; + out[2] = az * bw + aw * bz; + out[3] = aw * bw - az * bz; + return out; + } + /** + * Calculates the W component of a quat from the X, Y, and Z components. + * Assumes that quaternion is 1 unit in length. + * Any existing W component will be ignored. + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate W component of + * @returns {quat} out + */ + + function calculateW(out, a) { + var x = a[0], + y = a[1], + z = a[2]; + out[0] = x; + out[1] = y; + out[2] = z; + out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z)); + return out; + } + /** + * Performs a spherical linear interpolation between two quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {Number} t interpolation amount, in the range [0-1], between the two inputs + * @returns {quat} out + */ + + function slerp(out, a, b, t) { + // benchmarks: + // http://jsperf.com/quaternion-slerp-implementations + var ax = a[0], + ay = a[1], + az = a[2], + aw = a[3]; + var bx = b[0], + by = b[1], + bz = b[2], + bw = b[3]; + var omega, cosom, sinom, scale0, scale1; // calc cosine + + cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary) + + if (cosom < 0.0) { + cosom = -cosom; + bx = -bx; + by = -by; + bz = -bz; + bw = -bw; + } // calculate coefficients + + + if (1.0 - cosom > EPSILON) { + // standard case (slerp) + omega = Math.acos(cosom); + sinom = Math.sin(omega); + scale0 = Math.sin((1.0 - t) * omega) / sinom; + scale1 = Math.sin(t * omega) / sinom; + } else { + // "from" and "to" quaternions are very close + // ... so we can do a linear interpolation + scale0 = 1.0 - t; + scale1 = t; + } // calculate final values + + + out[0] = scale0 * ax + scale1 * bx; + out[1] = scale0 * ay + scale1 * by; + out[2] = scale0 * az + scale1 * bz; + out[3] = scale0 * aw + scale1 * bw; + return out; + } + /** + * Generates a random quaternion + * + * @param {quat} out the receiving quaternion + * @returns {quat} out + */ + + function random(out) { + // Implementation of http://planning.cs.uiuc.edu/node198.html + // TODO: Calling random 3 times is probably not the fastest solution + var u1 = RANDOM(); + var u2 = RANDOM(); + var u3 = RANDOM(); + var sqrt1MinusU1 = Math.sqrt(1 - u1); + var sqrtU1 = Math.sqrt(u1); + out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2); + out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2); + out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3); + out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3); + return out; + } + /** + * Calculates the inverse of a quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate inverse of + * @returns {quat} out + */ + + function invert$1(out, a) { + var a0 = a[0], + a1 = a[1], + a2 = a[2], + a3 = a[3]; + var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3; + var invDot = dot ? 1.0 / dot : 0; // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0 + + out[0] = -a0 * invDot; + out[1] = -a1 * invDot; + out[2] = -a2 * invDot; + out[3] = a3 * invDot; + return out; + } + /** + * Calculates the conjugate of a quat + * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result. + * + * @param {quat} out the receiving quaternion + * @param {quat} a quat to calculate conjugate of + * @returns {quat} out + */ + + function conjugate(out, a) { + out[0] = -a[0]; + out[1] = -a[1]; + out[2] = -a[2]; + out[3] = a[3]; + return out; + } + /** + * Creates a quaternion from the given 3x3 rotation matrix. + * + * NOTE: The resultant quaternion is not normalized, so you should be sure + * to renormalize the quaternion yourself where necessary. + * + * @param {quat} out the receiving quaternion + * @param {mat3} m rotation matrix + * @returns {quat} out + * @function + */ + + function fromMat3(out, m) { + // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes + // article "Quaternion Calculus and Fast Animation". + var fTrace = m[0] + m[4] + m[8]; + var fRoot; + + if (fTrace > 0.0) { + // |w| > 1/2, may as well choose w > 1/2 + fRoot = Math.sqrt(fTrace + 1.0); // 2w + + out[3] = 0.5 * fRoot; + fRoot = 0.5 / fRoot; // 1/(4w) + + out[0] = (m[5] - m[7]) * fRoot; + out[1] = (m[6] - m[2]) * fRoot; + out[2] = (m[1] - m[3]) * fRoot; + } else { + // |w| <= 1/2 + var i = 0; + if (m[4] > m[0]) i = 1; + if (m[8] > m[i * 3 + i]) i = 2; + var j = (i + 1) % 3; + var k = (i + 2) % 3; + fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0); + out[i] = 0.5 * fRoot; + fRoot = 0.5 / fRoot; + out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot; + out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot; + out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot; + } + + return out; + } + /** + * Creates a quaternion from the given euler angle x, y, z. + * + * @param {quat} out the receiving quaternion + * @param {x} Angle to rotate around X axis in degrees. + * @param {y} Angle to rotate around Y axis in degrees. + * @param {z} Angle to rotate around Z axis in degrees. + * @returns {quat} out + * @function + */ + + function fromEuler(out, x, y, z) { + var halfToRad = 0.5 * Math.PI / 180.0; + x *= halfToRad; + y *= halfToRad; + z *= halfToRad; + var sx = Math.sin(x); + var cx = Math.cos(x); + var sy = Math.sin(y); + var cy = Math.cos(y); + var sz = Math.sin(z); + var cz = Math.cos(z); + out[0] = sx * cy * cz - cx * sy * sz; + out[1] = cx * sy * cz + sx * cy * sz; + out[2] = cx * cy * sz - sx * sy * cz; + out[3] = cx * cy * cz + sx * sy * sz; + return out; + } + /** + * Returns a string representation of a quatenion + * + * @param {quat} a vector to represent as a string + * @returns {String} string representation of the vector + */ + + function str$1(a) { + return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')'; + } + /** + * Creates a new quat initialized with values from an existing quaternion + * + * @param {quat} a quaternion to clone + * @returns {quat} a new quaternion + * @function + */ + + var clone$3 = clone$2; + /** + * Creates a new quat initialized with the given values + * + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {quat} a new quaternion + * @function + */ + + var fromValues$3 = fromValues$2; + /** + * Copy the values from one quat to another + * + * @param {quat} out the receiving quaternion + * @param {quat} a the source quaternion + * @returns {quat} out + * @function + */ + + var copy$3 = copy$2; + /** + * Set the components of a quat to the given values + * + * @param {quat} out the receiving quaternion + * @param {Number} x X component + * @param {Number} y Y component + * @param {Number} z Z component + * @param {Number} w W component + * @returns {quat} out + * @function + */ + + var set$2 = set$1; + /** + * Adds two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {quat} out + * @function + */ + + var add$3 = add$2; + /** + * Alias for {@link quat.multiply} + * @function + */ + + var mul$1 = multiply$1; + /** + * Scales a quat by a scalar number + * + * @param {quat} out the receiving vector + * @param {quat} a the vector to scale + * @param {Number} b amount to scale the vector by + * @returns {quat} out + * @function + */ + + var scale$2 = scale$1; + /** + * Calculates the dot product of two quat's + * + * @param {quat} a the first operand + * @param {quat} b the second operand + * @returns {Number} dot product of a and b + * @function + */ + + var dot$2 = dot$1; + /** + * Performs a linear interpolation between two quat's + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {Number} t interpolation amount, in the range [0-1], between the two inputs + * @returns {quat} out + * @function + */ + + var lerp$1 = lerp; + /** + * Calculates the length of a quat + * + * @param {quat} a vector to calculate length of + * @returns {Number} length of a + */ + + var length$2 = length$1; + /** + * Alias for {@link quat.length} + * @function + */ + + var len$1 = length$2; + /** + * Calculates the squared length of a quat + * + * @param {quat} a vector to calculate squared length of + * @returns {Number} squared length of a + * @function + */ + + var squaredLength$1 = squaredLength; + /** + * Alias for {@link quat.squaredLength} + * @function + */ + + var sqrLen = squaredLength$1; + /** + * Normalize a quat + * + * @param {quat} out the receiving quaternion + * @param {quat} a quaternion to normalize + * @returns {quat} out + * @function + */ + + var normalize$2 = normalize$1; + /** + * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===) + * + * @param {quat} a The first quaternion. + * @param {quat} b The second quaternion. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + + var exactEquals$2 = exactEquals$1; + /** + * Returns whether or not the quaternions have approximately the same elements in the same position. + * + * @param {quat} a The first vector. + * @param {quat} b The second vector. + * @returns {Boolean} True if the vectors are equal, false otherwise. + */ + + var equals$2 = equals$1; + /** + * Sets a quaternion to represent the shortest rotation from one + * vector to another. + * + * Both vectors are assumed to be unit length. + * + * @param {quat} out the receiving quaternion. + * @param {vec3} a the initial vector + * @param {vec3} b the destination vector + * @returns {quat} out + */ + + var rotationTo = function () { + var tmpvec3 = create$2(); + var xUnitVec3 = fromValues$1(1, 0, 0); + var yUnitVec3 = fromValues$1(0, 1, 0); + return function (out, a, b) { + var dot$1 = dot(a, b); + + if (dot$1 < -0.999999) { + cross(tmpvec3, xUnitVec3, a); + if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a); + normalize(tmpvec3, tmpvec3); + setAxisAngle(out, tmpvec3, Math.PI); + return out; + } else if (dot$1 > 0.999999) { + out[0] = 0; + out[1] = 0; + out[2] = 0; + out[3] = 1; + return out; + } else { + cross(tmpvec3, a, b); + out[0] = tmpvec3[0]; + out[1] = tmpvec3[1]; + out[2] = tmpvec3[2]; + out[3] = 1 + dot$1; + return normalize$2(out, out); + } + }; + }(); + /** + * Performs a spherical linear interpolation with two control points + * + * @param {quat} out the receiving quaternion + * @param {quat} a the first operand + * @param {quat} b the second operand + * @param {quat} c the third operand + * @param {quat} d the fourth operand + * @param {Number} t interpolation amount, in the range [0-1], between the two inputs + * @returns {quat} out + */ + + var sqlerp = function () { + var temp1 = create$4(); + var temp2 = create$4(); + return function (out, a, b, c, d, t) { + slerp(temp1, a, d, t); + slerp(temp2, b, c, t); + slerp(out, temp1, temp2, 2 * t * (1 - t)); + return out; + }; + }(); + /** + * Sets the specified quaternion with values corresponding to the given + * axes. Each axis is a vec3 and is expected to be unit length and + * perpendicular to all other specified axes. + * + * @param {vec3} view the vector representing the viewing direction + * @param {vec3} right the vector representing the local "right" direction + * @param {vec3} up the vector representing the local "up" direction + * @returns {quat} out + */ + + var setAxes = function () { + var matr = create(); + return function (out, view, right, up) { + matr[0] = right[0]; + matr[3] = right[1]; + matr[6] = right[2]; + matr[1] = up[0]; + matr[4] = up[1]; + matr[7] = up[2]; + matr[2] = -view[0]; + matr[5] = -view[1]; + matr[8] = -view[2]; + return normalize$2(out, fromMat3(out, matr)); + }; + }(); + + var quat = ({ + create: create$4, + identity: identity$1, + setAxisAngle: setAxisAngle, + getAxisAngle: getAxisAngle, + multiply: multiply$1, + rotateX: rotateX$1, + rotateY: rotateY$1, + rotateZ: rotateZ$1, + calculateW: calculateW, + slerp: slerp, + random: random, + invert: invert$1, + conjugate: conjugate, + fromMat3: fromMat3, + fromEuler: fromEuler, + str: str$1, + clone: clone$3, + fromValues: fromValues$3, + copy: copy$3, + set: set$2, + add: add$3, + mul: mul$1, + scale: scale$2, + dot: dot$2, + lerp: lerp$1, + length: length$2, + len: len$1, + squaredLength: squaredLength$1, + sqrLen: sqrLen, + normalize: normalize$2, + exactEquals: exactEquals$2, + equals: equals$2, + rotationTo: rotationTo, + sqlerp: sqlerp, + setAxes: setAxes + }); + + /** + * Calculates the squared length of a dual quat + * + * @param {quat2} a dual quat to calculate squared length of + * @returns {Number} squared length of a + * @function + */ + + var squaredLength$2 = squaredLength$1; + + /** + * 2 Dimensional Vector + * @module vec2 + */ + + /** + * Creates a new, empty vec2 + * + * @returns {vec2} a new 2D vector + */ + + function create$5() { + var out = new ARRAY_TYPE(2); + + if (ARRAY_TYPE != Float32Array) { + out[0] = 0; + out[1] = 0; + } + + return out; + } + /** + * Perform some operation over an array of vec2s. + * + * @param {Array} a the array of vectors to iterate over + * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed + * @param {Number} offset Number of elements to skip at the beginning of the array + * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array + * @param {Function} fn Function to call for each vector in the array + * @param {Object} [arg] additional argument to pass to fn + * @returns {Array} a + * @function + */ + + var forEach$2 = function () { + var vec = create$5(); + return function (a, stride, offset, count, fn, arg) { + var i, l; + + if (!stride) { + stride = 2; + } + + if (!offset) { + offset = 0; + } + + if (count) { + l = Math.min(count * stride + offset, a.length); + } else { + l = a.length; + } + + for (i = offset; i < l; i += stride) { + vec[0] = a[i]; + vec[1] = a[i + 1]; + fn(vec, vec, arg); + a[i] = vec[0]; + a[i + 1] = vec[1]; + } + + return a; + }; + }(); + + var ELEMENT_NOT_EXIST = function (selector) { + return "Element with selector \"" + selector + "\" doesn't exist."; + }; + var MUST_STRING_OR_ELEMENT = function (received) { + return "Element should be provided in string or HTMLElement. Received: " + received; + }; + + var getElement = function (el, baseElement) { + if (typeof el === 'string') { + var queryResult = baseElement ? baseElement.querySelector(el) : document.querySelector(el); + + if (!queryResult) { + throw new Error(ELEMENT_NOT_EXIST(el)); + } + + return queryResult; + } else if (el.nodeName && el.nodeType === 1) { + return el; + } else { + throw new Error(MUST_STRING_OR_ELEMENT(el)); + } + }; + function applyCSS(element, cssObj) { + Object.keys(cssObj).forEach(function (property) { + element.style[property] = cssObj[property]; + }); + } + function getTransformMatrix(elStyle) { + var trVal = elStyle.getPropertyValue('transform'); + var transformStr = /\(((\s|\S)+)\)/.exec(trVal); + var matrixVal = transformStr ? transformStr[1].split(',').map(function (val) { + return parseFloat(val); + }) : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; + + if (matrixVal.length === 16) { + return fromValues.apply(mat4, __spread(matrixVal)); + } else { + var matrix = create$1(); + identity(matrix); + matrix[0] = matrixVal[0]; + matrix[1] = matrixVal[1]; + matrix[4] = matrixVal[2]; + matrix[5] = matrixVal[3]; + matrix[12] = matrixVal[4]; + matrix[13] = matrixVal[5]; + return matrix; + } + } + function getOffsetFromParent(currentOffset, parentOffset) { + var offsetLeft = currentOffset.left + (currentOffset.width - parentOffset.width) / 2; + var offsetTop = currentOffset.top + (currentOffset.height - parentOffset.height) / 2; + return fromValues$1(offsetLeft, offsetTop, 0); + } + function getRotateOffset(elStyle, currentOffset) { + var axis = elStyle.transformOrigin.split(' ').map(function (str) { + return parseFloat(str.substring(0, str.length - 2)); + }); + var ax = axis[0] - currentOffset.width / 2; + var ay = axis[1] - currentOffset.height / 2; + return fromValues$1(ax, ay, 0); + } + function findIndex(iterable, callback) { + for (var i = 0; i < iterable.length; i += 1) { + var element = iterable[i]; + + if (element && callback(element)) { + return i; + } + } + + return -1; + } + function clamp(val, min, max) { + return Math.max(Math.min(val, max), min); + } + function assign(target) { + var srcs = []; + + for (var _i = 1; _i < arguments.length; _i++) { + srcs[_i - 1] = arguments[_i]; + } + + srcs.forEach(function (source) { + Object.keys(source).forEach(function (key) { + var value = source[key]; + target[key] = value; + }); + }); + return target; + } + + function radToDeg(rad) { + return 180 * rad / Math.PI; + } + function quatToEuler(q) { + var rotM = create$1(); + fromQuat(rotM, q); + var m11 = rotM[0]; + var m12 = rotM[4]; + var m21 = rotM[1]; + var m22 = rotM[5]; + var m31 = rotM[2]; + var m32 = rotM[6]; + var m33 = rotM[10]; + var euler = create$2(); + euler[1] = Math.asin(-clamp(m31, -1, 1)); + + if (Math.abs(m31) < 0.99999) { + euler[0] = Math.atan2(m32, m33); + euler[2] = Math.atan2(m21, m11); + } else { + euler[0] = 0; + euler[2] = Math.atan2(-m12, m22); + } + + return euler.map(function (val) { + return radToDeg(val); + }); + } + + var STYLE = { + VIEWPORT: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + overflow: 'hidden' + }, + CAMERA: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + 'will-change': 'transform' + }, + WORLD: { + width: '100%', + height: '100%', + 'transform-style': 'preserve-3d', + 'will-change': 'transform' + } + }; + var CLASS = { + VIEWPORT: 'cc-viewport', + CAMERA: 'cc-camera', + WORLD: 'cc-world' + }; + var OPTIONS = { + position: [0, 0, 0], + scale: [1, 1, 1], + rotation: [0, 0, 0], + perspective: 0, + rotateOffset: 0 + }; + var UPDATE_OPTIONS = { + property: 'transform', + timingFunction: 'ease-out', + delay: '0ms' + }; + + var CSSCamera = function () { + function CSSCamera(el, options) { + if (options === void 0) { + options = {}; + } + + this._element = getElement(el); + var op = assign(assign({}, OPTIONS), options); + this._position = fromValues$1(op.position[0], op.position[1], op.position[2]); + this._scale = fromValues$1(op.scale[0], op.scale[1], op.scale[2]); + this._rotation = fromValues$1(op.rotation[0], op.rotation[1], op.rotation[2]); + this._perspective = op.perspective; + this._rotateOffset = op.rotateOffset; + this._updateTimer = -1; + var element = this._element; + var viewport = document.createElement('div'); + var camera = viewport.cloneNode(); + var world = viewport.cloneNode(); + viewport.className = CLASS.VIEWPORT; + camera.className = CLASS.CAMERA; + world.className = CLASS.WORLD; + applyCSS(viewport, STYLE.VIEWPORT); + applyCSS(camera, STYLE.CAMERA); + applyCSS(world, STYLE.WORLD); + camera.appendChild(world); + viewport.appendChild(camera); + this._viewportEl = viewport; + this._cameraEl = camera; + this._worldEl = world; + element.parentElement.insertBefore(viewport, element); + world.appendChild(element); + this.update(0); + } + + var __proto = CSSCamera.prototype; + Object.defineProperty(CSSCamera, "VERSION", { + get: function () { + return '1.0.1'; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "element", { + get: function () { + return this._element; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "viewportEl", { + get: function () { + return this._viewportEl; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "cameraEl", { + get: function () { + return this._cameraEl; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "worldEl", { + get: function () { + return this._worldEl; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "position", { + get: function () { + return __spread(this._position); + }, + set: function (val) { + this._position = fromValues$1(val[0], val[1], val[2]); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "scale", { + get: function () { + return __spread(this._scale); + }, + set: function (val) { + this._scale = fromValues$1(val[0], val[1], val[2]); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "rotation", { + get: function () { + return __spread(this._rotation); + }, + set: function (val) { + this._rotation = fromValues$1(val[0], val[1], val[2]); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "quaternion", { + get: function () { + var r = this._rotation; + var quaternion = fromEuler(create$4(), r[0], r[1], r[2]); + return __spread(quaternion); + }, + set: function (val) { + this._rotation = quatToEuler(fromValues$3(val[0], val[1], val[2], val[3])); + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "perspective", { + get: function () { + return this._perspective; + }, + set: function (val) { + this._perspective = val; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "rotateOffset", { + get: function () { + return this._rotateOffset; + }, + set: function (val) { + this._rotateOffset = val; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "cameraCSS", { + get: function () { + var perspective = this._perspective; + var rotateOffset = this._rotateOffset; + var rotation = this._rotation; + var scale = this._scale; + return "scale3d(" + scale[0] + ", " + scale[1] + ", " + scale[2] + ") translateZ(" + (perspective - rotateOffset) + "px) rotateX(" + rotation[0] + "deg) rotateY(" + rotation[1] + "deg) rotateZ(" + rotation[2] + "deg)"; + }, + enumerable: true, + configurable: true + }); + Object.defineProperty(__proto, "worldCSS", { + get: function () { + var position = this._position; + return "translate3d(" + -position[0] + "px, " + -position[1] + "px, " + -position[2] + "px)"; + }, + enumerable: true, + configurable: true + }); + + __proto.focus = function (el) { + var element = getElement(el); + + var focusMatrix = this._getFocusMatrix(element); + + var rotation = create$4(); + var translation = create$2(); + getRotation(rotation, focusMatrix); + getTranslation(translation, focusMatrix); + var eulerAngle = quatToEuler(rotation); + negate(eulerAngle, eulerAngle); + this._rotation = eulerAngle; + this._position = translation; + return this; + }; + + __proto.translateLocal = function (x, y, z) { + if (x === void 0) { + x = 0; + } + + if (y === void 0) { + y = 0; + } + + if (z === void 0) { + z = 0; + } + + var position = this._position; + var rotation = this._rotation; + var transVec = fromValues$1(x, y, z); + var rotQuat = create$4(); + fromEuler(rotQuat, -rotation[0], -rotation[1], -rotation[2]); + transformQuat(transVec, transVec, rotQuat); + add$1(position, position, transVec); + return this; + }; + + __proto.translate = function (x, y, z) { + if (x === void 0) { + x = 0; + } + + if (y === void 0) { + y = 0; + } + + if (z === void 0) { + z = 0; + } + + add$1(this._position, this._position, fromValues$1(x, y, z)); + return this; + }; + + __proto.rotate = function (x, y, z) { + if (x === void 0) { + x = 0; + } + + if (y === void 0) { + y = 0; + } + + if (z === void 0) { + z = 0; + } + + add$1(this._rotation, this._rotation, fromValues$1(x, y, z)); + return this; + }; + + __proto.update = function (duration, options) { + if (duration === void 0) { + duration = 0; + } + + if (options === void 0) { + options = {}; + } + + return __awaiter(this, void 0, Promise, function () { + var updateOptions, transitionDuration, updateOption, finalOption_1; + + var _this = this; + + return __generator(this, function (_a) { + applyCSS(this._viewportEl, { + perspective: this.perspective + "px" + }); + applyCSS(this._cameraEl, { + transform: this.cameraCSS + }); + applyCSS(this._worldEl, { + transform: this.worldCSS + }); + updateOptions = assign(assign({}, UPDATE_OPTIONS), options); + + if (duration > 0) { + if (this._updateTimer > 0) { + window.clearTimeout(this._updateTimer); + } + + transitionDuration = duration + "ms"; + updateOption = Object.keys(updateOptions).reduce(function (option, key) { + option["transition" + (key.charAt(0).toUpperCase() + key.slice(1))] = updateOptions[key]; + return option; + }, {}); + finalOption_1 = __assign({ + transitionDuration: transitionDuration + }, updateOption); + [this._viewportEl, this._cameraEl, this._worldEl].forEach(function (el) { + applyCSS(el, finalOption_1); + }); + } + + return [2, new Promise(function (resolve) { + if (duration > 0) { + _this._updateTimer = window.setTimeout(function () { + [_this._viewportEl, _this._cameraEl, _this._worldEl].forEach(function (el) { + applyCSS(el, { + transition: '' + }); + }); + _this._updateTimer = -1; + resolve(); + }, duration); + } else { + requestAnimationFrame(function () { + resolve(); + }); + } + })]; + }); + }); + }; + + __proto._getFocusMatrix = function (element) { + var elements = []; + + while (element) { + elements.push(element); + if (element === this._element) break; + element = element.parentElement; + } + + elements.reverse(); + var elStyles = elements.map(function (el) { + return window.getComputedStyle(el); + }); + var firstFlatIndex = findIndex(elStyles, function (style) { + return style.transformStyle !== 'preserve-3d'; + }); + + if (firstFlatIndex > 0) { + elStyles.splice(firstFlatIndex + 1); + } + + var parentOffset = { + left: 0, + top: 0, + width: this.viewportEl.offsetWidth, + height: this.viewportEl.offsetHeight + }; + var accRotation = identity$1(create$4()); + var centerPos = fromValues$1(0, 0, 0); + elStyles.forEach(function (style, idx) { + var el = elements[idx]; + var currentOffset = { + left: el.offsetLeft, + top: el.offsetTop, + width: el.offsetWidth, + height: el.offsetHeight + }; + var transformMat = getTransformMatrix(style); + var offsetFromParent = getOffsetFromParent(currentOffset, parentOffset); + transformQuat(offsetFromParent, offsetFromParent, accRotation); + add$1(centerPos, centerPos, offsetFromParent); + var rotateOffset = getRotateOffset(style, currentOffset); + transformQuat(rotateOffset, rotateOffset, accRotation); + var transformOrigin = clone$1(centerPos); + add$1(transformOrigin, transformOrigin, rotateOffset); + var centerFromOrigin = create$2(); + sub$1(centerFromOrigin, centerPos, transformOrigin); + var invAccRotation = invert$1(create$4(), accRotation); + transformQuat(centerFromOrigin, centerFromOrigin, invAccRotation); + transformMat4(centerFromOrigin, centerFromOrigin, transformMat); + transformQuat(centerFromOrigin, centerFromOrigin, accRotation); + var newCenterPos = add$1(create$2(), transformOrigin, centerFromOrigin); + var rotation = getRotation(create$4(), transformMat); + copy$1(centerPos, newCenterPos); + mul$1(accRotation, accRotation, rotation); + parentOffset = currentOffset; + }); + var perspective = fromValues$1(0, 0, this.perspective); + transformQuat(perspective, perspective, accRotation); + add$1(centerPos, centerPos, perspective); + var matrix = create$1(); + fromRotationTranslation(matrix, accRotation, centerPos); + return matrix; + }; + + return CSSCamera; + }(); + + return CSSCamera; + +})); +//# sourceMappingURL=css-camera.pkgd.js.map diff --git a/lib/css-camera.pkgd.js.map b/lib/css-camera.pkgd.js.map new file mode 100644 index 0000000..3ac5bbb --- /dev/null +++ b/lib/css-camera.pkgd.js.map @@ -0,0 +1 @@ +{"version":3,"file":"css-camera.pkgd.js","sources":["../node_modules/gl-matrix/esm/common.js","../node_modules/gl-matrix/esm/mat3.js","../node_modules/gl-matrix/esm/mat4.js","../node_modules/gl-matrix/esm/vec3.js","../node_modules/gl-matrix/esm/vec4.js","../node_modules/gl-matrix/esm/quat.js","../node_modules/gl-matrix/esm/quat2.js","../node_modules/gl-matrix/esm/vec2.js","../src/constants/error.ts","../src/utils/helper.ts","../src/utils/math.ts","../src/constants/default.ts","../src/CSSCamera.ts"],"sourcesContent":["/**\r\n * Common utilities\r\n * @module glMatrix\r\n */\n// Configuration Constants\nexport var EPSILON = 0.000001;\nexport var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;\nexport var RANDOM = Math.random;\n/**\r\n * Sets the type of array used when creating new vectors and matrices\r\n *\r\n * @param {Type} type Array type, such as Float32Array or Array\r\n */\n\nexport function setMatrixArrayType(type) {\n ARRAY_TYPE = type;\n}\nvar degree = Math.PI / 180;\n/**\r\n * Convert Degree To Radian\r\n *\r\n * @param {Number} a Angle in Degrees\r\n */\n\nexport function toRadian(a) {\n return a * degree;\n}\n/**\r\n * Tests whether or not the arguments have approximately the same value, within an absolute\r\n * or relative tolerance of glMatrix.EPSILON (an absolute tolerance is used for values less\r\n * than or equal to 1.0, and a relative tolerance is used for larger values)\r\n *\r\n * @param {Number} a The first number to test.\r\n * @param {Number} b The second number to test.\r\n * @returns {Boolean} True if the numbers are approximately equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n return Math.abs(a - b) <= EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));\n}","import * as glMatrix from \"./common.js\";\n/**\r\n * 3x3 Matrix\r\n * @module mat3\r\n */\n\n/**\r\n * Creates a new identity mat3\r\n *\r\n * @returns {mat3} a new 3x3 matrix\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(9);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n }\n\n out[0] = 1;\n out[4] = 1;\n out[8] = 1;\n return out;\n}\n/**\r\n * Copies the upper-left 3x3 values into the given mat3.\r\n *\r\n * @param {mat3} out the receiving 3x3 matrix\r\n * @param {mat4} a the source 4x4 matrix\r\n * @returns {mat3} out\r\n */\n\nexport function fromMat4(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[4];\n out[4] = a[5];\n out[5] = a[6];\n out[6] = a[8];\n out[7] = a[9];\n out[8] = a[10];\n return out;\n}\n/**\r\n * Creates a new mat3 initialized with values from an existing matrix\r\n *\r\n * @param {mat3} a matrix to clone\r\n * @returns {mat3} a new 3x3 matrix\r\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(9);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n}\n/**\r\n * Copy the values from one mat3 to another\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the source matrix\r\n * @returns {mat3} out\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n}\n/**\r\n * Create a new mat3 with the given values\r\n *\r\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\r\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\r\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\r\n * @param {Number} m10 Component in column 1, row 0 position (index 3)\r\n * @param {Number} m11 Component in column 1, row 1 position (index 4)\r\n * @param {Number} m12 Component in column 1, row 2 position (index 5)\r\n * @param {Number} m20 Component in column 2, row 0 position (index 6)\r\n * @param {Number} m21 Component in column 2, row 1 position (index 7)\r\n * @param {Number} m22 Component in column 2, row 2 position (index 8)\r\n * @returns {mat3} A new mat3\r\n */\n\nexport function fromValues(m00, m01, m02, m10, m11, m12, m20, m21, m22) {\n var out = new glMatrix.ARRAY_TYPE(9);\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m10;\n out[4] = m11;\n out[5] = m12;\n out[6] = m20;\n out[7] = m21;\n out[8] = m22;\n return out;\n}\n/**\r\n * Set the components of a mat3 to the given values\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\r\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\r\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\r\n * @param {Number} m10 Component in column 1, row 0 position (index 3)\r\n * @param {Number} m11 Component in column 1, row 1 position (index 4)\r\n * @param {Number} m12 Component in column 1, row 2 position (index 5)\r\n * @param {Number} m20 Component in column 2, row 0 position (index 6)\r\n * @param {Number} m21 Component in column 2, row 1 position (index 7)\r\n * @param {Number} m22 Component in column 2, row 2 position (index 8)\r\n * @returns {mat3} out\r\n */\n\nexport function set(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m10;\n out[4] = m11;\n out[5] = m12;\n out[6] = m20;\n out[7] = m21;\n out[8] = m22;\n return out;\n}\n/**\r\n * Set a mat3 to the identity matrix\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @returns {mat3} out\r\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 1;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n}\n/**\r\n * Transpose the values of a mat3\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the source matrix\r\n * @returns {mat3} out\r\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a01 = a[1],\n a02 = a[2],\n a12 = a[5];\n out[1] = a[3];\n out[2] = a[6];\n out[3] = a01;\n out[5] = a[7];\n out[6] = a02;\n out[7] = a12;\n } else {\n out[0] = a[0];\n out[1] = a[3];\n out[2] = a[6];\n out[3] = a[1];\n out[4] = a[4];\n out[5] = a[7];\n out[6] = a[2];\n out[7] = a[5];\n out[8] = a[8];\n }\n\n return out;\n}\n/**\r\n * Inverts a mat3\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the source matrix\r\n * @returns {mat3} out\r\n */\n\nexport function invert(out, a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2];\n var a10 = a[3],\n a11 = a[4],\n a12 = a[5];\n var a20 = a[6],\n a21 = a[7],\n a22 = a[8];\n var b01 = a22 * a11 - a12 * a21;\n var b11 = -a22 * a10 + a12 * a20;\n var b21 = a21 * a10 - a11 * a20; // Calculate the determinant\n\n var det = a00 * b01 + a01 * b11 + a02 * b21;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = b01 * det;\n out[1] = (-a22 * a01 + a02 * a21) * det;\n out[2] = (a12 * a01 - a02 * a11) * det;\n out[3] = b11 * det;\n out[4] = (a22 * a00 - a02 * a20) * det;\n out[5] = (-a12 * a00 + a02 * a10) * det;\n out[6] = b21 * det;\n out[7] = (-a21 * a00 + a01 * a20) * det;\n out[8] = (a11 * a00 - a01 * a10) * det;\n return out;\n}\n/**\r\n * Calculates the adjugate of a mat3\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the source matrix\r\n * @returns {mat3} out\r\n */\n\nexport function adjoint(out, a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2];\n var a10 = a[3],\n a11 = a[4],\n a12 = a[5];\n var a20 = a[6],\n a21 = a[7],\n a22 = a[8];\n out[0] = a11 * a22 - a12 * a21;\n out[1] = a02 * a21 - a01 * a22;\n out[2] = a01 * a12 - a02 * a11;\n out[3] = a12 * a20 - a10 * a22;\n out[4] = a00 * a22 - a02 * a20;\n out[5] = a02 * a10 - a00 * a12;\n out[6] = a10 * a21 - a11 * a20;\n out[7] = a01 * a20 - a00 * a21;\n out[8] = a00 * a11 - a01 * a10;\n return out;\n}\n/**\r\n * Calculates the determinant of a mat3\r\n *\r\n * @param {mat3} a the source matrix\r\n * @returns {Number} determinant of a\r\n */\n\nexport function determinant(a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2];\n var a10 = a[3],\n a11 = a[4],\n a12 = a[5];\n var a20 = a[6],\n a21 = a[7],\n a22 = a[8];\n return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);\n}\n/**\r\n * Multiplies two mat3's\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the first operand\r\n * @param {mat3} b the second operand\r\n * @returns {mat3} out\r\n */\n\nexport function multiply(out, a, b) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2];\n var a10 = a[3],\n a11 = a[4],\n a12 = a[5];\n var a20 = a[6],\n a21 = a[7],\n a22 = a[8];\n var b00 = b[0],\n b01 = b[1],\n b02 = b[2];\n var b10 = b[3],\n b11 = b[4],\n b12 = b[5];\n var b20 = b[6],\n b21 = b[7],\n b22 = b[8];\n out[0] = b00 * a00 + b01 * a10 + b02 * a20;\n out[1] = b00 * a01 + b01 * a11 + b02 * a21;\n out[2] = b00 * a02 + b01 * a12 + b02 * a22;\n out[3] = b10 * a00 + b11 * a10 + b12 * a20;\n out[4] = b10 * a01 + b11 * a11 + b12 * a21;\n out[5] = b10 * a02 + b11 * a12 + b12 * a22;\n out[6] = b20 * a00 + b21 * a10 + b22 * a20;\n out[7] = b20 * a01 + b21 * a11 + b22 * a21;\n out[8] = b20 * a02 + b21 * a12 + b22 * a22;\n return out;\n}\n/**\r\n * Translate a mat3 by the given vector\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the matrix to translate\r\n * @param {vec2} v vector to translate by\r\n * @returns {mat3} out\r\n */\n\nexport function translate(out, a, v) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a10 = a[3],\n a11 = a[4],\n a12 = a[5],\n a20 = a[6],\n a21 = a[7],\n a22 = a[8],\n x = v[0],\n y = v[1];\n out[0] = a00;\n out[1] = a01;\n out[2] = a02;\n out[3] = a10;\n out[4] = a11;\n out[5] = a12;\n out[6] = x * a00 + y * a10 + a20;\n out[7] = x * a01 + y * a11 + a21;\n out[8] = x * a02 + y * a12 + a22;\n return out;\n}\n/**\r\n * Rotates a mat3 by the given angle\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the matrix to rotate\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat3} out\r\n */\n\nexport function rotate(out, a, rad) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a10 = a[3],\n a11 = a[4],\n a12 = a[5],\n a20 = a[6],\n a21 = a[7],\n a22 = a[8],\n s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c * a00 + s * a10;\n out[1] = c * a01 + s * a11;\n out[2] = c * a02 + s * a12;\n out[3] = c * a10 - s * a00;\n out[4] = c * a11 - s * a01;\n out[5] = c * a12 - s * a02;\n out[6] = a20;\n out[7] = a21;\n out[8] = a22;\n return out;\n}\n;\n/**\r\n * Scales the mat3 by the dimensions in the given vec2\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the matrix to rotate\r\n * @param {vec2} v the vec2 to scale the matrix by\r\n * @returns {mat3} out\r\n **/\n\nexport function scale(out, a, v) {\n var x = v[0],\n y = v[1];\n out[0] = x * a[0];\n out[1] = x * a[1];\n out[2] = x * a[2];\n out[3] = y * a[3];\n out[4] = y * a[4];\n out[5] = y * a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n}\n/**\r\n * Creates a matrix from a vector translation\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat3.identity(dest);\r\n * mat3.translate(dest, dest, vec);\r\n *\r\n * @param {mat3} out mat3 receiving operation result\r\n * @param {vec2} v Translation vector\r\n * @returns {mat3} out\r\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 1;\n out[5] = 0;\n out[6] = v[0];\n out[7] = v[1];\n out[8] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a given angle\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat3.identity(dest);\r\n * mat3.rotate(dest, dest, rad);\r\n *\r\n * @param {mat3} out mat3 receiving operation result\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat3} out\r\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = 0;\n out[3] = -s;\n out[4] = c;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a vector scaling\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat3.identity(dest);\r\n * mat3.scale(dest, dest, vec);\r\n *\r\n * @param {mat3} out mat3 receiving operation result\r\n * @param {vec2} v Scaling vector\r\n * @returns {mat3} out\r\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = v[1];\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n}\n/**\r\n * Copies the values from a mat2d into a mat3\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat2d} a the matrix to copy\r\n * @returns {mat3} out\r\n **/\n\nexport function fromMat2d(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = 0;\n out[3] = a[2];\n out[4] = a[3];\n out[5] = 0;\n out[6] = a[4];\n out[7] = a[5];\n out[8] = 1;\n return out;\n}\n/**\r\n* Calculates a 3x3 matrix from the given quaternion\r\n*\r\n* @param {mat3} out mat3 receiving operation result\r\n* @param {quat} q Quaternion to create matrix from\r\n*\r\n* @returns {mat3} out\r\n*/\n\nexport function fromQuat(out, q) {\n var x = q[0],\n y = q[1],\n z = q[2],\n w = q[3];\n var x2 = x + x;\n var y2 = y + y;\n var z2 = z + z;\n var xx = x * x2;\n var yx = y * x2;\n var yy = y * y2;\n var zx = z * x2;\n var zy = z * y2;\n var zz = z * z2;\n var wx = w * x2;\n var wy = w * y2;\n var wz = w * z2;\n out[0] = 1 - yy - zz;\n out[3] = yx - wz;\n out[6] = zx + wy;\n out[1] = yx + wz;\n out[4] = 1 - xx - zz;\n out[7] = zy - wx;\n out[2] = zx - wy;\n out[5] = zy + wx;\n out[8] = 1 - xx - yy;\n return out;\n}\n/**\r\n* Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix\r\n*\r\n* @param {mat3} out mat3 receiving operation result\r\n* @param {mat4} a Mat4 to derive the normal matrix from\r\n*\r\n* @returns {mat3} out\r\n*/\n\nexport function normalFromMat4(out, a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n var a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n var a30 = a[12],\n a31 = a[13],\n a32 = a[14],\n a33 = a[15];\n var b00 = a00 * a11 - a01 * a10;\n var b01 = a00 * a12 - a02 * a10;\n var b02 = a00 * a13 - a03 * a10;\n var b03 = a01 * a12 - a02 * a11;\n var b04 = a01 * a13 - a03 * a11;\n var b05 = a02 * a13 - a03 * a12;\n var b06 = a20 * a31 - a21 * a30;\n var b07 = a20 * a32 - a22 * a30;\n var b08 = a20 * a33 - a23 * a30;\n var b09 = a21 * a32 - a22 * a31;\n var b10 = a21 * a33 - a23 * a31;\n var b11 = a22 * a33 - a23 * a32; // Calculate the determinant\n\n var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;\n out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;\n out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;\n out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;\n out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;\n out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;\n out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;\n out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;\n out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;\n return out;\n}\n/**\r\n * Generates a 2D projection matrix with the given bounds\r\n *\r\n * @param {mat3} out mat3 frustum matrix will be written into\r\n * @param {number} width Width of your gl context\r\n * @param {number} height Height of gl context\r\n * @returns {mat3} out\r\n */\n\nexport function projection(out, width, height) {\n out[0] = 2 / width;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = -2 / height;\n out[5] = 0;\n out[6] = -1;\n out[7] = 1;\n out[8] = 1;\n return out;\n}\n/**\r\n * Returns a string representation of a mat3\r\n *\r\n * @param {mat3} a matrix to represent as a string\r\n * @returns {String} string representation of the matrix\r\n */\n\nexport function str(a) {\n return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + a[8] + ')';\n}\n/**\r\n * Returns Frobenius norm of a mat3\r\n *\r\n * @param {mat3} a the matrix to calculate Frobenius norm of\r\n * @returns {Number} Frobenius norm\r\n */\n\nexport function frob(a) {\n return Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2));\n}\n/**\r\n * Adds two mat3's\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the first operand\r\n * @param {mat3} b the second operand\r\n * @returns {mat3} out\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n out[6] = a[6] + b[6];\n out[7] = a[7] + b[7];\n out[8] = a[8] + b[8];\n return out;\n}\n/**\r\n * Subtracts matrix b from matrix a\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the first operand\r\n * @param {mat3} b the second operand\r\n * @returns {mat3} out\r\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n out[6] = a[6] - b[6];\n out[7] = a[7] - b[7];\n out[8] = a[8] - b[8];\n return out;\n}\n/**\r\n * Multiply each element of the matrix by a scalar.\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the matrix to scale\r\n * @param {Number} b amount to scale the matrix's elements by\r\n * @returns {mat3} out\r\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n out[6] = a[6] * b;\n out[7] = a[7] * b;\n out[8] = a[8] * b;\n return out;\n}\n/**\r\n * Adds two mat3's after multiplying each element of the second operand by a scalar value.\r\n *\r\n * @param {mat3} out the receiving vector\r\n * @param {mat3} a the first operand\r\n * @param {mat3} b the second operand\r\n * @param {Number} scale the amount to scale b's elements by before adding\r\n * @returns {mat3} out\r\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n out[6] = a[6] + b[6] * scale;\n out[7] = a[7] + b[7] * scale;\n out[8] = a[8] + b[8] * scale;\n return out;\n}\n/**\r\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {mat3} a The first matrix.\r\n * @param {mat3} b The second matrix.\r\n * @returns {Boolean} True if the matrices are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8];\n}\n/**\r\n * Returns whether or not the matrices have approximately the same elements in the same position.\r\n *\r\n * @param {mat3} a The first matrix.\r\n * @param {mat3} b The second matrix.\r\n * @returns {Boolean} True if the matrices are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5],\n a6 = a[6],\n a7 = a[7],\n a8 = a[8];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5],\n b6 = b[6],\n b7 = b[7],\n b8 = b[8];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8));\n}\n/**\r\n * Alias for {@link mat3.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Alias for {@link mat3.subtract}\r\n * @function\r\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\r\n * 4x4 Matrix
Format: column-major, when typed out it looks like row-major
The matrices are being post multiplied.\r\n * @module mat4\r\n */\n\n/**\r\n * Creates a new identity mat4\r\n *\r\n * @returns {mat4} a new 4x4 matrix\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(16);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n }\n\n out[0] = 1;\n out[5] = 1;\n out[10] = 1;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a new mat4 initialized with values from an existing matrix\r\n *\r\n * @param {mat4} a matrix to clone\r\n * @returns {mat4} a new 4x4 matrix\r\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(16);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n}\n/**\r\n * Copy the values from one mat4 to another\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the source matrix\r\n * @returns {mat4} out\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n}\n/**\r\n * Create a new mat4 with the given values\r\n *\r\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\r\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\r\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\r\n * @param {Number} m03 Component in column 0, row 3 position (index 3)\r\n * @param {Number} m10 Component in column 1, row 0 position (index 4)\r\n * @param {Number} m11 Component in column 1, row 1 position (index 5)\r\n * @param {Number} m12 Component in column 1, row 2 position (index 6)\r\n * @param {Number} m13 Component in column 1, row 3 position (index 7)\r\n * @param {Number} m20 Component in column 2, row 0 position (index 8)\r\n * @param {Number} m21 Component in column 2, row 1 position (index 9)\r\n * @param {Number} m22 Component in column 2, row 2 position (index 10)\r\n * @param {Number} m23 Component in column 2, row 3 position (index 11)\r\n * @param {Number} m30 Component in column 3, row 0 position (index 12)\r\n * @param {Number} m31 Component in column 3, row 1 position (index 13)\r\n * @param {Number} m32 Component in column 3, row 2 position (index 14)\r\n * @param {Number} m33 Component in column 3, row 3 position (index 15)\r\n * @returns {mat4} A new mat4\r\n */\n\nexport function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {\n var out = new glMatrix.ARRAY_TYPE(16);\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m03;\n out[4] = m10;\n out[5] = m11;\n out[6] = m12;\n out[7] = m13;\n out[8] = m20;\n out[9] = m21;\n out[10] = m22;\n out[11] = m23;\n out[12] = m30;\n out[13] = m31;\n out[14] = m32;\n out[15] = m33;\n return out;\n}\n/**\r\n * Set the components of a mat4 to the given values\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\r\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\r\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\r\n * @param {Number} m03 Component in column 0, row 3 position (index 3)\r\n * @param {Number} m10 Component in column 1, row 0 position (index 4)\r\n * @param {Number} m11 Component in column 1, row 1 position (index 5)\r\n * @param {Number} m12 Component in column 1, row 2 position (index 6)\r\n * @param {Number} m13 Component in column 1, row 3 position (index 7)\r\n * @param {Number} m20 Component in column 2, row 0 position (index 8)\r\n * @param {Number} m21 Component in column 2, row 1 position (index 9)\r\n * @param {Number} m22 Component in column 2, row 2 position (index 10)\r\n * @param {Number} m23 Component in column 2, row 3 position (index 11)\r\n * @param {Number} m30 Component in column 3, row 0 position (index 12)\r\n * @param {Number} m31 Component in column 3, row 1 position (index 13)\r\n * @param {Number} m32 Component in column 3, row 2 position (index 14)\r\n * @param {Number} m33 Component in column 3, row 3 position (index 15)\r\n * @returns {mat4} out\r\n */\n\nexport function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m03;\n out[4] = m10;\n out[5] = m11;\n out[6] = m12;\n out[7] = m13;\n out[8] = m20;\n out[9] = m21;\n out[10] = m22;\n out[11] = m23;\n out[12] = m30;\n out[13] = m31;\n out[14] = m32;\n out[15] = m33;\n return out;\n}\n/**\r\n * Set a mat4 to the identity matrix\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @returns {mat4} out\r\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Transpose the values of a mat4\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the source matrix\r\n * @returns {mat4} out\r\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a12 = a[6],\n a13 = a[7];\n var a23 = a[11];\n out[1] = a[4];\n out[2] = a[8];\n out[3] = a[12];\n out[4] = a01;\n out[6] = a[9];\n out[7] = a[13];\n out[8] = a02;\n out[9] = a12;\n out[11] = a[14];\n out[12] = a03;\n out[13] = a13;\n out[14] = a23;\n } else {\n out[0] = a[0];\n out[1] = a[4];\n out[2] = a[8];\n out[3] = a[12];\n out[4] = a[1];\n out[5] = a[5];\n out[6] = a[9];\n out[7] = a[13];\n out[8] = a[2];\n out[9] = a[6];\n out[10] = a[10];\n out[11] = a[14];\n out[12] = a[3];\n out[13] = a[7];\n out[14] = a[11];\n out[15] = a[15];\n }\n\n return out;\n}\n/**\r\n * Inverts a mat4\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the source matrix\r\n * @returns {mat4} out\r\n */\n\nexport function invert(out, a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n var a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n var a30 = a[12],\n a31 = a[13],\n a32 = a[14],\n a33 = a[15];\n var b00 = a00 * a11 - a01 * a10;\n var b01 = a00 * a12 - a02 * a10;\n var b02 = a00 * a13 - a03 * a10;\n var b03 = a01 * a12 - a02 * a11;\n var b04 = a01 * a13 - a03 * a11;\n var b05 = a02 * a13 - a03 * a12;\n var b06 = a20 * a31 - a21 * a30;\n var b07 = a20 * a32 - a22 * a30;\n var b08 = a20 * a33 - a23 * a30;\n var b09 = a21 * a32 - a22 * a31;\n var b10 = a21 * a33 - a23 * a31;\n var b11 = a22 * a33 - a23 * a32; // Calculate the determinant\n\n var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;\n out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;\n out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;\n out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;\n out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;\n out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;\n out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;\n out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;\n out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;\n out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;\n out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;\n out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;\n out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;\n out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;\n out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;\n out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;\n return out;\n}\n/**\r\n * Calculates the adjugate of a mat4\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the source matrix\r\n * @returns {mat4} out\r\n */\n\nexport function adjoint(out, a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n var a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n var a30 = a[12],\n a31 = a[13],\n a32 = a[14],\n a33 = a[15];\n out[0] = a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22);\n out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));\n out[2] = a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12);\n out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));\n out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));\n out[5] = a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22);\n out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));\n out[7] = a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12);\n out[8] = a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21);\n out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));\n out[10] = a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11);\n out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));\n out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));\n out[13] = a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21);\n out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));\n out[15] = a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11);\n return out;\n}\n/**\r\n * Calculates the determinant of a mat4\r\n *\r\n * @param {mat4} a the source matrix\r\n * @returns {Number} determinant of a\r\n */\n\nexport function determinant(a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n var a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n var a30 = a[12],\n a31 = a[13],\n a32 = a[14],\n a33 = a[15];\n var b00 = a00 * a11 - a01 * a10;\n var b01 = a00 * a12 - a02 * a10;\n var b02 = a00 * a13 - a03 * a10;\n var b03 = a01 * a12 - a02 * a11;\n var b04 = a01 * a13 - a03 * a11;\n var b05 = a02 * a13 - a03 * a12;\n var b06 = a20 * a31 - a21 * a30;\n var b07 = a20 * a32 - a22 * a30;\n var b08 = a20 * a33 - a23 * a30;\n var b09 = a21 * a32 - a22 * a31;\n var b10 = a21 * a33 - a23 * a31;\n var b11 = a22 * a33 - a23 * a32; // Calculate the determinant\n\n return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n}\n/**\r\n * Multiplies two mat4s\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the first operand\r\n * @param {mat4} b the second operand\r\n * @returns {mat4} out\r\n */\n\nexport function multiply(out, a, b) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n var a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n var a30 = a[12],\n a31 = a[13],\n a32 = a[14],\n a33 = a[15]; // Cache only the current line of the second matrix\n\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;\n out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;\n out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;\n out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;\n b0 = b[4];\n b1 = b[5];\n b2 = b[6];\n b3 = b[7];\n out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;\n out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;\n out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;\n out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;\n b0 = b[8];\n b1 = b[9];\n b2 = b[10];\n b3 = b[11];\n out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;\n out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;\n out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;\n out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;\n b0 = b[12];\n b1 = b[13];\n b2 = b[14];\n b3 = b[15];\n out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;\n out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;\n out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;\n out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;\n return out;\n}\n/**\r\n * Translate a mat4 by the given vector\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to translate\r\n * @param {vec3} v vector to translate by\r\n * @returns {mat4} out\r\n */\n\nexport function translate(out, a, v) {\n var x = v[0],\n y = v[1],\n z = v[2];\n var a00, a01, a02, a03;\n var a10, a11, a12, a13;\n var a20, a21, a22, a23;\n\n if (a === out) {\n out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];\n out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];\n out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];\n out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];\n } else {\n a00 = a[0];\n a01 = a[1];\n a02 = a[2];\n a03 = a[3];\n a10 = a[4];\n a11 = a[5];\n a12 = a[6];\n a13 = a[7];\n a20 = a[8];\n a21 = a[9];\n a22 = a[10];\n a23 = a[11];\n out[0] = a00;\n out[1] = a01;\n out[2] = a02;\n out[3] = a03;\n out[4] = a10;\n out[5] = a11;\n out[6] = a12;\n out[7] = a13;\n out[8] = a20;\n out[9] = a21;\n out[10] = a22;\n out[11] = a23;\n out[12] = a00 * x + a10 * y + a20 * z + a[12];\n out[13] = a01 * x + a11 * y + a21 * z + a[13];\n out[14] = a02 * x + a12 * y + a22 * z + a[14];\n out[15] = a03 * x + a13 * y + a23 * z + a[15];\n }\n\n return out;\n}\n/**\r\n * Scales the mat4 by the dimensions in the given vec3 not using vectorization\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to scale\r\n * @param {vec3} v the vec3 to scale the matrix by\r\n * @returns {mat4} out\r\n **/\n\nexport function scale(out, a, v) {\n var x = v[0],\n y = v[1],\n z = v[2];\n out[0] = a[0] * x;\n out[1] = a[1] * x;\n out[2] = a[2] * x;\n out[3] = a[3] * x;\n out[4] = a[4] * y;\n out[5] = a[5] * y;\n out[6] = a[6] * y;\n out[7] = a[7] * y;\n out[8] = a[8] * z;\n out[9] = a[9] * z;\n out[10] = a[10] * z;\n out[11] = a[11] * z;\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n}\n/**\r\n * Rotates a mat4 by the given angle around the given axis\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to rotate\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @param {vec3} axis the axis to rotate around\r\n * @returns {mat4} out\r\n */\n\nexport function rotate(out, a, rad, axis) {\n var x = axis[0],\n y = axis[1],\n z = axis[2];\n var len = Math.sqrt(x * x + y * y + z * z);\n var s, c, t;\n var a00, a01, a02, a03;\n var a10, a11, a12, a13;\n var a20, a21, a22, a23;\n var b00, b01, b02;\n var b10, b11, b12;\n var b20, b21, b22;\n\n if (len < glMatrix.EPSILON) {\n return null;\n }\n\n len = 1 / len;\n x *= len;\n y *= len;\n z *= len;\n s = Math.sin(rad);\n c = Math.cos(rad);\n t = 1 - c;\n a00 = a[0];\n a01 = a[1];\n a02 = a[2];\n a03 = a[3];\n a10 = a[4];\n a11 = a[5];\n a12 = a[6];\n a13 = a[7];\n a20 = a[8];\n a21 = a[9];\n a22 = a[10];\n a23 = a[11]; // Construct the elements of the rotation matrix\n\n b00 = x * x * t + c;\n b01 = y * x * t + z * s;\n b02 = z * x * t - y * s;\n b10 = x * y * t - z * s;\n b11 = y * y * t + c;\n b12 = z * y * t + x * s;\n b20 = x * z * t + y * s;\n b21 = y * z * t - x * s;\n b22 = z * z * t + c; // Perform rotation-specific matrix multiplication\n\n out[0] = a00 * b00 + a10 * b01 + a20 * b02;\n out[1] = a01 * b00 + a11 * b01 + a21 * b02;\n out[2] = a02 * b00 + a12 * b01 + a22 * b02;\n out[3] = a03 * b00 + a13 * b01 + a23 * b02;\n out[4] = a00 * b10 + a10 * b11 + a20 * b12;\n out[5] = a01 * b10 + a11 * b11 + a21 * b12;\n out[6] = a02 * b10 + a12 * b11 + a22 * b12;\n out[7] = a03 * b10 + a13 * b11 + a23 * b12;\n out[8] = a00 * b20 + a10 * b21 + a20 * b22;\n out[9] = a01 * b20 + a11 * b21 + a21 * b22;\n out[10] = a02 * b20 + a12 * b21 + a22 * b22;\n out[11] = a03 * b20 + a13 * b21 + a23 * b22;\n\n if (a !== out) {\n // If the source and destination differ, copy the unchanged last row\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n return out;\n}\n/**\r\n * Rotates a matrix by the given angle around the X axis\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to rotate\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function rotateX(out, a, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n var a10 = a[4];\n var a11 = a[5];\n var a12 = a[6];\n var a13 = a[7];\n var a20 = a[8];\n var a21 = a[9];\n var a22 = a[10];\n var a23 = a[11];\n\n if (a !== out) {\n // If the source and destination differ, copy the unchanged rows\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n } // Perform axis-specific matrix multiplication\n\n\n out[4] = a10 * c + a20 * s;\n out[5] = a11 * c + a21 * s;\n out[6] = a12 * c + a22 * s;\n out[7] = a13 * c + a23 * s;\n out[8] = a20 * c - a10 * s;\n out[9] = a21 * c - a11 * s;\n out[10] = a22 * c - a12 * s;\n out[11] = a23 * c - a13 * s;\n return out;\n}\n/**\r\n * Rotates a matrix by the given angle around the Y axis\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to rotate\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function rotateY(out, a, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n var a00 = a[0];\n var a01 = a[1];\n var a02 = a[2];\n var a03 = a[3];\n var a20 = a[8];\n var a21 = a[9];\n var a22 = a[10];\n var a23 = a[11];\n\n if (a !== out) {\n // If the source and destination differ, copy the unchanged rows\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n } // Perform axis-specific matrix multiplication\n\n\n out[0] = a00 * c - a20 * s;\n out[1] = a01 * c - a21 * s;\n out[2] = a02 * c - a22 * s;\n out[3] = a03 * c - a23 * s;\n out[8] = a00 * s + a20 * c;\n out[9] = a01 * s + a21 * c;\n out[10] = a02 * s + a22 * c;\n out[11] = a03 * s + a23 * c;\n return out;\n}\n/**\r\n * Rotates a matrix by the given angle around the Z axis\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to rotate\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function rotateZ(out, a, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n var a00 = a[0];\n var a01 = a[1];\n var a02 = a[2];\n var a03 = a[3];\n var a10 = a[4];\n var a11 = a[5];\n var a12 = a[6];\n var a13 = a[7];\n\n if (a !== out) {\n // If the source and destination differ, copy the unchanged last row\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n } // Perform axis-specific matrix multiplication\n\n\n out[0] = a00 * c + a10 * s;\n out[1] = a01 * c + a11 * s;\n out[2] = a02 * c + a12 * s;\n out[3] = a03 * c + a13 * s;\n out[4] = a10 * c - a00 * s;\n out[5] = a11 * c - a01 * s;\n out[6] = a12 * c - a02 * s;\n out[7] = a13 * c - a03 * s;\n return out;\n}\n/**\r\n * Creates a matrix from a vector translation\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.translate(dest, dest, vec);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {vec3} v Translation vector\r\n * @returns {mat4} out\r\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a vector scaling\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.scale(dest, dest, vec);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {vec3} v Scaling vector\r\n * @returns {mat4} out\r\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = v[1];\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = v[2];\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a given angle around a given axis\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.rotate(dest, dest, rad, axis);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @param {vec3} axis the axis to rotate around\r\n * @returns {mat4} out\r\n */\n\nexport function fromRotation(out, rad, axis) {\n var x = axis[0],\n y = axis[1],\n z = axis[2];\n var len = Math.sqrt(x * x + y * y + z * z);\n var s, c, t;\n\n if (len < glMatrix.EPSILON) {\n return null;\n }\n\n len = 1 / len;\n x *= len;\n y *= len;\n z *= len;\n s = Math.sin(rad);\n c = Math.cos(rad);\n t = 1 - c; // Perform rotation-specific matrix multiplication\n\n out[0] = x * x * t + c;\n out[1] = y * x * t + z * s;\n out[2] = z * x * t - y * s;\n out[3] = 0;\n out[4] = x * y * t - z * s;\n out[5] = y * y * t + c;\n out[6] = z * y * t + x * s;\n out[7] = 0;\n out[8] = x * z * t + y * s;\n out[9] = y * z * t - x * s;\n out[10] = z * z * t + c;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from the given angle around the X axis\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.rotateX(dest, dest, rad);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function fromXRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad); // Perform axis-specific matrix multiplication\n\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = c;\n out[6] = s;\n out[7] = 0;\n out[8] = 0;\n out[9] = -s;\n out[10] = c;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from the given angle around the Y axis\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.rotateY(dest, dest, rad);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function fromYRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad); // Perform axis-specific matrix multiplication\n\n out[0] = c;\n out[1] = 0;\n out[2] = -s;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = s;\n out[9] = 0;\n out[10] = c;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from the given angle around the Z axis\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.rotateZ(dest, dest, rad);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function fromZRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad); // Perform axis-specific matrix multiplication\n\n out[0] = c;\n out[1] = s;\n out[2] = 0;\n out[3] = 0;\n out[4] = -s;\n out[5] = c;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a quaternion rotation and vector translation\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.translate(dest, vec);\r\n * let quatMat = mat4.create();\r\n * quat4.toMat4(quat, quatMat);\r\n * mat4.multiply(dest, quatMat);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {quat4} q Rotation quaternion\r\n * @param {vec3} v Translation vector\r\n * @returns {mat4} out\r\n */\n\nexport function fromRotationTranslation(out, q, v) {\n // Quaternion math\n var x = q[0],\n y = q[1],\n z = q[2],\n w = q[3];\n var x2 = x + x;\n var y2 = y + y;\n var z2 = z + z;\n var xx = x * x2;\n var xy = x * y2;\n var xz = x * z2;\n var yy = y * y2;\n var yz = y * z2;\n var zz = z * z2;\n var wx = w * x2;\n var wy = w * y2;\n var wz = w * z2;\n out[0] = 1 - (yy + zz);\n out[1] = xy + wz;\n out[2] = xz - wy;\n out[3] = 0;\n out[4] = xy - wz;\n out[5] = 1 - (xx + zz);\n out[6] = yz + wx;\n out[7] = 0;\n out[8] = xz + wy;\n out[9] = yz - wx;\n out[10] = 1 - (xx + yy);\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a new mat4 from a dual quat.\r\n *\r\n * @param {mat4} out Matrix\r\n * @param {quat2} a Dual Quaternion\r\n * @returns {mat4} mat4 receiving operation result\r\n */\n\nexport function fromQuat2(out, a) {\n var translation = new glMatrix.ARRAY_TYPE(3);\n var bx = -a[0],\n by = -a[1],\n bz = -a[2],\n bw = a[3],\n ax = a[4],\n ay = a[5],\n az = a[6],\n aw = a[7];\n var magnitude = bx * bx + by * by + bz * bz + bw * bw; //Only scale if it makes sense\n\n if (magnitude > 0) {\n translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude;\n translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude;\n translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude;\n } else {\n translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;\n translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;\n translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;\n }\n\n fromRotationTranslation(out, a, translation);\n return out;\n}\n/**\r\n * Returns the translation vector component of a transformation\r\n * matrix. If a matrix is built with fromRotationTranslation,\r\n * the returned vector will be the same as the translation vector\r\n * originally supplied.\r\n * @param {vec3} out Vector to receive translation component\r\n * @param {mat4} mat Matrix to be decomposed (input)\r\n * @return {vec3} out\r\n */\n\nexport function getTranslation(out, mat) {\n out[0] = mat[12];\n out[1] = mat[13];\n out[2] = mat[14];\n return out;\n}\n/**\r\n * Returns the scaling factor component of a transformation\r\n * matrix. If a matrix is built with fromRotationTranslationScale\r\n * with a normalized Quaternion paramter, the returned vector will be\r\n * the same as the scaling vector\r\n * originally supplied.\r\n * @param {vec3} out Vector to receive scaling factor component\r\n * @param {mat4} mat Matrix to be decomposed (input)\r\n * @return {vec3} out\r\n */\n\nexport function getScaling(out, mat) {\n var m11 = mat[0];\n var m12 = mat[1];\n var m13 = mat[2];\n var m21 = mat[4];\n var m22 = mat[5];\n var m23 = mat[6];\n var m31 = mat[8];\n var m32 = mat[9];\n var m33 = mat[10];\n out[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);\n out[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);\n out[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);\n return out;\n}\n/**\r\n * Returns a quaternion representing the rotational component\r\n * of a transformation matrix. If a matrix is built with\r\n * fromRotationTranslation, the returned quaternion will be the\r\n * same as the quaternion originally supplied.\r\n * @param {quat} out Quaternion to receive the rotation component\r\n * @param {mat4} mat Matrix to be decomposed (input)\r\n * @return {quat} out\r\n */\n\nexport function getRotation(out, mat) {\n // Algorithm taken from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm\n var trace = mat[0] + mat[5] + mat[10];\n var S = 0;\n\n if (trace > 0) {\n S = Math.sqrt(trace + 1.0) * 2;\n out[3] = 0.25 * S;\n out[0] = (mat[6] - mat[9]) / S;\n out[1] = (mat[8] - mat[2]) / S;\n out[2] = (mat[1] - mat[4]) / S;\n } else if (mat[0] > mat[5] && mat[0] > mat[10]) {\n S = Math.sqrt(1.0 + mat[0] - mat[5] - mat[10]) * 2;\n out[3] = (mat[6] - mat[9]) / S;\n out[0] = 0.25 * S;\n out[1] = (mat[1] + mat[4]) / S;\n out[2] = (mat[8] + mat[2]) / S;\n } else if (mat[5] > mat[10]) {\n S = Math.sqrt(1.0 + mat[5] - mat[0] - mat[10]) * 2;\n out[3] = (mat[8] - mat[2]) / S;\n out[0] = (mat[1] + mat[4]) / S;\n out[1] = 0.25 * S;\n out[2] = (mat[6] + mat[9]) / S;\n } else {\n S = Math.sqrt(1.0 + mat[10] - mat[0] - mat[5]) * 2;\n out[3] = (mat[1] - mat[4]) / S;\n out[0] = (mat[8] + mat[2]) / S;\n out[1] = (mat[6] + mat[9]) / S;\n out[2] = 0.25 * S;\n }\n\n return out;\n}\n/**\r\n * Creates a matrix from a quaternion rotation, vector translation and vector scale\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.translate(dest, vec);\r\n * let quatMat = mat4.create();\r\n * quat4.toMat4(quat, quatMat);\r\n * mat4.multiply(dest, quatMat);\r\n * mat4.scale(dest, scale)\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {quat4} q Rotation quaternion\r\n * @param {vec3} v Translation vector\r\n * @param {vec3} s Scaling vector\r\n * @returns {mat4} out\r\n */\n\nexport function fromRotationTranslationScale(out, q, v, s) {\n // Quaternion math\n var x = q[0],\n y = q[1],\n z = q[2],\n w = q[3];\n var x2 = x + x;\n var y2 = y + y;\n var z2 = z + z;\n var xx = x * x2;\n var xy = x * y2;\n var xz = x * z2;\n var yy = y * y2;\n var yz = y * z2;\n var zz = z * z2;\n var wx = w * x2;\n var wy = w * y2;\n var wz = w * z2;\n var sx = s[0];\n var sy = s[1];\n var sz = s[2];\n out[0] = (1 - (yy + zz)) * sx;\n out[1] = (xy + wz) * sx;\n out[2] = (xz - wy) * sx;\n out[3] = 0;\n out[4] = (xy - wz) * sy;\n out[5] = (1 - (xx + zz)) * sy;\n out[6] = (yz + wx) * sy;\n out[7] = 0;\n out[8] = (xz + wy) * sz;\n out[9] = (yz - wx) * sz;\n out[10] = (1 - (xx + yy)) * sz;\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.translate(dest, vec);\r\n * mat4.translate(dest, origin);\r\n * let quatMat = mat4.create();\r\n * quat4.toMat4(quat, quatMat);\r\n * mat4.multiply(dest, quatMat);\r\n * mat4.scale(dest, scale)\r\n * mat4.translate(dest, negativeOrigin);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {quat4} q Rotation quaternion\r\n * @param {vec3} v Translation vector\r\n * @param {vec3} s Scaling vector\r\n * @param {vec3} o The origin vector around which to scale and rotate\r\n * @returns {mat4} out\r\n */\n\nexport function fromRotationTranslationScaleOrigin(out, q, v, s, o) {\n // Quaternion math\n var x = q[0],\n y = q[1],\n z = q[2],\n w = q[3];\n var x2 = x + x;\n var y2 = y + y;\n var z2 = z + z;\n var xx = x * x2;\n var xy = x * y2;\n var xz = x * z2;\n var yy = y * y2;\n var yz = y * z2;\n var zz = z * z2;\n var wx = w * x2;\n var wy = w * y2;\n var wz = w * z2;\n var sx = s[0];\n var sy = s[1];\n var sz = s[2];\n var ox = o[0];\n var oy = o[1];\n var oz = o[2];\n var out0 = (1 - (yy + zz)) * sx;\n var out1 = (xy + wz) * sx;\n var out2 = (xz - wy) * sx;\n var out4 = (xy - wz) * sy;\n var out5 = (1 - (xx + zz)) * sy;\n var out6 = (yz + wx) * sy;\n var out8 = (xz + wy) * sz;\n var out9 = (yz - wx) * sz;\n var out10 = (1 - (xx + yy)) * sz;\n out[0] = out0;\n out[1] = out1;\n out[2] = out2;\n out[3] = 0;\n out[4] = out4;\n out[5] = out5;\n out[6] = out6;\n out[7] = 0;\n out[8] = out8;\n out[9] = out9;\n out[10] = out10;\n out[11] = 0;\n out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);\n out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);\n out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);\n out[15] = 1;\n return out;\n}\n/**\r\n * Calculates a 4x4 matrix from the given quaternion\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {quat} q Quaternion to create matrix from\r\n *\r\n * @returns {mat4} out\r\n */\n\nexport function fromQuat(out, q) {\n var x = q[0],\n y = q[1],\n z = q[2],\n w = q[3];\n var x2 = x + x;\n var y2 = y + y;\n var z2 = z + z;\n var xx = x * x2;\n var yx = y * x2;\n var yy = y * y2;\n var zx = z * x2;\n var zy = z * y2;\n var zz = z * z2;\n var wx = w * x2;\n var wy = w * y2;\n var wz = w * z2;\n out[0] = 1 - yy - zz;\n out[1] = yx + wz;\n out[2] = zx - wy;\n out[3] = 0;\n out[4] = yx - wz;\n out[5] = 1 - xx - zz;\n out[6] = zy + wx;\n out[7] = 0;\n out[8] = zx + wy;\n out[9] = zy - wx;\n out[10] = 1 - xx - yy;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Generates a frustum matrix with the given bounds\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {Number} left Left bound of the frustum\r\n * @param {Number} right Right bound of the frustum\r\n * @param {Number} bottom Bottom bound of the frustum\r\n * @param {Number} top Top bound of the frustum\r\n * @param {Number} near Near bound of the frustum\r\n * @param {Number} far Far bound of the frustum\r\n * @returns {mat4} out\r\n */\n\nexport function frustum(out, left, right, bottom, top, near, far) {\n var rl = 1 / (right - left);\n var tb = 1 / (top - bottom);\n var nf = 1 / (near - far);\n out[0] = near * 2 * rl;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = near * 2 * tb;\n out[6] = 0;\n out[7] = 0;\n out[8] = (right + left) * rl;\n out[9] = (top + bottom) * tb;\n out[10] = (far + near) * nf;\n out[11] = -1;\n out[12] = 0;\n out[13] = 0;\n out[14] = far * near * 2 * nf;\n out[15] = 0;\n return out;\n}\n/**\r\n * Generates a perspective projection matrix with the given bounds.\r\n * Passing null/undefined/no value for far will generate infinite projection matrix.\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {number} fovy Vertical field of view in radians\r\n * @param {number} aspect Aspect ratio. typically viewport width/height\r\n * @param {number} near Near bound of the frustum\r\n * @param {number} far Far bound of the frustum, can be null or Infinity\r\n * @returns {mat4} out\r\n */\n\nexport function perspective(out, fovy, aspect, near, far) {\n var f = 1.0 / Math.tan(fovy / 2),\n nf;\n out[0] = f / aspect;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = f;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[11] = -1;\n out[12] = 0;\n out[13] = 0;\n out[15] = 0;\n\n if (far != null && far !== Infinity) {\n nf = 1 / (near - far);\n out[10] = (far + near) * nf;\n out[14] = 2 * far * near * nf;\n } else {\n out[10] = -1;\n out[14] = -2 * near;\n }\n\n return out;\n}\n/**\r\n * Generates a perspective projection matrix with the given field of view.\r\n * This is primarily useful for generating projection matrices to be used\r\n * with the still experiemental WebVR API.\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees\r\n * @param {number} near Near bound of the frustum\r\n * @param {number} far Far bound of the frustum\r\n * @returns {mat4} out\r\n */\n\nexport function perspectiveFromFieldOfView(out, fov, near, far) {\n var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);\n var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);\n var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);\n var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);\n var xScale = 2.0 / (leftTan + rightTan);\n var yScale = 2.0 / (upTan + downTan);\n out[0] = xScale;\n out[1] = 0.0;\n out[2] = 0.0;\n out[3] = 0.0;\n out[4] = 0.0;\n out[5] = yScale;\n out[6] = 0.0;\n out[7] = 0.0;\n out[8] = -((leftTan - rightTan) * xScale * 0.5);\n out[9] = (upTan - downTan) * yScale * 0.5;\n out[10] = far / (near - far);\n out[11] = -1.0;\n out[12] = 0.0;\n out[13] = 0.0;\n out[14] = far * near / (near - far);\n out[15] = 0.0;\n return out;\n}\n/**\r\n * Generates a orthogonal projection matrix with the given bounds\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {number} left Left bound of the frustum\r\n * @param {number} right Right bound of the frustum\r\n * @param {number} bottom Bottom bound of the frustum\r\n * @param {number} top Top bound of the frustum\r\n * @param {number} near Near bound of the frustum\r\n * @param {number} far Far bound of the frustum\r\n * @returns {mat4} out\r\n */\n\nexport function ortho(out, left, right, bottom, top, near, far) {\n var lr = 1 / (left - right);\n var bt = 1 / (bottom - top);\n var nf = 1 / (near - far);\n out[0] = -2 * lr;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = -2 * bt;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 2 * nf;\n out[11] = 0;\n out[12] = (left + right) * lr;\n out[13] = (top + bottom) * bt;\n out[14] = (far + near) * nf;\n out[15] = 1;\n return out;\n}\n/**\r\n * Generates a look-at matrix with the given eye position, focal point, and up axis.\r\n * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {vec3} eye Position of the viewer\r\n * @param {vec3} center Point the viewer is looking at\r\n * @param {vec3} up vec3 pointing up\r\n * @returns {mat4} out\r\n */\n\nexport function lookAt(out, eye, center, up) {\n var x0, x1, x2, y0, y1, y2, z0, z1, z2, len;\n var eyex = eye[0];\n var eyey = eye[1];\n var eyez = eye[2];\n var upx = up[0];\n var upy = up[1];\n var upz = up[2];\n var centerx = center[0];\n var centery = center[1];\n var centerz = center[2];\n\n if (Math.abs(eyex - centerx) < glMatrix.EPSILON && Math.abs(eyey - centery) < glMatrix.EPSILON && Math.abs(eyez - centerz) < glMatrix.EPSILON) {\n return identity(out);\n }\n\n z0 = eyex - centerx;\n z1 = eyey - centery;\n z2 = eyez - centerz;\n len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);\n z0 *= len;\n z1 *= len;\n z2 *= len;\n x0 = upy * z2 - upz * z1;\n x1 = upz * z0 - upx * z2;\n x2 = upx * z1 - upy * z0;\n len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);\n\n if (!len) {\n x0 = 0;\n x1 = 0;\n x2 = 0;\n } else {\n len = 1 / len;\n x0 *= len;\n x1 *= len;\n x2 *= len;\n }\n\n y0 = z1 * x2 - z2 * x1;\n y1 = z2 * x0 - z0 * x2;\n y2 = z0 * x1 - z1 * x0;\n len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);\n\n if (!len) {\n y0 = 0;\n y1 = 0;\n y2 = 0;\n } else {\n len = 1 / len;\n y0 *= len;\n y1 *= len;\n y2 *= len;\n }\n\n out[0] = x0;\n out[1] = y0;\n out[2] = z0;\n out[3] = 0;\n out[4] = x1;\n out[5] = y1;\n out[6] = z1;\n out[7] = 0;\n out[8] = x2;\n out[9] = y2;\n out[10] = z2;\n out[11] = 0;\n out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);\n out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);\n out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);\n out[15] = 1;\n return out;\n}\n/**\r\n * Generates a matrix that makes something look at something else.\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {vec3} eye Position of the viewer\r\n * @param {vec3} center Point the viewer is looking at\r\n * @param {vec3} up vec3 pointing up\r\n * @returns {mat4} out\r\n */\n\nexport function targetTo(out, eye, target, up) {\n var eyex = eye[0],\n eyey = eye[1],\n eyez = eye[2],\n upx = up[0],\n upy = up[1],\n upz = up[2];\n var z0 = eyex - target[0],\n z1 = eyey - target[1],\n z2 = eyez - target[2];\n var len = z0 * z0 + z1 * z1 + z2 * z2;\n\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n z0 *= len;\n z1 *= len;\n z2 *= len;\n }\n\n var x0 = upy * z2 - upz * z1,\n x1 = upz * z0 - upx * z2,\n x2 = upx * z1 - upy * z0;\n len = x0 * x0 + x1 * x1 + x2 * x2;\n\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n x0 *= len;\n x1 *= len;\n x2 *= len;\n }\n\n out[0] = x0;\n out[1] = x1;\n out[2] = x2;\n out[3] = 0;\n out[4] = z1 * x2 - z2 * x1;\n out[5] = z2 * x0 - z0 * x2;\n out[6] = z0 * x1 - z1 * x0;\n out[7] = 0;\n out[8] = z0;\n out[9] = z1;\n out[10] = z2;\n out[11] = 0;\n out[12] = eyex;\n out[13] = eyey;\n out[14] = eyez;\n out[15] = 1;\n return out;\n}\n;\n/**\r\n * Returns a string representation of a mat4\r\n *\r\n * @param {mat4} a matrix to represent as a string\r\n * @returns {String} string representation of the matrix\r\n */\n\nexport function str(a) {\n return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' + a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';\n}\n/**\r\n * Returns Frobenius norm of a mat4\r\n *\r\n * @param {mat4} a the matrix to calculate Frobenius norm of\r\n * @returns {Number} Frobenius norm\r\n */\n\nexport function frob(a) {\n return Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2));\n}\n/**\r\n * Adds two mat4's\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the first operand\r\n * @param {mat4} b the second operand\r\n * @returns {mat4} out\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n out[6] = a[6] + b[6];\n out[7] = a[7] + b[7];\n out[8] = a[8] + b[8];\n out[9] = a[9] + b[9];\n out[10] = a[10] + b[10];\n out[11] = a[11] + b[11];\n out[12] = a[12] + b[12];\n out[13] = a[13] + b[13];\n out[14] = a[14] + b[14];\n out[15] = a[15] + b[15];\n return out;\n}\n/**\r\n * Subtracts matrix b from matrix a\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the first operand\r\n * @param {mat4} b the second operand\r\n * @returns {mat4} out\r\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n out[6] = a[6] - b[6];\n out[7] = a[7] - b[7];\n out[8] = a[8] - b[8];\n out[9] = a[9] - b[9];\n out[10] = a[10] - b[10];\n out[11] = a[11] - b[11];\n out[12] = a[12] - b[12];\n out[13] = a[13] - b[13];\n out[14] = a[14] - b[14];\n out[15] = a[15] - b[15];\n return out;\n}\n/**\r\n * Multiply each element of the matrix by a scalar.\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to scale\r\n * @param {Number} b amount to scale the matrix's elements by\r\n * @returns {mat4} out\r\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n out[6] = a[6] * b;\n out[7] = a[7] * b;\n out[8] = a[8] * b;\n out[9] = a[9] * b;\n out[10] = a[10] * b;\n out[11] = a[11] * b;\n out[12] = a[12] * b;\n out[13] = a[13] * b;\n out[14] = a[14] * b;\n out[15] = a[15] * b;\n return out;\n}\n/**\r\n * Adds two mat4's after multiplying each element of the second operand by a scalar value.\r\n *\r\n * @param {mat4} out the receiving vector\r\n * @param {mat4} a the first operand\r\n * @param {mat4} b the second operand\r\n * @param {Number} scale the amount to scale b's elements by before adding\r\n * @returns {mat4} out\r\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n out[6] = a[6] + b[6] * scale;\n out[7] = a[7] + b[7] * scale;\n out[8] = a[8] + b[8] * scale;\n out[9] = a[9] + b[9] * scale;\n out[10] = a[10] + b[10] * scale;\n out[11] = a[11] + b[11] * scale;\n out[12] = a[12] + b[12] * scale;\n out[13] = a[13] + b[13] * scale;\n out[14] = a[14] + b[14] * scale;\n out[15] = a[15] + b[15] * scale;\n return out;\n}\n/**\r\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {mat4} a The first matrix.\r\n * @param {mat4} b The second matrix.\r\n * @returns {Boolean} True if the matrices are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8] && a[9] === b[9] && a[10] === b[10] && a[11] === b[11] && a[12] === b[12] && a[13] === b[13] && a[14] === b[14] && a[15] === b[15];\n}\n/**\r\n * Returns whether or not the matrices have approximately the same elements in the same position.\r\n *\r\n * @param {mat4} a The first matrix.\r\n * @param {mat4} b The second matrix.\r\n * @returns {Boolean} True if the matrices are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var a4 = a[4],\n a5 = a[5],\n a6 = a[6],\n a7 = a[7];\n var a8 = a[8],\n a9 = a[9],\n a10 = a[10],\n a11 = a[11];\n var a12 = a[12],\n a13 = a[13],\n a14 = a[14],\n a15 = a[15];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n var b4 = b[4],\n b5 = b[5],\n b6 = b[6],\n b7 = b[7];\n var b8 = b[8],\n b9 = b[9],\n b10 = b[10],\n b11 = b[11];\n var b12 = b[12],\n b13 = b[13],\n b14 = b[14],\n b15 = b[15];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) && Math.abs(a9 - b9) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) && Math.abs(a10 - b10) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) && Math.abs(a11 - b11) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) && Math.abs(a12 - b12) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) && Math.abs(a13 - b13) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) && Math.abs(a14 - b14) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) && Math.abs(a15 - b15) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15));\n}\n/**\r\n * Alias for {@link mat4.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Alias for {@link mat4.subtract}\r\n * @function\r\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\r\n * 3 Dimensional Vector\r\n * @module vec3\r\n */\n\n/**\r\n * Creates a new, empty vec3\r\n *\r\n * @returns {vec3} a new 3D vector\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(3);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n }\n\n return out;\n}\n/**\r\n * Creates a new vec3 initialized with values from an existing vector\r\n *\r\n * @param {vec3} a vector to clone\r\n * @returns {vec3} a new 3D vector\r\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(3);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n return out;\n}\n/**\r\n * Calculates the length of a vec3\r\n *\r\n * @param {vec3} a vector to calculate length of\r\n * @returns {Number} length of a\r\n */\n\nexport function length(a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n return Math.sqrt(x * x + y * y + z * z);\n}\n/**\r\n * Creates a new vec3 initialized with the given values\r\n *\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @returns {vec3} a new 3D vector\r\n */\n\nexport function fromValues(x, y, z) {\n var out = new glMatrix.ARRAY_TYPE(3);\n out[0] = x;\n out[1] = y;\n out[2] = z;\n return out;\n}\n/**\r\n * Copy the values from one vec3 to another\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the source vector\r\n * @returns {vec3} out\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n return out;\n}\n/**\r\n * Set the components of a vec3 to the given values\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @returns {vec3} out\r\n */\n\nexport function set(out, x, y, z) {\n out[0] = x;\n out[1] = y;\n out[2] = z;\n return out;\n}\n/**\r\n * Adds two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n return out;\n}\n/**\r\n * Subtracts vector b from vector a\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n return out;\n}\n/**\r\n * Multiplies two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n out[2] = a[2] * b[2];\n return out;\n}\n/**\r\n * Divides two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n out[2] = a[2] / b[2];\n return out;\n}\n/**\r\n * Math.ceil the components of a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to ceil\r\n * @returns {vec3} out\r\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n out[2] = Math.ceil(a[2]);\n return out;\n}\n/**\r\n * Math.floor the components of a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to floor\r\n * @returns {vec3} out\r\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n out[2] = Math.floor(a[2]);\n return out;\n}\n/**\r\n * Returns the minimum of two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n out[2] = Math.min(a[2], b[2]);\n return out;\n}\n/**\r\n * Returns the maximum of two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n out[2] = Math.max(a[2], b[2]);\n return out;\n}\n/**\r\n * Math.round the components of a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to round\r\n * @returns {vec3} out\r\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n out[2] = Math.round(a[2]);\n return out;\n}\n/**\r\n * Scales a vec3 by a scalar number\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the vector to scale\r\n * @param {Number} b amount to scale the vector by\r\n * @returns {vec3} out\r\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n return out;\n}\n/**\r\n * Adds two vec3's after scaling the second operand by a scalar value\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @param {Number} scale the amount to scale b by before adding\r\n * @returns {vec3} out\r\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n return out;\n}\n/**\r\n * Calculates the euclidian distance between two vec3's\r\n *\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {Number} distance between a and b\r\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0];\n var y = b[1] - a[1];\n var z = b[2] - a[2];\n return Math.sqrt(x * x + y * y + z * z);\n}\n/**\r\n * Calculates the squared euclidian distance between two vec3's\r\n *\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {Number} squared distance between a and b\r\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0];\n var y = b[1] - a[1];\n var z = b[2] - a[2];\n return x * x + y * y + z * z;\n}\n/**\r\n * Calculates the squared length of a vec3\r\n *\r\n * @param {vec3} a vector to calculate squared length of\r\n * @returns {Number} squared length of a\r\n */\n\nexport function squaredLength(a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n return x * x + y * y + z * z;\n}\n/**\r\n * Negates the components of a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to negate\r\n * @returns {vec3} out\r\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n return out;\n}\n/**\r\n * Returns the inverse of the components of a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to invert\r\n * @returns {vec3} out\r\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n out[2] = 1.0 / a[2];\n return out;\n}\n/**\r\n * Normalize a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to normalize\r\n * @returns {vec3} out\r\n */\n\nexport function normalize(out, a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n var len = x * x + y * y + z * z;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n out[2] = a[2] * len;\n return out;\n}\n/**\r\n * Calculates the dot product of two vec3's\r\n *\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {Number} dot product of a and b\r\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n}\n/**\r\n * Computes the cross product of two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function cross(out, a, b) {\n var ax = a[0],\n ay = a[1],\n az = a[2];\n var bx = b[0],\n by = b[1],\n bz = b[2];\n out[0] = ay * bz - az * by;\n out[1] = az * bx - ax * bz;\n out[2] = ax * by - ay * bx;\n return out;\n}\n/**\r\n * Performs a linear interpolation between two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {vec3} out\r\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0];\n var ay = a[1];\n var az = a[2];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n out[2] = az + t * (b[2] - az);\n return out;\n}\n/**\r\n * Performs a hermite interpolation with two control points\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @param {vec3} c the third operand\r\n * @param {vec3} d the fourth operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {vec3} out\r\n */\n\nexport function hermite(out, a, b, c, d, t) {\n var factorTimes2 = t * t;\n var factor1 = factorTimes2 * (2 * t - 3) + 1;\n var factor2 = factorTimes2 * (t - 2) + t;\n var factor3 = factorTimes2 * (t - 1);\n var factor4 = factorTimes2 * (3 - 2 * t);\n out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;\n out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;\n out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;\n return out;\n}\n/**\r\n * Performs a bezier interpolation with two control points\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @param {vec3} c the third operand\r\n * @param {vec3} d the fourth operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {vec3} out\r\n */\n\nexport function bezier(out, a, b, c, d, t) {\n var inverseFactor = 1 - t;\n var inverseFactorTimesTwo = inverseFactor * inverseFactor;\n var factorTimes2 = t * t;\n var factor1 = inverseFactorTimesTwo * inverseFactor;\n var factor2 = 3 * t * inverseFactorTimesTwo;\n var factor3 = 3 * factorTimes2 * inverseFactor;\n var factor4 = factorTimes2 * t;\n out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;\n out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;\n out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;\n return out;\n}\n/**\r\n * Generates a random vector with the given scale\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\r\n * @returns {vec3} out\r\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n var z = glMatrix.RANDOM() * 2.0 - 1.0;\n var zScale = Math.sqrt(1.0 - z * z) * scale;\n out[0] = Math.cos(r) * zScale;\n out[1] = Math.sin(r) * zScale;\n out[2] = z * scale;\n return out;\n}\n/**\r\n * Transforms the vec3 with a mat4.\r\n * 4th vector component is implicitly '1'\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the vector to transform\r\n * @param {mat4} m matrix to transform with\r\n * @returns {vec3} out\r\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0],\n y = a[1],\n z = a[2];\n var w = m[3] * x + m[7] * y + m[11] * z + m[15];\n w = w || 1.0;\n out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;\n out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;\n out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;\n return out;\n}\n/**\r\n * Transforms the vec3 with a mat3.\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the vector to transform\r\n * @param {mat3} m the 3x3 matrix to transform with\r\n * @returns {vec3} out\r\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1],\n z = a[2];\n out[0] = x * m[0] + y * m[3] + z * m[6];\n out[1] = x * m[1] + y * m[4] + z * m[7];\n out[2] = x * m[2] + y * m[5] + z * m[8];\n return out;\n}\n/**\r\n * Transforms the vec3 with a quat\r\n * Can also be used for dual quaternions. (Multiply it with the real part)\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the vector to transform\r\n * @param {quat} q quaternion to transform with\r\n * @returns {vec3} out\r\n */\n\nexport function transformQuat(out, a, q) {\n // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed\n var qx = q[0],\n qy = q[1],\n qz = q[2],\n qw = q[3];\n var x = a[0],\n y = a[1],\n z = a[2]; // var qvec = [qx, qy, qz];\n // var uv = vec3.cross([], qvec, a);\n\n var uvx = qy * z - qz * y,\n uvy = qz * x - qx * z,\n uvz = qx * y - qy * x; // var uuv = vec3.cross([], qvec, uv);\n\n var uuvx = qy * uvz - qz * uvy,\n uuvy = qz * uvx - qx * uvz,\n uuvz = qx * uvy - qy * uvx; // vec3.scale(uv, uv, 2 * w);\n\n var w2 = qw * 2;\n uvx *= w2;\n uvy *= w2;\n uvz *= w2; // vec3.scale(uuv, uuv, 2);\n\n uuvx *= 2;\n uuvy *= 2;\n uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv));\n\n out[0] = x + uvx + uuvx;\n out[1] = y + uvy + uuvy;\n out[2] = z + uvz + uuvz;\n return out;\n}\n/**\r\n * Rotate a 3D vector around the x-axis\r\n * @param {vec3} out The receiving vec3\r\n * @param {vec3} a The vec3 point to rotate\r\n * @param {vec3} b The origin of the rotation\r\n * @param {Number} c The angle of rotation\r\n * @returns {vec3} out\r\n */\n\nexport function rotateX(out, a, b, c) {\n var p = [],\n r = []; //Translate point to the origin\n\n p[0] = a[0] - b[0];\n p[1] = a[1] - b[1];\n p[2] = a[2] - b[2]; //perform rotation\n\n r[0] = p[0];\n r[1] = p[1] * Math.cos(c) - p[2] * Math.sin(c);\n r[2] = p[1] * Math.sin(c) + p[2] * Math.cos(c); //translate to correct position\n\n out[0] = r[0] + b[0];\n out[1] = r[1] + b[1];\n out[2] = r[2] + b[2];\n return out;\n}\n/**\r\n * Rotate a 3D vector around the y-axis\r\n * @param {vec3} out The receiving vec3\r\n * @param {vec3} a The vec3 point to rotate\r\n * @param {vec3} b The origin of the rotation\r\n * @param {Number} c The angle of rotation\r\n * @returns {vec3} out\r\n */\n\nexport function rotateY(out, a, b, c) {\n var p = [],\n r = []; //Translate point to the origin\n\n p[0] = a[0] - b[0];\n p[1] = a[1] - b[1];\n p[2] = a[2] - b[2]; //perform rotation\n\n r[0] = p[2] * Math.sin(c) + p[0] * Math.cos(c);\n r[1] = p[1];\n r[2] = p[2] * Math.cos(c) - p[0] * Math.sin(c); //translate to correct position\n\n out[0] = r[0] + b[0];\n out[1] = r[1] + b[1];\n out[2] = r[2] + b[2];\n return out;\n}\n/**\r\n * Rotate a 3D vector around the z-axis\r\n * @param {vec3} out The receiving vec3\r\n * @param {vec3} a The vec3 point to rotate\r\n * @param {vec3} b The origin of the rotation\r\n * @param {Number} c The angle of rotation\r\n * @returns {vec3} out\r\n */\n\nexport function rotateZ(out, a, b, c) {\n var p = [],\n r = []; //Translate point to the origin\n\n p[0] = a[0] - b[0];\n p[1] = a[1] - b[1];\n p[2] = a[2] - b[2]; //perform rotation\n\n r[0] = p[0] * Math.cos(c) - p[1] * Math.sin(c);\n r[1] = p[0] * Math.sin(c) + p[1] * Math.cos(c);\n r[2] = p[2]; //translate to correct position\n\n out[0] = r[0] + b[0];\n out[1] = r[1] + b[1];\n out[2] = r[2] + b[2];\n return out;\n}\n/**\r\n * Get the angle between two 3D vectors\r\n * @param {vec3} a The first operand\r\n * @param {vec3} b The second operand\r\n * @returns {Number} The angle in radians\r\n */\n\nexport function angle(a, b) {\n var tempA = fromValues(a[0], a[1], a[2]);\n var tempB = fromValues(b[0], b[1], b[2]);\n normalize(tempA, tempA);\n normalize(tempB, tempB);\n var cosine = dot(tempA, tempB);\n\n if (cosine > 1.0) {\n return 0;\n } else if (cosine < -1.0) {\n return Math.PI;\n } else {\n return Math.acos(cosine);\n }\n}\n/**\r\n * Set the components of a vec3 to zero\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @returns {vec3} out\r\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n out[2] = 0.0;\n return out;\n}\n/**\r\n * Returns a string representation of a vector\r\n *\r\n * @param {vec3} a vector to represent as a string\r\n * @returns {String} string representation of the vector\r\n */\n\nexport function str(a) {\n return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';\n}\n/**\r\n * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {vec3} a The first vector.\r\n * @param {vec3} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];\n}\n/**\r\n * Returns whether or not the vectors have approximately the same elements in the same position.\r\n *\r\n * @param {vec3} a The first vector.\r\n * @param {vec3} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2));\n}\n/**\r\n * Alias for {@link vec3.subtract}\r\n * @function\r\n */\n\nexport var sub = subtract;\n/**\r\n * Alias for {@link vec3.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Alias for {@link vec3.divide}\r\n * @function\r\n */\n\nexport var div = divide;\n/**\r\n * Alias for {@link vec3.distance}\r\n * @function\r\n */\n\nexport var dist = distance;\n/**\r\n * Alias for {@link vec3.squaredDistance}\r\n * @function\r\n */\n\nexport var sqrDist = squaredDistance;\n/**\r\n * Alias for {@link vec3.length}\r\n * @function\r\n */\n\nexport var len = length;\n/**\r\n * Alias for {@link vec3.squaredLength}\r\n * @function\r\n */\n\nexport var sqrLen = squaredLength;\n/**\r\n * Perform some operation over an array of vec3s.\r\n *\r\n * @param {Array} a the array of vectors to iterate over\r\n * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed\r\n * @param {Number} offset Number of elements to skip at the beginning of the array\r\n * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array\r\n * @param {Function} fn Function to call for each vector in the array\r\n * @param {Object} [arg] additional argument to pass to fn\r\n * @returns {Array} a\r\n * @function\r\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 3;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n vec[2] = a[i + 2];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n a[i + 2] = vec[2];\n }\n\n return a;\n };\n}();","import * as glMatrix from \"./common.js\";\n/**\r\n * 4 Dimensional Vector\r\n * @module vec4\r\n */\n\n/**\r\n * Creates a new, empty vec4\r\n *\r\n * @returns {vec4} a new 4D vector\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n }\n\n return out;\n}\n/**\r\n * Creates a new vec4 initialized with values from an existing vector\r\n *\r\n * @param {vec4} a vector to clone\r\n * @returns {vec4} a new 4D vector\r\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\r\n * Creates a new vec4 initialized with the given values\r\n *\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @param {Number} w W component\r\n * @returns {vec4} a new 4D vector\r\n */\n\nexport function fromValues(x, y, z, w) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = w;\n return out;\n}\n/**\r\n * Copy the values from one vec4 to another\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the source vector\r\n * @returns {vec4} out\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\r\n * Set the components of a vec4 to the given values\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @param {Number} w W component\r\n * @returns {vec4} out\r\n */\n\nexport function set(out, x, y, z, w) {\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = w;\n return out;\n}\n/**\r\n * Adds two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\r\n * Subtracts vector b from vector a\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\r\n * Multiplies two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n out[2] = a[2] * b[2];\n out[3] = a[3] * b[3];\n return out;\n}\n/**\r\n * Divides two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n out[2] = a[2] / b[2];\n out[3] = a[3] / b[3];\n return out;\n}\n/**\r\n * Math.ceil the components of a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to ceil\r\n * @returns {vec4} out\r\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n out[2] = Math.ceil(a[2]);\n out[3] = Math.ceil(a[3]);\n return out;\n}\n/**\r\n * Math.floor the components of a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to floor\r\n * @returns {vec4} out\r\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n out[2] = Math.floor(a[2]);\n out[3] = Math.floor(a[3]);\n return out;\n}\n/**\r\n * Returns the minimum of two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n out[2] = Math.min(a[2], b[2]);\n out[3] = Math.min(a[3], b[3]);\n return out;\n}\n/**\r\n * Returns the maximum of two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n out[2] = Math.max(a[2], b[2]);\n out[3] = Math.max(a[3], b[3]);\n return out;\n}\n/**\r\n * Math.round the components of a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to round\r\n * @returns {vec4} out\r\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n out[2] = Math.round(a[2]);\n out[3] = Math.round(a[3]);\n return out;\n}\n/**\r\n * Scales a vec4 by a scalar number\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the vector to scale\r\n * @param {Number} b amount to scale the vector by\r\n * @returns {vec4} out\r\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\r\n * Adds two vec4's after scaling the second operand by a scalar value\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @param {Number} scale the amount to scale b by before adding\r\n * @returns {vec4} out\r\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\r\n * Calculates the euclidian distance between two vec4's\r\n *\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {Number} distance between a and b\r\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0];\n var y = b[1] - a[1];\n var z = b[2] - a[2];\n var w = b[3] - a[3];\n return Math.sqrt(x * x + y * y + z * z + w * w);\n}\n/**\r\n * Calculates the squared euclidian distance between two vec4's\r\n *\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {Number} squared distance between a and b\r\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0];\n var y = b[1] - a[1];\n var z = b[2] - a[2];\n var w = b[3] - a[3];\n return x * x + y * y + z * z + w * w;\n}\n/**\r\n * Calculates the length of a vec4\r\n *\r\n * @param {vec4} a vector to calculate length of\r\n * @returns {Number} length of a\r\n */\n\nexport function length(a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n var w = a[3];\n return Math.sqrt(x * x + y * y + z * z + w * w);\n}\n/**\r\n * Calculates the squared length of a vec4\r\n *\r\n * @param {vec4} a vector to calculate squared length of\r\n * @returns {Number} squared length of a\r\n */\n\nexport function squaredLength(a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n var w = a[3];\n return x * x + y * y + z * z + w * w;\n}\n/**\r\n * Negates the components of a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to negate\r\n * @returns {vec4} out\r\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = -a[3];\n return out;\n}\n/**\r\n * Returns the inverse of the components of a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to invert\r\n * @returns {vec4} out\r\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n out[2] = 1.0 / a[2];\n out[3] = 1.0 / a[3];\n return out;\n}\n/**\r\n * Normalize a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to normalize\r\n * @returns {vec4} out\r\n */\n\nexport function normalize(out, a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n var w = a[3];\n var len = x * x + y * y + z * z + w * w;\n\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = x * len;\n out[1] = y * len;\n out[2] = z * len;\n out[3] = w * len;\n return out;\n}\n/**\r\n * Calculates the dot product of two vec4's\r\n *\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {Number} dot product of a and b\r\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];\n}\n/**\r\n * Returns the cross-product of three vectors in a 4-dimensional space\r\n *\r\n * @param {vec4} result the receiving vector\r\n * @param {vec4} U the first vector\r\n * @param {vec4} V the second vector\r\n * @param {vec4} W the third vector\r\n * @returns {vec4} result\r\n */\n\nexport function cross(out, u, v, w) {\n var A = v[0] * w[1] - v[1] * w[0],\n B = v[0] * w[2] - v[2] * w[0],\n C = v[0] * w[3] - v[3] * w[0],\n D = v[1] * w[2] - v[2] * w[1],\n E = v[1] * w[3] - v[3] * w[1],\n F = v[2] * w[3] - v[3] * w[2];\n var G = u[0];\n var H = u[1];\n var I = u[2];\n var J = u[3];\n out[0] = H * F - I * E + J * D;\n out[1] = -(G * F) + I * C - J * B;\n out[2] = G * E - H * C + J * A;\n out[3] = -(G * D) + H * B - I * A;\n return out;\n}\n;\n/**\r\n * Performs a linear interpolation between two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {vec4} out\r\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0];\n var ay = a[1];\n var az = a[2];\n var aw = a[3];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n out[2] = az + t * (b[2] - az);\n out[3] = aw + t * (b[3] - aw);\n return out;\n}\n/**\r\n * Generates a random vector with the given scale\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\r\n * @returns {vec4} out\r\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0; // Marsaglia, George. Choosing a Point from the Surface of a\n // Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.\n // http://projecteuclid.org/euclid.aoms/1177692644;\n\n var v1, v2, v3, v4;\n var s1, s2;\n\n do {\n v1 = glMatrix.RANDOM() * 2 - 1;\n v2 = glMatrix.RANDOM() * 2 - 1;\n s1 = v1 * v1 + v2 * v2;\n } while (s1 >= 1);\n\n do {\n v3 = glMatrix.RANDOM() * 2 - 1;\n v4 = glMatrix.RANDOM() * 2 - 1;\n s2 = v3 * v3 + v4 * v4;\n } while (s2 >= 1);\n\n var d = Math.sqrt((1 - s1) / s2);\n out[0] = scale * v1;\n out[1] = scale * v2;\n out[2] = scale * v3 * d;\n out[3] = scale * v4 * d;\n return out;\n}\n/**\r\n * Transforms the vec4 with a mat4.\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the vector to transform\r\n * @param {mat4} m matrix to transform with\r\n * @returns {vec4} out\r\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;\n out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;\n out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;\n out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;\n return out;\n}\n/**\r\n * Transforms the vec4 with a quat\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the vector to transform\r\n * @param {quat} q quaternion to transform with\r\n * @returns {vec4} out\r\n */\n\nexport function transformQuat(out, a, q) {\n var x = a[0],\n y = a[1],\n z = a[2];\n var qx = q[0],\n qy = q[1],\n qz = q[2],\n qw = q[3]; // calculate quat * vec\n\n var ix = qw * x + qy * z - qz * y;\n var iy = qw * y + qz * x - qx * z;\n var iz = qw * z + qx * y - qy * x;\n var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat\n\n out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;\n out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;\n out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;\n out[3] = a[3];\n return out;\n}\n/**\r\n * Set the components of a vec4 to zero\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @returns {vec4} out\r\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n out[2] = 0.0;\n out[3] = 0.0;\n return out;\n}\n/**\r\n * Returns a string representation of a vector\r\n *\r\n * @param {vec4} a vector to represent as a string\r\n * @returns {String} string representation of the vector\r\n */\n\nexport function str(a) {\n return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n}\n/**\r\n * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {vec4} a The first vector.\r\n * @param {vec4} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\r\n * Returns whether or not the vectors have approximately the same elements in the same position.\r\n *\r\n * @param {vec4} a The first vector.\r\n * @param {vec4} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\r\n * Alias for {@link vec4.subtract}\r\n * @function\r\n */\n\nexport var sub = subtract;\n/**\r\n * Alias for {@link vec4.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Alias for {@link vec4.divide}\r\n * @function\r\n */\n\nexport var div = divide;\n/**\r\n * Alias for {@link vec4.distance}\r\n * @function\r\n */\n\nexport var dist = distance;\n/**\r\n * Alias for {@link vec4.squaredDistance}\r\n * @function\r\n */\n\nexport var sqrDist = squaredDistance;\n/**\r\n * Alias for {@link vec4.length}\r\n * @function\r\n */\n\nexport var len = length;\n/**\r\n * Alias for {@link vec4.squaredLength}\r\n * @function\r\n */\n\nexport var sqrLen = squaredLength;\n/**\r\n * Perform some operation over an array of vec4s.\r\n *\r\n * @param {Array} a the array of vectors to iterate over\r\n * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed\r\n * @param {Number} offset Number of elements to skip at the beginning of the array\r\n * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array\r\n * @param {Function} fn Function to call for each vector in the array\r\n * @param {Object} [arg] additional argument to pass to fn\r\n * @returns {Array} a\r\n * @function\r\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 4;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n vec[2] = a[i + 2];\n vec[3] = a[i + 3];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n a[i + 2] = vec[2];\n a[i + 3] = vec[3];\n }\n\n return a;\n };\n}();","import * as glMatrix from \"./common.js\";\nimport * as mat3 from \"./mat3.js\";\nimport * as vec3 from \"./vec3.js\";\nimport * as vec4 from \"./vec4.js\";\n/**\r\n * Quaternion\r\n * @module quat\r\n */\n\n/**\r\n * Creates a new identity quat\r\n *\r\n * @returns {quat} a new quaternion\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n }\n\n out[3] = 1;\n return out;\n}\n/**\r\n * Set a quat to the identity quaternion\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @returns {quat} out\r\n */\n\nexport function identity(out) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\r\n * Sets a quat from the given angle and rotation axis,\r\n * then returns it.\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {vec3} axis the axis around which to rotate\r\n * @param {Number} rad the angle in radians\r\n * @returns {quat} out\r\n **/\n\nexport function setAxisAngle(out, axis, rad) {\n rad = rad * 0.5;\n var s = Math.sin(rad);\n out[0] = s * axis[0];\n out[1] = s * axis[1];\n out[2] = s * axis[2];\n out[3] = Math.cos(rad);\n return out;\n}\n/**\r\n * Gets the rotation axis and angle for a given\r\n * quaternion. If a quaternion is created with\r\n * setAxisAngle, this method will return the same\r\n * values as providied in the original parameter list\r\n * OR functionally equivalent values.\r\n * Example: The quaternion formed by axis [0, 0, 1] and\r\n * angle -90 is the same as the quaternion formed by\r\n * [0, 0, 1] and 270. This method favors the latter.\r\n * @param {vec3} out_axis Vector receiving the axis of rotation\r\n * @param {quat} q Quaternion to be decomposed\r\n * @return {Number} Angle, in radians, of the rotation\r\n */\n\nexport function getAxisAngle(out_axis, q) {\n var rad = Math.acos(q[3]) * 2.0;\n var s = Math.sin(rad / 2.0);\n\n if (s > glMatrix.EPSILON) {\n out_axis[0] = q[0] / s;\n out_axis[1] = q[1] / s;\n out_axis[2] = q[2] / s;\n } else {\n // If s is zero, return any axis (no rotation - axis does not matter)\n out_axis[0] = 1;\n out_axis[1] = 0;\n out_axis[2] = 0;\n }\n\n return rad;\n}\n/**\r\n * Multiplies two quat's\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @returns {quat} out\r\n */\n\nexport function multiply(out, a, b) {\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n var bx = b[0],\n by = b[1],\n bz = b[2],\n bw = b[3];\n out[0] = ax * bw + aw * bx + ay * bz - az * by;\n out[1] = ay * bw + aw * by + az * bx - ax * bz;\n out[2] = az * bw + aw * bz + ax * by - ay * bx;\n out[3] = aw * bw - ax * bx - ay * by - az * bz;\n return out;\n}\n/**\r\n * Rotates a quaternion by the given angle about the X axis\r\n *\r\n * @param {quat} out quat receiving operation result\r\n * @param {quat} a quat to rotate\r\n * @param {number} rad angle (in radians) to rotate\r\n * @returns {quat} out\r\n */\n\nexport function rotateX(out, a, rad) {\n rad *= 0.5;\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n var bx = Math.sin(rad),\n bw = Math.cos(rad);\n out[0] = ax * bw + aw * bx;\n out[1] = ay * bw + az * bx;\n out[2] = az * bw - ay * bx;\n out[3] = aw * bw - ax * bx;\n return out;\n}\n/**\r\n * Rotates a quaternion by the given angle about the Y axis\r\n *\r\n * @param {quat} out quat receiving operation result\r\n * @param {quat} a quat to rotate\r\n * @param {number} rad angle (in radians) to rotate\r\n * @returns {quat} out\r\n */\n\nexport function rotateY(out, a, rad) {\n rad *= 0.5;\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n var by = Math.sin(rad),\n bw = Math.cos(rad);\n out[0] = ax * bw - az * by;\n out[1] = ay * bw + aw * by;\n out[2] = az * bw + ax * by;\n out[3] = aw * bw - ay * by;\n return out;\n}\n/**\r\n * Rotates a quaternion by the given angle about the Z axis\r\n *\r\n * @param {quat} out quat receiving operation result\r\n * @param {quat} a quat to rotate\r\n * @param {number} rad angle (in radians) to rotate\r\n * @returns {quat} out\r\n */\n\nexport function rotateZ(out, a, rad) {\n rad *= 0.5;\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n var bz = Math.sin(rad),\n bw = Math.cos(rad);\n out[0] = ax * bw + ay * bz;\n out[1] = ay * bw - ax * bz;\n out[2] = az * bw + aw * bz;\n out[3] = aw * bw - az * bz;\n return out;\n}\n/**\r\n * Calculates the W component of a quat from the X, Y, and Z components.\r\n * Assumes that quaternion is 1 unit in length.\r\n * Any existing W component will be ignored.\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a quat to calculate W component of\r\n * @returns {quat} out\r\n */\n\nexport function calculateW(out, a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));\n return out;\n}\n/**\r\n * Performs a spherical linear interpolation between two quat\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {quat} out\r\n */\n\nexport function slerp(out, a, b, t) {\n // benchmarks:\n // http://jsperf.com/quaternion-slerp-implementations\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n var bx = b[0],\n by = b[1],\n bz = b[2],\n bw = b[3];\n var omega, cosom, sinom, scale0, scale1; // calc cosine\n\n cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)\n\n if (cosom < 0.0) {\n cosom = -cosom;\n bx = -bx;\n by = -by;\n bz = -bz;\n bw = -bw;\n } // calculate coefficients\n\n\n if (1.0 - cosom > glMatrix.EPSILON) {\n // standard case (slerp)\n omega = Math.acos(cosom);\n sinom = Math.sin(omega);\n scale0 = Math.sin((1.0 - t) * omega) / sinom;\n scale1 = Math.sin(t * omega) / sinom;\n } else {\n // \"from\" and \"to\" quaternions are very close\n // ... so we can do a linear interpolation\n scale0 = 1.0 - t;\n scale1 = t;\n } // calculate final values\n\n\n out[0] = scale0 * ax + scale1 * bx;\n out[1] = scale0 * ay + scale1 * by;\n out[2] = scale0 * az + scale1 * bz;\n out[3] = scale0 * aw + scale1 * bw;\n return out;\n}\n/**\r\n * Generates a random quaternion\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @returns {quat} out\r\n */\n\nexport function random(out) {\n // Implementation of http://planning.cs.uiuc.edu/node198.html\n // TODO: Calling random 3 times is probably not the fastest solution\n var u1 = glMatrix.RANDOM();\n var u2 = glMatrix.RANDOM();\n var u3 = glMatrix.RANDOM();\n var sqrt1MinusU1 = Math.sqrt(1 - u1);\n var sqrtU1 = Math.sqrt(u1);\n out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);\n out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);\n out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);\n out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);\n return out;\n}\n/**\r\n * Calculates the inverse of a quat\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a quat to calculate inverse of\r\n * @returns {quat} out\r\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;\n var invDot = dot ? 1.0 / dot : 0; // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0\n\n out[0] = -a0 * invDot;\n out[1] = -a1 * invDot;\n out[2] = -a2 * invDot;\n out[3] = a3 * invDot;\n return out;\n}\n/**\r\n * Calculates the conjugate of a quat\r\n * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a quat to calculate conjugate of\r\n * @returns {quat} out\r\n */\n\nexport function conjugate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a[3];\n return out;\n}\n/**\r\n * Creates a quaternion from the given 3x3 rotation matrix.\r\n *\r\n * NOTE: The resultant quaternion is not normalized, so you should be sure\r\n * to renormalize the quaternion yourself where necessary.\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {mat3} m rotation matrix\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport function fromMat3(out, m) {\n // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes\n // article \"Quaternion Calculus and Fast Animation\".\n var fTrace = m[0] + m[4] + m[8];\n var fRoot;\n\n if (fTrace > 0.0) {\n // |w| > 1/2, may as well choose w > 1/2\n fRoot = Math.sqrt(fTrace + 1.0); // 2w\n\n out[3] = 0.5 * fRoot;\n fRoot = 0.5 / fRoot; // 1/(4w)\n\n out[0] = (m[5] - m[7]) * fRoot;\n out[1] = (m[6] - m[2]) * fRoot;\n out[2] = (m[1] - m[3]) * fRoot;\n } else {\n // |w| <= 1/2\n var i = 0;\n if (m[4] > m[0]) i = 1;\n if (m[8] > m[i * 3 + i]) i = 2;\n var j = (i + 1) % 3;\n var k = (i + 2) % 3;\n fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);\n out[i] = 0.5 * fRoot;\n fRoot = 0.5 / fRoot;\n out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;\n out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;\n out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;\n }\n\n return out;\n}\n/**\r\n * Creates a quaternion from the given euler angle x, y, z.\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {x} Angle to rotate around X axis in degrees.\r\n * @param {y} Angle to rotate around Y axis in degrees.\r\n * @param {z} Angle to rotate around Z axis in degrees.\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport function fromEuler(out, x, y, z) {\n var halfToRad = 0.5 * Math.PI / 180.0;\n x *= halfToRad;\n y *= halfToRad;\n z *= halfToRad;\n var sx = Math.sin(x);\n var cx = Math.cos(x);\n var sy = Math.sin(y);\n var cy = Math.cos(y);\n var sz = Math.sin(z);\n var cz = Math.cos(z);\n out[0] = sx * cy * cz - cx * sy * sz;\n out[1] = cx * sy * cz + sx * cy * sz;\n out[2] = cx * cy * sz - sx * sy * cz;\n out[3] = cx * cy * cz + sx * sy * sz;\n return out;\n}\n/**\r\n * Returns a string representation of a quatenion\r\n *\r\n * @param {quat} a vector to represent as a string\r\n * @returns {String} string representation of the vector\r\n */\n\nexport function str(a) {\n return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n}\n/**\r\n * Creates a new quat initialized with values from an existing quaternion\r\n *\r\n * @param {quat} a quaternion to clone\r\n * @returns {quat} a new quaternion\r\n * @function\r\n */\n\nexport var clone = vec4.clone;\n/**\r\n * Creates a new quat initialized with the given values\r\n *\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @param {Number} w W component\r\n * @returns {quat} a new quaternion\r\n * @function\r\n */\n\nexport var fromValues = vec4.fromValues;\n/**\r\n * Copy the values from one quat to another\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the source quaternion\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var copy = vec4.copy;\n/**\r\n * Set the components of a quat to the given values\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @param {Number} w W component\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var set = vec4.set;\n/**\r\n * Adds two quat's\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var add = vec4.add;\n/**\r\n * Alias for {@link quat.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Scales a quat by a scalar number\r\n *\r\n * @param {quat} out the receiving vector\r\n * @param {quat} a the vector to scale\r\n * @param {Number} b amount to scale the vector by\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var scale = vec4.scale;\n/**\r\n * Calculates the dot product of two quat's\r\n *\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @returns {Number} dot product of a and b\r\n * @function\r\n */\n\nexport var dot = vec4.dot;\n/**\r\n * Performs a linear interpolation between two quat's\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var lerp = vec4.lerp;\n/**\r\n * Calculates the length of a quat\r\n *\r\n * @param {quat} a vector to calculate length of\r\n * @returns {Number} length of a\r\n */\n\nexport var length = vec4.length;\n/**\r\n * Alias for {@link quat.length}\r\n * @function\r\n */\n\nexport var len = length;\n/**\r\n * Calculates the squared length of a quat\r\n *\r\n * @param {quat} a vector to calculate squared length of\r\n * @returns {Number} squared length of a\r\n * @function\r\n */\n\nexport var squaredLength = vec4.squaredLength;\n/**\r\n * Alias for {@link quat.squaredLength}\r\n * @function\r\n */\n\nexport var sqrLen = squaredLength;\n/**\r\n * Normalize a quat\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a quaternion to normalize\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var normalize = vec4.normalize;\n/**\r\n * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {quat} a The first quaternion.\r\n * @param {quat} b The second quaternion.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport var exactEquals = vec4.exactEquals;\n/**\r\n * Returns whether or not the quaternions have approximately the same elements in the same position.\r\n *\r\n * @param {quat} a The first vector.\r\n * @param {quat} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport var equals = vec4.equals;\n/**\r\n * Sets a quaternion to represent the shortest rotation from one\r\n * vector to another.\r\n *\r\n * Both vectors are assumed to be unit length.\r\n *\r\n * @param {quat} out the receiving quaternion.\r\n * @param {vec3} a the initial vector\r\n * @param {vec3} b the destination vector\r\n * @returns {quat} out\r\n */\n\nexport var rotationTo = function () {\n var tmpvec3 = vec3.create();\n var xUnitVec3 = vec3.fromValues(1, 0, 0);\n var yUnitVec3 = vec3.fromValues(0, 1, 0);\n return function (out, a, b) {\n var dot = vec3.dot(a, b);\n\n if (dot < -0.999999) {\n vec3.cross(tmpvec3, xUnitVec3, a);\n if (vec3.len(tmpvec3) < 0.000001) vec3.cross(tmpvec3, yUnitVec3, a);\n vec3.normalize(tmpvec3, tmpvec3);\n setAxisAngle(out, tmpvec3, Math.PI);\n return out;\n } else if (dot > 0.999999) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n } else {\n vec3.cross(tmpvec3, a, b);\n out[0] = tmpvec3[0];\n out[1] = tmpvec3[1];\n out[2] = tmpvec3[2];\n out[3] = 1 + dot;\n return normalize(out, out);\n }\n };\n}();\n/**\r\n * Performs a spherical linear interpolation with two control points\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @param {quat} c the third operand\r\n * @param {quat} d the fourth operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {quat} out\r\n */\n\nexport var sqlerp = function () {\n var temp1 = create();\n var temp2 = create();\n return function (out, a, b, c, d, t) {\n slerp(temp1, a, d, t);\n slerp(temp2, b, c, t);\n slerp(out, temp1, temp2, 2 * t * (1 - t));\n return out;\n };\n}();\n/**\r\n * Sets the specified quaternion with values corresponding to the given\r\n * axes. Each axis is a vec3 and is expected to be unit length and\r\n * perpendicular to all other specified axes.\r\n *\r\n * @param {vec3} view the vector representing the viewing direction\r\n * @param {vec3} right the vector representing the local \"right\" direction\r\n * @param {vec3} up the vector representing the local \"up\" direction\r\n * @returns {quat} out\r\n */\n\nexport var setAxes = function () {\n var matr = mat3.create();\n return function (out, view, right, up) {\n matr[0] = right[0];\n matr[3] = right[1];\n matr[6] = right[2];\n matr[1] = up[0];\n matr[4] = up[1];\n matr[7] = up[2];\n matr[2] = -view[0];\n matr[5] = -view[1];\n matr[8] = -view[2];\n return normalize(out, fromMat3(out, matr));\n };\n}();","import * as glMatrix from \"./common.js\";\nimport * as quat from \"./quat.js\";\nimport * as mat4 from \"./mat4.js\";\n/**\r\n * Dual Quaternion
\r\n * Format: [real, dual]
\r\n * Quaternion format: XYZW
\r\n * Make sure to have normalized dual quaternions, otherwise the functions may not work as intended.
\r\n * @module quat2\r\n */\n\n/**\r\n * Creates a new identity dual quat\r\n *\r\n * @returns {quat2} a new dual quaternion [real -> rotation, dual -> translation]\r\n */\n\nexport function create() {\n var dq = new glMatrix.ARRAY_TYPE(8);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n dq[0] = 0;\n dq[1] = 0;\n dq[2] = 0;\n dq[4] = 0;\n dq[5] = 0;\n dq[6] = 0;\n dq[7] = 0;\n }\n\n dq[3] = 1;\n return dq;\n}\n/**\r\n * Creates a new quat initialized with values from an existing quaternion\r\n *\r\n * @param {quat2} a dual quaternion to clone\r\n * @returns {quat2} new dual quaternion\r\n * @function\r\n */\n\nexport function clone(a) {\n var dq = new glMatrix.ARRAY_TYPE(8);\n dq[0] = a[0];\n dq[1] = a[1];\n dq[2] = a[2];\n dq[3] = a[3];\n dq[4] = a[4];\n dq[5] = a[5];\n dq[6] = a[6];\n dq[7] = a[7];\n return dq;\n}\n/**\r\n * Creates a new dual quat initialized with the given values\r\n *\r\n * @param {Number} x1 X component\r\n * @param {Number} y1 Y component\r\n * @param {Number} z1 Z component\r\n * @param {Number} w1 W component\r\n * @param {Number} x2 X component\r\n * @param {Number} y2 Y component\r\n * @param {Number} z2 Z component\r\n * @param {Number} w2 W component\r\n * @returns {quat2} new dual quaternion\r\n * @function\r\n */\n\nexport function fromValues(x1, y1, z1, w1, x2, y2, z2, w2) {\n var dq = new glMatrix.ARRAY_TYPE(8);\n dq[0] = x1;\n dq[1] = y1;\n dq[2] = z1;\n dq[3] = w1;\n dq[4] = x2;\n dq[5] = y2;\n dq[6] = z2;\n dq[7] = w2;\n return dq;\n}\n/**\r\n * Creates a new dual quat from the given values (quat and translation)\r\n *\r\n * @param {Number} x1 X component\r\n * @param {Number} y1 Y component\r\n * @param {Number} z1 Z component\r\n * @param {Number} w1 W component\r\n * @param {Number} x2 X component (translation)\r\n * @param {Number} y2 Y component (translation)\r\n * @param {Number} z2 Z component (translation)\r\n * @returns {quat2} new dual quaternion\r\n * @function\r\n */\n\nexport function fromRotationTranslationValues(x1, y1, z1, w1, x2, y2, z2) {\n var dq = new glMatrix.ARRAY_TYPE(8);\n dq[0] = x1;\n dq[1] = y1;\n dq[2] = z1;\n dq[3] = w1;\n var ax = x2 * 0.5,\n ay = y2 * 0.5,\n az = z2 * 0.5;\n dq[4] = ax * w1 + ay * z1 - az * y1;\n dq[5] = ay * w1 + az * x1 - ax * z1;\n dq[6] = az * w1 + ax * y1 - ay * x1;\n dq[7] = -ax * x1 - ay * y1 - az * z1;\n return dq;\n}\n/**\r\n * Creates a dual quat from a quaternion and a translation\r\n *\r\n * @param {quat2} dual quaternion receiving operation result\r\n * @param {quat} q quaternion\r\n * @param {vec3} t tranlation vector\r\n * @returns {quat2} dual quaternion receiving operation result\r\n * @function\r\n */\n\nexport function fromRotationTranslation(out, q, t) {\n var ax = t[0] * 0.5,\n ay = t[1] * 0.5,\n az = t[2] * 0.5,\n bx = q[0],\n by = q[1],\n bz = q[2],\n bw = q[3];\n out[0] = bx;\n out[1] = by;\n out[2] = bz;\n out[3] = bw;\n out[4] = ax * bw + ay * bz - az * by;\n out[5] = ay * bw + az * bx - ax * bz;\n out[6] = az * bw + ax * by - ay * bx;\n out[7] = -ax * bx - ay * by - az * bz;\n return out;\n}\n/**\r\n * Creates a dual quat from a translation\r\n *\r\n * @param {quat2} dual quaternion receiving operation result\r\n * @param {vec3} t translation vector\r\n * @returns {quat2} dual quaternion receiving operation result\r\n * @function\r\n */\n\nexport function fromTranslation(out, t) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = t[0] * 0.5;\n out[5] = t[1] * 0.5;\n out[6] = t[2] * 0.5;\n out[7] = 0;\n return out;\n}\n/**\r\n * Creates a dual quat from a quaternion\r\n *\r\n * @param {quat2} dual quaternion receiving operation result\r\n * @param {quat} q the quaternion\r\n * @returns {quat2} dual quaternion receiving operation result\r\n * @function\r\n */\n\nexport function fromRotation(out, q) {\n out[0] = q[0];\n out[1] = q[1];\n out[2] = q[2];\n out[3] = q[3];\n out[4] = 0;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n return out;\n}\n/**\r\n * Creates a new dual quat from a matrix (4x4)\r\n *\r\n * @param {quat2} out the dual quaternion\r\n * @param {mat4} a the matrix\r\n * @returns {quat2} dual quat receiving operation result\r\n * @function\r\n */\n\nexport function fromMat4(out, a) {\n //TODO Optimize this\n var outer = quat.create();\n mat4.getRotation(outer, a);\n var t = new glMatrix.ARRAY_TYPE(3);\n mat4.getTranslation(t, a);\n fromRotationTranslation(out, outer, t);\n return out;\n}\n/**\r\n * Copy the values from one dual quat to another\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a the source dual quaternion\r\n * @returns {quat2} out\r\n * @function\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n return out;\n}\n/**\r\n * Set a dual quat to the identity dual quaternion\r\n *\r\n * @param {quat2} out the receiving quaternion\r\n * @returns {quat2} out\r\n */\n\nexport function identity(out) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n out[4] = 0;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n return out;\n}\n/**\r\n * Set the components of a dual quat to the given values\r\n *\r\n * @param {quat2} out the receiving quaternion\r\n * @param {Number} x1 X component\r\n * @param {Number} y1 Y component\r\n * @param {Number} z1 Z component\r\n * @param {Number} w1 W component\r\n * @param {Number} x2 X component\r\n * @param {Number} y2 Y component\r\n * @param {Number} z2 Z component\r\n * @param {Number} w2 W component\r\n * @returns {quat2} out\r\n * @function\r\n */\n\nexport function set(out, x1, y1, z1, w1, x2, y2, z2, w2) {\n out[0] = x1;\n out[1] = y1;\n out[2] = z1;\n out[3] = w1;\n out[4] = x2;\n out[5] = y2;\n out[6] = z2;\n out[7] = w2;\n return out;\n}\n/**\r\n * Gets the real part of a dual quat\r\n * @param {quat} out real part\r\n * @param {quat2} a Dual Quaternion\r\n * @return {quat} real part\r\n */\n\nexport var getReal = quat.copy;\n/**\r\n * Gets the dual part of a dual quat\r\n * @param {quat} out dual part\r\n * @param {quat2} a Dual Quaternion\r\n * @return {quat} dual part\r\n */\n\nexport function getDual(out, a) {\n out[0] = a[4];\n out[1] = a[5];\n out[2] = a[6];\n out[3] = a[7];\n return out;\n}\n/**\r\n * Set the real component of a dual quat to the given quaternion\r\n *\r\n * @param {quat2} out the receiving quaternion\r\n * @param {quat} q a quaternion representing the real part\r\n * @returns {quat2} out\r\n * @function\r\n */\n\nexport var setReal = quat.copy;\n/**\r\n * Set the dual component of a dual quat to the given quaternion\r\n *\r\n * @param {quat2} out the receiving quaternion\r\n * @param {quat} q a quaternion representing the dual part\r\n * @returns {quat2} out\r\n * @function\r\n */\n\nexport function setDual(out, q) {\n out[4] = q[0];\n out[5] = q[1];\n out[6] = q[2];\n out[7] = q[3];\n return out;\n}\n/**\r\n * Gets the translation of a normalized dual quat\r\n * @param {vec3} out translation\r\n * @param {quat2} a Dual Quaternion to be decomposed\r\n * @return {vec3} translation\r\n */\n\nexport function getTranslation(out, a) {\n var ax = a[4],\n ay = a[5],\n az = a[6],\n aw = a[7],\n bx = -a[0],\n by = -a[1],\n bz = -a[2],\n bw = a[3];\n out[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;\n out[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;\n out[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;\n return out;\n}\n/**\r\n * Translates a dual quat by the given vector\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a the dual quaternion to translate\r\n * @param {vec3} v vector to translate by\r\n * @returns {quat2} out\r\n */\n\nexport function translate(out, a, v) {\n var ax1 = a[0],\n ay1 = a[1],\n az1 = a[2],\n aw1 = a[3],\n bx1 = v[0] * 0.5,\n by1 = v[1] * 0.5,\n bz1 = v[2] * 0.5,\n ax2 = a[4],\n ay2 = a[5],\n az2 = a[6],\n aw2 = a[7];\n out[0] = ax1;\n out[1] = ay1;\n out[2] = az1;\n out[3] = aw1;\n out[4] = aw1 * bx1 + ay1 * bz1 - az1 * by1 + ax2;\n out[5] = aw1 * by1 + az1 * bx1 - ax1 * bz1 + ay2;\n out[6] = aw1 * bz1 + ax1 * by1 - ay1 * bx1 + az2;\n out[7] = -ax1 * bx1 - ay1 * by1 - az1 * bz1 + aw2;\n return out;\n}\n/**\r\n * Rotates a dual quat around the X axis\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a the dual quaternion to rotate\r\n * @param {number} rad how far should the rotation be\r\n * @returns {quat2} out\r\n */\n\nexport function rotateX(out, a, rad) {\n var bx = -a[0],\n by = -a[1],\n bz = -a[2],\n bw = a[3],\n ax = a[4],\n ay = a[5],\n az = a[6],\n aw = a[7],\n ax1 = ax * bw + aw * bx + ay * bz - az * by,\n ay1 = ay * bw + aw * by + az * bx - ax * bz,\n az1 = az * bw + aw * bz + ax * by - ay * bx,\n aw1 = aw * bw - ax * bx - ay * by - az * bz;\n quat.rotateX(out, a, rad);\n bx = out[0];\n by = out[1];\n bz = out[2];\n bw = out[3];\n out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;\n out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;\n out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;\n out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;\n return out;\n}\n/**\r\n * Rotates a dual quat around the Y axis\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a the dual quaternion to rotate\r\n * @param {number} rad how far should the rotation be\r\n * @returns {quat2} out\r\n */\n\nexport function rotateY(out, a, rad) {\n var bx = -a[0],\n by = -a[1],\n bz = -a[2],\n bw = a[3],\n ax = a[4],\n ay = a[5],\n az = a[6],\n aw = a[7],\n ax1 = ax * bw + aw * bx + ay * bz - az * by,\n ay1 = ay * bw + aw * by + az * bx - ax * bz,\n az1 = az * bw + aw * bz + ax * by - ay * bx,\n aw1 = aw * bw - ax * bx - ay * by - az * bz;\n quat.rotateY(out, a, rad);\n bx = out[0];\n by = out[1];\n bz = out[2];\n bw = out[3];\n out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;\n out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;\n out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;\n out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;\n return out;\n}\n/**\r\n * Rotates a dual quat around the Z axis\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a the dual quaternion to rotate\r\n * @param {number} rad how far should the rotation be\r\n * @returns {quat2} out\r\n */\n\nexport function rotateZ(out, a, rad) {\n var bx = -a[0],\n by = -a[1],\n bz = -a[2],\n bw = a[3],\n ax = a[4],\n ay = a[5],\n az = a[6],\n aw = a[7],\n ax1 = ax * bw + aw * bx + ay * bz - az * by,\n ay1 = ay * bw + aw * by + az * bx - ax * bz,\n az1 = az * bw + aw * bz + ax * by - ay * bx,\n aw1 = aw * bw - ax * bx - ay * by - az * bz;\n quat.rotateZ(out, a, rad);\n bx = out[0];\n by = out[1];\n bz = out[2];\n bw = out[3];\n out[4] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;\n out[5] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;\n out[6] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;\n out[7] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;\n return out;\n}\n/**\r\n * Rotates a dual quat by a given quaternion (a * q)\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a the dual quaternion to rotate\r\n * @param {quat} q quaternion to rotate by\r\n * @returns {quat2} out\r\n */\n\nexport function rotateByQuatAppend(out, a, q) {\n var qx = q[0],\n qy = q[1],\n qz = q[2],\n qw = q[3],\n ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n out[0] = ax * qw + aw * qx + ay * qz - az * qy;\n out[1] = ay * qw + aw * qy + az * qx - ax * qz;\n out[2] = az * qw + aw * qz + ax * qy - ay * qx;\n out[3] = aw * qw - ax * qx - ay * qy - az * qz;\n ax = a[4];\n ay = a[5];\n az = a[6];\n aw = a[7];\n out[4] = ax * qw + aw * qx + ay * qz - az * qy;\n out[5] = ay * qw + aw * qy + az * qx - ax * qz;\n out[6] = az * qw + aw * qz + ax * qy - ay * qx;\n out[7] = aw * qw - ax * qx - ay * qy - az * qz;\n return out;\n}\n/**\r\n * Rotates a dual quat by a given quaternion (q * a)\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat} q quaternion to rotate by\r\n * @param {quat2} a the dual quaternion to rotate\r\n * @returns {quat2} out\r\n */\n\nexport function rotateByQuatPrepend(out, q, a) {\n var qx = q[0],\n qy = q[1],\n qz = q[2],\n qw = q[3],\n bx = a[0],\n by = a[1],\n bz = a[2],\n bw = a[3];\n out[0] = qx * bw + qw * bx + qy * bz - qz * by;\n out[1] = qy * bw + qw * by + qz * bx - qx * bz;\n out[2] = qz * bw + qw * bz + qx * by - qy * bx;\n out[3] = qw * bw - qx * bx - qy * by - qz * bz;\n bx = a[4];\n by = a[5];\n bz = a[6];\n bw = a[7];\n out[4] = qx * bw + qw * bx + qy * bz - qz * by;\n out[5] = qy * bw + qw * by + qz * bx - qx * bz;\n out[6] = qz * bw + qw * bz + qx * by - qy * bx;\n out[7] = qw * bw - qx * bx - qy * by - qz * bz;\n return out;\n}\n/**\r\n * Rotates a dual quat around a given axis. Does the normalisation automatically\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a the dual quaternion to rotate\r\n * @param {vec3} axis the axis to rotate around\r\n * @param {Number} rad how far the rotation should be\r\n * @returns {quat2} out\r\n */\n\nexport function rotateAroundAxis(out, a, axis, rad) {\n //Special case for rad = 0\n if (Math.abs(rad) < glMatrix.EPSILON) {\n return copy(out, a);\n }\n\n var axisLength = Math.sqrt(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]);\n rad = rad * 0.5;\n var s = Math.sin(rad);\n var bx = s * axis[0] / axisLength;\n var by = s * axis[1] / axisLength;\n var bz = s * axis[2] / axisLength;\n var bw = Math.cos(rad);\n var ax1 = a[0],\n ay1 = a[1],\n az1 = a[2],\n aw1 = a[3];\n out[0] = ax1 * bw + aw1 * bx + ay1 * bz - az1 * by;\n out[1] = ay1 * bw + aw1 * by + az1 * bx - ax1 * bz;\n out[2] = az1 * bw + aw1 * bz + ax1 * by - ay1 * bx;\n out[3] = aw1 * bw - ax1 * bx - ay1 * by - az1 * bz;\n var ax = a[4],\n ay = a[5],\n az = a[6],\n aw = a[7];\n out[4] = ax * bw + aw * bx + ay * bz - az * by;\n out[5] = ay * bw + aw * by + az * bx - ax * bz;\n out[6] = az * bw + aw * bz + ax * by - ay * bx;\n out[7] = aw * bw - ax * bx - ay * by - az * bz;\n return out;\n}\n/**\r\n * Adds two dual quat's\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a the first operand\r\n * @param {quat2} b the second operand\r\n * @returns {quat2} out\r\n * @function\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n out[6] = a[6] + b[6];\n out[7] = a[7] + b[7];\n return out;\n}\n/**\r\n * Multiplies two dual quat's\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a the first operand\r\n * @param {quat2} b the second operand\r\n * @returns {quat2} out\r\n */\n\nexport function multiply(out, a, b) {\n var ax0 = a[0],\n ay0 = a[1],\n az0 = a[2],\n aw0 = a[3],\n bx1 = b[4],\n by1 = b[5],\n bz1 = b[6],\n bw1 = b[7],\n ax1 = a[4],\n ay1 = a[5],\n az1 = a[6],\n aw1 = a[7],\n bx0 = b[0],\n by0 = b[1],\n bz0 = b[2],\n bw0 = b[3];\n out[0] = ax0 * bw0 + aw0 * bx0 + ay0 * bz0 - az0 * by0;\n out[1] = ay0 * bw0 + aw0 * by0 + az0 * bx0 - ax0 * bz0;\n out[2] = az0 * bw0 + aw0 * bz0 + ax0 * by0 - ay0 * bx0;\n out[3] = aw0 * bw0 - ax0 * bx0 - ay0 * by0 - az0 * bz0;\n out[4] = ax0 * bw1 + aw0 * bx1 + ay0 * bz1 - az0 * by1 + ax1 * bw0 + aw1 * bx0 + ay1 * bz0 - az1 * by0;\n out[5] = ay0 * bw1 + aw0 * by1 + az0 * bx1 - ax0 * bz1 + ay1 * bw0 + aw1 * by0 + az1 * bx0 - ax1 * bz0;\n out[6] = az0 * bw1 + aw0 * bz1 + ax0 * by1 - ay0 * bx1 + az1 * bw0 + aw1 * bz0 + ax1 * by0 - ay1 * bx0;\n out[7] = aw0 * bw1 - ax0 * bx1 - ay0 * by1 - az0 * bz1 + aw1 * bw0 - ax1 * bx0 - ay1 * by0 - az1 * bz0;\n return out;\n}\n/**\r\n * Alias for {@link quat2.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Scales a dual quat by a scalar number\r\n *\r\n * @param {quat2} out the receiving dual quat\r\n * @param {quat2} a the dual quat to scale\r\n * @param {Number} b amount to scale the dual quat by\r\n * @returns {quat2} out\r\n * @function\r\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n out[6] = a[6] * b;\n out[7] = a[7] * b;\n return out;\n}\n/**\r\n * Calculates the dot product of two dual quat's (The dot product of the real parts)\r\n *\r\n * @param {quat2} a the first operand\r\n * @param {quat2} b the second operand\r\n * @returns {Number} dot product of a and b\r\n * @function\r\n */\n\nexport var dot = quat.dot;\n/**\r\n * Performs a linear interpolation between two dual quats's\r\n * NOTE: The resulting dual quaternions won't always be normalized (The error is most noticeable when t = 0.5)\r\n *\r\n * @param {quat2} out the receiving dual quat\r\n * @param {quat2} a the first operand\r\n * @param {quat2} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {quat2} out\r\n */\n\nexport function lerp(out, a, b, t) {\n var mt = 1 - t;\n if (dot(a, b) < 0) t = -t;\n out[0] = a[0] * mt + b[0] * t;\n out[1] = a[1] * mt + b[1] * t;\n out[2] = a[2] * mt + b[2] * t;\n out[3] = a[3] * mt + b[3] * t;\n out[4] = a[4] * mt + b[4] * t;\n out[5] = a[5] * mt + b[5] * t;\n out[6] = a[6] * mt + b[6] * t;\n out[7] = a[7] * mt + b[7] * t;\n return out;\n}\n/**\r\n * Calculates the inverse of a dual quat. If they are normalized, conjugate is cheaper\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a dual quat to calculate inverse of\r\n * @returns {quat2} out\r\n */\n\nexport function invert(out, a) {\n var sqlen = squaredLength(a);\n out[0] = -a[0] / sqlen;\n out[1] = -a[1] / sqlen;\n out[2] = -a[2] / sqlen;\n out[3] = a[3] / sqlen;\n out[4] = -a[4] / sqlen;\n out[5] = -a[5] / sqlen;\n out[6] = -a[6] / sqlen;\n out[7] = a[7] / sqlen;\n return out;\n}\n/**\r\n * Calculates the conjugate of a dual quat\r\n * If the dual quaternion is normalized, this function is faster than quat2.inverse and produces the same result.\r\n *\r\n * @param {quat2} out the receiving quaternion\r\n * @param {quat2} a quat to calculate conjugate of\r\n * @returns {quat2} out\r\n */\n\nexport function conjugate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a[3];\n out[4] = -a[4];\n out[5] = -a[5];\n out[6] = -a[6];\n out[7] = a[7];\n return out;\n}\n/**\r\n * Calculates the length of a dual quat\r\n *\r\n * @param {quat2} a dual quat to calculate length of\r\n * @returns {Number} length of a\r\n * @function\r\n */\n\nexport var length = quat.length;\n/**\r\n * Alias for {@link quat2.length}\r\n * @function\r\n */\n\nexport var len = length;\n/**\r\n * Calculates the squared length of a dual quat\r\n *\r\n * @param {quat2} a dual quat to calculate squared length of\r\n * @returns {Number} squared length of a\r\n * @function\r\n */\n\nexport var squaredLength = quat.squaredLength;\n/**\r\n * Alias for {@link quat2.squaredLength}\r\n * @function\r\n */\n\nexport var sqrLen = squaredLength;\n/**\r\n * Normalize a dual quat\r\n *\r\n * @param {quat2} out the receiving dual quaternion\r\n * @param {quat2} a dual quaternion to normalize\r\n * @returns {quat2} out\r\n * @function\r\n */\n\nexport function normalize(out, a) {\n var magnitude = squaredLength(a);\n\n if (magnitude > 0) {\n magnitude = Math.sqrt(magnitude);\n var a0 = a[0] / magnitude;\n var a1 = a[1] / magnitude;\n var a2 = a[2] / magnitude;\n var a3 = a[3] / magnitude;\n var b0 = a[4];\n var b1 = a[5];\n var b2 = a[6];\n var b3 = a[7];\n var a_dot_b = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;\n out[0] = a0;\n out[1] = a1;\n out[2] = a2;\n out[3] = a3;\n out[4] = (b0 - a0 * a_dot_b) / magnitude;\n out[5] = (b1 - a1 * a_dot_b) / magnitude;\n out[6] = (b2 - a2 * a_dot_b) / magnitude;\n out[7] = (b3 - a3 * a_dot_b) / magnitude;\n }\n\n return out;\n}\n/**\r\n * Returns a string representation of a dual quatenion\r\n *\r\n * @param {quat2} a dual quaternion to represent as a string\r\n * @returns {String} string representation of the dual quat\r\n */\n\nexport function str(a) {\n return 'quat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ')';\n}\n/**\r\n * Returns whether or not the dual quaternions have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {quat2} a the first dual quaternion.\r\n * @param {quat2} b the second dual quaternion.\r\n * @returns {Boolean} true if the dual quaternions are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7];\n}\n/**\r\n * Returns whether or not the dual quaternions have approximately the same elements in the same position.\r\n *\r\n * @param {quat2} a the first dual quat.\r\n * @param {quat2} b the second dual quat.\r\n * @returns {Boolean} true if the dual quats are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5],\n a6 = a[6],\n a7 = a[7];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5],\n b6 = b[6],\n b7 = b[7];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7));\n}","import * as glMatrix from \"./common.js\";\n/**\r\n * 2 Dimensional Vector\r\n * @module vec2\r\n */\n\n/**\r\n * Creates a new, empty vec2\r\n *\r\n * @returns {vec2} a new 2D vector\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\r\n * Creates a new vec2 initialized with values from an existing vector\r\n *\r\n * @param {vec2} a vector to clone\r\n * @returns {vec2} a new 2D vector\r\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\r\n * Creates a new vec2 initialized with the given values\r\n *\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @returns {vec2} a new 2D vector\r\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\r\n * Copy the values from one vec2 to another\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the source vector\r\n * @returns {vec2} out\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\r\n * Set the components of a vec2 to the given values\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @returns {vec2} out\r\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\r\n * Adds two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\r\n * Subtracts vector b from vector a\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\r\n * Multiplies two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\r\n * Divides two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\r\n * Math.ceil the components of a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to ceil\r\n * @returns {vec2} out\r\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\r\n * Math.floor the components of a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to floor\r\n * @returns {vec2} out\r\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\r\n * Returns the minimum of two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\r\n * Returns the maximum of two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\r\n * Math.round the components of a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to round\r\n * @returns {vec2} out\r\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\r\n * Scales a vec2 by a scalar number\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the vector to scale\r\n * @param {Number} b amount to scale the vector by\r\n * @returns {vec2} out\r\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\r\n * Adds two vec2's after scaling the second operand by a scalar value\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @param {Number} scale the amount to scale b by before adding\r\n * @returns {vec2} out\r\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\r\n * Calculates the euclidian distance between two vec2's\r\n *\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {Number} distance between a and b\r\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.sqrt(x * x + y * y);\n}\n/**\r\n * Calculates the squared euclidian distance between two vec2's\r\n *\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {Number} squared distance between a and b\r\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\r\n * Calculates the length of a vec2\r\n *\r\n * @param {vec2} a vector to calculate length of\r\n * @returns {Number} length of a\r\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.sqrt(x * x + y * y);\n}\n/**\r\n * Calculates the squared length of a vec2\r\n *\r\n * @param {vec2} a vector to calculate squared length of\r\n * @returns {Number} squared length of a\r\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\r\n * Negates the components of a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to negate\r\n * @returns {vec2} out\r\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\r\n * Returns the inverse of the components of a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to invert\r\n * @returns {vec2} out\r\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\r\n * Normalize a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to normalize\r\n * @returns {vec2} out\r\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\r\n * Calculates the dot product of two vec2's\r\n *\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {Number} dot product of a and b\r\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\r\n * Computes the cross product of two vec2's\r\n * Note that the cross product must by definition produce a 3D vector\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\r\n * Performs a linear interpolation between two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {vec2} out\r\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\r\n * Generates a random vector with the given scale\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\r\n * @returns {vec2} out\r\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\r\n * Transforms the vec2 with a mat2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the vector to transform\r\n * @param {mat2} m matrix to transform with\r\n * @returns {vec2} out\r\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\r\n * Transforms the vec2 with a mat2d\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the vector to transform\r\n * @param {mat2d} m matrix to transform with\r\n * @returns {vec2} out\r\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\r\n * Transforms the vec2 with a mat3\r\n * 3rd vector component is implicitly '1'\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the vector to transform\r\n * @param {mat3} m matrix to transform with\r\n * @returns {vec2} out\r\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\r\n * Transforms the vec2 with a mat4\r\n * 3rd vector component is implicitly '0'\r\n * 4th vector component is implicitly '1'\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the vector to transform\r\n * @param {mat4} m matrix to transform with\r\n * @returns {vec2} out\r\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\r\n * Rotate a 2D vector\r\n * @param {vec2} out The receiving vec2\r\n * @param {vec2} a The vec2 point to rotate\r\n * @param {vec2} b The origin of the rotation\r\n * @param {Number} c The angle of rotation\r\n * @returns {vec2} out\r\n */\n\nexport function rotate(out, a, b, c) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(c),\n cosC = Math.cos(c); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\r\n * Get the angle between two 2D vectors\r\n * @param {vec2} a The first operand\r\n * @param {vec2} b The second operand\r\n * @returns {Number} The angle in radians\r\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1];\n var len1 = x1 * x1 + y1 * y1;\n\n if (len1 > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len1 = 1 / Math.sqrt(len1);\n }\n\n var len2 = x2 * x2 + y2 * y2;\n\n if (len2 > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len2 = 1 / Math.sqrt(len2);\n }\n\n var cosine = (x1 * x2 + y1 * y2) * len1 * len2;\n\n if (cosine > 1.0) {\n return 0;\n } else if (cosine < -1.0) {\n return Math.PI;\n } else {\n return Math.acos(cosine);\n }\n}\n/**\r\n * Set the components of a vec2 to zero\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @returns {vec2} out\r\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\r\n * Returns a string representation of a vector\r\n *\r\n * @param {vec2} a vector to represent as a string\r\n * @returns {String} string representation of the vector\r\n */\n\nexport function str(a) {\n return 'vec2(' + a[0] + ', ' + a[1] + ')';\n}\n/**\r\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\r\n *\r\n * @param {vec2} a The first vector.\r\n * @param {vec2} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\r\n * Returns whether or not the vectors have approximately the same elements in the same position.\r\n *\r\n * @param {vec2} a The first vector.\r\n * @param {vec2} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\r\n * Alias for {@link vec2.length}\r\n * @function\r\n */\n\nexport var len = length;\n/**\r\n * Alias for {@link vec2.subtract}\r\n * @function\r\n */\n\nexport var sub = subtract;\n/**\r\n * Alias for {@link vec2.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Alias for {@link vec2.divide}\r\n * @function\r\n */\n\nexport var div = divide;\n/**\r\n * Alias for {@link vec2.distance}\r\n * @function\r\n */\n\nexport var dist = distance;\n/**\r\n * Alias for {@link vec2.squaredDistance}\r\n * @function\r\n */\n\nexport var sqrDist = squaredDistance;\n/**\r\n * Alias for {@link vec2.squaredLength}\r\n * @function\r\n */\n\nexport var sqrLen = squaredLength;\n/**\r\n * Perform some operation over an array of vec2s.\r\n *\r\n * @param {Array} a the array of vectors to iterate over\r\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\r\n * @param {Number} offset Number of elements to skip at the beginning of the array\r\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\r\n * @param {Function} fn Function to call for each vector in the array\r\n * @param {Object} [arg] additional argument to pass to fn\r\n * @returns {Array} a\r\n * @function\r\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","export const ELEMENT_NOT_EXIST = (selector: string) => `Element with selector \"${selector}\" doesn't exist.`;\nexport const MUST_STRING_OR_ELEMENT = (received: any) => `Element should be provided in string or HTMLElement. Received: ${received}`;\n","import { mat4, vec3 } from 'gl-matrix';\nimport { ELEMENT_NOT_EXIST, MUST_STRING_OR_ELEMENT } from '../constants/error';\nimport { Matrix4x4, Offset } from '../types';\n\nexport const getElement = (el: string | HTMLElement, baseElement?: HTMLElement): HTMLElement => {\n if (typeof el === 'string') {\n const queryResult = baseElement\n ? baseElement.querySelector(el)\n : document.querySelector(el);\n if (!queryResult) {\n throw new Error(ELEMENT_NOT_EXIST(el));\n }\n return queryResult as HTMLElement;\n } else if (el.nodeName && el.nodeType === 1) {\n return el;\n } else {\n throw new Error(MUST_STRING_OR_ELEMENT(el));\n }\n};\n\nexport function applyCSS(element: HTMLElement, cssObj: { [keys: string]: string }): void {\n Object.keys(cssObj).forEach(property => {\n (element.style as any)[property] = cssObj[property];\n });\n}\n\nexport function getTransformMatrix(elStyle: CSSStyleDeclaration): mat4 {\n const trVal = elStyle.getPropertyValue('transform');\n const transformStr = /\\(((\\s|\\S)+)\\)/.exec(trVal);\n const matrixVal = transformStr\n ? transformStr[1].split(',').map(val => parseFloat(val)) as Matrix4x4\n : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] as Matrix4x4;\n if (matrixVal.length === 16 ) {\n return mat4.fromValues(...matrixVal);\n } else {\n // Convert 2d matrix(length 6) to 3d\n const matrix = mat4.create();\n mat4.identity(matrix);\n\n matrix[0] = matrixVal[0];\n matrix[1] = matrixVal[1];\n matrix[4] = matrixVal[2];\n matrix[5] = matrixVal[3];\n matrix[12] = matrixVal[4];\n matrix[13] = matrixVal[5];\n\n return matrix;\n }\n}\n\nexport function getOffsetFromParent(currentOffset: Offset, parentOffset: Offset): vec3 {\n const offsetLeft = currentOffset.left + (currentOffset.width - parentOffset.width) / 2;\n const offsetTop = currentOffset.top + (currentOffset.height - parentOffset.height) / 2;\n\n return vec3.fromValues(offsetLeft, offsetTop, 0);\n}\n\nexport function getRotateOffset(elStyle: CSSStyleDeclaration, currentOffset: Offset): vec3 {\n const axis = (elStyle.transformOrigin as string)\n .split(' ')\n .map(str => parseFloat(str.substring(0, str.length - 2)));\n const ax = axis[0] - currentOffset.width / 2;\n const ay = axis[1] - currentOffset.height / 2;\n\n return vec3.fromValues(ax, ay, 0);\n}\n\nexport function findIndex(iterable: T[], callback: (el: T) => boolean): number {\n for (let i = 0; i < iterable.length; i += 1) {\n const element = iterable[i];\n if (element && callback(element)) {\n return i;\n }\n }\n\n return -1;\n}\n\n// return [0, 1, ...., max - 1]\nexport function range(max: number): number[] {\n const counterArray: number[] = [];\n for (let i = 0; i < max; i += 1) {\n counterArray[i] = i;\n }\n return counterArray;\n}\n\nexport function clamp(val: number, min: number, max: number): number {\n return Math.max(Math.min(val, max), min);\n}\n\nexport function assign(target: object, ...srcs: object[]): object {\n srcs.forEach(source => {\n Object.keys(source).forEach(key => {\n const value = (source as any)[key];\n (target as any)[key] = value;\n });\n });\n\n return target;\n}\n","import { mat4, quat, vec3 } from 'gl-matrix';\nimport { clamp } from './helper';\n\nexport function degToRad(deg: number): number {\n return Math.PI * deg / 180;\n}\n\nexport function radToDeg(rad: number): number {\n return 180 * rad / Math.PI;\n}\n\n// From Three.js https://github.com/mrdoob/three.js/blob/dev/src/math/Euler.js\nexport function quatToEuler(q: quat): vec3 {\n const rotM = mat4.create();\n mat4.fromQuat(rotM, q);\n\n const m11 = rotM[0];\n const m12 = rotM[4];\n // const m13 = rotM[8];\n const m21 = rotM[1];\n const m22 = rotM[5];\n // const m23 = rotM[9];\n const m31 = rotM[2];\n const m32 = rotM[6];\n const m33 = rotM[10];\n\n const euler = vec3.create();\n\n // ZYX\n euler[1] = Math.asin(-clamp(m31, -1, 1));\n if (Math.abs(m31) < 0.99999) {\n euler[0] = Math.atan2(m32, m33);\n euler[2] = Math.atan2(m21, m11);\n } else {\n euler[0] = 0;\n euler[2] = Math.atan2(-m12, m22);\n }\n\n return euler.map(val => radToDeg(val)) as vec3;\n}\n","export const STYLE = {\n VIEWPORT: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n overflow: 'hidden',\n },\n CAMERA: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n 'will-change': 'transform',\n },\n WORLD: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n 'will-change': 'transform',\n },\n};\n\nexport const CLASS = {\n VIEWPORT: 'cc-viewport',\n CAMERA: 'cc-camera',\n WORLD: 'cc-world',\n};\n\nexport const OPTIONS = {\n position: [0, 0, 0],\n scale: [1, 1, 1],\n rotation: [0, 0, 0],\n perspective: 0,\n rotateOffset: 0,\n};\n\nexport const UPDATE_OPTIONS = {\n property: 'transform',\n timingFunction: 'ease-out',\n delay: '0ms',\n};\n","import { mat4, vec3, quat } from 'gl-matrix';\nimport { getElement, applyCSS, getTransformMatrix, findIndex, getOffsetFromParent, getRotateOffset, assign } from './utils/helper';\nimport { quatToEuler } from './utils/math';\nimport * as DEFAULT from './constants/default';\nimport { Offset, UpdateOption, ValueOf, Options } from './types';\n\nclass CSSCamera {\n private _element: HTMLElement;\n private _viewportEl: HTMLElement;\n private _cameraEl: HTMLElement;\n private _worldEl: HTMLElement;\n\n private _position: vec3;\n private _scale: vec3;\n private _rotation: vec3;\n private _perspective: number;\n private _rotateOffset: number;\n private _updateTimer: number;\n\n /**\n * Current version of CSSCamera.\n * @example\n * console.log(CSSCamera.VERSION); // ex) 1.0.0\n * @type {string}\n */\n static get VERSION() { return '#__VERSION__#'; }\n\n /**\n * The element provided in the constructor.\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.element === el); // true\n * @type {HTMLElement}\n */\n public get element() { return this._element; }\n\n /**\n * The reference of viewport DOM element.\n * @type {HTMLElement}\n */\n public get viewportEl() { return this._viewportEl; }\n\n /**\n * The reference of camera DOM element.\n * @type {HTMLElement}\n */\n public get cameraEl() { return this._cameraEl; }\n\n /**\n * The reference of world DOM element.\n * @type {HTMLElement}\n */\n public get worldEl() { return this._worldEl; }\n\n /**\n * The current position as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.position); // [0, 0, 0];\n * camera.position = [0, 0, 300];\n * console.log(camera.position); // [0, 0, 300];\n * @type {number[]}\n */\n public get position() { return [...this._position]; }\n\n /**\n * The current scale as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.scale); // [1, 1, 1];\n * camera.scale = [5, 1, 1];\n * console.log(camera.scale); // [5, 1, 1];\n * @type {number[]}\n */\n public get scale() { return [...this._scale]; }\n\n /**\n * The current Euler rotation angles in degree as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.rotation); // [0, 0, 0];\n * camera.rotation = [90, 0, 0];\n * console.log(camera.rotation); // [90, 0, 0];\n * @type {number[]}\n */\n public get rotation() { return [...this._rotation]; }\n\n /**\n * The current quaternion rotation as number array([x, y, z, w]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.quaternion); // [0, 0, 0, 1];\n * camera.rotation = [90, 0, 0];\n * console.log(camera.quaternion); // [0.7071067690849304, 0, 0, 0.7071067690849304];\n * camera.quaternion = [0, 0, 0, 1];\n * console.log(camera.rotation); // [0, -0, 0];\n * @type {number[]}\n */\n public get quaternion() {\n const r = this._rotation;\n const quaternion = quat.fromEuler(quat.create(), r[0], r[1], r[2]);\n\n return [...quaternion];\n }\n\n /**\n * The current perspective value that will be applied to viewport element.\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.perspective); // 300\n * @type {number}\n */\n public get perspective() { return this._perspective; }\n\n /**\n * The current rotate offset value that will be applied to camera element.\n * The camera will be as far away from the focal point as this value.\n * |![rot0](https://woodneck.github.io/css-camera/asset/rot0.gif)|![rot150](https://woodneck.github.io/css-camera/asset/rot150.gif)|\n * |:---:|:---:|\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * camera.rotateOffset = 100;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(400px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * @type {number}\n */\n public get rotateOffset() { return this._rotateOffset; }\n\n /**\n * CSS string can be applied to camera element based on current transform.\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * @type {string}\n */\n public get cameraCSS() {\n const perspective = this._perspective;\n const rotateOffset = this._rotateOffset;\n const rotation = this._rotation;\n const scale = this._scale;\n\n // Rotate in order of Z - Y - X\n // tslint:disable-next-line: max-line-length\n return `scale3d(${scale[0]}, ${scale[1]}, ${scale[2]}) translateZ(${perspective - rotateOffset}px) rotateX(${rotation[0]}deg) rotateY(${rotation[1]}deg) rotateZ(${rotation[2]}deg)`;\n }\n\n /**\n * CSS string can be applied to world element based on current transform.\n * ```\n * const camera = new CSSCamera(el);\n * console.log(camera.worldCSS); // \"translate3d(0px, 0px, 0px)\";\n * camera.translate(0, 0, 300);\n * console.log(camera.worldCSS); // \"translate3d(0px, 0px, -300px)\";\n * ```\n * @type {string}\n */\n public get worldCSS() {\n const position = this._position;\n\n return `translate3d(${-position[0]}px, ${-position[1]}px, ${-position[2]}px)`;\n }\n\n public set position(val: number[]) { this._position = vec3.fromValues(val[0], val[1], val[2]); }\n public set scale(val: number[]) { this._scale = vec3.fromValues(val[0], val[1], val[2]); }\n public set rotation(val: number[]) { this._rotation = vec3.fromValues(val[0], val[1], val[2]); }\n public set quaternion(val: number[]) { this._rotation = quatToEuler(quat.fromValues(val[0], val[1], val[2], val[3])); }\n public set perspective(val: number) { this._perspective = val; }\n public set rotateOffset(val: number) { this._rotateOffset = val; }\n\n /**\n * Create new CSSCamera with given element / selector.\n * @param - The element to apply camera. Can be HTMLElement or CSS selector.\n * @param {Partial} [options] Camera options\n * @param {number[]} [options.position=[0, 0, 0]] Initial position of the camera.\n * @param {number[]} [options.scale=[1, 1, 1]] Initial scale of the camera.\n * @param {number[]} [options.rotation=[0, 0, 0]] Initial Euler rotation angles(x, y, z) of the camera in degree.\n * @param {number} [options.perspective=0] Initial perspective of the camera.\n * @param {number} [options.rotateOffset=0] Initial rotate offset of the camera.\n * @example\n * const camera = new CSSCamera(\"#el\", {\n * position: [0, 0, 150], // Initial pos(x, y, z)\n * rotation: [90, 0, 0], // Initial rotation(x, y, z, in degree)\n * perspective: 300 // CSS \"perspective\" value to apply\n * });\n */\n constructor(el: string | HTMLElement, options: Partial = {}) {\n this._element = getElement(el);\n\n const op = assign(assign({}, DEFAULT.OPTIONS), options) as Options;\n\n this._position = vec3.fromValues(op.position[0], op.position[1], op.position[2]);\n this._scale = vec3.fromValues(op.scale[0], op.scale[1], op.scale[2]);\n this._rotation = vec3.fromValues(op.rotation[0], op.rotation[1], op.rotation[2]);\n this._perspective = op.perspective;\n this._rotateOffset = op.rotateOffset;\n this._updateTimer = -1;\n\n const element = this._element;\n const viewport = document.createElement('div');\n const camera = viewport.cloneNode() as HTMLElement;\n const world = viewport.cloneNode() as HTMLElement;\n\n viewport.className = DEFAULT.CLASS.VIEWPORT;\n camera.className = DEFAULT.CLASS.CAMERA;\n world.className = DEFAULT.CLASS.WORLD;\n\n applyCSS(viewport, DEFAULT.STYLE.VIEWPORT);\n applyCSS(camera, DEFAULT.STYLE.CAMERA);\n applyCSS(world, DEFAULT.STYLE.WORLD);\n\n camera.appendChild(world);\n viewport.appendChild(camera);\n\n this._viewportEl = viewport;\n this._cameraEl = camera;\n this._worldEl = world;\n\n // EL's PARENT -> VIEWPORT -> CAMERA -> WORLD -> EL\n element.parentElement!.insertBefore(viewport, element);\n world.appendChild(element);\n\n this.update(0);\n }\n\n /**\n * Focus a camera to given element.\n * After focus, element will be in front of camera with no rotation applied.\n * Also, it will have original width / height if neither [scale](#scale) nor [perspectiveOffset](#perspectiveOffset) is applied.\n * This method won't work if any of element's parent except camera element has scale applied.\n * @param - The element to focus. Can be HTMLElement or CSS selector.\n * @return {CSSCamera} The instance itself\n */\n public focus(el: string | HTMLElement): this {\n const element = getElement(el);\n const focusMatrix = this._getFocusMatrix(element);\n\n const rotation = quat.create();\n const translation = vec3.create();\n mat4.getRotation(rotation, focusMatrix);\n mat4.getTranslation(translation, focusMatrix);\n\n const eulerAngle = quatToEuler(rotation);\n\n vec3.negate(eulerAngle, eulerAngle);\n\n this._rotation = eulerAngle;\n this._position = translation;\n return this;\n }\n\n /**\n * Translate a camera in its local coordinate space.\n * For example, `camera.translateLocal(0, 0, -300)` will always move camera to direction where it's seeing.\n * @param - Amount of horizontal translation, in px.\n * @param - Amount of vertical translation, in px.\n * @param - Amount of translation in view direction, in px.\n * @return {CSSCamera} The instance itself\n */\n public translateLocal(x: number = 0, y: number = 0, z: number = 0): this {\n const position = this._position;\n const rotation = this._rotation;\n\n const transVec = vec3.fromValues(x, y, z);\n const rotQuat = quat.create();\n quat.fromEuler(rotQuat, -rotation[0], -rotation[1], -rotation[2]);\n vec3.transformQuat(transVec, transVec, rotQuat);\n\n vec3.add(position, position, transVec);\n return this;\n }\n\n /**\n * Translate a camera in world(absolute) coordinate space.\n * @param - Amount of translation in x axis, in px.\n * @param - Amount of translation in y axis, in px.\n * @param - Amount of translation in z axis, in px.\n * @return {CSSCamera} The instance itself\n */\n public translate(x: number = 0, y: number = 0, z: number = 0): this {\n vec3.add(this._position, this._position, vec3.fromValues(x, y, z));\n\n return this;\n }\n\n /**\n * Rotate a camera in world(absolute) coordinate space.\n * @param - Amount of rotation in x axis, in degree.\n * @param - Amount of rotation in y axis, in degree.\n * @param - Amount of rotation in z axis, in degree.\n * @return {CSSCamera} The instance itself\n */\n public rotate(x: number = 0, y: number = 0, z: number = 0): this {\n vec3.add(this._rotation, this._rotation, vec3.fromValues(x, y, z));\n\n return this;\n }\n\n /**\n * Updates a camera CSS with given duration.\n * Every other camera transforming properties / methods will be batched until this method is called.\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.cameraEl.style.transform); // ''\n *\n * camera.perspective = 300;\n * camera.translate(0, 0, 300);\n * camera.rotate(0, 90, 0);\n * console.log(camera.cameraEl.style.transform); // '', Not changed!\n *\n * await camera.update(1000); // Camera style is updated.\n * console.log(camera.cameraEl.style.transform); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(90deg) rotateZ(0deg)\n *\n * // When if you want to apply multiple properties\n * camera.update(1000, {\n * property: \"transform, background-color\",\n * timingFunction: \"ease-out, ease-out\", // As same with CSS, you should assign values to each property\n * delay: \"0ms, 100ms\"\n * });\n * @param - Transition duration in ms.\n * @param {Partial} [options] Transition options.\n * @param {string} [options.property=\"transform\"] CSS [transition-property](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-property) to apply.\n * @param {string} [options.timingFunction=\"ease-out\"] CSS [transition-timing-function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function) to apply.\n * @param {string} [options.delay=\"0ms\"] CSS [transition-delay](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-delay) to apply.\n * @return {Promise} A promise resolving instance itself\n */\n public async update(duration: number = 0, options: Partial = {}): Promise {\n applyCSS(this._viewportEl, { perspective: `${this.perspective}px` });\n applyCSS(this._cameraEl, { transform: this.cameraCSS });\n applyCSS(this._worldEl, { transform: this.worldCSS });\n\n const updateOptions = assign(assign({}, DEFAULT.UPDATE_OPTIONS), options) as UpdateOption;\n\n if (duration > 0) {\n if (this._updateTimer > 0) {\n window.clearTimeout(this._updateTimer);\n }\n\n const transitionDuration = `${duration}ms`;\n const updateOption = Object.keys(updateOptions).reduce((option: {[key: string]: ValueOf}, key) => {\n option[`transition${key.charAt(0).toUpperCase() + key.slice(1)}`] = updateOptions[key as keyof UpdateOption]!;\n return option;\n }, {});\n\n const finalOption = {\n transitionDuration,\n ...updateOption,\n };\n\n [this._viewportEl, this._cameraEl, this._worldEl].forEach(el => {\n applyCSS(el, finalOption);\n });\n }\n\n return new Promise(resolve => {\n // Make sure to use requestAnimationFrame even if duration is 0\n // To make sure DOM is updated, for successive update() calls.\n if (duration > 0) {\n this._updateTimer = window.setTimeout(() => {\n // Reset transition values\n [this._viewportEl, this._cameraEl, this._worldEl].forEach(el => {\n applyCSS(el, { transition: '' });\n });\n this._updateTimer = -1;\n resolve();\n }, duration);\n } else {\n requestAnimationFrame(() => {\n resolve();\n });\n }\n });\n }\n\n private _getFocusMatrix(element: HTMLElement): mat4 {\n const elements: HTMLElement[] = [];\n while (element) {\n elements.push(element);\n if (element === this._element) break;\n element = element.parentElement!;\n }\n\n // Order by shallow to deep\n elements.reverse();\n\n const elStyles = elements.map(el => window.getComputedStyle(el));\n\n // Find first element that transform-style is not preserve-3d\n // As all childs of that element is affected by its matrix\n const firstFlatIndex = findIndex(elStyles, style => style.transformStyle !== 'preserve-3d');\n if (firstFlatIndex > 0) { // el doesn't have to be preserve-3d'ed\n elStyles.splice(firstFlatIndex + 1);\n }\n\n let parentOffset: Offset = {\n left: 0,\n top: 0,\n width: this.viewportEl.offsetWidth,\n height: this.viewportEl.offsetHeight,\n };\n\n // Accumulated rotation\n const accRotation = quat.identity(quat.create());\n // Assume center of screen as (0, 0, 0)\n const centerPos = vec3.fromValues(0, 0, 0);\n\n elStyles.forEach((style, idx) => {\n const el = elements[idx];\n const currentOffset = {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n };\n const transformMat = getTransformMatrix(style);\n const offsetFromParent = getOffsetFromParent(currentOffset, parentOffset);\n vec3.transformQuat(offsetFromParent, offsetFromParent, accRotation);\n\n vec3.add(centerPos, centerPos, offsetFromParent);\n\n const rotateOffset = getRotateOffset(style, currentOffset);\n vec3.transformQuat(rotateOffset, rotateOffset, accRotation);\n\n const transformOrigin = vec3.clone(centerPos);\n vec3.add(transformOrigin, transformOrigin, rotateOffset);\n\n const centerFromOrigin = vec3.create();\n vec3.sub(centerFromOrigin, centerPos, transformOrigin);\n\n const invAccRotation = quat.invert(quat.create(), accRotation);\n vec3.transformQuat(centerFromOrigin, centerFromOrigin, invAccRotation);\n vec3.transformMat4(centerFromOrigin, centerFromOrigin, transformMat);\n vec3.transformQuat(centerFromOrigin, centerFromOrigin, accRotation);\n\n const newCenterPos = vec3.add(vec3.create(), transformOrigin, centerFromOrigin);\n const rotation = mat4.getRotation(quat.create(), transformMat);\n\n vec3.copy(centerPos, newCenterPos);\n quat.mul(accRotation, accRotation, rotation);\n parentOffset = currentOffset;\n });\n\n const perspective = vec3.fromValues(0, 0, this.perspective);\n vec3.transformQuat(perspective, perspective, accRotation);\n vec3.add(centerPos, centerPos, perspective);\n\n const matrix = mat4.create();\n mat4.fromRotationTranslation(matrix, accRotation, centerPos);\n\n return matrix;\n }\n}\n\nexport default CSSCamera;\n"],"names":["EPSILON","ARRAY_TYPE","Float32Array","Array","RANDOM","Math","random","degree","PI","create","out","glMatrix","clone","a","copy","fromValues","m00","m01","m02","m03","m10","m11","m12","m13","m20","m21","m22","m23","m30","m31","m32","m33","set","identity","transpose","a01","a02","a03","a12","a13","a23","invert","a00","a10","a11","a20","a21","a22","a30","a31","a32","a33","b00","b01","b02","b03","b04","b05","b06","b07","b08","b09","b10","b11","det","adjoint","determinant","multiply","b","b0","b1","b2","b3","translate","v","x","y","z","scale","rotate","rad","axis","len","sqrt","s","c","t","b12","b20","b21","b22","sin","cos","rotateX","rotateY","rotateZ","fromTranslation","fromScaling","fromRotation","fromXRotation","fromYRotation","fromZRotation","fromRotationTranslation","q","w","x2","y2","z2","xx","xy","xz","yy","yz","zz","wx","wy","wz","fromQuat2","translation","bx","by","bz","bw","ax","ay","az","aw","magnitude","getTranslation","mat","getScaling","getRotation","trace","S","fromRotationTranslationScale","sx","sy","sz","fromRotationTranslationScaleOrigin","o","ox","oy","oz","out0","out1","out2","out4","out5","out6","out8","out9","out10","fromQuat","yx","zx","zy","frustum","left","right","bottom","top","near","far","rl","tb","nf","perspective","fovy","aspect","f","tan","Infinity","perspectiveFromFieldOfView","fov","upTan","upDegrees","downTan","downDegrees","leftTan","leftDegrees","rightTan","rightDegrees","xScale","yScale","ortho","lr","bt","lookAt","eye","center","up","x0","x1","y0","y1","z0","z1","eyex","eyey","eyez","upx","upy","upz","centerx","centery","centerz","abs","targetTo","target","str","frob","pow","add","subtract","multiplyScalar","multiplyScalarAndAdd","exactEquals","equals","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","a14","a15","b4","b5","b6","b7","b8","b9","b13","b14","b15","max","mul","sub","length","negate","normalize","dot","cross","transformMat4","m","transformQuat","qx","qy","qz","qw","uvx","uvy","uvz","uuvx","uuvy","uuvz","w2","forEach","vec","stride","offset","count","fn","arg","i","l","min","squaredLength","lerp","setAxisAngle","getAxisAngle","out_axis","acos","calculateW","slerp","omega","cosom","sinom","scale0","scale1","u1","u2","u3","sqrt1MinusU1","sqrtU1","invDot","conjugate","fromMat3","fTrace","fRoot","j","k","fromEuler","halfToRad","cx","cy","cz","vec4","sqrLen","rotationTo","tmpvec3","vec3","xUnitVec3","yUnitVec3","sqlerp","temp1","temp2","d","setAxes","matr","mat3","view","quat","ELEMENT_NOT_EXIST","selector","MUST_STRING_OR_ELEMENT","received","getElement","el","baseElement","queryResult","querySelector","document","Error","nodeName","nodeType","applyCSS","element","cssObj","Object","keys","property","style","getTransformMatrix","elStyle","trVal","getPropertyValue","transformStr","exec","matrixVal","split","map","val","parseFloat","mat4","matrix","getOffsetFromParent","currentOffset","parentOffset","offsetLeft","width","offsetTop","height","getRotateOffset","transformOrigin","substring","findIndex","iterable","callback","clamp","assign","_i","srcs","source","key","value","radToDeg","quatToEuler","rotM","euler","asin","atan2","STYLE","VIEWPORT","overflow","CAMERA","WORLD","CLASS","OPTIONS","position","rotation","rotateOffset","UPDATE_OPTIONS","timingFunction","delay","options","_element","op","DEFAULT","_position","_scale","_rotation","_perspective","_rotateOffset","_updateTimer","viewport","createElement","camera","cloneNode","world","className","appendChild","_viewportEl","_cameraEl","_worldEl","parentElement","insertBefore","update","CSSCamera","r","quaternion","focusMatrix","_getFocusMatrix","eulerAngle","transVec","rotQuat","duration","Promise","transform","cameraCSS","worldCSS","updateOptions","window","clearTimeout","transitionDuration","updateOption","reduce","option","charAt","toUpperCase","slice","finalOption_1","resolve","_this","setTimeout","transition","requestAnimationFrame","elements","push","reverse","elStyles","getComputedStyle","firstFlatIndex","transformStyle","splice","viewportEl","offsetWidth","offsetHeight","accRotation","centerPos","idx","transformMat","offsetFromParent","centerFromOrigin","invAccRotation","newCenterPos"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA;;;;IAIA;AACA,IAAO,IAAIA,OAAO,GAAG,QAAd;AACP,IAAO,IAAIC,UAAU,GAAG,OAAOC,YAAP,KAAwB,WAAxB,GAAsCA,YAAtC,GAAqDC,KAAtE;AACP,IAAO,IAAIC,MAAM,GAAGC,IAAI,CAACC,MAAlB;AACP,IASA,IAAIC,MAAM,GAAGF,IAAI,CAACG,EAAL,GAAU,GAAvB;;IChBA;;;;;IAKA;;;;;;AAMA,IAAO,SAASC,MAAT,GAAkB;IACvB,MAAIC,GAAG,GAAG,IAAIC,UAAJ,CAAwB,CAAxB,CAAV;;IAEA,MAAIA,UAAA,IAAuBT,YAA3B,EAAyC;IACvCQ,IAAAA,GAAG,CAAC,CAAD,CAAH,GAAS,CAAT;IACAA,IAAAA,GAAG,CAAC,CAAD,CAAH,GAAS,CAAT;IACAA,IAAAA,GAAG,CAAC,CAAD,CAAH,GAAS,CAAT;IACAA,IAAAA,GAAG,CAAC,CAAD,CAAH,GAAS,CAAT;IACAA,IAAAA,GAAG,CAAC,CAAD,CAAH,GAAS,CAAT;IACAA,IAAAA,GAAG,CAAC,CAAD,CAAH,GAAS,CAAT;IACD;;IAEDA,EAAAA,GAAG,CAAC,CAAD,CAAH,GAAS,CAAT;IACAA,EAAAA,GAAG,CAAC,CAAD,CAAH,GAAS,CAAT;IACAA,EAAAA,GAAG,CAAC,CA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AAuDL,WAAvD;IAEA,UAAMO,YAAY,GAAG1J,KAAA,CAASA,QAAA,EAAT,EAAwBqD,eAAxB,EAAyCmG,gBAAzC,CAArB;IACA,UAAMzE,QAAQ,GAAGpC,WAAA,CAAiBhC,QAAA,EAAjB,EAAgC2I,YAAhC,CAAjB;IAEAtJ,MAAAA,MAAA,CAAUoJ,SAAV,EAAqBM,YAArB;IACA/I,MAAAA,KAAA,CAASwI,WAAT,EAAsBA,WAAtB,EAAmCpE,QAAnC;IACAhC,MAAAA,YAAY,GAAGD,aAAf;IACD,KAlCD;IAoCA,QAAMzL,WAAW,GAAG2I,YAAA,CAAgB,CAAhB,EAAmB,CAAnB,EAAsB,KAAK3I,WAA3B,CAApB;IACA2I,IAAAA,aAAA,CAAmB3I,WAAnB,EAAgCA,WAAhC,EAA6C8R,WAA7C;IACAnJ,IAAAA,KAAA,CAASoJ,SAAT,EAAoBA,SAApB,EAA+B/R,WAA/B;IAEA,QAAMuL,MAAM,GAAGD,QAAA,EAAf;IACAA,IAAAA,uBAAA,CAA6BC,MAA7B,EAAqCuG,WAArC,EAAkDC,SAAlD;IAEA,WAAOxG,MAAP;IACD,GA5EO;;IA6EV,kBAAA;IAAC,GA/bD;;;;;;;;"} \ No newline at end of file diff --git a/lib/css-camera.pkgd.min.js b/lib/css-camera.pkgd.min.js new file mode 100644 index 0000000..c2cb357 --- /dev/null +++ b/lib/css-camera.pkgd.min.js @@ -0,0 +1,10 @@ +/* +Copyright (c) 2019 WoodNeck +name: css-camera +license: MIT +author: WoodNeck +repository: git+https://github.com/WoodNeck/css-camera.git +version: 1.0.1 +*/ +!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t=t||self).CSSCamera=r()}(this,function(){"use strict";var s=function(){return(s=Object.assign||function(t){for(var r,n=1,e=arguments.length;ni[0]&&r[1]r[5]&&r[0]>r[10]?(e=2*Math.sqrt(1+r[0]-r[5]-r[10]),t[3]=(r[6]-r[9])/e,t[0]=.25*e,t[1]=(r[1]+r[4])/e,t[2]=(r[8]+r[2])/e):r[5]>r[10]?(e=2*Math.sqrt(1+r[5]-r[0]-r[10]),t[3]=(r[8]-r[2])/e,t[0]=(r[1]+r[4])/e,t[1]=.25*e,t[2]=(r[6]+r[9])/e):(e=2*Math.sqrt(1+r[10]-r[0]-r[5]),t[3]=(r[1]-r[4])/e,t[0]=(r[8]+r[2])/e,t[1]=(r[6]+r[9])/e,t[2]=.25*e),t}function h(t,r){var n=r[0],e=r[1],a=r[2],o=r[3],i=n+n,u=e+e,s=a+a,c=n*i,h=e*i,f=e*u,l=a*i,p=a*u,M=a*s,v=o*i,b=o*u,d=o*s;return t[0]=1-f-M,t[1]=h+d,t[2]=l-b,t[3]=0,t[4]=h-d,t[5]=1-c-M,t[6]=p+v,t[7]=0,t[8]=l+b,t[9]=p-v,t[10]=1-c-f,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function e(t,r,n){return t[0]=r[0]-n[0],t[1]=r[1]-n[1],t[2]=r[2]-n[2],t[3]=r[3]-n[3],t[4]=r[4]-n[4],t[5]=r[5]-n[5],t[6]=r[6]-n[6],t[7]=r[7]-n[7],t[8]=r[8]-n[8],t[9]=r[9]-n[9],t[10]=r[10]-n[10],t[11]=r[11]-n[11],t[12]=r[12]-n[12],t[13]=r[13]-n[13],t[14]=r[14]-n[14],t[15]=r[15]-n[15],t}var g={create:b,clone:function(t){var r=new d(16);return r[0]=t[0],r[1]=t[1],r[2]=t[2],r[3]=t[3],r[4]=t[4],r[5]=t[5],r[6]=t[6],r[7]=t[7],r[8]=t[8],r[9]=t[9],r[10]=t[10],r[11]=t[11],r[12]=t[12],r[13]=t[13],r[14]=t[14],r[15]=t[15],r},copy:function(t,r){return t[0]=r[0],t[1]=r[1],t[2]=r[2],t[3]=r[3],t[4]=r[4],t[5]=r[5],t[6]=r[6],t[7]=r[7],t[8]=r[8],t[9]=r[9],t[10]=r[10],t[11]=r[11],t[12]=r[12],t[13]=r[13],t[14]=r[14],t[15]=r[15],t},fromValues:m,set:function(t,r,n,e,a,o,i,u,s,c,h,f,l,p,M,v,b){return t[0]=r,t[1]=n,t[2]=e,t[3]=a,t[4]=o,t[5]=i,t[6]=u,t[7]=s,t[8]=c,t[9]=h,t[10]=f,t[11]=l,t[12]=p,t[13]=M,t[14]=v,t[15]=b,t},identity:E,transpose:function(t,r){if(t===r){var n=r[1],e=r[2],a=r[3],o=r[6],i=r[7],u=r[11];t[1]=r[4],t[2]=r[8],t[3]=r[12],t[4]=n,t[6]=r[9],t[7]=r[13],t[8]=e,t[9]=o,t[11]=r[14],t[12]=a,t[13]=i,t[14]=u}else t[0]=r[0],t[1]=r[4],t[2]=r[8],t[3]=r[12],t[4]=r[1],t[5]=r[5],t[6]=r[9],t[7]=r[13],t[8]=r[2],t[9]=r[6],t[10]=r[10],t[11]=r[14],t[12]=r[3],t[13]=r[7],t[14]=r[11],t[15]=r[15];return t},invert:function(t,r){var n=r[0],e=r[1],a=r[2],o=r[3],i=r[4],u=r[5],s=r[6],c=r[7],h=r[8],f=r[9],l=r[10],p=r[11],M=r[12],v=r[13],b=r[14],d=r[15],m=n*u-e*i,w=n*s-a*i,y=n*c-o*i,g=e*s-a*u,_=e*c-o*u,E=a*c-o*s,x=h*v-f*M,O=h*b-l*M,S=h*d-p*M,q=f*b-l*v,P=f*d-p*v,j=l*d-p*b,T=m*j-w*P+y*q+g*S-_*O+E*x;return T?(T=1/T,t[0]=(u*j-s*P+c*q)*T,t[1]=(a*P-e*j-o*q)*T,t[2]=(v*E-b*_+d*g)*T,t[3]=(l*_-f*E-p*g)*T,t[4]=(s*S-i*j-c*O)*T,t[5]=(n*j-a*S+o*O)*T,t[6]=(b*y-M*E-d*w)*T,t[7]=(h*E-l*y+p*w)*T,t[8]=(i*P-u*S+c*x)*T,t[9]=(e*S-n*P-o*x)*T,t[10]=(M*_-v*y+d*m)*T,t[11]=(f*y-h*_-p*m)*T,t[12]=(u*O-i*q-s*x)*T,t[13]=(n*q-e*O+a*x)*T,t[14]=(v*w-M*g-b*m)*T,t[15]=(h*g-f*w+l*m)*T,t):null},adjoint:function(t,r){var n=r[0],e=r[1],a=r[2],o=r[3],i=r[4],u=r[5],s=r[6],c=r[7],h=r[8],f=r[9],l=r[10],p=r[11],M=r[12],v=r[13],b=r[14],d=r[15];return t[0]=u*(l*d-p*b)-f*(s*d-c*b)+v*(s*p-c*l),t[1]=-(e*(l*d-p*b)-f*(a*d-o*b)+v*(a*p-o*l)),t[2]=e*(s*d-c*b)-u*(a*d-o*b)+v*(a*c-o*s),t[3]=-(e*(s*p-c*l)-u*(a*p-o*l)+f*(a*c-o*s)),t[4]=-(i*(l*d-p*b)-h*(s*d-c*b)+M*(s*p-c*l)),t[5]=n*(l*d-p*b)-h*(a*d-o*b)+M*(a*p-o*l),t[6]=-(n*(s*d-c*b)-i*(a*d-o*b)+M*(a*c-o*s)),t[7]=n*(s*p-c*l)-i*(a*p-o*l)+h*(a*c-o*s),t[8]=i*(f*d-p*v)-h*(u*d-c*v)+M*(u*p-c*f),t[9]=-(n*(f*d-p*v)-h*(e*d-o*v)+M*(e*p-o*f)),t[10]=n*(u*d-c*v)-i*(e*d-o*v)+M*(e*c-o*u),t[11]=-(n*(u*p-c*f)-i*(e*p-o*f)+h*(e*c-o*u)),t[12]=-(i*(f*b-l*v)-h*(u*b-s*v)+M*(u*l-s*f)),t[13]=n*(f*b-l*v)-h*(e*b-a*v)+M*(e*l-a*f),t[14]=-(n*(u*b-s*v)-i*(e*b-a*v)+M*(e*s-a*u)),t[15]=n*(u*l-s*f)-i*(e*l-a*f)+h*(e*s-a*u),t},determinant:function(t){var r=t[0],n=t[1],e=t[2],a=t[3],o=t[4],i=t[5],u=t[6],s=t[7],c=t[8],h=t[9],f=t[10],l=t[11],p=t[12],M=t[13],v=t[14],b=t[15];return(r*i-n*o)*(f*b-l*v)-(r*u-e*o)*(h*b-l*M)+(r*s-a*o)*(h*v-f*M)+(n*u-e*i)*(c*b-l*p)-(n*s-a*i)*(c*v-f*p)+(e*s-a*u)*(c*M-h*p)},multiply:r,translate:function(t,r,n){var e,a,o,i,u,s,c,h,f,l,p,M,v=n[0],b=n[1],d=n[2];return r===t?(t[12]=r[0]*v+r[4]*b+r[8]*d+r[12],t[13]=r[1]*v+r[5]*b+r[9]*d+r[13],t[14]=r[2]*v+r[6]*b+r[10]*d+r[14],t[15]=r[3]*v+r[7]*b+r[11]*d+r[15]):(e=r[0],a=r[1],o=r[2],i=r[3],u=r[4],s=r[5],c=r[6],h=r[7],f=r[8],l=r[9],p=r[10],M=r[11],t[0]=e,t[1]=a,t[2]=o,t[3]=i,t[4]=u,t[5]=s,t[6]=c,t[7]=h,t[8]=f,t[9]=l,t[10]=p,t[11]=M,t[12]=e*v+u*b+f*d+r[12],t[13]=a*v+s*b+l*d+r[13],t[14]=o*v+c*b+p*d+r[14],t[15]=i*v+h*b+M*d+r[15]),t},scale:function(t,r,n){var e=n[0],a=n[1],o=n[2];return t[0]=r[0]*e,t[1]=r[1]*e,t[2]=r[2]*e,t[3]=r[3]*e,t[4]=r[4]*a,t[5]=r[5]*a,t[6]=r[6]*a,t[7]=r[7]*a,t[8]=r[8]*o,t[9]=r[9]*o,t[10]=r[10]*o,t[11]=r[11]*o,t[12]=r[12],t[13]=r[13],t[14]=r[14],t[15]=r[15],t},rotate:function(t,r,n,e){var a,o,i,u,s,c,h,f,l,p,M,v,b,d,m,w,y,g,_,E,x,O,S,q,P=e[0],j=e[1],T=e[2],F=Math.sqrt(P*P+j*j+T*T);return Fr[0]&&(a=1),r[8]>r[3*a+a]&&(a=2);var o=(a+1)%3,i=(a+2)%3;n=Math.sqrt(r[3*a+a]-r[3*o+o]-r[3*i+i]+1),t[a]=.5*n,n=.5/n,t[3]=(r[3*o+i]-r[3*i+o])*n,t[o]=(r[3*o+a]+r[3*a+o])*n,t[i]=(r[3*i+a]+r[3*a+i])*n}return t}function F(t,r,n,e){var a=.5*Math.PI/180;r*=a,n*=a,e*=a;var o=Math.sin(r),i=Math.cos(r),u=Math.sin(n),s=Math.cos(n),c=Math.sin(e),h=Math.cos(e);return t[0]=o*s*h-i*u*c,t[1]=i*u*h+o*s*c,t[2]=i*s*c-o*u*h,t[3]=i*s*h+o*u*c,t}var A,C,k,I,N,D,V=function(t,r,n,e){var a=new d(4);return a[0]=t,a[1]=r,a[2]=n,a[3]=e,a},Z=l,H=function(t,r){var n=r[0],e=r[1],a=r[2],o=r[3],i=n*n+e*e+a*a+o*o;return 0Format: column-major, when typed out it looks like row-major
The matrices are being post multiplied.\r\n * @module mat4\r\n */\n\n/**\r\n * Creates a new identity mat4\r\n *\r\n * @returns {mat4} a new 4x4 matrix\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(16);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n }\n\n out[0] = 1;\n out[5] = 1;\n out[10] = 1;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a new mat4 initialized with values from an existing matrix\r\n *\r\n * @param {mat4} a matrix to clone\r\n * @returns {mat4} a new 4x4 matrix\r\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(16);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n}\n/**\r\n * Copy the values from one mat4 to another\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the source matrix\r\n * @returns {mat4} out\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n}\n/**\r\n * Create a new mat4 with the given values\r\n *\r\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\r\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\r\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\r\n * @param {Number} m03 Component in column 0, row 3 position (index 3)\r\n * @param {Number} m10 Component in column 1, row 0 position (index 4)\r\n * @param {Number} m11 Component in column 1, row 1 position (index 5)\r\n * @param {Number} m12 Component in column 1, row 2 position (index 6)\r\n * @param {Number} m13 Component in column 1, row 3 position (index 7)\r\n * @param {Number} m20 Component in column 2, row 0 position (index 8)\r\n * @param {Number} m21 Component in column 2, row 1 position (index 9)\r\n * @param {Number} m22 Component in column 2, row 2 position (index 10)\r\n * @param {Number} m23 Component in column 2, row 3 position (index 11)\r\n * @param {Number} m30 Component in column 3, row 0 position (index 12)\r\n * @param {Number} m31 Component in column 3, row 1 position (index 13)\r\n * @param {Number} m32 Component in column 3, row 2 position (index 14)\r\n * @param {Number} m33 Component in column 3, row 3 position (index 15)\r\n * @returns {mat4} A new mat4\r\n */\n\nexport function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {\n var out = new glMatrix.ARRAY_TYPE(16);\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m03;\n out[4] = m10;\n out[5] = m11;\n out[6] = m12;\n out[7] = m13;\n out[8] = m20;\n out[9] = m21;\n out[10] = m22;\n out[11] = m23;\n out[12] = m30;\n out[13] = m31;\n out[14] = m32;\n out[15] = m33;\n return out;\n}\n/**\r\n * Set the components of a mat4 to the given values\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\r\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\r\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\r\n * @param {Number} m03 Component in column 0, row 3 position (index 3)\r\n * @param {Number} m10 Component in column 1, row 0 position (index 4)\r\n * @param {Number} m11 Component in column 1, row 1 position (index 5)\r\n * @param {Number} m12 Component in column 1, row 2 position (index 6)\r\n * @param {Number} m13 Component in column 1, row 3 position (index 7)\r\n * @param {Number} m20 Component in column 2, row 0 position (index 8)\r\n * @param {Number} m21 Component in column 2, row 1 position (index 9)\r\n * @param {Number} m22 Component in column 2, row 2 position (index 10)\r\n * @param {Number} m23 Component in column 2, row 3 position (index 11)\r\n * @param {Number} m30 Component in column 3, row 0 position (index 12)\r\n * @param {Number} m31 Component in column 3, row 1 position (index 13)\r\n * @param {Number} m32 Component in column 3, row 2 position (index 14)\r\n * @param {Number} m33 Component in column 3, row 3 position (index 15)\r\n * @returns {mat4} out\r\n */\n\nexport function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m03;\n out[4] = m10;\n out[5] = m11;\n out[6] = m12;\n out[7] = m13;\n out[8] = m20;\n out[9] = m21;\n out[10] = m22;\n out[11] = m23;\n out[12] = m30;\n out[13] = m31;\n out[14] = m32;\n out[15] = m33;\n return out;\n}\n/**\r\n * Set a mat4 to the identity matrix\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @returns {mat4} out\r\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Transpose the values of a mat4\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the source matrix\r\n * @returns {mat4} out\r\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a12 = a[6],\n a13 = a[7];\n var a23 = a[11];\n out[1] = a[4];\n out[2] = a[8];\n out[3] = a[12];\n out[4] = a01;\n out[6] = a[9];\n out[7] = a[13];\n out[8] = a02;\n out[9] = a12;\n out[11] = a[14];\n out[12] = a03;\n out[13] = a13;\n out[14] = a23;\n } else {\n out[0] = a[0];\n out[1] = a[4];\n out[2] = a[8];\n out[3] = a[12];\n out[4] = a[1];\n out[5] = a[5];\n out[6] = a[9];\n out[7] = a[13];\n out[8] = a[2];\n out[9] = a[6];\n out[10] = a[10];\n out[11] = a[14];\n out[12] = a[3];\n out[13] = a[7];\n out[14] = a[11];\n out[15] = a[15];\n }\n\n return out;\n}\n/**\r\n * Inverts a mat4\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the source matrix\r\n * @returns {mat4} out\r\n */\n\nexport function invert(out, a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n var a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n var a30 = a[12],\n a31 = a[13],\n a32 = a[14],\n a33 = a[15];\n var b00 = a00 * a11 - a01 * a10;\n var b01 = a00 * a12 - a02 * a10;\n var b02 = a00 * a13 - a03 * a10;\n var b03 = a01 * a12 - a02 * a11;\n var b04 = a01 * a13 - a03 * a11;\n var b05 = a02 * a13 - a03 * a12;\n var b06 = a20 * a31 - a21 * a30;\n var b07 = a20 * a32 - a22 * a30;\n var b08 = a20 * a33 - a23 * a30;\n var b09 = a21 * a32 - a22 * a31;\n var b10 = a21 * a33 - a23 * a31;\n var b11 = a22 * a33 - a23 * a32; // Calculate the determinant\n\n var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;\n out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;\n out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;\n out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;\n out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;\n out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;\n out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;\n out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;\n out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;\n out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;\n out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;\n out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;\n out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;\n out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;\n out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;\n out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;\n return out;\n}\n/**\r\n * Calculates the adjugate of a mat4\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the source matrix\r\n * @returns {mat4} out\r\n */\n\nexport function adjoint(out, a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n var a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n var a30 = a[12],\n a31 = a[13],\n a32 = a[14],\n a33 = a[15];\n out[0] = a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22);\n out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));\n out[2] = a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12);\n out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));\n out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));\n out[5] = a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22);\n out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));\n out[7] = a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12);\n out[8] = a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21);\n out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));\n out[10] = a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11);\n out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));\n out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));\n out[13] = a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21);\n out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));\n out[15] = a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11);\n return out;\n}\n/**\r\n * Calculates the determinant of a mat4\r\n *\r\n * @param {mat4} a the source matrix\r\n * @returns {Number} determinant of a\r\n */\n\nexport function determinant(a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n var a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n var a30 = a[12],\n a31 = a[13],\n a32 = a[14],\n a33 = a[15];\n var b00 = a00 * a11 - a01 * a10;\n var b01 = a00 * a12 - a02 * a10;\n var b02 = a00 * a13 - a03 * a10;\n var b03 = a01 * a12 - a02 * a11;\n var b04 = a01 * a13 - a03 * a11;\n var b05 = a02 * a13 - a03 * a12;\n var b06 = a20 * a31 - a21 * a30;\n var b07 = a20 * a32 - a22 * a30;\n var b08 = a20 * a33 - a23 * a30;\n var b09 = a21 * a32 - a22 * a31;\n var b10 = a21 * a33 - a23 * a31;\n var b11 = a22 * a33 - a23 * a32; // Calculate the determinant\n\n return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n}\n/**\r\n * Multiplies two mat4s\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the first operand\r\n * @param {mat4} b the second operand\r\n * @returns {mat4} out\r\n */\n\nexport function multiply(out, a, b) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n var a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n var a30 = a[12],\n a31 = a[13],\n a32 = a[14],\n a33 = a[15]; // Cache only the current line of the second matrix\n\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;\n out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;\n out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;\n out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;\n b0 = b[4];\n b1 = b[5];\n b2 = b[6];\n b3 = b[7];\n out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;\n out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;\n out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;\n out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;\n b0 = b[8];\n b1 = b[9];\n b2 = b[10];\n b3 = b[11];\n out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;\n out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;\n out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;\n out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;\n b0 = b[12];\n b1 = b[13];\n b2 = b[14];\n b3 = b[15];\n out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;\n out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;\n out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;\n out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;\n return out;\n}\n/**\r\n * Translate a mat4 by the given vector\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to translate\r\n * @param {vec3} v vector to translate by\r\n * @returns {mat4} out\r\n */\n\nexport function translate(out, a, v) {\n var x = v[0],\n y = v[1],\n z = v[2];\n var a00, a01, a02, a03;\n var a10, a11, a12, a13;\n var a20, a21, a22, a23;\n\n if (a === out) {\n out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];\n out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];\n out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];\n out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];\n } else {\n a00 = a[0];\n a01 = a[1];\n a02 = a[2];\n a03 = a[3];\n a10 = a[4];\n a11 = a[5];\n a12 = a[6];\n a13 = a[7];\n a20 = a[8];\n a21 = a[9];\n a22 = a[10];\n a23 = a[11];\n out[0] = a00;\n out[1] = a01;\n out[2] = a02;\n out[3] = a03;\n out[4] = a10;\n out[5] = a11;\n out[6] = a12;\n out[7] = a13;\n out[8] = a20;\n out[9] = a21;\n out[10] = a22;\n out[11] = a23;\n out[12] = a00 * x + a10 * y + a20 * z + a[12];\n out[13] = a01 * x + a11 * y + a21 * z + a[13];\n out[14] = a02 * x + a12 * y + a22 * z + a[14];\n out[15] = a03 * x + a13 * y + a23 * z + a[15];\n }\n\n return out;\n}\n/**\r\n * Scales the mat4 by the dimensions in the given vec3 not using vectorization\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to scale\r\n * @param {vec3} v the vec3 to scale the matrix by\r\n * @returns {mat4} out\r\n **/\n\nexport function scale(out, a, v) {\n var x = v[0],\n y = v[1],\n z = v[2];\n out[0] = a[0] * x;\n out[1] = a[1] * x;\n out[2] = a[2] * x;\n out[3] = a[3] * x;\n out[4] = a[4] * y;\n out[5] = a[5] * y;\n out[6] = a[6] * y;\n out[7] = a[7] * y;\n out[8] = a[8] * z;\n out[9] = a[9] * z;\n out[10] = a[10] * z;\n out[11] = a[11] * z;\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n return out;\n}\n/**\r\n * Rotates a mat4 by the given angle around the given axis\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to rotate\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @param {vec3} axis the axis to rotate around\r\n * @returns {mat4} out\r\n */\n\nexport function rotate(out, a, rad, axis) {\n var x = axis[0],\n y = axis[1],\n z = axis[2];\n var len = Math.sqrt(x * x + y * y + z * z);\n var s, c, t;\n var a00, a01, a02, a03;\n var a10, a11, a12, a13;\n var a20, a21, a22, a23;\n var b00, b01, b02;\n var b10, b11, b12;\n var b20, b21, b22;\n\n if (len < glMatrix.EPSILON) {\n return null;\n }\n\n len = 1 / len;\n x *= len;\n y *= len;\n z *= len;\n s = Math.sin(rad);\n c = Math.cos(rad);\n t = 1 - c;\n a00 = a[0];\n a01 = a[1];\n a02 = a[2];\n a03 = a[3];\n a10 = a[4];\n a11 = a[5];\n a12 = a[6];\n a13 = a[7];\n a20 = a[8];\n a21 = a[9];\n a22 = a[10];\n a23 = a[11]; // Construct the elements of the rotation matrix\n\n b00 = x * x * t + c;\n b01 = y * x * t + z * s;\n b02 = z * x * t - y * s;\n b10 = x * y * t - z * s;\n b11 = y * y * t + c;\n b12 = z * y * t + x * s;\n b20 = x * z * t + y * s;\n b21 = y * z * t - x * s;\n b22 = z * z * t + c; // Perform rotation-specific matrix multiplication\n\n out[0] = a00 * b00 + a10 * b01 + a20 * b02;\n out[1] = a01 * b00 + a11 * b01 + a21 * b02;\n out[2] = a02 * b00 + a12 * b01 + a22 * b02;\n out[3] = a03 * b00 + a13 * b01 + a23 * b02;\n out[4] = a00 * b10 + a10 * b11 + a20 * b12;\n out[5] = a01 * b10 + a11 * b11 + a21 * b12;\n out[6] = a02 * b10 + a12 * b11 + a22 * b12;\n out[7] = a03 * b10 + a13 * b11 + a23 * b12;\n out[8] = a00 * b20 + a10 * b21 + a20 * b22;\n out[9] = a01 * b20 + a11 * b21 + a21 * b22;\n out[10] = a02 * b20 + a12 * b21 + a22 * b22;\n out[11] = a03 * b20 + a13 * b21 + a23 * b22;\n\n if (a !== out) {\n // If the source and destination differ, copy the unchanged last row\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n }\n\n return out;\n}\n/**\r\n * Rotates a matrix by the given angle around the X axis\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to rotate\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function rotateX(out, a, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n var a10 = a[4];\n var a11 = a[5];\n var a12 = a[6];\n var a13 = a[7];\n var a20 = a[8];\n var a21 = a[9];\n var a22 = a[10];\n var a23 = a[11];\n\n if (a !== out) {\n // If the source and destination differ, copy the unchanged rows\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n } // Perform axis-specific matrix multiplication\n\n\n out[4] = a10 * c + a20 * s;\n out[5] = a11 * c + a21 * s;\n out[6] = a12 * c + a22 * s;\n out[7] = a13 * c + a23 * s;\n out[8] = a20 * c - a10 * s;\n out[9] = a21 * c - a11 * s;\n out[10] = a22 * c - a12 * s;\n out[11] = a23 * c - a13 * s;\n return out;\n}\n/**\r\n * Rotates a matrix by the given angle around the Y axis\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to rotate\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function rotateY(out, a, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n var a00 = a[0];\n var a01 = a[1];\n var a02 = a[2];\n var a03 = a[3];\n var a20 = a[8];\n var a21 = a[9];\n var a22 = a[10];\n var a23 = a[11];\n\n if (a !== out) {\n // If the source and destination differ, copy the unchanged rows\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n } // Perform axis-specific matrix multiplication\n\n\n out[0] = a00 * c - a20 * s;\n out[1] = a01 * c - a21 * s;\n out[2] = a02 * c - a22 * s;\n out[3] = a03 * c - a23 * s;\n out[8] = a00 * s + a20 * c;\n out[9] = a01 * s + a21 * c;\n out[10] = a02 * s + a22 * c;\n out[11] = a03 * s + a23 * c;\n return out;\n}\n/**\r\n * Rotates a matrix by the given angle around the Z axis\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to rotate\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function rotateZ(out, a, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad);\n var a00 = a[0];\n var a01 = a[1];\n var a02 = a[2];\n var a03 = a[3];\n var a10 = a[4];\n var a11 = a[5];\n var a12 = a[6];\n var a13 = a[7];\n\n if (a !== out) {\n // If the source and destination differ, copy the unchanged last row\n out[8] = a[8];\n out[9] = a[9];\n out[10] = a[10];\n out[11] = a[11];\n out[12] = a[12];\n out[13] = a[13];\n out[14] = a[14];\n out[15] = a[15];\n } // Perform axis-specific matrix multiplication\n\n\n out[0] = a00 * c + a10 * s;\n out[1] = a01 * c + a11 * s;\n out[2] = a02 * c + a12 * s;\n out[3] = a03 * c + a13 * s;\n out[4] = a10 * c - a00 * s;\n out[5] = a11 * c - a01 * s;\n out[6] = a12 * c - a02 * s;\n out[7] = a13 * c - a03 * s;\n return out;\n}\n/**\r\n * Creates a matrix from a vector translation\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.translate(dest, dest, vec);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {vec3} v Translation vector\r\n * @returns {mat4} out\r\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a vector scaling\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.scale(dest, dest, vec);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {vec3} v Scaling vector\r\n * @returns {mat4} out\r\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = v[1];\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = v[2];\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a given angle around a given axis\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.rotate(dest, dest, rad, axis);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @param {vec3} axis the axis to rotate around\r\n * @returns {mat4} out\r\n */\n\nexport function fromRotation(out, rad, axis) {\n var x = axis[0],\n y = axis[1],\n z = axis[2];\n var len = Math.sqrt(x * x + y * y + z * z);\n var s, c, t;\n\n if (len < glMatrix.EPSILON) {\n return null;\n }\n\n len = 1 / len;\n x *= len;\n y *= len;\n z *= len;\n s = Math.sin(rad);\n c = Math.cos(rad);\n t = 1 - c; // Perform rotation-specific matrix multiplication\n\n out[0] = x * x * t + c;\n out[1] = y * x * t + z * s;\n out[2] = z * x * t - y * s;\n out[3] = 0;\n out[4] = x * y * t - z * s;\n out[5] = y * y * t + c;\n out[6] = z * y * t + x * s;\n out[7] = 0;\n out[8] = x * z * t + y * s;\n out[9] = y * z * t - x * s;\n out[10] = z * z * t + c;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from the given angle around the X axis\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.rotateX(dest, dest, rad);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function fromXRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad); // Perform axis-specific matrix multiplication\n\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = c;\n out[6] = s;\n out[7] = 0;\n out[8] = 0;\n out[9] = -s;\n out[10] = c;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from the given angle around the Y axis\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.rotateY(dest, dest, rad);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function fromYRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad); // Perform axis-specific matrix multiplication\n\n out[0] = c;\n out[1] = 0;\n out[2] = -s;\n out[3] = 0;\n out[4] = 0;\n out[5] = 1;\n out[6] = 0;\n out[7] = 0;\n out[8] = s;\n out[9] = 0;\n out[10] = c;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from the given angle around the Z axis\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.rotateZ(dest, dest, rad);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat4} out\r\n */\n\nexport function fromZRotation(out, rad) {\n var s = Math.sin(rad);\n var c = Math.cos(rad); // Perform axis-specific matrix multiplication\n\n out[0] = c;\n out[1] = s;\n out[2] = 0;\n out[3] = 0;\n out[4] = -s;\n out[5] = c;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 1;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a quaternion rotation and vector translation\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.translate(dest, vec);\r\n * let quatMat = mat4.create();\r\n * quat4.toMat4(quat, quatMat);\r\n * mat4.multiply(dest, quatMat);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {quat4} q Rotation quaternion\r\n * @param {vec3} v Translation vector\r\n * @returns {mat4} out\r\n */\n\nexport function fromRotationTranslation(out, q, v) {\n // Quaternion math\n var x = q[0],\n y = q[1],\n z = q[2],\n w = q[3];\n var x2 = x + x;\n var y2 = y + y;\n var z2 = z + z;\n var xx = x * x2;\n var xy = x * y2;\n var xz = x * z2;\n var yy = y * y2;\n var yz = y * z2;\n var zz = z * z2;\n var wx = w * x2;\n var wy = w * y2;\n var wz = w * z2;\n out[0] = 1 - (yy + zz);\n out[1] = xy + wz;\n out[2] = xz - wy;\n out[3] = 0;\n out[4] = xy - wz;\n out[5] = 1 - (xx + zz);\n out[6] = yz + wx;\n out[7] = 0;\n out[8] = xz + wy;\n out[9] = yz - wx;\n out[10] = 1 - (xx + yy);\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a new mat4 from a dual quat.\r\n *\r\n * @param {mat4} out Matrix\r\n * @param {quat2} a Dual Quaternion\r\n * @returns {mat4} mat4 receiving operation result\r\n */\n\nexport function fromQuat2(out, a) {\n var translation = new glMatrix.ARRAY_TYPE(3);\n var bx = -a[0],\n by = -a[1],\n bz = -a[2],\n bw = a[3],\n ax = a[4],\n ay = a[5],\n az = a[6],\n aw = a[7];\n var magnitude = bx * bx + by * by + bz * bz + bw * bw; //Only scale if it makes sense\n\n if (magnitude > 0) {\n translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude;\n translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude;\n translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude;\n } else {\n translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;\n translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;\n translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;\n }\n\n fromRotationTranslation(out, a, translation);\n return out;\n}\n/**\r\n * Returns the translation vector component of a transformation\r\n * matrix. If a matrix is built with fromRotationTranslation,\r\n * the returned vector will be the same as the translation vector\r\n * originally supplied.\r\n * @param {vec3} out Vector to receive translation component\r\n * @param {mat4} mat Matrix to be decomposed (input)\r\n * @return {vec3} out\r\n */\n\nexport function getTranslation(out, mat) {\n out[0] = mat[12];\n out[1] = mat[13];\n out[2] = mat[14];\n return out;\n}\n/**\r\n * Returns the scaling factor component of a transformation\r\n * matrix. If a matrix is built with fromRotationTranslationScale\r\n * with a normalized Quaternion paramter, the returned vector will be\r\n * the same as the scaling vector\r\n * originally supplied.\r\n * @param {vec3} out Vector to receive scaling factor component\r\n * @param {mat4} mat Matrix to be decomposed (input)\r\n * @return {vec3} out\r\n */\n\nexport function getScaling(out, mat) {\n var m11 = mat[0];\n var m12 = mat[1];\n var m13 = mat[2];\n var m21 = mat[4];\n var m22 = mat[5];\n var m23 = mat[6];\n var m31 = mat[8];\n var m32 = mat[9];\n var m33 = mat[10];\n out[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);\n out[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);\n out[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);\n return out;\n}\n/**\r\n * Returns a quaternion representing the rotational component\r\n * of a transformation matrix. If a matrix is built with\r\n * fromRotationTranslation, the returned quaternion will be the\r\n * same as the quaternion originally supplied.\r\n * @param {quat} out Quaternion to receive the rotation component\r\n * @param {mat4} mat Matrix to be decomposed (input)\r\n * @return {quat} out\r\n */\n\nexport function getRotation(out, mat) {\n // Algorithm taken from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm\n var trace = mat[0] + mat[5] + mat[10];\n var S = 0;\n\n if (trace > 0) {\n S = Math.sqrt(trace + 1.0) * 2;\n out[3] = 0.25 * S;\n out[0] = (mat[6] - mat[9]) / S;\n out[1] = (mat[8] - mat[2]) / S;\n out[2] = (mat[1] - mat[4]) / S;\n } else if (mat[0] > mat[5] && mat[0] > mat[10]) {\n S = Math.sqrt(1.0 + mat[0] - mat[5] - mat[10]) * 2;\n out[3] = (mat[6] - mat[9]) / S;\n out[0] = 0.25 * S;\n out[1] = (mat[1] + mat[4]) / S;\n out[2] = (mat[8] + mat[2]) / S;\n } else if (mat[5] > mat[10]) {\n S = Math.sqrt(1.0 + mat[5] - mat[0] - mat[10]) * 2;\n out[3] = (mat[8] - mat[2]) / S;\n out[0] = (mat[1] + mat[4]) / S;\n out[1] = 0.25 * S;\n out[2] = (mat[6] + mat[9]) / S;\n } else {\n S = Math.sqrt(1.0 + mat[10] - mat[0] - mat[5]) * 2;\n out[3] = (mat[1] - mat[4]) / S;\n out[0] = (mat[8] + mat[2]) / S;\n out[1] = (mat[6] + mat[9]) / S;\n out[2] = 0.25 * S;\n }\n\n return out;\n}\n/**\r\n * Creates a matrix from a quaternion rotation, vector translation and vector scale\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.translate(dest, vec);\r\n * let quatMat = mat4.create();\r\n * quat4.toMat4(quat, quatMat);\r\n * mat4.multiply(dest, quatMat);\r\n * mat4.scale(dest, scale)\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {quat4} q Rotation quaternion\r\n * @param {vec3} v Translation vector\r\n * @param {vec3} s Scaling vector\r\n * @returns {mat4} out\r\n */\n\nexport function fromRotationTranslationScale(out, q, v, s) {\n // Quaternion math\n var x = q[0],\n y = q[1],\n z = q[2],\n w = q[3];\n var x2 = x + x;\n var y2 = y + y;\n var z2 = z + z;\n var xx = x * x2;\n var xy = x * y2;\n var xz = x * z2;\n var yy = y * y2;\n var yz = y * z2;\n var zz = z * z2;\n var wx = w * x2;\n var wy = w * y2;\n var wz = w * z2;\n var sx = s[0];\n var sy = s[1];\n var sz = s[2];\n out[0] = (1 - (yy + zz)) * sx;\n out[1] = (xy + wz) * sx;\n out[2] = (xz - wy) * sx;\n out[3] = 0;\n out[4] = (xy - wz) * sy;\n out[5] = (1 - (xx + zz)) * sy;\n out[6] = (yz + wx) * sy;\n out[7] = 0;\n out[8] = (xz + wy) * sz;\n out[9] = (yz - wx) * sz;\n out[10] = (1 - (xx + yy)) * sz;\n out[11] = 0;\n out[12] = v[0];\n out[13] = v[1];\n out[14] = v[2];\n out[15] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat4.identity(dest);\r\n * mat4.translate(dest, vec);\r\n * mat4.translate(dest, origin);\r\n * let quatMat = mat4.create();\r\n * quat4.toMat4(quat, quatMat);\r\n * mat4.multiply(dest, quatMat);\r\n * mat4.scale(dest, scale)\r\n * mat4.translate(dest, negativeOrigin);\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {quat4} q Rotation quaternion\r\n * @param {vec3} v Translation vector\r\n * @param {vec3} s Scaling vector\r\n * @param {vec3} o The origin vector around which to scale and rotate\r\n * @returns {mat4} out\r\n */\n\nexport function fromRotationTranslationScaleOrigin(out, q, v, s, o) {\n // Quaternion math\n var x = q[0],\n y = q[1],\n z = q[2],\n w = q[3];\n var x2 = x + x;\n var y2 = y + y;\n var z2 = z + z;\n var xx = x * x2;\n var xy = x * y2;\n var xz = x * z2;\n var yy = y * y2;\n var yz = y * z2;\n var zz = z * z2;\n var wx = w * x2;\n var wy = w * y2;\n var wz = w * z2;\n var sx = s[0];\n var sy = s[1];\n var sz = s[2];\n var ox = o[0];\n var oy = o[1];\n var oz = o[2];\n var out0 = (1 - (yy + zz)) * sx;\n var out1 = (xy + wz) * sx;\n var out2 = (xz - wy) * sx;\n var out4 = (xy - wz) * sy;\n var out5 = (1 - (xx + zz)) * sy;\n var out6 = (yz + wx) * sy;\n var out8 = (xz + wy) * sz;\n var out9 = (yz - wx) * sz;\n var out10 = (1 - (xx + yy)) * sz;\n out[0] = out0;\n out[1] = out1;\n out[2] = out2;\n out[3] = 0;\n out[4] = out4;\n out[5] = out5;\n out[6] = out6;\n out[7] = 0;\n out[8] = out8;\n out[9] = out9;\n out[10] = out10;\n out[11] = 0;\n out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);\n out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);\n out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);\n out[15] = 1;\n return out;\n}\n/**\r\n * Calculates a 4x4 matrix from the given quaternion\r\n *\r\n * @param {mat4} out mat4 receiving operation result\r\n * @param {quat} q Quaternion to create matrix from\r\n *\r\n * @returns {mat4} out\r\n */\n\nexport function fromQuat(out, q) {\n var x = q[0],\n y = q[1],\n z = q[2],\n w = q[3];\n var x2 = x + x;\n var y2 = y + y;\n var z2 = z + z;\n var xx = x * x2;\n var yx = y * x2;\n var yy = y * y2;\n var zx = z * x2;\n var zy = z * y2;\n var zz = z * z2;\n var wx = w * x2;\n var wy = w * y2;\n var wz = w * z2;\n out[0] = 1 - yy - zz;\n out[1] = yx + wz;\n out[2] = zx - wy;\n out[3] = 0;\n out[4] = yx - wz;\n out[5] = 1 - xx - zz;\n out[6] = zy + wx;\n out[7] = 0;\n out[8] = zx + wy;\n out[9] = zy - wx;\n out[10] = 1 - xx - yy;\n out[11] = 0;\n out[12] = 0;\n out[13] = 0;\n out[14] = 0;\n out[15] = 1;\n return out;\n}\n/**\r\n * Generates a frustum matrix with the given bounds\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {Number} left Left bound of the frustum\r\n * @param {Number} right Right bound of the frustum\r\n * @param {Number} bottom Bottom bound of the frustum\r\n * @param {Number} top Top bound of the frustum\r\n * @param {Number} near Near bound of the frustum\r\n * @param {Number} far Far bound of the frustum\r\n * @returns {mat4} out\r\n */\n\nexport function frustum(out, left, right, bottom, top, near, far) {\n var rl = 1 / (right - left);\n var tb = 1 / (top - bottom);\n var nf = 1 / (near - far);\n out[0] = near * 2 * rl;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = near * 2 * tb;\n out[6] = 0;\n out[7] = 0;\n out[8] = (right + left) * rl;\n out[9] = (top + bottom) * tb;\n out[10] = (far + near) * nf;\n out[11] = -1;\n out[12] = 0;\n out[13] = 0;\n out[14] = far * near * 2 * nf;\n out[15] = 0;\n return out;\n}\n/**\r\n * Generates a perspective projection matrix with the given bounds.\r\n * Passing null/undefined/no value for far will generate infinite projection matrix.\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {number} fovy Vertical field of view in radians\r\n * @param {number} aspect Aspect ratio. typically viewport width/height\r\n * @param {number} near Near bound of the frustum\r\n * @param {number} far Far bound of the frustum, can be null or Infinity\r\n * @returns {mat4} out\r\n */\n\nexport function perspective(out, fovy, aspect, near, far) {\n var f = 1.0 / Math.tan(fovy / 2),\n nf;\n out[0] = f / aspect;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = f;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[11] = -1;\n out[12] = 0;\n out[13] = 0;\n out[15] = 0;\n\n if (far != null && far !== Infinity) {\n nf = 1 / (near - far);\n out[10] = (far + near) * nf;\n out[14] = 2 * far * near * nf;\n } else {\n out[10] = -1;\n out[14] = -2 * near;\n }\n\n return out;\n}\n/**\r\n * Generates a perspective projection matrix with the given field of view.\r\n * This is primarily useful for generating projection matrices to be used\r\n * with the still experiemental WebVR API.\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees\r\n * @param {number} near Near bound of the frustum\r\n * @param {number} far Far bound of the frustum\r\n * @returns {mat4} out\r\n */\n\nexport function perspectiveFromFieldOfView(out, fov, near, far) {\n var upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);\n var downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);\n var leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);\n var rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);\n var xScale = 2.0 / (leftTan + rightTan);\n var yScale = 2.0 / (upTan + downTan);\n out[0] = xScale;\n out[1] = 0.0;\n out[2] = 0.0;\n out[3] = 0.0;\n out[4] = 0.0;\n out[5] = yScale;\n out[6] = 0.0;\n out[7] = 0.0;\n out[8] = -((leftTan - rightTan) * xScale * 0.5);\n out[9] = (upTan - downTan) * yScale * 0.5;\n out[10] = far / (near - far);\n out[11] = -1.0;\n out[12] = 0.0;\n out[13] = 0.0;\n out[14] = far * near / (near - far);\n out[15] = 0.0;\n return out;\n}\n/**\r\n * Generates a orthogonal projection matrix with the given bounds\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {number} left Left bound of the frustum\r\n * @param {number} right Right bound of the frustum\r\n * @param {number} bottom Bottom bound of the frustum\r\n * @param {number} top Top bound of the frustum\r\n * @param {number} near Near bound of the frustum\r\n * @param {number} far Far bound of the frustum\r\n * @returns {mat4} out\r\n */\n\nexport function ortho(out, left, right, bottom, top, near, far) {\n var lr = 1 / (left - right);\n var bt = 1 / (bottom - top);\n var nf = 1 / (near - far);\n out[0] = -2 * lr;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 0;\n out[5] = -2 * bt;\n out[6] = 0;\n out[7] = 0;\n out[8] = 0;\n out[9] = 0;\n out[10] = 2 * nf;\n out[11] = 0;\n out[12] = (left + right) * lr;\n out[13] = (top + bottom) * bt;\n out[14] = (far + near) * nf;\n out[15] = 1;\n return out;\n}\n/**\r\n * Generates a look-at matrix with the given eye position, focal point, and up axis.\r\n * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {vec3} eye Position of the viewer\r\n * @param {vec3} center Point the viewer is looking at\r\n * @param {vec3} up vec3 pointing up\r\n * @returns {mat4} out\r\n */\n\nexport function lookAt(out, eye, center, up) {\n var x0, x1, x2, y0, y1, y2, z0, z1, z2, len;\n var eyex = eye[0];\n var eyey = eye[1];\n var eyez = eye[2];\n var upx = up[0];\n var upy = up[1];\n var upz = up[2];\n var centerx = center[0];\n var centery = center[1];\n var centerz = center[2];\n\n if (Math.abs(eyex - centerx) < glMatrix.EPSILON && Math.abs(eyey - centery) < glMatrix.EPSILON && Math.abs(eyez - centerz) < glMatrix.EPSILON) {\n return identity(out);\n }\n\n z0 = eyex - centerx;\n z1 = eyey - centery;\n z2 = eyez - centerz;\n len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);\n z0 *= len;\n z1 *= len;\n z2 *= len;\n x0 = upy * z2 - upz * z1;\n x1 = upz * z0 - upx * z2;\n x2 = upx * z1 - upy * z0;\n len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);\n\n if (!len) {\n x0 = 0;\n x1 = 0;\n x2 = 0;\n } else {\n len = 1 / len;\n x0 *= len;\n x1 *= len;\n x2 *= len;\n }\n\n y0 = z1 * x2 - z2 * x1;\n y1 = z2 * x0 - z0 * x2;\n y2 = z0 * x1 - z1 * x0;\n len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);\n\n if (!len) {\n y0 = 0;\n y1 = 0;\n y2 = 0;\n } else {\n len = 1 / len;\n y0 *= len;\n y1 *= len;\n y2 *= len;\n }\n\n out[0] = x0;\n out[1] = y0;\n out[2] = z0;\n out[3] = 0;\n out[4] = x1;\n out[5] = y1;\n out[6] = z1;\n out[7] = 0;\n out[8] = x2;\n out[9] = y2;\n out[10] = z2;\n out[11] = 0;\n out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);\n out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);\n out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);\n out[15] = 1;\n return out;\n}\n/**\r\n * Generates a matrix that makes something look at something else.\r\n *\r\n * @param {mat4} out mat4 frustum matrix will be written into\r\n * @param {vec3} eye Position of the viewer\r\n * @param {vec3} center Point the viewer is looking at\r\n * @param {vec3} up vec3 pointing up\r\n * @returns {mat4} out\r\n */\n\nexport function targetTo(out, eye, target, up) {\n var eyex = eye[0],\n eyey = eye[1],\n eyez = eye[2],\n upx = up[0],\n upy = up[1],\n upz = up[2];\n var z0 = eyex - target[0],\n z1 = eyey - target[1],\n z2 = eyez - target[2];\n var len = z0 * z0 + z1 * z1 + z2 * z2;\n\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n z0 *= len;\n z1 *= len;\n z2 *= len;\n }\n\n var x0 = upy * z2 - upz * z1,\n x1 = upz * z0 - upx * z2,\n x2 = upx * z1 - upy * z0;\n len = x0 * x0 + x1 * x1 + x2 * x2;\n\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n x0 *= len;\n x1 *= len;\n x2 *= len;\n }\n\n out[0] = x0;\n out[1] = x1;\n out[2] = x2;\n out[3] = 0;\n out[4] = z1 * x2 - z2 * x1;\n out[5] = z2 * x0 - z0 * x2;\n out[6] = z0 * x1 - z1 * x0;\n out[7] = 0;\n out[8] = z0;\n out[9] = z1;\n out[10] = z2;\n out[11] = 0;\n out[12] = eyex;\n out[13] = eyey;\n out[14] = eyez;\n out[15] = 1;\n return out;\n}\n;\n/**\r\n * Returns a string representation of a mat4\r\n *\r\n * @param {mat4} a matrix to represent as a string\r\n * @returns {String} string representation of the matrix\r\n */\n\nexport function str(a) {\n return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' + a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';\n}\n/**\r\n * Returns Frobenius norm of a mat4\r\n *\r\n * @param {mat4} a the matrix to calculate Frobenius norm of\r\n * @returns {Number} Frobenius norm\r\n */\n\nexport function frob(a) {\n return Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2) + Math.pow(a[9], 2) + Math.pow(a[10], 2) + Math.pow(a[11], 2) + Math.pow(a[12], 2) + Math.pow(a[13], 2) + Math.pow(a[14], 2) + Math.pow(a[15], 2));\n}\n/**\r\n * Adds two mat4's\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the first operand\r\n * @param {mat4} b the second operand\r\n * @returns {mat4} out\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n out[6] = a[6] + b[6];\n out[7] = a[7] + b[7];\n out[8] = a[8] + b[8];\n out[9] = a[9] + b[9];\n out[10] = a[10] + b[10];\n out[11] = a[11] + b[11];\n out[12] = a[12] + b[12];\n out[13] = a[13] + b[13];\n out[14] = a[14] + b[14];\n out[15] = a[15] + b[15];\n return out;\n}\n/**\r\n * Subtracts matrix b from matrix a\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the first operand\r\n * @param {mat4} b the second operand\r\n * @returns {mat4} out\r\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n out[6] = a[6] - b[6];\n out[7] = a[7] - b[7];\n out[8] = a[8] - b[8];\n out[9] = a[9] - b[9];\n out[10] = a[10] - b[10];\n out[11] = a[11] - b[11];\n out[12] = a[12] - b[12];\n out[13] = a[13] - b[13];\n out[14] = a[14] - b[14];\n out[15] = a[15] - b[15];\n return out;\n}\n/**\r\n * Multiply each element of the matrix by a scalar.\r\n *\r\n * @param {mat4} out the receiving matrix\r\n * @param {mat4} a the matrix to scale\r\n * @param {Number} b amount to scale the matrix's elements by\r\n * @returns {mat4} out\r\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n out[6] = a[6] * b;\n out[7] = a[7] * b;\n out[8] = a[8] * b;\n out[9] = a[9] * b;\n out[10] = a[10] * b;\n out[11] = a[11] * b;\n out[12] = a[12] * b;\n out[13] = a[13] * b;\n out[14] = a[14] * b;\n out[15] = a[15] * b;\n return out;\n}\n/**\r\n * Adds two mat4's after multiplying each element of the second operand by a scalar value.\r\n *\r\n * @param {mat4} out the receiving vector\r\n * @param {mat4} a the first operand\r\n * @param {mat4} b the second operand\r\n * @param {Number} scale the amount to scale b's elements by before adding\r\n * @returns {mat4} out\r\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n out[6] = a[6] + b[6] * scale;\n out[7] = a[7] + b[7] * scale;\n out[8] = a[8] + b[8] * scale;\n out[9] = a[9] + b[9] * scale;\n out[10] = a[10] + b[10] * scale;\n out[11] = a[11] + b[11] * scale;\n out[12] = a[12] + b[12] * scale;\n out[13] = a[13] + b[13] * scale;\n out[14] = a[14] + b[14] * scale;\n out[15] = a[15] + b[15] * scale;\n return out;\n}\n/**\r\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {mat4} a The first matrix.\r\n * @param {mat4} b The second matrix.\r\n * @returns {Boolean} True if the matrices are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8] && a[9] === b[9] && a[10] === b[10] && a[11] === b[11] && a[12] === b[12] && a[13] === b[13] && a[14] === b[14] && a[15] === b[15];\n}\n/**\r\n * Returns whether or not the matrices have approximately the same elements in the same position.\r\n *\r\n * @param {mat4} a The first matrix.\r\n * @param {mat4} b The second matrix.\r\n * @returns {Boolean} True if the matrices are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var a4 = a[4],\n a5 = a[5],\n a6 = a[6],\n a7 = a[7];\n var a8 = a[8],\n a9 = a[9],\n a10 = a[10],\n a11 = a[11];\n var a12 = a[12],\n a13 = a[13],\n a14 = a[14],\n a15 = a[15];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n var b4 = b[4],\n b5 = b[5],\n b6 = b[6],\n b7 = b[7];\n var b8 = b[8],\n b9 = b[9],\n b10 = b[10],\n b11 = b[11];\n var b12 = b[12],\n b13 = b[13],\n b14 = b[14],\n b15 = b[15];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) && Math.abs(a9 - b9) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) && Math.abs(a10 - b10) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) && Math.abs(a11 - b11) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) && Math.abs(a12 - b12) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) && Math.abs(a13 - b13) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) && Math.abs(a14 - b14) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) && Math.abs(a15 - b15) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15));\n}\n/**\r\n * Alias for {@link mat4.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Alias for {@link mat4.subtract}\r\n * @function\r\n */\n\nexport var sub = subtract;","import * as glMatrix from \"./common.js\";\n/**\r\n * 3 Dimensional Vector\r\n * @module vec3\r\n */\n\n/**\r\n * Creates a new, empty vec3\r\n *\r\n * @returns {vec3} a new 3D vector\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(3);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n }\n\n return out;\n}\n/**\r\n * Creates a new vec3 initialized with values from an existing vector\r\n *\r\n * @param {vec3} a vector to clone\r\n * @returns {vec3} a new 3D vector\r\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(3);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n return out;\n}\n/**\r\n * Calculates the length of a vec3\r\n *\r\n * @param {vec3} a vector to calculate length of\r\n * @returns {Number} length of a\r\n */\n\nexport function length(a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n return Math.sqrt(x * x + y * y + z * z);\n}\n/**\r\n * Creates a new vec3 initialized with the given values\r\n *\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @returns {vec3} a new 3D vector\r\n */\n\nexport function fromValues(x, y, z) {\n var out = new glMatrix.ARRAY_TYPE(3);\n out[0] = x;\n out[1] = y;\n out[2] = z;\n return out;\n}\n/**\r\n * Copy the values from one vec3 to another\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the source vector\r\n * @returns {vec3} out\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n return out;\n}\n/**\r\n * Set the components of a vec3 to the given values\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @returns {vec3} out\r\n */\n\nexport function set(out, x, y, z) {\n out[0] = x;\n out[1] = y;\n out[2] = z;\n return out;\n}\n/**\r\n * Adds two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n return out;\n}\n/**\r\n * Subtracts vector b from vector a\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n return out;\n}\n/**\r\n * Multiplies two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n out[2] = a[2] * b[2];\n return out;\n}\n/**\r\n * Divides two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n out[2] = a[2] / b[2];\n return out;\n}\n/**\r\n * Math.ceil the components of a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to ceil\r\n * @returns {vec3} out\r\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n out[2] = Math.ceil(a[2]);\n return out;\n}\n/**\r\n * Math.floor the components of a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to floor\r\n * @returns {vec3} out\r\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n out[2] = Math.floor(a[2]);\n return out;\n}\n/**\r\n * Returns the minimum of two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n out[2] = Math.min(a[2], b[2]);\n return out;\n}\n/**\r\n * Returns the maximum of two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n out[2] = Math.max(a[2], b[2]);\n return out;\n}\n/**\r\n * Math.round the components of a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to round\r\n * @returns {vec3} out\r\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n out[2] = Math.round(a[2]);\n return out;\n}\n/**\r\n * Scales a vec3 by a scalar number\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the vector to scale\r\n * @param {Number} b amount to scale the vector by\r\n * @returns {vec3} out\r\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n return out;\n}\n/**\r\n * Adds two vec3's after scaling the second operand by a scalar value\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @param {Number} scale the amount to scale b by before adding\r\n * @returns {vec3} out\r\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n return out;\n}\n/**\r\n * Calculates the euclidian distance between two vec3's\r\n *\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {Number} distance between a and b\r\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0];\n var y = b[1] - a[1];\n var z = b[2] - a[2];\n return Math.sqrt(x * x + y * y + z * z);\n}\n/**\r\n * Calculates the squared euclidian distance between two vec3's\r\n *\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {Number} squared distance between a and b\r\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0];\n var y = b[1] - a[1];\n var z = b[2] - a[2];\n return x * x + y * y + z * z;\n}\n/**\r\n * Calculates the squared length of a vec3\r\n *\r\n * @param {vec3} a vector to calculate squared length of\r\n * @returns {Number} squared length of a\r\n */\n\nexport function squaredLength(a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n return x * x + y * y + z * z;\n}\n/**\r\n * Negates the components of a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to negate\r\n * @returns {vec3} out\r\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n return out;\n}\n/**\r\n * Returns the inverse of the components of a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to invert\r\n * @returns {vec3} out\r\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n out[2] = 1.0 / a[2];\n return out;\n}\n/**\r\n * Normalize a vec3\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a vector to normalize\r\n * @returns {vec3} out\r\n */\n\nexport function normalize(out, a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n var len = x * x + y * y + z * z;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n out[2] = a[2] * len;\n return out;\n}\n/**\r\n * Calculates the dot product of two vec3's\r\n *\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {Number} dot product of a and b\r\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];\n}\n/**\r\n * Computes the cross product of two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function cross(out, a, b) {\n var ax = a[0],\n ay = a[1],\n az = a[2];\n var bx = b[0],\n by = b[1],\n bz = b[2];\n out[0] = ay * bz - az * by;\n out[1] = az * bx - ax * bz;\n out[2] = ax * by - ay * bx;\n return out;\n}\n/**\r\n * Performs a linear interpolation between two vec3's\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {vec3} out\r\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0];\n var ay = a[1];\n var az = a[2];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n out[2] = az + t * (b[2] - az);\n return out;\n}\n/**\r\n * Performs a hermite interpolation with two control points\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @param {vec3} c the third operand\r\n * @param {vec3} d the fourth operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {vec3} out\r\n */\n\nexport function hermite(out, a, b, c, d, t) {\n var factorTimes2 = t * t;\n var factor1 = factorTimes2 * (2 * t - 3) + 1;\n var factor2 = factorTimes2 * (t - 2) + t;\n var factor3 = factorTimes2 * (t - 1);\n var factor4 = factorTimes2 * (3 - 2 * t);\n out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;\n out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;\n out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;\n return out;\n}\n/**\r\n * Performs a bezier interpolation with two control points\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the first operand\r\n * @param {vec3} b the second operand\r\n * @param {vec3} c the third operand\r\n * @param {vec3} d the fourth operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {vec3} out\r\n */\n\nexport function bezier(out, a, b, c, d, t) {\n var inverseFactor = 1 - t;\n var inverseFactorTimesTwo = inverseFactor * inverseFactor;\n var factorTimes2 = t * t;\n var factor1 = inverseFactorTimesTwo * inverseFactor;\n var factor2 = 3 * t * inverseFactorTimesTwo;\n var factor3 = 3 * factorTimes2 * inverseFactor;\n var factor4 = factorTimes2 * t;\n out[0] = a[0] * factor1 + b[0] * factor2 + c[0] * factor3 + d[0] * factor4;\n out[1] = a[1] * factor1 + b[1] * factor2 + c[1] * factor3 + d[1] * factor4;\n out[2] = a[2] * factor1 + b[2] * factor2 + c[2] * factor3 + d[2] * factor4;\n return out;\n}\n/**\r\n * Generates a random vector with the given scale\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\r\n * @returns {vec3} out\r\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n var z = glMatrix.RANDOM() * 2.0 - 1.0;\n var zScale = Math.sqrt(1.0 - z * z) * scale;\n out[0] = Math.cos(r) * zScale;\n out[1] = Math.sin(r) * zScale;\n out[2] = z * scale;\n return out;\n}\n/**\r\n * Transforms the vec3 with a mat4.\r\n * 4th vector component is implicitly '1'\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the vector to transform\r\n * @param {mat4} m matrix to transform with\r\n * @returns {vec3} out\r\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0],\n y = a[1],\n z = a[2];\n var w = m[3] * x + m[7] * y + m[11] * z + m[15];\n w = w || 1.0;\n out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;\n out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;\n out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;\n return out;\n}\n/**\r\n * Transforms the vec3 with a mat3.\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the vector to transform\r\n * @param {mat3} m the 3x3 matrix to transform with\r\n * @returns {vec3} out\r\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1],\n z = a[2];\n out[0] = x * m[0] + y * m[3] + z * m[6];\n out[1] = x * m[1] + y * m[4] + z * m[7];\n out[2] = x * m[2] + y * m[5] + z * m[8];\n return out;\n}\n/**\r\n * Transforms the vec3 with a quat\r\n * Can also be used for dual quaternions. (Multiply it with the real part)\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec3} a the vector to transform\r\n * @param {quat} q quaternion to transform with\r\n * @returns {vec3} out\r\n */\n\nexport function transformQuat(out, a, q) {\n // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed\n var qx = q[0],\n qy = q[1],\n qz = q[2],\n qw = q[3];\n var x = a[0],\n y = a[1],\n z = a[2]; // var qvec = [qx, qy, qz];\n // var uv = vec3.cross([], qvec, a);\n\n var uvx = qy * z - qz * y,\n uvy = qz * x - qx * z,\n uvz = qx * y - qy * x; // var uuv = vec3.cross([], qvec, uv);\n\n var uuvx = qy * uvz - qz * uvy,\n uuvy = qz * uvx - qx * uvz,\n uuvz = qx * uvy - qy * uvx; // vec3.scale(uv, uv, 2 * w);\n\n var w2 = qw * 2;\n uvx *= w2;\n uvy *= w2;\n uvz *= w2; // vec3.scale(uuv, uuv, 2);\n\n uuvx *= 2;\n uuvy *= 2;\n uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv));\n\n out[0] = x + uvx + uuvx;\n out[1] = y + uvy + uuvy;\n out[2] = z + uvz + uuvz;\n return out;\n}\n/**\r\n * Rotate a 3D vector around the x-axis\r\n * @param {vec3} out The receiving vec3\r\n * @param {vec3} a The vec3 point to rotate\r\n * @param {vec3} b The origin of the rotation\r\n * @param {Number} c The angle of rotation\r\n * @returns {vec3} out\r\n */\n\nexport function rotateX(out, a, b, c) {\n var p = [],\n r = []; //Translate point to the origin\n\n p[0] = a[0] - b[0];\n p[1] = a[1] - b[1];\n p[2] = a[2] - b[2]; //perform rotation\n\n r[0] = p[0];\n r[1] = p[1] * Math.cos(c) - p[2] * Math.sin(c);\n r[2] = p[1] * Math.sin(c) + p[2] * Math.cos(c); //translate to correct position\n\n out[0] = r[0] + b[0];\n out[1] = r[1] + b[1];\n out[2] = r[2] + b[2];\n return out;\n}\n/**\r\n * Rotate a 3D vector around the y-axis\r\n * @param {vec3} out The receiving vec3\r\n * @param {vec3} a The vec3 point to rotate\r\n * @param {vec3} b The origin of the rotation\r\n * @param {Number} c The angle of rotation\r\n * @returns {vec3} out\r\n */\n\nexport function rotateY(out, a, b, c) {\n var p = [],\n r = []; //Translate point to the origin\n\n p[0] = a[0] - b[0];\n p[1] = a[1] - b[1];\n p[2] = a[2] - b[2]; //perform rotation\n\n r[0] = p[2] * Math.sin(c) + p[0] * Math.cos(c);\n r[1] = p[1];\n r[2] = p[2] * Math.cos(c) - p[0] * Math.sin(c); //translate to correct position\n\n out[0] = r[0] + b[0];\n out[1] = r[1] + b[1];\n out[2] = r[2] + b[2];\n return out;\n}\n/**\r\n * Rotate a 3D vector around the z-axis\r\n * @param {vec3} out The receiving vec3\r\n * @param {vec3} a The vec3 point to rotate\r\n * @param {vec3} b The origin of the rotation\r\n * @param {Number} c The angle of rotation\r\n * @returns {vec3} out\r\n */\n\nexport function rotateZ(out, a, b, c) {\n var p = [],\n r = []; //Translate point to the origin\n\n p[0] = a[0] - b[0];\n p[1] = a[1] - b[1];\n p[2] = a[2] - b[2]; //perform rotation\n\n r[0] = p[0] * Math.cos(c) - p[1] * Math.sin(c);\n r[1] = p[0] * Math.sin(c) + p[1] * Math.cos(c);\n r[2] = p[2]; //translate to correct position\n\n out[0] = r[0] + b[0];\n out[1] = r[1] + b[1];\n out[2] = r[2] + b[2];\n return out;\n}\n/**\r\n * Get the angle between two 3D vectors\r\n * @param {vec3} a The first operand\r\n * @param {vec3} b The second operand\r\n * @returns {Number} The angle in radians\r\n */\n\nexport function angle(a, b) {\n var tempA = fromValues(a[0], a[1], a[2]);\n var tempB = fromValues(b[0], b[1], b[2]);\n normalize(tempA, tempA);\n normalize(tempB, tempB);\n var cosine = dot(tempA, tempB);\n\n if (cosine > 1.0) {\n return 0;\n } else if (cosine < -1.0) {\n return Math.PI;\n } else {\n return Math.acos(cosine);\n }\n}\n/**\r\n * Set the components of a vec3 to zero\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @returns {vec3} out\r\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n out[2] = 0.0;\n return out;\n}\n/**\r\n * Returns a string representation of a vector\r\n *\r\n * @param {vec3} a vector to represent as a string\r\n * @returns {String} string representation of the vector\r\n */\n\nexport function str(a) {\n return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';\n}\n/**\r\n * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {vec3} a The first vector.\r\n * @param {vec3} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];\n}\n/**\r\n * Returns whether or not the vectors have approximately the same elements in the same position.\r\n *\r\n * @param {vec3} a The first vector.\r\n * @param {vec3} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2));\n}\n/**\r\n * Alias for {@link vec3.subtract}\r\n * @function\r\n */\n\nexport var sub = subtract;\n/**\r\n * Alias for {@link vec3.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Alias for {@link vec3.divide}\r\n * @function\r\n */\n\nexport var div = divide;\n/**\r\n * Alias for {@link vec3.distance}\r\n * @function\r\n */\n\nexport var dist = distance;\n/**\r\n * Alias for {@link vec3.squaredDistance}\r\n * @function\r\n */\n\nexport var sqrDist = squaredDistance;\n/**\r\n * Alias for {@link vec3.length}\r\n * @function\r\n */\n\nexport var len = length;\n/**\r\n * Alias for {@link vec3.squaredLength}\r\n * @function\r\n */\n\nexport var sqrLen = squaredLength;\n/**\r\n * Perform some operation over an array of vec3s.\r\n *\r\n * @param {Array} a the array of vectors to iterate over\r\n * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed\r\n * @param {Number} offset Number of elements to skip at the beginning of the array\r\n * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array\r\n * @param {Function} fn Function to call for each vector in the array\r\n * @param {Object} [arg] additional argument to pass to fn\r\n * @returns {Array} a\r\n * @function\r\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 3;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n vec[2] = a[i + 2];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n a[i + 2] = vec[2];\n }\n\n return a;\n };\n}();","import * as glMatrix from \"./common.js\";\n/**\r\n * 4 Dimensional Vector\r\n * @module vec4\r\n */\n\n/**\r\n * Creates a new, empty vec4\r\n *\r\n * @returns {vec4} a new 4D vector\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n }\n\n return out;\n}\n/**\r\n * Creates a new vec4 initialized with values from an existing vector\r\n *\r\n * @param {vec4} a vector to clone\r\n * @returns {vec4} a new 4D vector\r\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\r\n * Creates a new vec4 initialized with the given values\r\n *\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @param {Number} w W component\r\n * @returns {vec4} a new 4D vector\r\n */\n\nexport function fromValues(x, y, z, w) {\n var out = new glMatrix.ARRAY_TYPE(4);\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = w;\n return out;\n}\n/**\r\n * Copy the values from one vec4 to another\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the source vector\r\n * @returns {vec4} out\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n return out;\n}\n/**\r\n * Set the components of a vec4 to the given values\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @param {Number} w W component\r\n * @returns {vec4} out\r\n */\n\nexport function set(out, x, y, z, w) {\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = w;\n return out;\n}\n/**\r\n * Adds two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n return out;\n}\n/**\r\n * Subtracts vector b from vector a\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n return out;\n}\n/**\r\n * Multiplies two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n out[2] = a[2] * b[2];\n out[3] = a[3] * b[3];\n return out;\n}\n/**\r\n * Divides two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n out[2] = a[2] / b[2];\n out[3] = a[3] / b[3];\n return out;\n}\n/**\r\n * Math.ceil the components of a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to ceil\r\n * @returns {vec4} out\r\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n out[2] = Math.ceil(a[2]);\n out[3] = Math.ceil(a[3]);\n return out;\n}\n/**\r\n * Math.floor the components of a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to floor\r\n * @returns {vec4} out\r\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n out[2] = Math.floor(a[2]);\n out[3] = Math.floor(a[3]);\n return out;\n}\n/**\r\n * Returns the minimum of two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n out[2] = Math.min(a[2], b[2]);\n out[3] = Math.min(a[3], b[3]);\n return out;\n}\n/**\r\n * Returns the maximum of two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {vec4} out\r\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n out[2] = Math.max(a[2], b[2]);\n out[3] = Math.max(a[3], b[3]);\n return out;\n}\n/**\r\n * Math.round the components of a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to round\r\n * @returns {vec4} out\r\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n out[2] = Math.round(a[2]);\n out[3] = Math.round(a[3]);\n return out;\n}\n/**\r\n * Scales a vec4 by a scalar number\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the vector to scale\r\n * @param {Number} b amount to scale the vector by\r\n * @returns {vec4} out\r\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n return out;\n}\n/**\r\n * Adds two vec4's after scaling the second operand by a scalar value\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @param {Number} scale the amount to scale b by before adding\r\n * @returns {vec4} out\r\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n return out;\n}\n/**\r\n * Calculates the euclidian distance between two vec4's\r\n *\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {Number} distance between a and b\r\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0];\n var y = b[1] - a[1];\n var z = b[2] - a[2];\n var w = b[3] - a[3];\n return Math.sqrt(x * x + y * y + z * z + w * w);\n}\n/**\r\n * Calculates the squared euclidian distance between two vec4's\r\n *\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {Number} squared distance between a and b\r\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0];\n var y = b[1] - a[1];\n var z = b[2] - a[2];\n var w = b[3] - a[3];\n return x * x + y * y + z * z + w * w;\n}\n/**\r\n * Calculates the length of a vec4\r\n *\r\n * @param {vec4} a vector to calculate length of\r\n * @returns {Number} length of a\r\n */\n\nexport function length(a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n var w = a[3];\n return Math.sqrt(x * x + y * y + z * z + w * w);\n}\n/**\r\n * Calculates the squared length of a vec4\r\n *\r\n * @param {vec4} a vector to calculate squared length of\r\n * @returns {Number} squared length of a\r\n */\n\nexport function squaredLength(a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n var w = a[3];\n return x * x + y * y + z * z + w * w;\n}\n/**\r\n * Negates the components of a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to negate\r\n * @returns {vec4} out\r\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = -a[3];\n return out;\n}\n/**\r\n * Returns the inverse of the components of a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to invert\r\n * @returns {vec4} out\r\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n out[2] = 1.0 / a[2];\n out[3] = 1.0 / a[3];\n return out;\n}\n/**\r\n * Normalize a vec4\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a vector to normalize\r\n * @returns {vec4} out\r\n */\n\nexport function normalize(out, a) {\n var x = a[0];\n var y = a[1];\n var z = a[2];\n var w = a[3];\n var len = x * x + y * y + z * z + w * w;\n\n if (len > 0) {\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = x * len;\n out[1] = y * len;\n out[2] = z * len;\n out[3] = w * len;\n return out;\n}\n/**\r\n * Calculates the dot product of two vec4's\r\n *\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @returns {Number} dot product of a and b\r\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];\n}\n/**\r\n * Returns the cross-product of three vectors in a 4-dimensional space\r\n *\r\n * @param {vec4} result the receiving vector\r\n * @param {vec4} U the first vector\r\n * @param {vec4} V the second vector\r\n * @param {vec4} W the third vector\r\n * @returns {vec4} result\r\n */\n\nexport function cross(out, u, v, w) {\n var A = v[0] * w[1] - v[1] * w[0],\n B = v[0] * w[2] - v[2] * w[0],\n C = v[0] * w[3] - v[3] * w[0],\n D = v[1] * w[2] - v[2] * w[1],\n E = v[1] * w[3] - v[3] * w[1],\n F = v[2] * w[3] - v[3] * w[2];\n var G = u[0];\n var H = u[1];\n var I = u[2];\n var J = u[3];\n out[0] = H * F - I * E + J * D;\n out[1] = -(G * F) + I * C - J * B;\n out[2] = G * E - H * C + J * A;\n out[3] = -(G * D) + H * B - I * A;\n return out;\n}\n;\n/**\r\n * Performs a linear interpolation between two vec4's\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the first operand\r\n * @param {vec4} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {vec4} out\r\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0];\n var ay = a[1];\n var az = a[2];\n var aw = a[3];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n out[2] = az + t * (b[2] - az);\n out[3] = aw + t * (b[3] - aw);\n return out;\n}\n/**\r\n * Generates a random vector with the given scale\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\r\n * @returns {vec4} out\r\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0; // Marsaglia, George. Choosing a Point from the Surface of a\n // Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.\n // http://projecteuclid.org/euclid.aoms/1177692644;\n\n var v1, v2, v3, v4;\n var s1, s2;\n\n do {\n v1 = glMatrix.RANDOM() * 2 - 1;\n v2 = glMatrix.RANDOM() * 2 - 1;\n s1 = v1 * v1 + v2 * v2;\n } while (s1 >= 1);\n\n do {\n v3 = glMatrix.RANDOM() * 2 - 1;\n v4 = glMatrix.RANDOM() * 2 - 1;\n s2 = v3 * v3 + v4 * v4;\n } while (s2 >= 1);\n\n var d = Math.sqrt((1 - s1) / s2);\n out[0] = scale * v1;\n out[1] = scale * v2;\n out[2] = scale * v3 * d;\n out[3] = scale * v4 * d;\n return out;\n}\n/**\r\n * Transforms the vec4 with a mat4.\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the vector to transform\r\n * @param {mat4} m matrix to transform with\r\n * @returns {vec4} out\r\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0],\n y = a[1],\n z = a[2],\n w = a[3];\n out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;\n out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;\n out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;\n out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;\n return out;\n}\n/**\r\n * Transforms the vec4 with a quat\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @param {vec4} a the vector to transform\r\n * @param {quat} q quaternion to transform with\r\n * @returns {vec4} out\r\n */\n\nexport function transformQuat(out, a, q) {\n var x = a[0],\n y = a[1],\n z = a[2];\n var qx = q[0],\n qy = q[1],\n qz = q[2],\n qw = q[3]; // calculate quat * vec\n\n var ix = qw * x + qy * z - qz * y;\n var iy = qw * y + qz * x - qx * z;\n var iz = qw * z + qx * y - qy * x;\n var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat\n\n out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;\n out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;\n out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;\n out[3] = a[3];\n return out;\n}\n/**\r\n * Set the components of a vec4 to zero\r\n *\r\n * @param {vec4} out the receiving vector\r\n * @returns {vec4} out\r\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n out[2] = 0.0;\n out[3] = 0.0;\n return out;\n}\n/**\r\n * Returns a string representation of a vector\r\n *\r\n * @param {vec4} a vector to represent as a string\r\n * @returns {String} string representation of the vector\r\n */\n\nexport function str(a) {\n return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n}\n/**\r\n * Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {vec4} a The first vector.\r\n * @param {vec4} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n/**\r\n * Returns whether or not the vectors have approximately the same elements in the same position.\r\n *\r\n * @param {vec4} a The first vector.\r\n * @param {vec4} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3));\n}\n/**\r\n * Alias for {@link vec4.subtract}\r\n * @function\r\n */\n\nexport var sub = subtract;\n/**\r\n * Alias for {@link vec4.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Alias for {@link vec4.divide}\r\n * @function\r\n */\n\nexport var div = divide;\n/**\r\n * Alias for {@link vec4.distance}\r\n * @function\r\n */\n\nexport var dist = distance;\n/**\r\n * Alias for {@link vec4.squaredDistance}\r\n * @function\r\n */\n\nexport var sqrDist = squaredDistance;\n/**\r\n * Alias for {@link vec4.length}\r\n * @function\r\n */\n\nexport var len = length;\n/**\r\n * Alias for {@link vec4.squaredLength}\r\n * @function\r\n */\n\nexport var sqrLen = squaredLength;\n/**\r\n * Perform some operation over an array of vec4s.\r\n *\r\n * @param {Array} a the array of vectors to iterate over\r\n * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed\r\n * @param {Number} offset Number of elements to skip at the beginning of the array\r\n * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array\r\n * @param {Function} fn Function to call for each vector in the array\r\n * @param {Object} [arg] additional argument to pass to fn\r\n * @returns {Array} a\r\n * @function\r\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 4;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n vec[2] = a[i + 2];\n vec[3] = a[i + 3];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n a[i + 2] = vec[2];\n a[i + 3] = vec[3];\n }\n\n return a;\n };\n}();","import * as glMatrix from \"./common.js\";\nimport * as mat3 from \"./mat3.js\";\nimport * as vec3 from \"./vec3.js\";\nimport * as vec4 from \"./vec4.js\";\n/**\r\n * Quaternion\r\n * @module quat\r\n */\n\n/**\r\n * Creates a new identity quat\r\n *\r\n * @returns {quat} a new quaternion\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(4);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n }\n\n out[3] = 1;\n return out;\n}\n/**\r\n * Set a quat to the identity quaternion\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @returns {quat} out\r\n */\n\nexport function identity(out) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n}\n/**\r\n * Sets a quat from the given angle and rotation axis,\r\n * then returns it.\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {vec3} axis the axis around which to rotate\r\n * @param {Number} rad the angle in radians\r\n * @returns {quat} out\r\n **/\n\nexport function setAxisAngle(out, axis, rad) {\n rad = rad * 0.5;\n var s = Math.sin(rad);\n out[0] = s * axis[0];\n out[1] = s * axis[1];\n out[2] = s * axis[2];\n out[3] = Math.cos(rad);\n return out;\n}\n/**\r\n * Gets the rotation axis and angle for a given\r\n * quaternion. If a quaternion is created with\r\n * setAxisAngle, this method will return the same\r\n * values as providied in the original parameter list\r\n * OR functionally equivalent values.\r\n * Example: The quaternion formed by axis [0, 0, 1] and\r\n * angle -90 is the same as the quaternion formed by\r\n * [0, 0, 1] and 270. This method favors the latter.\r\n * @param {vec3} out_axis Vector receiving the axis of rotation\r\n * @param {quat} q Quaternion to be decomposed\r\n * @return {Number} Angle, in radians, of the rotation\r\n */\n\nexport function getAxisAngle(out_axis, q) {\n var rad = Math.acos(q[3]) * 2.0;\n var s = Math.sin(rad / 2.0);\n\n if (s > glMatrix.EPSILON) {\n out_axis[0] = q[0] / s;\n out_axis[1] = q[1] / s;\n out_axis[2] = q[2] / s;\n } else {\n // If s is zero, return any axis (no rotation - axis does not matter)\n out_axis[0] = 1;\n out_axis[1] = 0;\n out_axis[2] = 0;\n }\n\n return rad;\n}\n/**\r\n * Multiplies two quat's\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @returns {quat} out\r\n */\n\nexport function multiply(out, a, b) {\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n var bx = b[0],\n by = b[1],\n bz = b[2],\n bw = b[3];\n out[0] = ax * bw + aw * bx + ay * bz - az * by;\n out[1] = ay * bw + aw * by + az * bx - ax * bz;\n out[2] = az * bw + aw * bz + ax * by - ay * bx;\n out[3] = aw * bw - ax * bx - ay * by - az * bz;\n return out;\n}\n/**\r\n * Rotates a quaternion by the given angle about the X axis\r\n *\r\n * @param {quat} out quat receiving operation result\r\n * @param {quat} a quat to rotate\r\n * @param {number} rad angle (in radians) to rotate\r\n * @returns {quat} out\r\n */\n\nexport function rotateX(out, a, rad) {\n rad *= 0.5;\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n var bx = Math.sin(rad),\n bw = Math.cos(rad);\n out[0] = ax * bw + aw * bx;\n out[1] = ay * bw + az * bx;\n out[2] = az * bw - ay * bx;\n out[3] = aw * bw - ax * bx;\n return out;\n}\n/**\r\n * Rotates a quaternion by the given angle about the Y axis\r\n *\r\n * @param {quat} out quat receiving operation result\r\n * @param {quat} a quat to rotate\r\n * @param {number} rad angle (in radians) to rotate\r\n * @returns {quat} out\r\n */\n\nexport function rotateY(out, a, rad) {\n rad *= 0.5;\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n var by = Math.sin(rad),\n bw = Math.cos(rad);\n out[0] = ax * bw - az * by;\n out[1] = ay * bw + aw * by;\n out[2] = az * bw + ax * by;\n out[3] = aw * bw - ay * by;\n return out;\n}\n/**\r\n * Rotates a quaternion by the given angle about the Z axis\r\n *\r\n * @param {quat} out quat receiving operation result\r\n * @param {quat} a quat to rotate\r\n * @param {number} rad angle (in radians) to rotate\r\n * @returns {quat} out\r\n */\n\nexport function rotateZ(out, a, rad) {\n rad *= 0.5;\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n var bz = Math.sin(rad),\n bw = Math.cos(rad);\n out[0] = ax * bw + ay * bz;\n out[1] = ay * bw - ax * bz;\n out[2] = az * bw + aw * bz;\n out[3] = aw * bw - az * bz;\n return out;\n}\n/**\r\n * Calculates the W component of a quat from the X, Y, and Z components.\r\n * Assumes that quaternion is 1 unit in length.\r\n * Any existing W component will be ignored.\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a quat to calculate W component of\r\n * @returns {quat} out\r\n */\n\nexport function calculateW(out, a) {\n var x = a[0],\n y = a[1],\n z = a[2];\n out[0] = x;\n out[1] = y;\n out[2] = z;\n out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));\n return out;\n}\n/**\r\n * Performs a spherical linear interpolation between two quat\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {quat} out\r\n */\n\nexport function slerp(out, a, b, t) {\n // benchmarks:\n // http://jsperf.com/quaternion-slerp-implementations\n var ax = a[0],\n ay = a[1],\n az = a[2],\n aw = a[3];\n var bx = b[0],\n by = b[1],\n bz = b[2],\n bw = b[3];\n var omega, cosom, sinom, scale0, scale1; // calc cosine\n\n cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)\n\n if (cosom < 0.0) {\n cosom = -cosom;\n bx = -bx;\n by = -by;\n bz = -bz;\n bw = -bw;\n } // calculate coefficients\n\n\n if (1.0 - cosom > glMatrix.EPSILON) {\n // standard case (slerp)\n omega = Math.acos(cosom);\n sinom = Math.sin(omega);\n scale0 = Math.sin((1.0 - t) * omega) / sinom;\n scale1 = Math.sin(t * omega) / sinom;\n } else {\n // \"from\" and \"to\" quaternions are very close\n // ... so we can do a linear interpolation\n scale0 = 1.0 - t;\n scale1 = t;\n } // calculate final values\n\n\n out[0] = scale0 * ax + scale1 * bx;\n out[1] = scale0 * ay + scale1 * by;\n out[2] = scale0 * az + scale1 * bz;\n out[3] = scale0 * aw + scale1 * bw;\n return out;\n}\n/**\r\n * Generates a random quaternion\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @returns {quat} out\r\n */\n\nexport function random(out) {\n // Implementation of http://planning.cs.uiuc.edu/node198.html\n // TODO: Calling random 3 times is probably not the fastest solution\n var u1 = glMatrix.RANDOM();\n var u2 = glMatrix.RANDOM();\n var u3 = glMatrix.RANDOM();\n var sqrt1MinusU1 = Math.sqrt(1 - u1);\n var sqrtU1 = Math.sqrt(u1);\n out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);\n out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);\n out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);\n out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);\n return out;\n}\n/**\r\n * Calculates the inverse of a quat\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a quat to calculate inverse of\r\n * @returns {quat} out\r\n */\n\nexport function invert(out, a) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3];\n var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;\n var invDot = dot ? 1.0 / dot : 0; // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0\n\n out[0] = -a0 * invDot;\n out[1] = -a1 * invDot;\n out[2] = -a2 * invDot;\n out[3] = a3 * invDot;\n return out;\n}\n/**\r\n * Calculates the conjugate of a quat\r\n * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a quat to calculate conjugate of\r\n * @returns {quat} out\r\n */\n\nexport function conjugate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n out[2] = -a[2];\n out[3] = a[3];\n return out;\n}\n/**\r\n * Creates a quaternion from the given 3x3 rotation matrix.\r\n *\r\n * NOTE: The resultant quaternion is not normalized, so you should be sure\r\n * to renormalize the quaternion yourself where necessary.\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {mat3} m rotation matrix\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport function fromMat3(out, m) {\n // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes\n // article \"Quaternion Calculus and Fast Animation\".\n var fTrace = m[0] + m[4] + m[8];\n var fRoot;\n\n if (fTrace > 0.0) {\n // |w| > 1/2, may as well choose w > 1/2\n fRoot = Math.sqrt(fTrace + 1.0); // 2w\n\n out[3] = 0.5 * fRoot;\n fRoot = 0.5 / fRoot; // 1/(4w)\n\n out[0] = (m[5] - m[7]) * fRoot;\n out[1] = (m[6] - m[2]) * fRoot;\n out[2] = (m[1] - m[3]) * fRoot;\n } else {\n // |w| <= 1/2\n var i = 0;\n if (m[4] > m[0]) i = 1;\n if (m[8] > m[i * 3 + i]) i = 2;\n var j = (i + 1) % 3;\n var k = (i + 2) % 3;\n fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);\n out[i] = 0.5 * fRoot;\n fRoot = 0.5 / fRoot;\n out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;\n out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;\n out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;\n }\n\n return out;\n}\n/**\r\n * Creates a quaternion from the given euler angle x, y, z.\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {x} Angle to rotate around X axis in degrees.\r\n * @param {y} Angle to rotate around Y axis in degrees.\r\n * @param {z} Angle to rotate around Z axis in degrees.\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport function fromEuler(out, x, y, z) {\n var halfToRad = 0.5 * Math.PI / 180.0;\n x *= halfToRad;\n y *= halfToRad;\n z *= halfToRad;\n var sx = Math.sin(x);\n var cx = Math.cos(x);\n var sy = Math.sin(y);\n var cy = Math.cos(y);\n var sz = Math.sin(z);\n var cz = Math.cos(z);\n out[0] = sx * cy * cz - cx * sy * sz;\n out[1] = cx * sy * cz + sx * cy * sz;\n out[2] = cx * cy * sz - sx * sy * cz;\n out[3] = cx * cy * cz + sx * sy * sz;\n return out;\n}\n/**\r\n * Returns a string representation of a quatenion\r\n *\r\n * @param {quat} a vector to represent as a string\r\n * @returns {String} string representation of the vector\r\n */\n\nexport function str(a) {\n return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';\n}\n/**\r\n * Creates a new quat initialized with values from an existing quaternion\r\n *\r\n * @param {quat} a quaternion to clone\r\n * @returns {quat} a new quaternion\r\n * @function\r\n */\n\nexport var clone = vec4.clone;\n/**\r\n * Creates a new quat initialized with the given values\r\n *\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @param {Number} w W component\r\n * @returns {quat} a new quaternion\r\n * @function\r\n */\n\nexport var fromValues = vec4.fromValues;\n/**\r\n * Copy the values from one quat to another\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the source quaternion\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var copy = vec4.copy;\n/**\r\n * Set the components of a quat to the given values\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @param {Number} z Z component\r\n * @param {Number} w W component\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var set = vec4.set;\n/**\r\n * Adds two quat's\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var add = vec4.add;\n/**\r\n * Alias for {@link quat.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Scales a quat by a scalar number\r\n *\r\n * @param {quat} out the receiving vector\r\n * @param {quat} a the vector to scale\r\n * @param {Number} b amount to scale the vector by\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var scale = vec4.scale;\n/**\r\n * Calculates the dot product of two quat's\r\n *\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @returns {Number} dot product of a and b\r\n * @function\r\n */\n\nexport var dot = vec4.dot;\n/**\r\n * Performs a linear interpolation between two quat's\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var lerp = vec4.lerp;\n/**\r\n * Calculates the length of a quat\r\n *\r\n * @param {quat} a vector to calculate length of\r\n * @returns {Number} length of a\r\n */\n\nexport var length = vec4.length;\n/**\r\n * Alias for {@link quat.length}\r\n * @function\r\n */\n\nexport var len = length;\n/**\r\n * Calculates the squared length of a quat\r\n *\r\n * @param {quat} a vector to calculate squared length of\r\n * @returns {Number} squared length of a\r\n * @function\r\n */\n\nexport var squaredLength = vec4.squaredLength;\n/**\r\n * Alias for {@link quat.squaredLength}\r\n * @function\r\n */\n\nexport var sqrLen = squaredLength;\n/**\r\n * Normalize a quat\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a quaternion to normalize\r\n * @returns {quat} out\r\n * @function\r\n */\n\nexport var normalize = vec4.normalize;\n/**\r\n * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {quat} a The first quaternion.\r\n * @param {quat} b The second quaternion.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport var exactEquals = vec4.exactEquals;\n/**\r\n * Returns whether or not the quaternions have approximately the same elements in the same position.\r\n *\r\n * @param {quat} a The first vector.\r\n * @param {quat} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport var equals = vec4.equals;\n/**\r\n * Sets a quaternion to represent the shortest rotation from one\r\n * vector to another.\r\n *\r\n * Both vectors are assumed to be unit length.\r\n *\r\n * @param {quat} out the receiving quaternion.\r\n * @param {vec3} a the initial vector\r\n * @param {vec3} b the destination vector\r\n * @returns {quat} out\r\n */\n\nexport var rotationTo = function () {\n var tmpvec3 = vec3.create();\n var xUnitVec3 = vec3.fromValues(1, 0, 0);\n var yUnitVec3 = vec3.fromValues(0, 1, 0);\n return function (out, a, b) {\n var dot = vec3.dot(a, b);\n\n if (dot < -0.999999) {\n vec3.cross(tmpvec3, xUnitVec3, a);\n if (vec3.len(tmpvec3) < 0.000001) vec3.cross(tmpvec3, yUnitVec3, a);\n vec3.normalize(tmpvec3, tmpvec3);\n setAxisAngle(out, tmpvec3, Math.PI);\n return out;\n } else if (dot > 0.999999) {\n out[0] = 0;\n out[1] = 0;\n out[2] = 0;\n out[3] = 1;\n return out;\n } else {\n vec3.cross(tmpvec3, a, b);\n out[0] = tmpvec3[0];\n out[1] = tmpvec3[1];\n out[2] = tmpvec3[2];\n out[3] = 1 + dot;\n return normalize(out, out);\n }\n };\n}();\n/**\r\n * Performs a spherical linear interpolation with two control points\r\n *\r\n * @param {quat} out the receiving quaternion\r\n * @param {quat} a the first operand\r\n * @param {quat} b the second operand\r\n * @param {quat} c the third operand\r\n * @param {quat} d the fourth operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {quat} out\r\n */\n\nexport var sqlerp = function () {\n var temp1 = create();\n var temp2 = create();\n return function (out, a, b, c, d, t) {\n slerp(temp1, a, d, t);\n slerp(temp2, b, c, t);\n slerp(out, temp1, temp2, 2 * t * (1 - t));\n return out;\n };\n}();\n/**\r\n * Sets the specified quaternion with values corresponding to the given\r\n * axes. Each axis is a vec3 and is expected to be unit length and\r\n * perpendicular to all other specified axes.\r\n *\r\n * @param {vec3} view the vector representing the viewing direction\r\n * @param {vec3} right the vector representing the local \"right\" direction\r\n * @param {vec3} up the vector representing the local \"up\" direction\r\n * @returns {quat} out\r\n */\n\nexport var setAxes = function () {\n var matr = mat3.create();\n return function (out, view, right, up) {\n matr[0] = right[0];\n matr[3] = right[1];\n matr[6] = right[2];\n matr[1] = up[0];\n matr[4] = up[1];\n matr[7] = up[2];\n matr[2] = -view[0];\n matr[5] = -view[1];\n matr[8] = -view[2];\n return normalize(out, fromMat3(out, matr));\n };\n}();","import * as glMatrix from \"./common.js\";\n/**\r\n * 3x3 Matrix\r\n * @module mat3\r\n */\n\n/**\r\n * Creates a new identity mat3\r\n *\r\n * @returns {mat3} a new 3x3 matrix\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(9);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n }\n\n out[0] = 1;\n out[4] = 1;\n out[8] = 1;\n return out;\n}\n/**\r\n * Copies the upper-left 3x3 values into the given mat3.\r\n *\r\n * @param {mat3} out the receiving 3x3 matrix\r\n * @param {mat4} a the source 4x4 matrix\r\n * @returns {mat3} out\r\n */\n\nexport function fromMat4(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[4];\n out[4] = a[5];\n out[5] = a[6];\n out[6] = a[8];\n out[7] = a[9];\n out[8] = a[10];\n return out;\n}\n/**\r\n * Creates a new mat3 initialized with values from an existing matrix\r\n *\r\n * @param {mat3} a matrix to clone\r\n * @returns {mat3} a new 3x3 matrix\r\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(9);\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n}\n/**\r\n * Copy the values from one mat3 to another\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the source matrix\r\n * @returns {mat3} out\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = a[2];\n out[3] = a[3];\n out[4] = a[4];\n out[5] = a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n}\n/**\r\n * Create a new mat3 with the given values\r\n *\r\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\r\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\r\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\r\n * @param {Number} m10 Component in column 1, row 0 position (index 3)\r\n * @param {Number} m11 Component in column 1, row 1 position (index 4)\r\n * @param {Number} m12 Component in column 1, row 2 position (index 5)\r\n * @param {Number} m20 Component in column 2, row 0 position (index 6)\r\n * @param {Number} m21 Component in column 2, row 1 position (index 7)\r\n * @param {Number} m22 Component in column 2, row 2 position (index 8)\r\n * @returns {mat3} A new mat3\r\n */\n\nexport function fromValues(m00, m01, m02, m10, m11, m12, m20, m21, m22) {\n var out = new glMatrix.ARRAY_TYPE(9);\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m10;\n out[4] = m11;\n out[5] = m12;\n out[6] = m20;\n out[7] = m21;\n out[8] = m22;\n return out;\n}\n/**\r\n * Set the components of a mat3 to the given values\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {Number} m00 Component in column 0, row 0 position (index 0)\r\n * @param {Number} m01 Component in column 0, row 1 position (index 1)\r\n * @param {Number} m02 Component in column 0, row 2 position (index 2)\r\n * @param {Number} m10 Component in column 1, row 0 position (index 3)\r\n * @param {Number} m11 Component in column 1, row 1 position (index 4)\r\n * @param {Number} m12 Component in column 1, row 2 position (index 5)\r\n * @param {Number} m20 Component in column 2, row 0 position (index 6)\r\n * @param {Number} m21 Component in column 2, row 1 position (index 7)\r\n * @param {Number} m22 Component in column 2, row 2 position (index 8)\r\n * @returns {mat3} out\r\n */\n\nexport function set(out, m00, m01, m02, m10, m11, m12, m20, m21, m22) {\n out[0] = m00;\n out[1] = m01;\n out[2] = m02;\n out[3] = m10;\n out[4] = m11;\n out[5] = m12;\n out[6] = m20;\n out[7] = m21;\n out[8] = m22;\n return out;\n}\n/**\r\n * Set a mat3 to the identity matrix\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @returns {mat3} out\r\n */\n\nexport function identity(out) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 1;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n}\n/**\r\n * Transpose the values of a mat3\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the source matrix\r\n * @returns {mat3} out\r\n */\n\nexport function transpose(out, a) {\n // If we are transposing ourselves we can skip a few steps but have to cache some values\n if (out === a) {\n var a01 = a[1],\n a02 = a[2],\n a12 = a[5];\n out[1] = a[3];\n out[2] = a[6];\n out[3] = a01;\n out[5] = a[7];\n out[6] = a02;\n out[7] = a12;\n } else {\n out[0] = a[0];\n out[1] = a[3];\n out[2] = a[6];\n out[3] = a[1];\n out[4] = a[4];\n out[5] = a[7];\n out[6] = a[2];\n out[7] = a[5];\n out[8] = a[8];\n }\n\n return out;\n}\n/**\r\n * Inverts a mat3\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the source matrix\r\n * @returns {mat3} out\r\n */\n\nexport function invert(out, a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2];\n var a10 = a[3],\n a11 = a[4],\n a12 = a[5];\n var a20 = a[6],\n a21 = a[7],\n a22 = a[8];\n var b01 = a22 * a11 - a12 * a21;\n var b11 = -a22 * a10 + a12 * a20;\n var b21 = a21 * a10 - a11 * a20; // Calculate the determinant\n\n var det = a00 * b01 + a01 * b11 + a02 * b21;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = b01 * det;\n out[1] = (-a22 * a01 + a02 * a21) * det;\n out[2] = (a12 * a01 - a02 * a11) * det;\n out[3] = b11 * det;\n out[4] = (a22 * a00 - a02 * a20) * det;\n out[5] = (-a12 * a00 + a02 * a10) * det;\n out[6] = b21 * det;\n out[7] = (-a21 * a00 + a01 * a20) * det;\n out[8] = (a11 * a00 - a01 * a10) * det;\n return out;\n}\n/**\r\n * Calculates the adjugate of a mat3\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the source matrix\r\n * @returns {mat3} out\r\n */\n\nexport function adjoint(out, a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2];\n var a10 = a[3],\n a11 = a[4],\n a12 = a[5];\n var a20 = a[6],\n a21 = a[7],\n a22 = a[8];\n out[0] = a11 * a22 - a12 * a21;\n out[1] = a02 * a21 - a01 * a22;\n out[2] = a01 * a12 - a02 * a11;\n out[3] = a12 * a20 - a10 * a22;\n out[4] = a00 * a22 - a02 * a20;\n out[5] = a02 * a10 - a00 * a12;\n out[6] = a10 * a21 - a11 * a20;\n out[7] = a01 * a20 - a00 * a21;\n out[8] = a00 * a11 - a01 * a10;\n return out;\n}\n/**\r\n * Calculates the determinant of a mat3\r\n *\r\n * @param {mat3} a the source matrix\r\n * @returns {Number} determinant of a\r\n */\n\nexport function determinant(a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2];\n var a10 = a[3],\n a11 = a[4],\n a12 = a[5];\n var a20 = a[6],\n a21 = a[7],\n a22 = a[8];\n return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);\n}\n/**\r\n * Multiplies two mat3's\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the first operand\r\n * @param {mat3} b the second operand\r\n * @returns {mat3} out\r\n */\n\nexport function multiply(out, a, b) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2];\n var a10 = a[3],\n a11 = a[4],\n a12 = a[5];\n var a20 = a[6],\n a21 = a[7],\n a22 = a[8];\n var b00 = b[0],\n b01 = b[1],\n b02 = b[2];\n var b10 = b[3],\n b11 = b[4],\n b12 = b[5];\n var b20 = b[6],\n b21 = b[7],\n b22 = b[8];\n out[0] = b00 * a00 + b01 * a10 + b02 * a20;\n out[1] = b00 * a01 + b01 * a11 + b02 * a21;\n out[2] = b00 * a02 + b01 * a12 + b02 * a22;\n out[3] = b10 * a00 + b11 * a10 + b12 * a20;\n out[4] = b10 * a01 + b11 * a11 + b12 * a21;\n out[5] = b10 * a02 + b11 * a12 + b12 * a22;\n out[6] = b20 * a00 + b21 * a10 + b22 * a20;\n out[7] = b20 * a01 + b21 * a11 + b22 * a21;\n out[8] = b20 * a02 + b21 * a12 + b22 * a22;\n return out;\n}\n/**\r\n * Translate a mat3 by the given vector\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the matrix to translate\r\n * @param {vec2} v vector to translate by\r\n * @returns {mat3} out\r\n */\n\nexport function translate(out, a, v) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a10 = a[3],\n a11 = a[4],\n a12 = a[5],\n a20 = a[6],\n a21 = a[7],\n a22 = a[8],\n x = v[0],\n y = v[1];\n out[0] = a00;\n out[1] = a01;\n out[2] = a02;\n out[3] = a10;\n out[4] = a11;\n out[5] = a12;\n out[6] = x * a00 + y * a10 + a20;\n out[7] = x * a01 + y * a11 + a21;\n out[8] = x * a02 + y * a12 + a22;\n return out;\n}\n/**\r\n * Rotates a mat3 by the given angle\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the matrix to rotate\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat3} out\r\n */\n\nexport function rotate(out, a, rad) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a10 = a[3],\n a11 = a[4],\n a12 = a[5],\n a20 = a[6],\n a21 = a[7],\n a22 = a[8],\n s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c * a00 + s * a10;\n out[1] = c * a01 + s * a11;\n out[2] = c * a02 + s * a12;\n out[3] = c * a10 - s * a00;\n out[4] = c * a11 - s * a01;\n out[5] = c * a12 - s * a02;\n out[6] = a20;\n out[7] = a21;\n out[8] = a22;\n return out;\n}\n;\n/**\r\n * Scales the mat3 by the dimensions in the given vec2\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the matrix to rotate\r\n * @param {vec2} v the vec2 to scale the matrix by\r\n * @returns {mat3} out\r\n **/\n\nexport function scale(out, a, v) {\n var x = v[0],\n y = v[1];\n out[0] = x * a[0];\n out[1] = x * a[1];\n out[2] = x * a[2];\n out[3] = y * a[3];\n out[4] = y * a[4];\n out[5] = y * a[5];\n out[6] = a[6];\n out[7] = a[7];\n out[8] = a[8];\n return out;\n}\n/**\r\n * Creates a matrix from a vector translation\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat3.identity(dest);\r\n * mat3.translate(dest, dest, vec);\r\n *\r\n * @param {mat3} out mat3 receiving operation result\r\n * @param {vec2} v Translation vector\r\n * @returns {mat3} out\r\n */\n\nexport function fromTranslation(out, v) {\n out[0] = 1;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = 1;\n out[5] = 0;\n out[6] = v[0];\n out[7] = v[1];\n out[8] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a given angle\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat3.identity(dest);\r\n * mat3.rotate(dest, dest, rad);\r\n *\r\n * @param {mat3} out mat3 receiving operation result\r\n * @param {Number} rad the angle to rotate the matrix by\r\n * @returns {mat3} out\r\n */\n\nexport function fromRotation(out, rad) {\n var s = Math.sin(rad),\n c = Math.cos(rad);\n out[0] = c;\n out[1] = s;\n out[2] = 0;\n out[3] = -s;\n out[4] = c;\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n}\n/**\r\n * Creates a matrix from a vector scaling\r\n * This is equivalent to (but much faster than):\r\n *\r\n * mat3.identity(dest);\r\n * mat3.scale(dest, dest, vec);\r\n *\r\n * @param {mat3} out mat3 receiving operation result\r\n * @param {vec2} v Scaling vector\r\n * @returns {mat3} out\r\n */\n\nexport function fromScaling(out, v) {\n out[0] = v[0];\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = v[1];\n out[5] = 0;\n out[6] = 0;\n out[7] = 0;\n out[8] = 1;\n return out;\n}\n/**\r\n * Copies the values from a mat2d into a mat3\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat2d} a the matrix to copy\r\n * @returns {mat3} out\r\n **/\n\nexport function fromMat2d(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n out[2] = 0;\n out[3] = a[2];\n out[4] = a[3];\n out[5] = 0;\n out[6] = a[4];\n out[7] = a[5];\n out[8] = 1;\n return out;\n}\n/**\r\n* Calculates a 3x3 matrix from the given quaternion\r\n*\r\n* @param {mat3} out mat3 receiving operation result\r\n* @param {quat} q Quaternion to create matrix from\r\n*\r\n* @returns {mat3} out\r\n*/\n\nexport function fromQuat(out, q) {\n var x = q[0],\n y = q[1],\n z = q[2],\n w = q[3];\n var x2 = x + x;\n var y2 = y + y;\n var z2 = z + z;\n var xx = x * x2;\n var yx = y * x2;\n var yy = y * y2;\n var zx = z * x2;\n var zy = z * y2;\n var zz = z * z2;\n var wx = w * x2;\n var wy = w * y2;\n var wz = w * z2;\n out[0] = 1 - yy - zz;\n out[3] = yx - wz;\n out[6] = zx + wy;\n out[1] = yx + wz;\n out[4] = 1 - xx - zz;\n out[7] = zy - wx;\n out[2] = zx - wy;\n out[5] = zy + wx;\n out[8] = 1 - xx - yy;\n return out;\n}\n/**\r\n* Calculates a 3x3 normal matrix (transpose inverse) from the 4x4 matrix\r\n*\r\n* @param {mat3} out mat3 receiving operation result\r\n* @param {mat4} a Mat4 to derive the normal matrix from\r\n*\r\n* @returns {mat3} out\r\n*/\n\nexport function normalFromMat4(out, a) {\n var a00 = a[0],\n a01 = a[1],\n a02 = a[2],\n a03 = a[3];\n var a10 = a[4],\n a11 = a[5],\n a12 = a[6],\n a13 = a[7];\n var a20 = a[8],\n a21 = a[9],\n a22 = a[10],\n a23 = a[11];\n var a30 = a[12],\n a31 = a[13],\n a32 = a[14],\n a33 = a[15];\n var b00 = a00 * a11 - a01 * a10;\n var b01 = a00 * a12 - a02 * a10;\n var b02 = a00 * a13 - a03 * a10;\n var b03 = a01 * a12 - a02 * a11;\n var b04 = a01 * a13 - a03 * a11;\n var b05 = a02 * a13 - a03 * a12;\n var b06 = a20 * a31 - a21 * a30;\n var b07 = a20 * a32 - a22 * a30;\n var b08 = a20 * a33 - a23 * a30;\n var b09 = a21 * a32 - a22 * a31;\n var b10 = a21 * a33 - a23 * a31;\n var b11 = a22 * a33 - a23 * a32; // Calculate the determinant\n\n var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;\n\n if (!det) {\n return null;\n }\n\n det = 1.0 / det;\n out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;\n out[1] = (a12 * b08 - a10 * b11 - a13 * b07) * det;\n out[2] = (a10 * b10 - a11 * b08 + a13 * b06) * det;\n out[3] = (a02 * b10 - a01 * b11 - a03 * b09) * det;\n out[4] = (a00 * b11 - a02 * b08 + a03 * b07) * det;\n out[5] = (a01 * b08 - a00 * b10 - a03 * b06) * det;\n out[6] = (a31 * b05 - a32 * b04 + a33 * b03) * det;\n out[7] = (a32 * b02 - a30 * b05 - a33 * b01) * det;\n out[8] = (a30 * b04 - a31 * b02 + a33 * b00) * det;\n return out;\n}\n/**\r\n * Generates a 2D projection matrix with the given bounds\r\n *\r\n * @param {mat3} out mat3 frustum matrix will be written into\r\n * @param {number} width Width of your gl context\r\n * @param {number} height Height of gl context\r\n * @returns {mat3} out\r\n */\n\nexport function projection(out, width, height) {\n out[0] = 2 / width;\n out[1] = 0;\n out[2] = 0;\n out[3] = 0;\n out[4] = -2 / height;\n out[5] = 0;\n out[6] = -1;\n out[7] = 1;\n out[8] = 1;\n return out;\n}\n/**\r\n * Returns a string representation of a mat3\r\n *\r\n * @param {mat3} a matrix to represent as a string\r\n * @returns {String} string representation of the matrix\r\n */\n\nexport function str(a) {\n return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' + a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' + a[8] + ')';\n}\n/**\r\n * Returns Frobenius norm of a mat3\r\n *\r\n * @param {mat3} a the matrix to calculate Frobenius norm of\r\n * @returns {Number} Frobenius norm\r\n */\n\nexport function frob(a) {\n return Math.sqrt(Math.pow(a[0], 2) + Math.pow(a[1], 2) + Math.pow(a[2], 2) + Math.pow(a[3], 2) + Math.pow(a[4], 2) + Math.pow(a[5], 2) + Math.pow(a[6], 2) + Math.pow(a[7], 2) + Math.pow(a[8], 2));\n}\n/**\r\n * Adds two mat3's\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the first operand\r\n * @param {mat3} b the second operand\r\n * @returns {mat3} out\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n out[2] = a[2] + b[2];\n out[3] = a[3] + b[3];\n out[4] = a[4] + b[4];\n out[5] = a[5] + b[5];\n out[6] = a[6] + b[6];\n out[7] = a[7] + b[7];\n out[8] = a[8] + b[8];\n return out;\n}\n/**\r\n * Subtracts matrix b from matrix a\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the first operand\r\n * @param {mat3} b the second operand\r\n * @returns {mat3} out\r\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n out[2] = a[2] - b[2];\n out[3] = a[3] - b[3];\n out[4] = a[4] - b[4];\n out[5] = a[5] - b[5];\n out[6] = a[6] - b[6];\n out[7] = a[7] - b[7];\n out[8] = a[8] - b[8];\n return out;\n}\n/**\r\n * Multiply each element of the matrix by a scalar.\r\n *\r\n * @param {mat3} out the receiving matrix\r\n * @param {mat3} a the matrix to scale\r\n * @param {Number} b amount to scale the matrix's elements by\r\n * @returns {mat3} out\r\n */\n\nexport function multiplyScalar(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n out[2] = a[2] * b;\n out[3] = a[3] * b;\n out[4] = a[4] * b;\n out[5] = a[5] * b;\n out[6] = a[6] * b;\n out[7] = a[7] * b;\n out[8] = a[8] * b;\n return out;\n}\n/**\r\n * Adds two mat3's after multiplying each element of the second operand by a scalar value.\r\n *\r\n * @param {mat3} out the receiving vector\r\n * @param {mat3} a the first operand\r\n * @param {mat3} b the second operand\r\n * @param {Number} scale the amount to scale b's elements by before adding\r\n * @returns {mat3} out\r\n */\n\nexport function multiplyScalarAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n out[2] = a[2] + b[2] * scale;\n out[3] = a[3] + b[3] * scale;\n out[4] = a[4] + b[4] * scale;\n out[5] = a[5] + b[5] * scale;\n out[6] = a[6] + b[6] * scale;\n out[7] = a[7] + b[7] * scale;\n out[8] = a[8] + b[8] * scale;\n return out;\n}\n/**\r\n * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)\r\n *\r\n * @param {mat3} a The first matrix.\r\n * @param {mat3} b The second matrix.\r\n * @returns {Boolean} True if the matrices are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8];\n}\n/**\r\n * Returns whether or not the matrices have approximately the same elements in the same position.\r\n *\r\n * @param {mat3} a The first matrix.\r\n * @param {mat3} b The second matrix.\r\n * @returns {Boolean} True if the matrices are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1],\n a2 = a[2],\n a3 = a[3],\n a4 = a[4],\n a5 = a[5],\n a6 = a[6],\n a7 = a[7],\n a8 = a[8];\n var b0 = b[0],\n b1 = b[1],\n b2 = b[2],\n b3 = b[3],\n b4 = b[4],\n b5 = b[5],\n b6 = b[6],\n b7 = b[7],\n b8 = b[8];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8));\n}\n/**\r\n * Alias for {@link mat3.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Alias for {@link mat3.subtract}\r\n * @function\r\n */\n\nexport var sub = subtract;","import { mat4, vec3 } from 'gl-matrix';\nimport { ELEMENT_NOT_EXIST, MUST_STRING_OR_ELEMENT } from '../constants/error';\nimport { Matrix4x4, Offset } from '../types';\n\nexport const getElement = (el: string | HTMLElement, baseElement?: HTMLElement): HTMLElement => {\n if (typeof el === 'string') {\n const queryResult = baseElement\n ? baseElement.querySelector(el)\n : document.querySelector(el);\n if (!queryResult) {\n throw new Error(ELEMENT_NOT_EXIST(el));\n }\n return queryResult as HTMLElement;\n } else if (el.nodeName && el.nodeType === 1) {\n return el;\n } else {\n throw new Error(MUST_STRING_OR_ELEMENT(el));\n }\n};\n\nexport function applyCSS(element: HTMLElement, cssObj: { [keys: string]: string }): void {\n Object.keys(cssObj).forEach(property => {\n (element.style as any)[property] = cssObj[property];\n });\n}\n\nexport function getTransformMatrix(elStyle: CSSStyleDeclaration): mat4 {\n const trVal = elStyle.getPropertyValue('transform');\n const transformStr = /\\(((\\s|\\S)+)\\)/.exec(trVal);\n const matrixVal = transformStr\n ? transformStr[1].split(',').map(val => parseFloat(val)) as Matrix4x4\n : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1] as Matrix4x4;\n if (matrixVal.length === 16 ) {\n return mat4.fromValues(...matrixVal);\n } else {\n // Convert 2d matrix(length 6) to 3d\n const matrix = mat4.create();\n mat4.identity(matrix);\n\n matrix[0] = matrixVal[0];\n matrix[1] = matrixVal[1];\n matrix[4] = matrixVal[2];\n matrix[5] = matrixVal[3];\n matrix[12] = matrixVal[4];\n matrix[13] = matrixVal[5];\n\n return matrix;\n }\n}\n\nexport function getOffsetFromParent(currentOffset: Offset, parentOffset: Offset): vec3 {\n const offsetLeft = currentOffset.left + (currentOffset.width - parentOffset.width) / 2;\n const offsetTop = currentOffset.top + (currentOffset.height - parentOffset.height) / 2;\n\n return vec3.fromValues(offsetLeft, offsetTop, 0);\n}\n\nexport function getRotateOffset(elStyle: CSSStyleDeclaration, currentOffset: Offset): vec3 {\n const axis = (elStyle.transformOrigin as string)\n .split(' ')\n .map(str => parseFloat(str.substring(0, str.length - 2)));\n const ax = axis[0] - currentOffset.width / 2;\n const ay = axis[1] - currentOffset.height / 2;\n\n return vec3.fromValues(ax, ay, 0);\n}\n\nexport function findIndex(iterable: T[], callback: (el: T) => boolean): number {\n for (let i = 0; i < iterable.length; i += 1) {\n const element = iterable[i];\n if (element && callback(element)) {\n return i;\n }\n }\n\n return -1;\n}\n\n// return [0, 1, ...., max - 1]\nexport function range(max: number): number[] {\n const counterArray: number[] = [];\n for (let i = 0; i < max; i += 1) {\n counterArray[i] = i;\n }\n return counterArray;\n}\n\nexport function clamp(val: number, min: number, max: number): number {\n return Math.max(Math.min(val, max), min);\n}\n\nexport function assign(target: object, ...srcs: object[]): object {\n srcs.forEach(source => {\n Object.keys(source).forEach(key => {\n const value = (source as any)[key];\n (target as any)[key] = value;\n });\n });\n\n return target;\n}\n","export const ELEMENT_NOT_EXIST = (selector: string) => `Element with selector \"${selector}\" doesn't exist.`;\nexport const MUST_STRING_OR_ELEMENT = (received: any) => `Element should be provided in string or HTMLElement. Received: ${received}`;\n","import * as glMatrix from \"./common.js\";\n/**\r\n * 2 Dimensional Vector\r\n * @module vec2\r\n */\n\n/**\r\n * Creates a new, empty vec2\r\n *\r\n * @returns {vec2} a new 2D vector\r\n */\n\nexport function create() {\n var out = new glMatrix.ARRAY_TYPE(2);\n\n if (glMatrix.ARRAY_TYPE != Float32Array) {\n out[0] = 0;\n out[1] = 0;\n }\n\n return out;\n}\n/**\r\n * Creates a new vec2 initialized with values from an existing vector\r\n *\r\n * @param {vec2} a vector to clone\r\n * @returns {vec2} a new 2D vector\r\n */\n\nexport function clone(a) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\r\n * Creates a new vec2 initialized with the given values\r\n *\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @returns {vec2} a new 2D vector\r\n */\n\nexport function fromValues(x, y) {\n var out = new glMatrix.ARRAY_TYPE(2);\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\r\n * Copy the values from one vec2 to another\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the source vector\r\n * @returns {vec2} out\r\n */\n\nexport function copy(out, a) {\n out[0] = a[0];\n out[1] = a[1];\n return out;\n}\n/**\r\n * Set the components of a vec2 to the given values\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {Number} x X component\r\n * @param {Number} y Y component\r\n * @returns {vec2} out\r\n */\n\nexport function set(out, x, y) {\n out[0] = x;\n out[1] = y;\n return out;\n}\n/**\r\n * Adds two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function add(out, a, b) {\n out[0] = a[0] + b[0];\n out[1] = a[1] + b[1];\n return out;\n}\n/**\r\n * Subtracts vector b from vector a\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function subtract(out, a, b) {\n out[0] = a[0] - b[0];\n out[1] = a[1] - b[1];\n return out;\n}\n/**\r\n * Multiplies two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function multiply(out, a, b) {\n out[0] = a[0] * b[0];\n out[1] = a[1] * b[1];\n return out;\n}\n/**\r\n * Divides two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function divide(out, a, b) {\n out[0] = a[0] / b[0];\n out[1] = a[1] / b[1];\n return out;\n}\n/**\r\n * Math.ceil the components of a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to ceil\r\n * @returns {vec2} out\r\n */\n\nexport function ceil(out, a) {\n out[0] = Math.ceil(a[0]);\n out[1] = Math.ceil(a[1]);\n return out;\n}\n/**\r\n * Math.floor the components of a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to floor\r\n * @returns {vec2} out\r\n */\n\nexport function floor(out, a) {\n out[0] = Math.floor(a[0]);\n out[1] = Math.floor(a[1]);\n return out;\n}\n/**\r\n * Returns the minimum of two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function min(out, a, b) {\n out[0] = Math.min(a[0], b[0]);\n out[1] = Math.min(a[1], b[1]);\n return out;\n}\n/**\r\n * Returns the maximum of two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec2} out\r\n */\n\nexport function max(out, a, b) {\n out[0] = Math.max(a[0], b[0]);\n out[1] = Math.max(a[1], b[1]);\n return out;\n}\n/**\r\n * Math.round the components of a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to round\r\n * @returns {vec2} out\r\n */\n\nexport function round(out, a) {\n out[0] = Math.round(a[0]);\n out[1] = Math.round(a[1]);\n return out;\n}\n/**\r\n * Scales a vec2 by a scalar number\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the vector to scale\r\n * @param {Number} b amount to scale the vector by\r\n * @returns {vec2} out\r\n */\n\nexport function scale(out, a, b) {\n out[0] = a[0] * b;\n out[1] = a[1] * b;\n return out;\n}\n/**\r\n * Adds two vec2's after scaling the second operand by a scalar value\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @param {Number} scale the amount to scale b by before adding\r\n * @returns {vec2} out\r\n */\n\nexport function scaleAndAdd(out, a, b, scale) {\n out[0] = a[0] + b[0] * scale;\n out[1] = a[1] + b[1] * scale;\n return out;\n}\n/**\r\n * Calculates the euclidian distance between two vec2's\r\n *\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {Number} distance between a and b\r\n */\n\nexport function distance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return Math.sqrt(x * x + y * y);\n}\n/**\r\n * Calculates the squared euclidian distance between two vec2's\r\n *\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {Number} squared distance between a and b\r\n */\n\nexport function squaredDistance(a, b) {\n var x = b[0] - a[0],\n y = b[1] - a[1];\n return x * x + y * y;\n}\n/**\r\n * Calculates the length of a vec2\r\n *\r\n * @param {vec2} a vector to calculate length of\r\n * @returns {Number} length of a\r\n */\n\nexport function length(a) {\n var x = a[0],\n y = a[1];\n return Math.sqrt(x * x + y * y);\n}\n/**\r\n * Calculates the squared length of a vec2\r\n *\r\n * @param {vec2} a vector to calculate squared length of\r\n * @returns {Number} squared length of a\r\n */\n\nexport function squaredLength(a) {\n var x = a[0],\n y = a[1];\n return x * x + y * y;\n}\n/**\r\n * Negates the components of a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to negate\r\n * @returns {vec2} out\r\n */\n\nexport function negate(out, a) {\n out[0] = -a[0];\n out[1] = -a[1];\n return out;\n}\n/**\r\n * Returns the inverse of the components of a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to invert\r\n * @returns {vec2} out\r\n */\n\nexport function inverse(out, a) {\n out[0] = 1.0 / a[0];\n out[1] = 1.0 / a[1];\n return out;\n}\n/**\r\n * Normalize a vec2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a vector to normalize\r\n * @returns {vec2} out\r\n */\n\nexport function normalize(out, a) {\n var x = a[0],\n y = a[1];\n var len = x * x + y * y;\n\n if (len > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len = 1 / Math.sqrt(len);\n }\n\n out[0] = a[0] * len;\n out[1] = a[1] * len;\n return out;\n}\n/**\r\n * Calculates the dot product of two vec2's\r\n *\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {Number} dot product of a and b\r\n */\n\nexport function dot(a, b) {\n return a[0] * b[0] + a[1] * b[1];\n}\n/**\r\n * Computes the cross product of two vec2's\r\n * Note that the cross product must by definition produce a 3D vector\r\n *\r\n * @param {vec3} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @returns {vec3} out\r\n */\n\nexport function cross(out, a, b) {\n var z = a[0] * b[1] - a[1] * b[0];\n out[0] = out[1] = 0;\n out[2] = z;\n return out;\n}\n/**\r\n * Performs a linear interpolation between two vec2's\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the first operand\r\n * @param {vec2} b the second operand\r\n * @param {Number} t interpolation amount, in the range [0-1], between the two inputs\r\n * @returns {vec2} out\r\n */\n\nexport function lerp(out, a, b, t) {\n var ax = a[0],\n ay = a[1];\n out[0] = ax + t * (b[0] - ax);\n out[1] = ay + t * (b[1] - ay);\n return out;\n}\n/**\r\n * Generates a random vector with the given scale\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {Number} [scale] Length of the resulting vector. If ommitted, a unit vector will be returned\r\n * @returns {vec2} out\r\n */\n\nexport function random(out, scale) {\n scale = scale || 1.0;\n var r = glMatrix.RANDOM() * 2.0 * Math.PI;\n out[0] = Math.cos(r) * scale;\n out[1] = Math.sin(r) * scale;\n return out;\n}\n/**\r\n * Transforms the vec2 with a mat2\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the vector to transform\r\n * @param {mat2} m matrix to transform with\r\n * @returns {vec2} out\r\n */\n\nexport function transformMat2(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y;\n out[1] = m[1] * x + m[3] * y;\n return out;\n}\n/**\r\n * Transforms the vec2 with a mat2d\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the vector to transform\r\n * @param {mat2d} m matrix to transform with\r\n * @returns {vec2} out\r\n */\n\nexport function transformMat2d(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[2] * y + m[4];\n out[1] = m[1] * x + m[3] * y + m[5];\n return out;\n}\n/**\r\n * Transforms the vec2 with a mat3\r\n * 3rd vector component is implicitly '1'\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the vector to transform\r\n * @param {mat3} m matrix to transform with\r\n * @returns {vec2} out\r\n */\n\nexport function transformMat3(out, a, m) {\n var x = a[0],\n y = a[1];\n out[0] = m[0] * x + m[3] * y + m[6];\n out[1] = m[1] * x + m[4] * y + m[7];\n return out;\n}\n/**\r\n * Transforms the vec2 with a mat4\r\n * 3rd vector component is implicitly '0'\r\n * 4th vector component is implicitly '1'\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @param {vec2} a the vector to transform\r\n * @param {mat4} m matrix to transform with\r\n * @returns {vec2} out\r\n */\n\nexport function transformMat4(out, a, m) {\n var x = a[0];\n var y = a[1];\n out[0] = m[0] * x + m[4] * y + m[12];\n out[1] = m[1] * x + m[5] * y + m[13];\n return out;\n}\n/**\r\n * Rotate a 2D vector\r\n * @param {vec2} out The receiving vec2\r\n * @param {vec2} a The vec2 point to rotate\r\n * @param {vec2} b The origin of the rotation\r\n * @param {Number} c The angle of rotation\r\n * @returns {vec2} out\r\n */\n\nexport function rotate(out, a, b, c) {\n //Translate point to the origin\n var p0 = a[0] - b[0],\n p1 = a[1] - b[1],\n sinC = Math.sin(c),\n cosC = Math.cos(c); //perform rotation and translate to correct position\n\n out[0] = p0 * cosC - p1 * sinC + b[0];\n out[1] = p0 * sinC + p1 * cosC + b[1];\n return out;\n}\n/**\r\n * Get the angle between two 2D vectors\r\n * @param {vec2} a The first operand\r\n * @param {vec2} b The second operand\r\n * @returns {Number} The angle in radians\r\n */\n\nexport function angle(a, b) {\n var x1 = a[0],\n y1 = a[1],\n x2 = b[0],\n y2 = b[1];\n var len1 = x1 * x1 + y1 * y1;\n\n if (len1 > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len1 = 1 / Math.sqrt(len1);\n }\n\n var len2 = x2 * x2 + y2 * y2;\n\n if (len2 > 0) {\n //TODO: evaluate use of glm_invsqrt here?\n len2 = 1 / Math.sqrt(len2);\n }\n\n var cosine = (x1 * x2 + y1 * y2) * len1 * len2;\n\n if (cosine > 1.0) {\n return 0;\n } else if (cosine < -1.0) {\n return Math.PI;\n } else {\n return Math.acos(cosine);\n }\n}\n/**\r\n * Set the components of a vec2 to zero\r\n *\r\n * @param {vec2} out the receiving vector\r\n * @returns {vec2} out\r\n */\n\nexport function zero(out) {\n out[0] = 0.0;\n out[1] = 0.0;\n return out;\n}\n/**\r\n * Returns a string representation of a vector\r\n *\r\n * @param {vec2} a vector to represent as a string\r\n * @returns {String} string representation of the vector\r\n */\n\nexport function str(a) {\n return 'vec2(' + a[0] + ', ' + a[1] + ')';\n}\n/**\r\n * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)\r\n *\r\n * @param {vec2} a The first vector.\r\n * @param {vec2} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function exactEquals(a, b) {\n return a[0] === b[0] && a[1] === b[1];\n}\n/**\r\n * Returns whether or not the vectors have approximately the same elements in the same position.\r\n *\r\n * @param {vec2} a The first vector.\r\n * @param {vec2} b The second vector.\r\n * @returns {Boolean} True if the vectors are equal, false otherwise.\r\n */\n\nexport function equals(a, b) {\n var a0 = a[0],\n a1 = a[1];\n var b0 = b[0],\n b1 = b[1];\n return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1));\n}\n/**\r\n * Alias for {@link vec2.length}\r\n * @function\r\n */\n\nexport var len = length;\n/**\r\n * Alias for {@link vec2.subtract}\r\n * @function\r\n */\n\nexport var sub = subtract;\n/**\r\n * Alias for {@link vec2.multiply}\r\n * @function\r\n */\n\nexport var mul = multiply;\n/**\r\n * Alias for {@link vec2.divide}\r\n * @function\r\n */\n\nexport var div = divide;\n/**\r\n * Alias for {@link vec2.distance}\r\n * @function\r\n */\n\nexport var dist = distance;\n/**\r\n * Alias for {@link vec2.squaredDistance}\r\n * @function\r\n */\n\nexport var sqrDist = squaredDistance;\n/**\r\n * Alias for {@link vec2.squaredLength}\r\n * @function\r\n */\n\nexport var sqrLen = squaredLength;\n/**\r\n * Perform some operation over an array of vec2s.\r\n *\r\n * @param {Array} a the array of vectors to iterate over\r\n * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed\r\n * @param {Number} offset Number of elements to skip at the beginning of the array\r\n * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array\r\n * @param {Function} fn Function to call for each vector in the array\r\n * @param {Object} [arg] additional argument to pass to fn\r\n * @returns {Array} a\r\n * @function\r\n */\n\nexport var forEach = function () {\n var vec = create();\n return function (a, stride, offset, count, fn, arg) {\n var i, l;\n\n if (!stride) {\n stride = 2;\n }\n\n if (!offset) {\n offset = 0;\n }\n\n if (count) {\n l = Math.min(count * stride + offset, a.length);\n } else {\n l = a.length;\n }\n\n for (i = offset; i < l; i += stride) {\n vec[0] = a[i];\n vec[1] = a[i + 1];\n fn(vec, vec, arg);\n a[i] = vec[0];\n a[i + 1] = vec[1];\n }\n\n return a;\n };\n}();","import { mat4, quat, vec3 } from 'gl-matrix';\nimport { clamp } from './helper';\n\nexport function degToRad(deg: number): number {\n return Math.PI * deg / 180;\n}\n\nexport function radToDeg(rad: number): number {\n return 180 * rad / Math.PI;\n}\n\n// From Three.js https://github.com/mrdoob/three.js/blob/dev/src/math/Euler.js\nexport function quatToEuler(q: quat): vec3 {\n const rotM = mat4.create();\n mat4.fromQuat(rotM, q);\n\n const m11 = rotM[0];\n const m12 = rotM[4];\n // const m13 = rotM[8];\n const m21 = rotM[1];\n const m22 = rotM[5];\n // const m23 = rotM[9];\n const m31 = rotM[2];\n const m32 = rotM[6];\n const m33 = rotM[10];\n\n const euler = vec3.create();\n\n // ZYX\n euler[1] = Math.asin(-clamp(m31, -1, 1));\n if (Math.abs(m31) < 0.99999) {\n euler[0] = Math.atan2(m32, m33);\n euler[2] = Math.atan2(m21, m11);\n } else {\n euler[0] = 0;\n euler[2] = Math.atan2(-m12, m22);\n }\n\n return euler.map(val => radToDeg(val)) as vec3;\n}\n","export const STYLE = {\n VIEWPORT: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n overflow: 'hidden',\n },\n CAMERA: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n 'will-change': 'transform',\n },\n WORLD: {\n width: '100%',\n height: '100%',\n 'transform-style': 'preserve-3d',\n 'will-change': 'transform',\n },\n};\n\nexport const CLASS = {\n VIEWPORT: 'cc-viewport',\n CAMERA: 'cc-camera',\n WORLD: 'cc-world',\n};\n\nexport const OPTIONS = {\n position: [0, 0, 0],\n scale: [1, 1, 1],\n rotation: [0, 0, 0],\n perspective: 0,\n rotateOffset: 0,\n};\n\nexport const UPDATE_OPTIONS = {\n property: 'transform',\n timingFunction: 'ease-out',\n delay: '0ms',\n};\n","import { mat4, vec3, quat } from 'gl-matrix';\nimport { getElement, applyCSS, getTransformMatrix, findIndex, getOffsetFromParent, getRotateOffset, assign } from './utils/helper';\nimport { quatToEuler } from './utils/math';\nimport * as DEFAULT from './constants/default';\nimport { Offset, UpdateOption, ValueOf, Options } from './types';\n\nclass CSSCamera {\n private _element: HTMLElement;\n private _viewportEl: HTMLElement;\n private _cameraEl: HTMLElement;\n private _worldEl: HTMLElement;\n\n private _position: vec3;\n private _scale: vec3;\n private _rotation: vec3;\n private _perspective: number;\n private _rotateOffset: number;\n private _updateTimer: number;\n\n /**\n * Current version of CSSCamera.\n * @example\n * console.log(CSSCamera.VERSION); // ex) 1.0.0\n * @type {string}\n */\n static get VERSION() { return '#__VERSION__#'; }\n\n /**\n * The element provided in the constructor.\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.element === el); // true\n * @type {HTMLElement}\n */\n public get element() { return this._element; }\n\n /**\n * The reference of viewport DOM element.\n * @type {HTMLElement}\n */\n public get viewportEl() { return this._viewportEl; }\n\n /**\n * The reference of camera DOM element.\n * @type {HTMLElement}\n */\n public get cameraEl() { return this._cameraEl; }\n\n /**\n * The reference of world DOM element.\n * @type {HTMLElement}\n */\n public get worldEl() { return this._worldEl; }\n\n /**\n * The current position as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.position); // [0, 0, 0];\n * camera.position = [0, 0, 300];\n * console.log(camera.position); // [0, 0, 300];\n * @type {number[]}\n */\n public get position() { return [...this._position]; }\n\n /**\n * The current scale as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.scale); // [1, 1, 1];\n * camera.scale = [5, 1, 1];\n * console.log(camera.scale); // [5, 1, 1];\n * @type {number[]}\n */\n public get scale() { return [...this._scale]; }\n\n /**\n * The current Euler rotation angles in degree as number array([x, y, z]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.rotation); // [0, 0, 0];\n * camera.rotation = [90, 0, 0];\n * console.log(camera.rotation); // [90, 0, 0];\n * @type {number[]}\n */\n public get rotation() { return [...this._rotation]; }\n\n /**\n * The current quaternion rotation as number array([x, y, z, w]).\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.quaternion); // [0, 0, 0, 1];\n * camera.rotation = [90, 0, 0];\n * console.log(camera.quaternion); // [0.7071067690849304, 0, 0, 0.7071067690849304];\n * camera.quaternion = [0, 0, 0, 1];\n * console.log(camera.rotation); // [0, -0, 0];\n * @type {number[]}\n */\n public get quaternion() {\n const r = this._rotation;\n const quaternion = quat.fromEuler(quat.create(), r[0], r[1], r[2]);\n\n return [...quaternion];\n }\n\n /**\n * The current perspective value that will be applied to viewport element.\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.perspective); // 300\n * @type {number}\n */\n public get perspective() { return this._perspective; }\n\n /**\n * The current rotate offset value that will be applied to camera element.\n * The camera will be as far away from the focal point as this value.\n * |![rot0](https://woodneck.github.io/css-camera/asset/rot0.gif)|![rot150](https://woodneck.github.io/css-camera/asset/rot150.gif)|\n * |:---:|:---:|\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * camera.rotateOffset = 100;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(400px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * @type {number}\n */\n public get rotateOffset() { return this._rotateOffset; }\n\n /**\n * CSS string can be applied to camera element based on current transform.\n * @example\n * const camera = new CSSCamera(el);\n * camera.perspective = 300;\n * console.log(camera.cameraCSS); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);\n * @type {string}\n */\n public get cameraCSS() {\n const perspective = this._perspective;\n const rotateOffset = this._rotateOffset;\n const rotation = this._rotation;\n const scale = this._scale;\n\n // Rotate in order of Z - Y - X\n // tslint:disable-next-line: max-line-length\n return `scale3d(${scale[0]}, ${scale[1]}, ${scale[2]}) translateZ(${perspective - rotateOffset}px) rotateX(${rotation[0]}deg) rotateY(${rotation[1]}deg) rotateZ(${rotation[2]}deg)`;\n }\n\n /**\n * CSS string can be applied to world element based on current transform.\n * ```\n * const camera = new CSSCamera(el);\n * console.log(camera.worldCSS); // \"translate3d(0px, 0px, 0px)\";\n * camera.translate(0, 0, 300);\n * console.log(camera.worldCSS); // \"translate3d(0px, 0px, -300px)\";\n * ```\n * @type {string}\n */\n public get worldCSS() {\n const position = this._position;\n\n return `translate3d(${-position[0]}px, ${-position[1]}px, ${-position[2]}px)`;\n }\n\n public set position(val: number[]) { this._position = vec3.fromValues(val[0], val[1], val[2]); }\n public set scale(val: number[]) { this._scale = vec3.fromValues(val[0], val[1], val[2]); }\n public set rotation(val: number[]) { this._rotation = vec3.fromValues(val[0], val[1], val[2]); }\n public set quaternion(val: number[]) { this._rotation = quatToEuler(quat.fromValues(val[0], val[1], val[2], val[3])); }\n public set perspective(val: number) { this._perspective = val; }\n public set rotateOffset(val: number) { this._rotateOffset = val; }\n\n /**\n * Create new CSSCamera with given element / selector.\n * @param - The element to apply camera. Can be HTMLElement or CSS selector.\n * @param {Partial} [options] Camera options\n * @param {number[]} [options.position=[0, 0, 0]] Initial position of the camera.\n * @param {number[]} [options.scale=[1, 1, 1]] Initial scale of the camera.\n * @param {number[]} [options.rotation=[0, 0, 0]] Initial Euler rotation angles(x, y, z) of the camera in degree.\n * @param {number} [options.perspective=0] Initial perspective of the camera.\n * @param {number} [options.rotateOffset=0] Initial rotate offset of the camera.\n * @example\n * const camera = new CSSCamera(\"#el\", {\n * position: [0, 0, 150], // Initial pos(x, y, z)\n * rotation: [90, 0, 0], // Initial rotation(x, y, z, in degree)\n * perspective: 300 // CSS \"perspective\" value to apply\n * });\n */\n constructor(el: string | HTMLElement, options: Partial = {}) {\n this._element = getElement(el);\n\n const op = assign(assign({}, DEFAULT.OPTIONS), options) as Options;\n\n this._position = vec3.fromValues(op.position[0], op.position[1], op.position[2]);\n this._scale = vec3.fromValues(op.scale[0], op.scale[1], op.scale[2]);\n this._rotation = vec3.fromValues(op.rotation[0], op.rotation[1], op.rotation[2]);\n this._perspective = op.perspective;\n this._rotateOffset = op.rotateOffset;\n this._updateTimer = -1;\n\n const element = this._element;\n const viewport = document.createElement('div');\n const camera = viewport.cloneNode() as HTMLElement;\n const world = viewport.cloneNode() as HTMLElement;\n\n viewport.className = DEFAULT.CLASS.VIEWPORT;\n camera.className = DEFAULT.CLASS.CAMERA;\n world.className = DEFAULT.CLASS.WORLD;\n\n applyCSS(viewport, DEFAULT.STYLE.VIEWPORT);\n applyCSS(camera, DEFAULT.STYLE.CAMERA);\n applyCSS(world, DEFAULT.STYLE.WORLD);\n\n camera.appendChild(world);\n viewport.appendChild(camera);\n\n this._viewportEl = viewport;\n this._cameraEl = camera;\n this._worldEl = world;\n\n // EL's PARENT -> VIEWPORT -> CAMERA -> WORLD -> EL\n element.parentElement!.insertBefore(viewport, element);\n world.appendChild(element);\n\n this.update(0);\n }\n\n /**\n * Focus a camera to given element.\n * After focus, element will be in front of camera with no rotation applied.\n * Also, it will have original width / height if neither [scale](#scale) nor [perspectiveOffset](#perspectiveOffset) is applied.\n * This method won't work if any of element's parent except camera element has scale applied.\n * @param - The element to focus. Can be HTMLElement or CSS selector.\n * @return {CSSCamera} The instance itself\n */\n public focus(el: string | HTMLElement): this {\n const element = getElement(el);\n const focusMatrix = this._getFocusMatrix(element);\n\n const rotation = quat.create();\n const translation = vec3.create();\n mat4.getRotation(rotation, focusMatrix);\n mat4.getTranslation(translation, focusMatrix);\n\n const eulerAngle = quatToEuler(rotation);\n\n vec3.negate(eulerAngle, eulerAngle);\n\n this._rotation = eulerAngle;\n this._position = translation;\n return this;\n }\n\n /**\n * Translate a camera in its local coordinate space.\n * For example, `camera.translateLocal(0, 0, -300)` will always move camera to direction where it's seeing.\n * @param - Amount of horizontal translation, in px.\n * @param - Amount of vertical translation, in px.\n * @param - Amount of translation in view direction, in px.\n * @return {CSSCamera} The instance itself\n */\n public translateLocal(x: number = 0, y: number = 0, z: number = 0): this {\n const position = this._position;\n const rotation = this._rotation;\n\n const transVec = vec3.fromValues(x, y, z);\n const rotQuat = quat.create();\n quat.fromEuler(rotQuat, -rotation[0], -rotation[1], -rotation[2]);\n vec3.transformQuat(transVec, transVec, rotQuat);\n\n vec3.add(position, position, transVec);\n return this;\n }\n\n /**\n * Translate a camera in world(absolute) coordinate space.\n * @param - Amount of translation in x axis, in px.\n * @param - Amount of translation in y axis, in px.\n * @param - Amount of translation in z axis, in px.\n * @return {CSSCamera} The instance itself\n */\n public translate(x: number = 0, y: number = 0, z: number = 0): this {\n vec3.add(this._position, this._position, vec3.fromValues(x, y, z));\n\n return this;\n }\n\n /**\n * Rotate a camera in world(absolute) coordinate space.\n * @param - Amount of rotation in x axis, in degree.\n * @param - Amount of rotation in y axis, in degree.\n * @param - Amount of rotation in z axis, in degree.\n * @return {CSSCamera} The instance itself\n */\n public rotate(x: number = 0, y: number = 0, z: number = 0): this {\n vec3.add(this._rotation, this._rotation, vec3.fromValues(x, y, z));\n\n return this;\n }\n\n /**\n * Updates a camera CSS with given duration.\n * Every other camera transforming properties / methods will be batched until this method is called.\n * @example\n * const camera = new CSSCamera(el);\n * console.log(camera.cameraEl.style.transform); // ''\n *\n * camera.perspective = 300;\n * camera.translate(0, 0, 300);\n * camera.rotate(0, 90, 0);\n * console.log(camera.cameraEl.style.transform); // '', Not changed!\n *\n * await camera.update(1000); // Camera style is updated.\n * console.log(camera.cameraEl.style.transform); // scale3d(1, 1, 1) translateZ(300px) rotateX(0deg) rotateY(90deg) rotateZ(0deg)\n *\n * // When if you want to apply multiple properties\n * camera.update(1000, {\n * property: \"transform, background-color\",\n * timingFunction: \"ease-out, ease-out\", // As same with CSS, you should assign values to each property\n * delay: \"0ms, 100ms\"\n * });\n * @param - Transition duration in ms.\n * @param {Partial} [options] Transition options.\n * @param {string} [options.property=\"transform\"] CSS [transition-property](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-property) to apply.\n * @param {string} [options.timingFunction=\"ease-out\"] CSS [transition-timing-function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function) to apply.\n * @param {string} [options.delay=\"0ms\"] CSS [transition-delay](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-delay) to apply.\n * @return {Promise} A promise resolving instance itself\n */\n public async update(duration: number = 0, options: Partial = {}): Promise {\n applyCSS(this._viewportEl, { perspective: `${this.perspective}px` });\n applyCSS(this._cameraEl, { transform: this.cameraCSS });\n applyCSS(this._worldEl, { transform: this.worldCSS });\n\n const updateOptions = assign(assign({}, DEFAULT.UPDATE_OPTIONS), options) as UpdateOption;\n\n if (duration > 0) {\n if (this._updateTimer > 0) {\n window.clearTimeout(this._updateTimer);\n }\n\n const transitionDuration = `${duration}ms`;\n const updateOption = Object.keys(updateOptions).reduce((option: {[key: string]: ValueOf}, key) => {\n option[`transition${key.charAt(0).toUpperCase() + key.slice(1)}`] = updateOptions[key as keyof UpdateOption]!;\n return option;\n }, {});\n\n const finalOption = {\n transitionDuration,\n ...updateOption,\n };\n\n [this._viewportEl, this._cameraEl, this._worldEl].forEach(el => {\n applyCSS(el, finalOption);\n });\n }\n\n return new Promise(resolve => {\n // Make sure to use requestAnimationFrame even if duration is 0\n // To make sure DOM is updated, for successive update() calls.\n if (duration > 0) {\n this._updateTimer = window.setTimeout(() => {\n // Reset transition values\n [this._viewportEl, this._cameraEl, this._worldEl].forEach(el => {\n applyCSS(el, { transition: '' });\n });\n this._updateTimer = -1;\n resolve();\n }, duration);\n } else {\n requestAnimationFrame(() => {\n resolve();\n });\n }\n });\n }\n\n private _getFocusMatrix(element: HTMLElement): mat4 {\n const elements: HTMLElement[] = [];\n while (element) {\n elements.push(element);\n if (element === this._element) break;\n element = element.parentElement!;\n }\n\n // Order by shallow to deep\n elements.reverse();\n\n const elStyles = elements.map(el => window.getComputedStyle(el));\n\n // Find first element that transform-style is not preserve-3d\n // As all childs of that element is affected by its matrix\n const firstFlatIndex = findIndex(elStyles, style => style.transformStyle !== 'preserve-3d');\n if (firstFlatIndex > 0) { // el doesn't have to be preserve-3d'ed\n elStyles.splice(firstFlatIndex + 1);\n }\n\n let parentOffset: Offset = {\n left: 0,\n top: 0,\n width: this.viewportEl.offsetWidth,\n height: this.viewportEl.offsetHeight,\n };\n\n // Accumulated rotation\n const accRotation = quat.identity(quat.create());\n // Assume center of screen as (0, 0, 0)\n const centerPos = vec3.fromValues(0, 0, 0);\n\n elStyles.forEach((style, idx) => {\n const el = elements[idx];\n const currentOffset = {\n left: el.offsetLeft,\n top: el.offsetTop,\n width: el.offsetWidth,\n height: el.offsetHeight,\n };\n const transformMat = getTransformMatrix(style);\n const offsetFromParent = getOffsetFromParent(currentOffset, parentOffset);\n vec3.transformQuat(offsetFromParent, offsetFromParent, accRotation);\n\n vec3.add(centerPos, centerPos, offsetFromParent);\n\n const rotateOffset = getRotateOffset(style, currentOffset);\n vec3.transformQuat(rotateOffset, rotateOffset, accRotation);\n\n const transformOrigin = vec3.clone(centerPos);\n vec3.add(transformOrigin, transformOrigin, rotateOffset);\n\n const centerFromOrigin = vec3.create();\n vec3.sub(centerFromOrigin, centerPos, transformOrigin);\n\n const invAccRotation = quat.invert(quat.create(), accRotation);\n vec3.transformQuat(centerFromOrigin, centerFromOrigin, invAccRotation);\n vec3.transformMat4(centerFromOrigin, centerFromOrigin, transformMat);\n vec3.transformQuat(centerFromOrigin, centerFromOrigin, accRotation);\n\n const newCenterPos = vec3.add(vec3.create(), transformOrigin, centerFromOrigin);\n const rotation = mat4.getRotation(quat.create(), transformMat);\n\n vec3.copy(centerPos, newCenterPos);\n quat.mul(accRotation, accRotation, rotation);\n parentOffset = currentOffset;\n });\n\n const perspective = vec3.fromValues(0, 0, this.perspective);\n vec3.transformQuat(perspective, perspective, accRotation);\n vec3.add(centerPos, centerPos, perspective);\n\n const matrix = mat4.create();\n mat4.fromRotationTranslation(matrix, accRotation, centerPos);\n\n return matrix;\n }\n}\n\nexport default CSSCamera;\n"],"names":["EPSILON","ARRAY_TYPE","Float32Array","Array","Math","random","PI","create","out","glMatrix","fromValues","m00","m01","m02","m03","m10","m11","m12","m13","m20","m21","m22","m23","m30","m31","m32","m33","identity","multiply","a","b","a00","a01","a02","a03","a10","a11","a12","a13","a20","a21","a22","a23","a30","a31","a32","a33","b0","b1","b2","b3","fromRotationTranslation","q","v","x","y","z","w","x2","y2","z2","xx","xy","xz","yy","yz","zz","wx","wy","wz","getTranslation","mat","getRotation","trace","S","sqrt","fromQuat","yx","zx","zy","subtract","b00","b01","b02","b03","b04","b05","b06","b07","b08","b09","b10","b11","det","rad","axis","s","c","t","b12","b20","b21","b22","len","sin","cos","translation","bx","by","bz","bw","ax","ay","az","aw","magnitude","sx","sy","sz","o","ox","oy","oz","out0","out1","out2","out4","out5","out6","out8","out9","out10","left","right","bottom","top","near","far","rl","tb","nf","fovy","aspect","f","tan","Infinity","fov","upTan","upDegrees","downTan","downDegrees","leftTan","leftDegrees","rightTan","rightDegrees","xScale","yScale","lr","bt","eye","center","up","x0","x1","y0","y1","z0","z1","eyex","eyey","eyez","upx","upy","upz","centerx","centery","centerz","abs","target","pow","scale","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","a14","a15","b4","b5","b6","b7","b8","b9","b13","b14","b15","max","add","cross","transformQuat","qx","qy","qz","qw","uvx","uvy","uvz","uuvx","uuvy","uuvz","w2","vec","sub","setAxisAngle","slerp","omega","cosom","sinom","scale0","scale1","acos","invert","dot","invDot","fromMat3","m","fRoot","fTrace","i","j","k","fromEuler","halfToRad","cx","cy","cz","tmpvec3","xUnitVec3","yUnitVec3","temp1","temp2","matr","mul","normalize","vec3","mat3","getElement","el","baseElement","queryResult","querySelector","document","Error","selector","ELEMENT_NOT_EXIST","nodeName","nodeType","received","MUST_STRING_OR_ELEMENT","applyCSS","element","cssObj","Object","keys","forEach","property","style","assign","_i","srcs","source","key","value","quatToEuler","rotM","mat4","euler","asin","val","min","clamp","atan2","map","radToDeg","STYLE","width","height","overflow","CLASS","OPTIONS","position","rotation","perspective","rotateOffset","UPDATE_OPTIONS","timingFunction","delay","options","_element","op","DEFAULT","_position","_scale","_rotation","_perspective","_rotateOffset","_updateTimer","this","viewport","createElement","camera","cloneNode","world","className","appendChild","_viewportEl","_cameraEl","_worldEl","parentElement","insertBefore","update","CSSCamera","r","quat","focusMatrix","_getFocusMatrix","eulerAngle","transVec","rotQuat","duration","Promise","transform","cameraCSS","worldCSS","updateOptions","window","clearTimeout","transitionDuration","updateOption","reduce","option","charAt","toUpperCase","slice","finalOption_1","resolve","_this","setTimeout","transition","requestAnimationFrame","elements","push","reverse","elStyles","getComputedStyle","firstFlatIndex","iterable","callback","length","findIndex","transformStyle","splice","parentOffset","viewportEl","offsetWidth","offsetHeight","accRotation","centerPos","idx","currentOffset","offsetLeft","offsetTop","transformMat","elStyle","trVal","getPropertyValue","transformStr","exec","matrixVal","split","parseFloat","matrix","getTransformMatrix","offsetFromParent","getOffsetFromParent","transformOrigin","str","substring","getRotateOffset","centerFromOrigin","newCenterPos"],"mappings":";;;;;;;;0yDAKO,IAAIA,EAAU,KACVC,EAAqC,oBAAjBC,aAA+BA,aAAeC,MACzDC,KAAKC,OAUZD,KAAKE,GCLX,SAASC,QACVC,EAAM,IAAIC,EAAoB,WAE9BA,GAAuBP,eACzBM,EAAI,GAAK,EACTA,EAAI,GAAK,EACTA,EAAI,GAAK,EACTA,EAAI,GAAK,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B,EAAI3B,EAAE,GACN4B,EAAI8K,EAAE,GAAKjL,EAAIiL,EAAE,GAAKhL,EAAIgL,EAAE,IAAM/K,EAAI+K,EAAE,IAC5C9K,EAAIA,GAAK,EACTjD,EAAI,IAAM+N,EAAE,GAAKjL,EAAIiL,EAAE,GAAKhL,EAAIgL,EAAE,GAAK/K,EAAI+K,EAAE,KAAO9K,EACpDjD,EAAI,IAAM+N,EAAE,GAAKjL,EAAIiL,EAAE,GAAKhL,EAAIgL,EAAE,GAAK/K,EAAI+K,EAAE,KAAO9K,EACpDjD,EAAI,IAAM+N,EAAE,GAAKjL,EAAIiL,EAAE,GAAKhL,EAAIgL,EAAE,IAAM/K,EAAI+K,EAAE,KAAO9K,EStDjDiM,CAAmBiJ,EAAkBA,EAAkBjB,GACvDhI,EAAmBiJ,EAAkBA,EAAkBvB,OAEjDwB,EAAelJ,EAASA,IAAe6I,EAAiBI,GACxDlG,EAAWhB,EAAiBgD,IAAeiD,IT3WhD,SAAclX,EAAKqB,GACxBrB,EAAI,GAAKqB,EAAE,GACXrB,EAAI,GAAKqB,EAAE,GACXrB,EAAI,GAAKqB,EAAE,GS0WP6N,CAAU2H,EAAWuB,GACrBnE,EAAS2C,EAAaA,EAAa3E,GACnCuE,EAAeO,QAGX7E,EAAchD,EAAgB,EAAG,EAAG+D,KAAKf,aAC/ChD,EAAmBgD,EAAaA,EAAa0E,GAC7C1H,EAAS2H,EAAWA,EAAW3E,OAEzByF,EAAS1G,WACfA,EAA6B0G,EAAQf,EAAaC,GAE3Cc"} \ No newline at end of file diff --git a/lib/declaration/CSSCamera.d.ts b/lib/declaration/CSSCamera.d.ts new file mode 100644 index 0000000..6bc8cc1 --- /dev/null +++ b/lib/declaration/CSSCamera.d.ts @@ -0,0 +1,34 @@ +import { UpdateOption, Options } from './types'; +declare class CSSCamera { + private _element; + private _viewportEl; + private _cameraEl; + private _worldEl; + private _position; + private _scale; + private _rotation; + private _perspective; + private _rotateOffset; + private _updateTimer; + static readonly VERSION: string; + readonly element: HTMLElement; + readonly viewportEl: HTMLElement; + readonly cameraEl: HTMLElement; + readonly worldEl: HTMLElement; + position: number[]; + scale: number[]; + rotation: number[]; + quaternion: number[]; + perspective: number; + rotateOffset: number; + readonly cameraCSS: string; + readonly worldCSS: string; + constructor(el: string | HTMLElement, options?: Partial); + focus(el: string | HTMLElement): this; + translateLocal(x?: number, y?: number, z?: number): this; + translate(x?: number, y?: number, z?: number): this; + rotate(x?: number, y?: number, z?: number): this; + update(duration?: number, options?: Partial): Promise; + private _getFocusMatrix; +} +export default CSSCamera; diff --git a/lib/declaration/constants/default.d.ts b/lib/declaration/constants/default.d.ts new file mode 100644 index 0000000..ca54810 --- /dev/null +++ b/lib/declaration/constants/default.d.ts @@ -0,0 +1,37 @@ +export declare const STYLE: { + VIEWPORT: { + width: string; + height: string; + 'transform-style': string; + overflow: string; + }; + CAMERA: { + width: string; + height: string; + 'transform-style': string; + 'will-change': string; + }; + WORLD: { + width: string; + height: string; + 'transform-style': string; + 'will-change': string; + }; +}; +export declare const CLASS: { + VIEWPORT: string; + CAMERA: string; + WORLD: string; +}; +export declare const OPTIONS: { + position: number[]; + scale: number[]; + rotation: number[]; + perspective: number; + rotateOffset: number; +}; +export declare const UPDATE_OPTIONS: { + property: string; + timingFunction: string; + delay: string; +}; diff --git a/lib/declaration/constants/error.d.ts b/lib/declaration/constants/error.d.ts new file mode 100644 index 0000000..c5b6257 --- /dev/null +++ b/lib/declaration/constants/error.d.ts @@ -0,0 +1,2 @@ +export declare const ELEMENT_NOT_EXIST: (selector: string) => string; +export declare const MUST_STRING_OR_ELEMENT: (received: any) => string; diff --git a/lib/declaration/index.d.ts b/lib/declaration/index.d.ts new file mode 100644 index 0000000..ac83edb --- /dev/null +++ b/lib/declaration/index.d.ts @@ -0,0 +1,3 @@ +import CSSCamera from './CSSCamera'; +export * from './types'; +export default CSSCamera; diff --git a/lib/declaration/index.umd.d.ts b/lib/declaration/index.umd.d.ts new file mode 100644 index 0000000..513764c --- /dev/null +++ b/lib/declaration/index.umd.d.ts @@ -0,0 +1,2 @@ +import CSSCamera from './CSSCamera'; +export default CSSCamera; diff --git a/lib/declaration/types.d.ts b/lib/declaration/types.d.ts new file mode 100644 index 0000000..b6541db --- /dev/null +++ b/lib/declaration/types.d.ts @@ -0,0 +1,20 @@ +export declare type ValueOf = T[keyof T]; +export declare type Matrix4x4 = [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number]; +export interface Options { + position: number[]; + scale: number[]; + rotation: number[]; + perspective: number; + rotateOffset: number; +} +export interface Offset { + left: number; + top: number; + width: number; + height: number; +} +export interface UpdateOption { + property: string; + timingFunction: string; + delay: string; +} diff --git a/lib/declaration/utils/helper.d.ts b/lib/declaration/utils/helper.d.ts new file mode 100644 index 0000000..1afbf05 --- /dev/null +++ b/lib/declaration/utils/helper.d.ts @@ -0,0 +1,13 @@ +import { mat4, vec3 } from 'gl-matrix'; +import { Offset } from '../types'; +export declare const getElement: (el: string | HTMLElement, baseElement?: HTMLElement | undefined) => HTMLElement; +export declare function applyCSS(element: HTMLElement, cssObj: { + [keys: string]: string; +}): void; +export declare function getTransformMatrix(elStyle: CSSStyleDeclaration): mat4; +export declare function getOffsetFromParent(currentOffset: Offset, parentOffset: Offset): vec3; +export declare function getRotateOffset(elStyle: CSSStyleDeclaration, currentOffset: Offset): vec3; +export declare function findIndex(iterable: T[], callback: (el: T) => boolean): number; +export declare function range(max: number): number[]; +export declare function clamp(val: number, min: number, max: number): number; +export declare function assign(target: object, ...srcs: object[]): object; diff --git a/lib/declaration/utils/math.d.ts b/lib/declaration/utils/math.d.ts new file mode 100644 index 0000000..814205b --- /dev/null +++ b/lib/declaration/utils/math.d.ts @@ -0,0 +1,4 @@ +import { quat, vec3 } from 'gl-matrix'; +export declare function degToRad(deg: number): number; +export declare function radToDeg(rad: number): number; +export declare function quatToEuler(q: quat): vec3; diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..f349f04 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,3 @@ +import CSSCamera from './CSSCamera'; +export default CSSCamera; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/index.js.map b/lib/index.js.map new file mode 100644 index 0000000..2951f58 --- /dev/null +++ b/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AAGpC,eAAe,SAAS,CAAC"} \ No newline at end of file diff --git a/lib/index.umd.js b/lib/index.umd.js new file mode 100644 index 0000000..d62e44f --- /dev/null +++ b/lib/index.umd.js @@ -0,0 +1,3 @@ +import CSSCamera from './CSSCamera'; +export default CSSCamera; +//# sourceMappingURL=index.umd.js.map \ No newline at end of file diff --git a/lib/index.umd.js.map b/lib/index.umd.js.map new file mode 100644 index 0000000..120a8c8 --- /dev/null +++ b/lib/index.umd.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.umd.js","sourceRoot":"","sources":["../src/index.umd.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC,eAAe,SAAS,CAAC"} \ No newline at end of file diff --git a/lib/types.js b/lib/types.js new file mode 100644 index 0000000..5b2306a --- /dev/null +++ b/lib/types.js @@ -0,0 +1 @@ +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/lib/types.js.map b/lib/types.js.map new file mode 100644 index 0000000..c768b79 --- /dev/null +++ b/lib/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib/utils/helper.js b/lib/utils/helper.js new file mode 100644 index 0000000..a0ca974 --- /dev/null +++ b/lib/utils/helper.js @@ -0,0 +1,92 @@ +import * as tslib_1 from "tslib"; +import { mat4, vec3 } from 'gl-matrix'; +import { ELEMENT_NOT_EXIST, MUST_STRING_OR_ELEMENT } from '../constants/error'; +export var getElement = function (el, baseElement) { + if (typeof el === 'string') { + var queryResult = baseElement + ? baseElement.querySelector(el) + : document.querySelector(el); + if (!queryResult) { + throw new Error(ELEMENT_NOT_EXIST(el)); + } + return queryResult; + } + else if (el.nodeName && el.nodeType === 1) { + return el; + } + else { + throw new Error(MUST_STRING_OR_ELEMENT(el)); + } +}; +export function applyCSS(element, cssObj) { + Object.keys(cssObj).forEach(function (property) { + element.style[property] = cssObj[property]; + }); +} +export function getTransformMatrix(elStyle) { + var trVal = elStyle.getPropertyValue('transform'); + var transformStr = /\(((\s|\S)+)\)/.exec(trVal); + var matrixVal = transformStr + ? transformStr[1].split(',').map(function (val) { return parseFloat(val); }) + : [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; + if (matrixVal.length === 16) { + return mat4.fromValues.apply(mat4, tslib_1.__spread(matrixVal)); + } + else { + var matrix = mat4.create(); + mat4.identity(matrix); + matrix[0] = matrixVal[0]; + matrix[1] = matrixVal[1]; + matrix[4] = matrixVal[2]; + matrix[5] = matrixVal[3]; + matrix[12] = matrixVal[4]; + matrix[13] = matrixVal[5]; + return matrix; + } +} +export function getOffsetFromParent(currentOffset, parentOffset) { + var offsetLeft = currentOffset.left + (currentOffset.width - parentOffset.width) / 2; + var offsetTop = currentOffset.top + (currentOffset.height - parentOffset.height) / 2; + return vec3.fromValues(offsetLeft, offsetTop, 0); +} +export function getRotateOffset(elStyle, currentOffset) { + var axis = elStyle.transformOrigin + .split(' ') + .map(function (str) { return parseFloat(str.substring(0, str.length - 2)); }); + var ax = axis[0] - currentOffset.width / 2; + var ay = axis[1] - currentOffset.height / 2; + return vec3.fromValues(ax, ay, 0); +} +export function findIndex(iterable, callback) { + for (var i = 0; i < iterable.length; i += 1) { + var element = iterable[i]; + if (element && callback(element)) { + return i; + } + } + return -1; +} +export function range(max) { + var counterArray = []; + for (var i = 0; i < max; i += 1) { + counterArray[i] = i; + } + return counterArray; +} +export function clamp(val, min, max) { + return Math.max(Math.min(val, max), min); +} +export function assign(target) { + var srcs = []; + for (var _i = 1; _i < arguments.length; _i++) { + srcs[_i - 1] = arguments[_i]; + } + srcs.forEach(function (source) { + Object.keys(source).forEach(function (key) { + var value = source[key]; + target[key] = value; + }); + }); + return target; +} +//# sourceMappingURL=helper.js.map \ No newline at end of file diff --git a/lib/utils/helper.js.map b/lib/utils/helper.js.map new file mode 100644 index 0000000..ea83b74 --- /dev/null +++ b/lib/utils/helper.js.map @@ -0,0 +1 @@ +{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/utils/helper.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAG/E,MAAM,CAAC,IAAM,UAAU,GAAG,UAAC,EAAwB,EAAE,WAAyB;IAC1E,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE;QACxB,IAAM,WAAW,GAAG,WAAW;YAC7B,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC;YAC/B,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;QAC/B,IAAI,CAAC,WAAW,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC;SAC1C;QACD,OAAO,WAA0B,CAAC;KACrC;SAAM,IAAI,EAAE,CAAC,QAAQ,IAAI,EAAE,CAAC,QAAQ,KAAK,CAAC,EAAE;QACzC,OAAO,EAAE,CAAC;KACb;SAAM;QACH,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC;KAC/C;AACL,CAAC,CAAC;AAEF,MAAM,UAAU,QAAQ,CAAC,OAAoB,EAAE,MAAkC;IAC/E,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAA,QAAQ;QACjC,OAAO,CAAC,KAAa,CAAC,QAAQ,CAAC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,CAAC,CAAC;QAC5B,IAAI,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,EAAE;YAChC,OAAO,CAAC,CAAC;SACV;KACF;IAED,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC;AAGD,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,IAAM,YAAY,GAAa,EAAE,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE;QAC/B,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;KACrB;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,GAAW,EAAE,GAAW,EAAE,GAAW;IACzD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,MAAc;IAAE,cAAiB;SAAjB,UAAiB,EAAjB,qBAAiB,EAAjB,IAAiB;QAAjB,6BAAiB;;IACtD,IAAI,CAAC,OAAO,CAAC,UAAA,MAAM;QACjB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,UAAA,GAAG;YAC7B,IAAM,KAAK,GAAI,MAAc,CAAC,GAAG,CAAC,CAAC;YAClC,MAAc,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"} \ No newline at end of file diff --git a/lib/utils/math.js b/lib/utils/math.js new file mode 100644 index 0000000..e6997b2 --- /dev/null +++ b/lib/utils/math.js @@ -0,0 +1,31 @@ +import { mat4, vec3 } from 'gl-matrix'; +import { clamp } from './helper'; +export function degToRad(deg) { + return Math.PI * deg / 180; +} +export function radToDeg(rad) { + return 180 * rad / Math.PI; +} +export function quatToEuler(q) { + var rotM = mat4.create(); + mat4.fromQuat(rotM, q); + var m11 = rotM[0]; + var m12 = rotM[4]; + var m21 = rotM[1]; + var m22 = rotM[5]; + var m31 = rotM[2]; + var m32 = rotM[6]; + var m33 = rotM[10]; + var euler = vec3.create(); + euler[1] = Math.asin(-clamp(m31, -1, 1)); + if (Math.abs(m31) < 0.99999) { + euler[0] = Math.atan2(m32, m33); + euler[2] = Math.atan2(m21, m11); + } + else { + euler[0] = 0; + euler[2] = Math.atan2(-m12, m22); + } + return euler.map(function (val) { return radToDeg(val); }); +} +//# sourceMappingURL=math.js.map \ No newline at end of file diff --git a/lib/utils/math.js.map b/lib/utils/math.js.map new file mode 100644 index 0000000..9970a25 --- /dev/null +++ b/lib/utils/math.js.map @@ -0,0 +1 @@ +{"version":3,"file":"math.js","sourceRoot":"","sources":["../../src/utils/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAQ,IAAI,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,OAAO,IAAI,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,GAAW;IAClC,OAAO,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC;AAC7B,CAAC;AAGD,MAAM,UAAU,WAAW,CAAC,CAAO;IACjC,IAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC3B,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAEvB,IAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAEpB,IAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAEpB,IAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,IAAM,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IAErB,IAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAG5B,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACzC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,OAAO,EAAE;QAC3B,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAChC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KACjC;SAAM;QACL,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACb,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KAClC;IAED,OAAO,KAAK,CAAC,GAAG,CAAC,UAAA,GAAG,IAAI,OAAA,QAAQ,CAAC,GAAG,CAAC,EAAb,CAAa,CAAS,CAAC;AACjD,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index c2b29d2..ae89825 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "css-camera", - "version": "1.0.0-rc", + "version": "1.0.1", "description": "Add a depth to your web page with CSS3 3D transform.", "main": "lib/css-camera.js", "module": "lib/css-camera.esm.js",