UNPKG

@turbox3d/math

Version:

Large-scale graphics application math library

811 lines (809 loc) 26.1 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.Matrix4 = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _MathUtils = require("../MathUtils"); var _Vector = require("./Vector3"); /* eslint-disable function-call-argument-newline */ var _v1 = new _Vector.Vector3(); var _zero = new _Vector.Vector3(0, 0, 0); var _one = new _Vector.Vector3(1, 1, 1); var _x = new _Vector.Vector3(); var _y = new _Vector.Vector3(); var _z = new _Vector.Vector3(); var Matrix4 = exports.Matrix4 = /*#__PURE__*/function () { function Matrix4() { (0, _classCallCheck2["default"])(this, Matrix4); this.isMatrix4 = true; this.elements = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]; if (arguments.length > 0) { console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.'); } } return (0, _createClass2["default"])(Matrix4, [{ key: "set", value: function set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) { var te = this.elements; te[0] = n11; te[4] = n12; te[8] = n13; te[12] = n14; te[1] = n21; te[5] = n22; te[9] = n23; te[13] = n24; te[2] = n31; te[6] = n32; te[10] = n33; te[14] = n34; te[3] = n41; te[7] = n42; te[11] = n43; te[15] = n44; return this; } }, { key: "identity", value: function identity() { this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); return this; } }, { key: "clone", value: function clone() { return new Matrix4().fromArray(this.elements); } }, { key: "copy", value: function copy(m) { var te = this.elements; var me = m.elements; te[0] = me[0]; te[1] = me[1]; te[2] = me[2]; te[3] = me[3]; te[4] = me[4]; te[5] = me[5]; te[6] = me[6]; te[7] = me[7]; te[8] = me[8]; te[9] = me[9]; te[10] = me[10]; te[11] = me[11]; te[12] = me[12]; te[13] = me[13]; te[14] = me[14]; te[15] = me[15]; return this; } }, { key: "copyPosition", value: function copyPosition(m) { var te = this.elements; var me = m.elements; te[12] = me[12]; te[13] = me[13]; te[14] = me[14]; return this; } }, { key: "setFromMatrix3", value: function setFromMatrix3(m) { var me = m.elements; this.set(me[0], me[3], me[6], 0, me[1], me[4], me[7], 0, me[2], me[5], me[8], 0, 0, 0, 0, 1); return this; } }, { key: "extractBasis", value: function extractBasis(xAxis, yAxis, zAxis) { xAxis.setFromMatrixColumn(this, 0); yAxis.setFromMatrixColumn(this, 1); zAxis.setFromMatrixColumn(this, 2); return this; } }, { key: "makeBasis", value: function makeBasis(xAxis, yAxis, zAxis) { this.set(xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1); return this; } }, { key: "extractRotation", value: function extractRotation(m) { // this method does not support reflection matrices var te = this.elements; var me = m.elements; var scaleX = 1 / _v1.setFromMatrixColumn(m, 0).length; var scaleY = 1 / _v1.setFromMatrixColumn(m, 1).length; var scaleZ = 1 / _v1.setFromMatrixColumn(m, 2).length; te[0] = me[0] * scaleX; te[1] = me[1] * scaleX; te[2] = me[2] * scaleX; te[3] = 0; te[4] = me[4] * scaleY; te[5] = me[5] * scaleY; te[6] = me[6] * scaleY; te[7] = 0; te[8] = me[8] * scaleZ; te[9] = me[9] * scaleZ; te[10] = me[10] * scaleZ; te[11] = 0; te[12] = 0; te[13] = 0; te[14] = 0; te[15] = 1; return this; } }, { key: "makeRotationFromEuler", value: function makeRotationFromEuler(euler) { var te = this.elements; var x = euler.x; var y = euler.y; var z = euler.z; var a = Math.cos(x); var b = Math.sin(x); var c = Math.cos(y); var d = Math.sin(y); var e = Math.cos(z); var f = Math.sin(z); if (euler.order === 'XYZ') { var ae = a * e; var af = a * f; var be = b * e; var bf = b * f; te[0] = c * e; te[4] = -c * f; te[8] = d; te[1] = af + be * d; te[5] = ae - bf * d; te[9] = -b * c; te[2] = bf - ae * d; te[6] = be + af * d; te[10] = a * c; } else if (euler.order === 'YXZ') { var ce = c * e; var cf = c * f; var de = d * e; var df = d * f; te[0] = ce + df * b; te[4] = de * b - cf; te[8] = a * d; te[1] = a * f; te[5] = a * e; te[9] = -b; te[2] = cf * b - de; te[6] = df + ce * b; te[10] = a * c; } else if (euler.order === 'ZXY') { var _ce = c * e; var _cf = c * f; var _de = d * e; var _df = d * f; te[0] = _ce - _df * b; te[4] = -a * f; te[8] = _de + _cf * b; te[1] = _cf + _de * b; te[5] = a * e; te[9] = _df - _ce * b; te[2] = -a * d; te[6] = b; te[10] = a * c; } else if (euler.order === 'ZYX') { var _ae = a * e; var _af = a * f; var _be = b * e; var _bf = b * f; te[0] = c * e; te[4] = _be * d - _af; te[8] = _ae * d + _bf; te[1] = c * f; te[5] = _bf * d + _ae; te[9] = _af * d - _be; te[2] = -d; te[6] = b * c; te[10] = a * c; } else if (euler.order === 'YZX') { var ac = a * c; var ad = a * d; var bc = b * c; var bd = b * d; te[0] = c * e; te[4] = bd - ac * f; te[8] = bc * f + ad; te[1] = f; te[5] = a * e; te[9] = -b * e; te[2] = -d * e; te[6] = ad * f + bc; te[10] = ac - bd * f; } else if (euler.order === 'XZY') { var _ac = a * c; var _ad = a * d; var _bc = b * c; var _bd = b * d; te[0] = c * e; te[4] = -f; te[8] = d * e; te[1] = _ac * f + _bd; te[5] = a * e; te[9] = _ad * f - _bc; te[2] = _bc * f - _ad; te[6] = b * e; te[10] = _bd * f + _ac; } // bottom row te[3] = 0; te[7] = 0; te[11] = 0; // last column te[12] = 0; te[13] = 0; te[14] = 0; te[15] = 1; return this; } }, { key: "makeRotationFromQuaternion", value: function makeRotationFromQuaternion(q) { return this.compose(_zero, q, _one); } }, { key: "lookAt", value: function lookAt(eye, target, up) { var te = this.elements; _z.subVectors(eye, target); if (_z.lengthSq === 0) { // eye and target are in the same position _z.z = 1; } _z.normalize(); _x.crossVectors(up, _z); if (_x.lengthSq === 0) { // up and z are parallel if (Math.abs(up.z) === 1) { _z.x += 0.0001; } else { _z.z += 0.0001; } _z.normalize(); _x.crossVectors(up, _z); } _x.normalize(); _y.crossVectors(_z, _x); te[0] = _x.x; te[4] = _y.x; te[8] = _z.x; te[1] = _x.y; te[5] = _y.y; te[9] = _z.y; te[2] = _x.z; te[6] = _y.z; te[10] = _z.z; return this; } }, { key: "multiply", value: function multiply(m) { return this.multiplyMatrices(this, m); } }, { key: "multiplied", value: function multiplied(m) { return new Matrix4().multiplyMatrices(this, m); } }, { key: "premultiply", value: function premultiply(m) { return this.multiplyMatrices(m, this); } }, { key: "premultiplied", value: function premultiplied(m) { return new Matrix4().multiplyMatrices(m, this); } }, { key: "multiplyMatrices", value: function multiplyMatrices(a, b) { var ae = a.elements; var be = b.elements; var te = this.elements; var a11 = ae[0]; var a12 = ae[4]; var a13 = ae[8]; var a14 = ae[12]; var a21 = ae[1]; var a22 = ae[5]; var a23 = ae[9]; var a24 = ae[13]; var a31 = ae[2]; var a32 = ae[6]; var a33 = ae[10]; var a34 = ae[14]; var a41 = ae[3]; var a42 = ae[7]; var a43 = ae[11]; var a44 = ae[15]; var b11 = be[0]; var b12 = be[4]; var b13 = be[8]; var b14 = be[12]; var b21 = be[1]; var b22 = be[5]; var b23 = be[9]; var b24 = be[13]; var b31 = be[2]; var b32 = be[6]; var b33 = be[10]; var b34 = be[14]; var b41 = be[3]; var b42 = be[7]; var b43 = be[11]; var b44 = be[15]; te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41; te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42; te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43; te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44; te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41; te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42; te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43; te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44; te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41; te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42; te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43; te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44; te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41; te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42; te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43; te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44; return this; } }, { key: "multiplyScalar", value: function multiplyScalar(s) { var te = this.elements; te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s; te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s; te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s; te[3] *= s; te[7] *= s; te[11] *= s; te[15] *= s; return this; } }, { key: "determinant", value: function determinant() { var te = this.elements; var n11 = te[0]; var n12 = te[4]; var n13 = te[8]; var n14 = te[12]; var n21 = te[1]; var n22 = te[5]; var n23 = te[9]; var n24 = te[13]; var n31 = te[2]; var n32 = te[6]; var n33 = te[10]; var n34 = te[14]; var n41 = te[3]; var n42 = te[7]; var n43 = te[11]; var n44 = te[15]; // TODO: make this more efficient // ( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm ) return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31); } }, { key: "transpose", value: function transpose() { var te = this.elements; var tmp; tmp = te[1]; te[1] = te[4]; te[4] = tmp; tmp = te[2]; te[2] = te[8]; te[8] = tmp; tmp = te[6]; te[6] = te[9]; te[9] = tmp; tmp = te[3]; te[3] = te[12]; te[12] = tmp; tmp = te[7]; te[7] = te[13]; te[13] = tmp; tmp = te[11]; te[11] = te[14]; te[14] = tmp; return this; } }, { key: "setPosition", value: function setPosition() { var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0; var te = this.elements; te[12] = x; te[13] = y; te[14] = z; return this; } }, { key: "invert", value: function invert() { // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm var te = this.elements; var n11 = te[0]; var n21 = te[1]; var n31 = te[2]; var n41 = te[3]; var n12 = te[4]; var n22 = te[5]; var n32 = te[6]; var n42 = te[7]; var n13 = te[8]; var n23 = te[9]; var n33 = te[10]; var n43 = te[11]; var n14 = te[12]; var n24 = te[13]; var n34 = te[14]; var n44 = te[15]; var t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44; var t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44; var t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44; var t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34; var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14; if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); var detInv = 1 / det; te[0] = t11 * detInv; te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv; te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv; te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv; te[4] = t12 * detInv; te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv; te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv; te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv; te[8] = t13 * detInv; te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv; te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv; te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv; te[12] = t14 * detInv; te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv; te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv; te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv; return this; } }, { key: "inverted", value: function inverted() { var te = this.elements; var n11 = te[0]; var n21 = te[1]; var n31 = te[2]; var n41 = te[3]; var n12 = te[4]; var n22 = te[5]; var n32 = te[6]; var n42 = te[7]; var n13 = te[8]; var n23 = te[9]; var n33 = te[10]; var n43 = te[11]; var n14 = te[12]; var n24 = te[13]; var n34 = te[14]; var n44 = te[15]; var t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44; var t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44; var t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44; var t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34; var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14; if (det === 0) return new Matrix4(); var detInv = 1 / det; var ne = new Array(16); ne[0] = t11 * detInv; ne[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv; ne[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv; ne[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv; ne[4] = t12 * detInv; ne[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv; ne[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv; ne[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv; ne[8] = t13 * detInv; ne[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv; ne[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv; ne[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv; ne[12] = t14 * detInv; ne[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv; ne[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv; ne[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv; var result = new Matrix4(); result.elements = ne; return result; } }, { key: "scale", value: function scale(v) { var te = this.elements; var x = v.x; var y = v.y; var z = v.z; te[0] *= x; te[4] *= y; te[8] *= z; te[1] *= x; te[5] *= y; te[9] *= z; te[2] *= x; te[6] *= y; te[10] *= z; te[3] *= x; te[7] *= y; te[11] *= z; return this; } }, { key: "getMaxScaleOnAxis", value: function getMaxScaleOnAxis() { var te = this.elements; var scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2]; var scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6]; var scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10]; return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq)); } }, { key: "makeTranslation", value: function makeTranslation(x, y, z) { this.set(1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1); return this; } }, { key: "makeRotationX", value: function makeRotationX(theta) { var c = Math.cos(theta); var s = Math.sin(theta); this.set(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1); return this; } }, { key: "makeRotationY", value: function makeRotationY(theta) { var c = Math.cos(theta); var s = Math.sin(theta); this.set(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1); return this; } }, { key: "makeRotationZ", value: function makeRotationZ(theta) { var c = Math.cos(theta); var s = Math.sin(theta); this.set(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); return this; } }, { key: "makeRotationAxis", value: function makeRotationAxis(axis, angle) { // Based on http://www.gamedev.net/reference/articles/article1199.asp var c = Math.cos(angle); var s = Math.sin(angle); var t = 1 - c; var x = axis.x; var y = axis.y; var z = axis.z; var tx = t * x; var ty = t * y; this.set(tx * x + c, tx * y - s * z, tx * z + s * y, 0, tx * y + s * z, ty * y + c, ty * z - s * x, 0, tx * z - s * y, ty * z + s * x, t * z * z + c, 0, 0, 0, 0, 1); return this; } }, { key: "makeScale", value: function makeScale(x, y, z) { this.set(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1); return this; } }, { key: "makeShear", value: function makeShear(x, y, z) { this.set(1, y, z, 0, x, 1, z, 0, x, y, 1, 0, 0, 0, 0, 1); return this; } }, { key: "compose", value: function compose(position, quaternion, scale) { var te = this.elements; var x = quaternion._x; var y = quaternion._y; var z = quaternion._z; var w = quaternion._w; 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 = scale.x; var sy = scale.y; var sz = scale.z; te[0] = (1 - (yy + zz)) * sx; te[1] = (xy + wz) * sx; te[2] = (xz - wy) * sx; te[3] = 0; te[4] = (xy - wz) * sy; te[5] = (1 - (xx + zz)) * sy; te[6] = (yz + wx) * sy; te[7] = 0; te[8] = (xz + wy) * sz; te[9] = (yz - wx) * sz; te[10] = (1 - (xx + yy)) * sz; te[11] = 0; te[12] = position.x; te[13] = position.y; te[14] = position.z; te[15] = 1; return this; } }, { key: "decompose", value: function decompose(position, quaternion, scale) { var te = this.elements; var sx = _v1.set(te[0], te[1], te[2]).length; var sy = _v1.set(te[4], te[5], te[6]).length; var sz = _v1.set(te[8], te[9], te[10]).length; // if determine is negative, we need to invert one scale var det = this.determinant(); if (det < 0) sx = -sx; position.x = te[12]; position.y = te[13]; position.z = te[14]; // scale the rotation part _m1.copy(this); var invSX = 1 / sx; var invSY = 1 / sy; var invSZ = 1 / sz; _m1.elements[0] *= invSX; _m1.elements[1] *= invSX; _m1.elements[2] *= invSX; _m1.elements[4] *= invSY; _m1.elements[5] *= invSY; _m1.elements[6] *= invSY; _m1.elements[8] *= invSZ; _m1.elements[9] *= invSZ; _m1.elements[10] *= invSZ; quaternion.setFromRotationMatrix(_m1); scale.x = sx; scale.y = sy; scale.z = sz; return this; } }, { key: "makePerspective", value: function makePerspective(left, right, top, bottom, near, far) { if (far === undefined) { console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.'); } var te = this.elements; var x = 2 * near / (right - left); var y = 2 * near / (top - bottom); var a = (right + left) / (right - left); var b = (top + bottom) / (top - bottom); var c = -(far + near) / (far - near); var d = -2 * far * near / (far - near); te[0] = x; te[4] = 0; te[8] = a; te[12] = 0; te[1] = 0; te[5] = y; te[9] = b; te[13] = 0; te[2] = 0; te[6] = 0; te[10] = c; te[14] = d; te[3] = 0; te[7] = 0; te[11] = -1; te[15] = 0; return this; } }, { key: "makeOrthographic", value: function makeOrthographic(left, right, top, bottom, near, far) { var te = this.elements; var w = 1.0 / (right - left); var h = 1.0 / (top - bottom); var p = 1.0 / (far - near); var x = (right + left) * w; var y = (top + bottom) * h; var z = (far + near) * p; te[0] = 2 * w; te[4] = 0; te[8] = 0; te[12] = -x; te[1] = 0; te[5] = 2 * h; te[9] = 0; te[13] = -y; te[2] = 0; te[6] = 0; te[10] = -2 * p; te[14] = -z; te[3] = 0; te[7] = 0; te[11] = 0; te[15] = 1; return this; } }, { key: "equals", value: function equals(matrix) { var te = this.elements; var me = matrix.elements; for (var i = 0; i < 16; i++) { if (!_MathUtils.MathUtils.isEqual(te[i], me[i])) { return false; } } return true; } }, { key: "fromArray", value: function fromArray(array) { var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; for (var i = 0; i < 16; i++) { this.elements[i] = array[i + offset]; } return this; } }, { key: "toArray", value: function toArray() { var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; var te = this.elements; array[offset] = te[0]; array[offset + 1] = te[1]; array[offset + 2] = te[2]; array[offset + 3] = te[3]; array[offset + 4] = te[4]; array[offset + 5] = te[5]; array[offset + 6] = te[6]; array[offset + 7] = te[7]; array[offset + 8] = te[8]; array[offset + 9] = te[9]; array[offset + 10] = te[10]; array[offset + 11] = te[11]; array[offset + 12] = te[12]; array[offset + 13] = te[13]; array[offset + 14] = te[14]; array[offset + 15] = te[15]; return array; } }]); }(); var _m1 = new Matrix4();