meta-client
Version:
Meta.js (Client)
1 lines • 9.29 MB
JSON
{"id":"node_modules\\oimo\\build\\oimo.module.js","dependencies":[{"name":"C:\\Users\\florianmaxim\\work\\meta\\node_modules\\oimo\\package.json","includedInParent":true,"mtime":1531738247433},{"name":"C:\\Users\\florianmaxim\\work\\meta\\package.json","includedInParent":true,"mtime":1531759463299},{"name":"C:\\Users\\florianmaxim\\work\\meta\\.babelrc","includedInParent":true,"mtime":1531746256699}],"generated":{"js":"'use strict';\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n// Polyfills\n\nif (Number.EPSILON === undefined) {\n\n Number.EPSILON = Math.pow(2, -52);\n}\n\n//\n\nif (Math.sign === undefined) {\n\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign\n\n Math.sign = function (x) {\n\n return x < 0 ? -1 : x > 0 ? 1 : +x;\n };\n}\n\nif (Function.prototype.name === undefined) {\n\n // Missing in IE9-11.\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name\n\n Object.defineProperty(Function.prototype, 'name', {\n\n get: function () {\n\n return this.toString().match(/^\\s*function\\s*([^\\(\\s]*)/)[1];\n }\n\n });\n}\n\nif (Object.assign === undefined) {\n\n // Missing in IE.\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign\n\n (function () {\n\n Object.assign = function (target) {\n\n 'use strict';\n\n if (target === undefined || target === null) {\n\n throw new TypeError('Cannot convert undefined or null to object');\n }\n\n var output = Object(target);\n\n for (var index = 1; index < arguments.length; index++) {\n\n var source = arguments[index];\n\n if (source !== undefined && source !== null) {\n\n for (var nextKey in source) {\n\n if (Object.prototype.hasOwnProperty.call(source, nextKey)) {\n\n output[nextKey] = source[nextKey];\n }\n }\n }\n }\n\n return output;\n };\n })();\n}\n\n/*\r\n * A list of constants built-in for\r\n * the physics engine.\r\n */\n\nvar REVISION = '1.0.9';\n\n// BroadPhase\nvar BR_NULL = 0;\nvar BR_BRUTE_FORCE = 1;\nvar BR_SWEEP_AND_PRUNE = 2;\nvar BR_BOUNDING_VOLUME_TREE = 3;\n\n// Body type\nvar BODY_NULL = 0;\nvar BODY_DYNAMIC = 1;\nvar BODY_STATIC = 2;\nvar BODY_KINEMATIC = 3;\nvar BODY_GHOST = 4;\n\n// Shape type\nvar SHAPE_NULL = 0;\nvar SHAPE_SPHERE = 1;\nvar SHAPE_BOX = 2;\nvar SHAPE_CYLINDER = 3;\nvar SHAPE_PLANE = 4;\nvar SHAPE_PARTICLE = 5;\nvar SHAPE_TETRA = 6;\n\n// Joint type\nvar JOINT_NULL = 0;\nvar JOINT_DISTANCE = 1;\nvar JOINT_BALL_AND_SOCKET = 2;\nvar JOINT_HINGE = 3;\nvar JOINT_WHEEL = 4;\nvar JOINT_SLIDER = 5;\nvar JOINT_PRISMATIC = 6;\n\n// AABB aproximation\nvar AABB_PROX = 0.005;\n\nvar _Math = {\n\n sqrt: Math.sqrt,\n abs: Math.abs,\n floor: Math.floor,\n cos: Math.cos,\n sin: Math.sin,\n acos: Math.acos,\n asin: Math.asin,\n atan2: Math.atan2,\n round: Math.round,\n pow: Math.pow,\n max: Math.max,\n min: Math.min,\n random: Math.random,\n\n degtorad: 0.0174532925199432957,\n radtodeg: 57.295779513082320876,\n PI: 3.141592653589793,\n TwoPI: 6.283185307179586,\n PI90: 1.570796326794896,\n PI270: 4.712388980384689,\n\n INF: Infinity,\n EPZ: 0.00001,\n EPZ2: 0.000001,\n\n lerp: function (x, y, t) {\n\n return (1 - t) * x + t * y;\n },\n\n randInt: function (low, high) {\n\n return low + _Math.floor(_Math.random() * (high - low + 1));\n },\n\n rand: function (low, high) {\n\n return low + _Math.random() * (high - low);\n },\n\n generateUUID: function () {\n\n // http://www.broofa.com/Tools/Math.uuid.htm\n\n var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');\n var uuid = new Array(36);\n var rnd = 0,\n r;\n\n return function generateUUID() {\n\n for (var i = 0; i < 36; i++) {\n\n if (i === 8 || i === 13 || i === 18 || i === 23) {\n\n uuid[i] = '-';\n } else if (i === 14) {\n\n uuid[i] = '4';\n } else {\n\n if (rnd <= 0x02) rnd = 0x2000000 + Math.random() * 0x1000000 | 0;\n r = rnd & 0xf;\n rnd = rnd >> 4;\n uuid[i] = chars[i === 19 ? r & 0x3 | 0x8 : r];\n }\n }\n\n return uuid.join('');\n };\n }(),\n\n int: function (x) {\n\n return _Math.floor(x);\n },\n\n fix: function (x, n) {\n\n return x.toFixed(n || 3, 10);\n },\n\n clamp: function (value, min, max) {\n\n return _Math.max(min, _Math.min(max, value));\n },\n\n //clamp: function ( x, a, b ) { return ( x < a ) ? a : ( ( x > b ) ? b : x ); },\n\n\n distance: function (p1, p2) {\n\n var xd = p2[0] - p1[0];\n var yd = p2[1] - p1[1];\n var zd = p2[2] - p1[2];\n return _Math.sqrt(xd * xd + yd * yd + zd * zd);\n },\n\n /*unwrapDegrees: function ( r ) {\r\n r = r % 360;\r\n if (r > 180) r -= 360;\r\n if (r < -180) r += 360;\r\n return r;\r\n },\r\n unwrapRadian: function( r ){\r\n r = r % _Math.TwoPI;\r\n if (r > _Math.PI) r -= _Math.TwoPI;\r\n if (r < -_Math.PI) r += _Math.TwoPI;\r\n return r;\r\n },*/\n\n acosClamp: function (cos) {\n\n if (cos > 1) return 0;else if (cos < -1) return _Math.PI;else return _Math.acos(cos);\n },\n\n distanceVector: function (v1, v2) {\n\n var xd = v1.x - v2.x;\n var yd = v1.y - v2.y;\n var zd = v1.z - v2.z;\n return xd * xd + yd * yd + zd * zd;\n },\n\n dotVectors: function (a, b) {\n\n return a.x * b.x + a.y * b.y + a.z * b.z;\n }\n\n};\n\nfunction printError(clazz, msg) {\n console.error(\"[OIMO] \" + clazz + \": \" + msg);\n}\n\n// A performance evaluator\n\nfunction InfoDisplay(world) {\n\n this.parent = world;\n\n this.infos = new Float32Array(13);\n this.f = [0, 0, 0];\n\n this.times = [0, 0, 0, 0];\n\n this.broadPhase = this.parent.broadPhaseType;\n\n this.version = REVISION;\n\n this.fps = 0;\n\n this.tt = 0;\n\n this.broadPhaseTime = 0;\n this.narrowPhaseTime = 0;\n this.solvingTime = 0;\n this.totalTime = 0;\n this.updateTime = 0;\n\n this.MaxBroadPhaseTime = 0;\n this.MaxNarrowPhaseTime = 0;\n this.MaxSolvingTime = 0;\n this.MaxTotalTime = 0;\n this.MaxUpdateTime = 0;\n}\n\nObject.assign(InfoDisplay.prototype, {\n\n setTime: function (n) {\n this.times[n || 0] = performance.now();\n },\n\n resetMax: function () {\n\n this.MaxBroadPhaseTime = 0;\n this.MaxNarrowPhaseTime = 0;\n this.MaxSolvingTime = 0;\n this.MaxTotalTime = 0;\n this.MaxUpdateTime = 0;\n },\n\n calcBroadPhase: function () {\n\n this.setTime(2);\n this.broadPhaseTime = this.times[2] - this.times[1];\n },\n\n calcNarrowPhase: function () {\n\n this.setTime(3);\n this.narrowPhaseTime = this.times[3] - this.times[2];\n },\n\n calcEnd: function () {\n\n this.setTime(2);\n this.solvingTime = this.times[2] - this.times[1];\n this.totalTime = this.times[2] - this.times[0];\n this.updateTime = this.totalTime - (this.broadPhaseTime + this.narrowPhaseTime + this.solvingTime);\n\n if (this.tt === 100) this.resetMax();\n\n if (this.tt > 100) {\n if (this.broadPhaseTime > this.MaxBroadPhaseTime) this.MaxBroadPhaseTime = this.broadPhaseTime;\n if (this.narrowPhaseTime > this.MaxNarrowPhaseTime) this.MaxNarrowPhaseTime = this.narrowPhaseTime;\n if (this.solvingTime > this.MaxSolvingTime) this.MaxSolvingTime = this.solvingTime;\n if (this.totalTime > this.MaxTotalTime) this.MaxTotalTime = this.totalTime;\n if (this.updateTime > this.MaxUpdateTime) this.MaxUpdateTime = this.updateTime;\n }\n\n this.upfps();\n\n this.tt++;\n if (this.tt > 500) this.tt = 0;\n },\n\n upfps: function () {\n this.f[1] = Date.now();\n if (this.f[1] - 1000 > this.f[0]) {\n this.f[0] = this.f[1];this.fps = this.f[2];this.f[2] = 0;\n }this.f[2]++;\n },\n\n show: function () {\n var info = [\"Oimo.js \" + this.version + \"<br>\", this.broadPhase + \"<br><br>\", \"FPS: \" + this.fps + \" fps<br><br>\", \"rigidbody \" + this.parent.numRigidBodies + \"<br>\", \"contact \" + this.parent.numContacts + \"<br>\", \"ct-point \" + this.parent.numContactPoints + \"<br>\", \"paircheck \" + this.parent.broadPhase.numPairChecks + \"<br>\", \"island \" + this.parent.numIslands + \"<br><br>\", \"Time in milliseconds<br><br>\", \"broadphase \" + _Math.fix(this.broadPhaseTime) + \" | \" + _Math.fix(this.MaxBroadPhaseTime) + \"<br>\", \"narrowphase \" + _Math.fix(this.narrowPhaseTime) + \" | \" + _Math.fix(this.MaxNarrowPhaseTime) + \"<br>\", \"solving \" + _Math.fix(this.solvingTime) + \" | \" + _Math.fix(this.MaxSolvingTime) + \"<br>\", \"total \" + _Math.fix(this.totalTime) + \" | \" + _Math.fix(this.MaxTotalTime) + \"<br>\", \"updating \" + _Math.fix(this.updateTime) + \" | \" + _Math.fix(this.MaxUpdateTime) + \"<br>\"].join(\"\\n\");\n return info;\n },\n\n toArray: function () {\n this.infos[0] = this.parent.broadPhase.types;\n this.infos[1] = this.parent.numRigidBodies;\n this.infos[2] = this.parent.numContacts;\n this.infos[3] = this.parent.broadPhase.numPairChecks;\n this.infos[4] = this.parent.numContactPoints;\n this.infos[5] = this.parent.numIslands;\n this.infos[6] = this.broadPhaseTime;\n this.infos[7] = this.narrowPhaseTime;\n this.infos[8] = this.solvingTime;\n this.infos[9] = this.updateTime;\n this.infos[10] = this.totalTime;\n this.infos[11] = this.fps;\n return this.infos;\n }\n\n});\n\nfunction Vec3(x, y, z) {\n\n this.x = x || 0;\n this.y = y || 0;\n this.z = z || 0;\n}\n\nObject.assign(Vec3.prototype, {\n\n Vec3: true,\n\n set: function (x, y, z) {\n\n this.x = x;\n this.y = y;\n this.z = z;\n return this;\n },\n\n add: function (a, b) {\n\n if (b !== undefined) return this.addVectors(a, b);\n\n this.x += a.x;\n this.y += a.y;\n this.z += a.z;\n return this;\n },\n\n addVectors: function (a, b) {\n\n this.x = a.x + b.x;\n this.y = a.y + b.y;\n this.z = a.z + b.z;\n return this;\n },\n\n addEqual: function (v) {\n\n this.x += v.x;\n this.y += v.y;\n this.z += v.z;\n return this;\n },\n\n sub: function (a, b) {\n\n if (b !== undefined) return this.subVectors(a, b);\n\n this.x -= a.x;\n this.y -= a.y;\n this.z -= a.z;\n return this;\n },\n\n subVectors: function (a, b) {\n\n this.x = a.x - b.x;\n this.y = a.y - b.y;\n this.z = a.z - b.z;\n return this;\n },\n\n subEqual: function (v) {\n\n this.x -= v.x;\n this.y -= v.y;\n this.z -= v.z;\n return this;\n },\n\n scale: function (v, s) {\n\n this.x = v.x * s;\n this.y = v.y * s;\n this.z = v.z * s;\n return this;\n },\n\n scaleEqual: function (s) {\n\n this.x *= s;\n this.y *= s;\n this.z *= s;\n return this;\n },\n\n multiply: function (v) {\n\n this.x *= v.x;\n this.y *= v.y;\n this.z *= v.z;\n return this;\n },\n\n multiplyScalar: function (s) {\n\n this.x *= s;\n this.y *= s;\n this.z *= s;\n return this;\n },\n\n /*scaleV: function( v ){\n this.x *= v.x;\n this.y *= v.y;\n this.z *= v.z;\n return this;\n },\n scaleVectorEqual: function( v ){\n this.x *= v.x;\n this.y *= v.y;\n this.z *= v.z;\n return this;\n },*/\n\n addScaledVector: function (v, s) {\n\n this.x += v.x * s;\n this.y += v.y * s;\n this.z += v.z * s;\n\n return this;\n },\n\n subScaledVector: function (v, s) {\n\n this.x -= v.x * s;\n this.y -= v.y * s;\n this.z -= v.z * s;\n\n return this;\n },\n\n /*addTime: function ( v, t ) {\n this.x += v.x * t;\n this.y += v.y * t;\n this.z += v.z * t;\n return this;\n },\n \n addScale: function ( v, s ) {\n this.x += v.x * s;\n this.y += v.y * s;\n this.z += v.z * s;\n return this;\n },\n subScale: function ( v, s ) {\n this.x -= v.x * s;\n this.y -= v.y * s;\n this.z -= v.z * s;\n return this;\n },*/\n\n cross: function (a, b) {\n\n if (b !== undefined) return this.crossVectors(a, b);\n\n var x = this.x,\n y = this.y,\n z = this.z;\n\n this.x = y * a.z - z * a.y;\n this.y = z * a.x - x * a.z;\n this.z = x * a.y - y * a.x;\n\n return this;\n },\n\n crossVectors: function (a, b) {\n\n var ax = a.x,\n ay = a.y,\n az = a.z;\n var bx = b.x,\n by = b.y,\n bz = b.z;\n\n this.x = ay * bz - az * by;\n this.y = az * bx - ax * bz;\n this.z = ax * by - ay * bx;\n\n return this;\n },\n\n tangent: function (a) {\n\n var ax = a.x,\n ay = a.y,\n az = a.z;\n\n this.x = ay * ax - az * az;\n this.y = -az * ay - ax * ax;\n this.z = ax * az + ay * ay;\n\n return this;\n },\n\n invert: function (v) {\n\n this.x = -v.x;\n this.y = -v.y;\n this.z = -v.z;\n return this;\n },\n\n negate: function () {\n\n this.x = -this.x;\n this.y = -this.y;\n this.z = -this.z;\n\n return this;\n },\n\n dot: function (v) {\n\n return this.x * v.x + this.y * v.y + this.z * v.z;\n },\n\n addition: function () {\n\n return this.x + this.y + this.z;\n },\n\n lengthSq: function () {\n\n return this.x * this.x + this.y * this.y + this.z * this.z;\n },\n\n length: function () {\n\n return _Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);\n },\n\n copy: function (v) {\n\n this.x = v.x;\n this.y = v.y;\n this.z = v.z;\n return this;\n },\n\n /*mul: function( b, a, m ){\n return this.mulMat( m, a ).add( b );\n },\n mulMat: function( m, a ){\n var e = m.elements;\n var x = a.x, y = a.y, z = a.z;\n this.x = e[ 0 ] * x + e[ 1 ] * y + e[ 2 ] * z;\n this.y = e[ 3 ] * x + e[ 4 ] * y + e[ 5 ] * z;\n this.z = e[ 6 ] * x + e[ 7 ] * y + e[ 8 ] * z;\n return this;\n },*/\n\n applyMatrix3: function (m, transpose) {\n\n //if( transpose ) m = m.clone().transpose();\n var x = this.x,\n y = this.y,\n z = this.z;\n var e = m.elements;\n\n if (transpose) {\n\n this.x = e[0] * x + e[1] * y + e[2] * z;\n this.y = e[3] * x + e[4] * y + e[5] * z;\n this.z = e[6] * x + e[7] * y + e[8] * z;\n } else {\n\n this.x = e[0] * x + e[3] * y + e[6] * z;\n this.y = e[1] * x + e[4] * y + e[7] * z;\n this.z = e[2] * x + e[5] * y + e[8] * z;\n }\n\n return this;\n },\n\n applyQuaternion: function (q) {\n\n var x = this.x;\n var y = this.y;\n var z = this.z;\n\n var qx = q.x;\n var qy = q.y;\n var qz = q.z;\n var qw = q.w;\n\n // calculate quat * vector\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;\n\n // calculate result * inverse quat\n\n this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;\n this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;\n this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;\n\n return this;\n },\n\n testZero: function () {\n\n if (this.x !== 0 || this.y !== 0 || this.z !== 0) return true;else return false;\n },\n\n testDiff: function (v) {\n\n return this.equals(v) ? false : true;\n },\n\n equals: function (v) {\n\n return v.x === this.x && v.y === this.y && v.z === this.z;\n },\n\n clone: function () {\n\n return new this.constructor(this.x, this.y, this.z);\n },\n\n toString: function () {\n\n return \"Vec3[\" + this.x.toFixed(4) + \", \" + this.y.toFixed(4) + \", \" + this.z.toFixed(4) + \"]\";\n },\n\n multiplyScalar: function (scalar) {\n\n if (isFinite(scalar)) {\n this.x *= scalar;\n this.y *= scalar;\n this.z *= scalar;\n } else {\n this.x = 0;\n this.y = 0;\n this.z = 0;\n }\n\n return this;\n },\n\n divideScalar: function (scalar) {\n\n return this.multiplyScalar(1 / scalar);\n },\n\n normalize: function () {\n\n return this.divideScalar(this.length());\n },\n\n toArray: function (array, offset) {\n\n if (offset === undefined) offset = 0;\n\n array[offset] = this.x;\n array[offset + 1] = this.y;\n array[offset + 2] = this.z;\n },\n\n fromArray: function (array, offset) {\n\n if (offset === undefined) offset = 0;\n\n this.x = array[offset];\n this.y = array[offset + 1];\n this.z = array[offset + 2];\n return this;\n }\n\n});\n\nfunction Quat(x, y, z, w) {\n\n this.x = x || 0;\n this.y = y || 0;\n this.z = z || 0;\n this.w = w !== undefined ? w : 1;\n}\n\nObject.assign(Quat.prototype, {\n\n Quat: true,\n\n set: function (x, y, z, w) {\n\n this.x = x;\n this.y = y;\n this.z = z;\n this.w = w;\n\n return this;\n },\n\n addTime: function (v, t) {\n\n var ax = v.x,\n ay = v.y,\n az = v.z;\n var qw = this.w,\n qx = this.x,\n qy = this.y,\n qz = this.z;\n t *= 0.5;\n this.x += t * (ax * qw + ay * qz - az * qy);\n this.y += t * (ay * qw + az * qx - ax * qz);\n this.z += t * (az * qw + ax * qy - ay * qx);\n this.w += t * (-ax * qx - ay * qy - az * qz);\n this.normalize();\n return this;\n },\n\n /*mul: function( q1, q2 ){\n var ax = q1.x, ay = q1.y, az = q1.z, as = q1.w,\n bx = q2.x, by = q2.y, bz = q2.z, bs = q2.w;\n this.x = ax * bs + as * bx + ay * bz - az * by;\n this.y = ay * bs + as * by + az * bx - ax * bz;\n this.z = az * bs + as * bz + ax * by - ay * bx;\n this.w = as * bs - ax * bx - ay * by - az * bz;\n return this;\n },*/\n\n multiply: function (q, p) {\n\n if (p !== undefined) return this.multiplyQuaternions(q, p);\n return this.multiplyQuaternions(this, q);\n },\n\n multiplyQuaternions: function (a, b) {\n\n var qax = a.x,\n qay = a.y,\n qaz = a.z,\n qaw = a.w;\n var qbx = b.x,\n qby = b.y,\n qbz = b.z,\n qbw = b.w;\n\n this.x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;\n this.y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;\n this.z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;\n this.w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;\n return this;\n },\n\n setFromUnitVectors: function (v1, v2) {\n\n var vx = new Vec3();\n var r = v1.dot(v2) + 1;\n\n if (r < _Math.EPS2) {\n\n r = 0;\n if (_Math.abs(v1.x) > _Math.abs(v1.z)) vx.set(-v1.y, v1.x, 0);else vx.set(0, -v1.z, v1.y);\n } else {\n\n vx.crossVectors(v1, v2);\n }\n\n this._x = vx.x;\n this._y = vx.y;\n this._z = vx.z;\n this._w = r;\n\n return this.normalize();\n },\n\n arc: function (v1, v2) {\n\n var x1 = v1.x;\n var y1 = v1.y;\n var z1 = v1.z;\n var x2 = v2.x;\n var y2 = v2.y;\n var z2 = v2.z;\n var d = x1 * x2 + y1 * y2 + z1 * z2;\n if (d == -1) {\n x2 = y1 * x1 - z1 * z1;\n y2 = -z1 * y1 - x1 * x1;\n z2 = x1 * z1 + y1 * y1;\n d = 1 / _Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2);\n this.w = 0;\n this.x = x2 * d;\n this.y = y2 * d;\n this.z = z2 * d;\n return this;\n }\n var cx = y1 * z2 - z1 * y2;\n var cy = z1 * x2 - x1 * z2;\n var cz = x1 * y2 - y1 * x2;\n this.w = _Math.sqrt((1 + d) * 0.5);\n d = 0.5 / this.w;\n this.x = cx * d;\n this.y = cy * d;\n this.z = cz * d;\n return this;\n },\n\n normalize: function () {\n\n var l = this.length();\n if (l === 0) {\n this.set(0, 0, 0, 1);\n } else {\n l = 1 / l;\n this.x = this.x * l;\n this.y = this.y * l;\n this.z = this.z * l;\n this.w = this.w * l;\n }\n return this;\n },\n\n inverse: function () {\n\n return this.conjugate().normalize();\n },\n\n invert: function (q) {\n\n this.x = q.x;\n this.y = q.y;\n this.z = q.z;\n this.w = q.w;\n this.conjugate().normalize();\n return this;\n },\n\n conjugate: function () {\n\n this.x *= -1;\n this.y *= -1;\n this.z *= -1;\n return this;\n },\n\n length: function () {\n\n return _Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);\n },\n\n lengthSq: function () {\n\n return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;\n },\n\n copy: function (q) {\n\n this.x = q.x;\n this.y = q.y;\n this.z = q.z;\n this.w = q.w;\n return this;\n },\n\n clone: function (q) {\n\n return new Quat(this.x, this.y, this.z, this.w);\n },\n\n testDiff: function (q) {\n\n return this.equals(q) ? false : true;\n },\n\n equals: function (q) {\n\n return this.x === q.x && this.y === q.y && this.z === q.z && this.w === q.w;\n },\n\n toString: function () {\n\n return \"Quat[\" + this.x.toFixed(4) + \", (\" + this.y.toFixed(4) + \", \" + this.z.toFixed(4) + \", \" + this.w.toFixed(4) + \")]\";\n },\n\n setFromEuler: function (x, y, z) {\n\n var c1 = Math.cos(x * 0.5);\n var c2 = Math.cos(y * 0.5);\n var c3 = Math.cos(z * 0.5);\n var s1 = Math.sin(x * 0.5);\n var s2 = Math.sin(y * 0.5);\n var s3 = Math.sin(z * 0.5);\n\n // XYZ\n this.x = s1 * c2 * c3 + c1 * s2 * s3;\n this.y = c1 * s2 * c3 - s1 * c2 * s3;\n this.z = c1 * c2 * s3 + s1 * s2 * c3;\n this.w = c1 * c2 * c3 - s1 * s2 * s3;\n\n return this;\n },\n\n setFromAxis: function (axis, rad) {\n\n axis.normalize();\n rad = rad * 0.5;\n var s = _Math.sin(rad);\n this.x = s * axis.x;\n this.y = s * axis.y;\n this.z = s * axis.z;\n this.w = _Math.cos(rad);\n return this;\n },\n\n setFromMat33: function (m) {\n\n var trace = m[0] + m[4] + m[8];\n var s;\n\n if (trace > 0) {\n\n s = _Math.sqrt(trace + 1.0);\n this.w = 0.5 / s;\n s = 0.5 / s;\n this.x = (m[5] - m[7]) * s;\n this.y = (m[6] - m[2]) * s;\n this.z = (m[1] - m[3]) * s;\n } else {\n\n var out = [];\n var i = 0;\n if (m[4] > m[0]) i = 1;\n if (m[8] > m[i * 3 + i]) i = 2;\n\n var j = (i + 1) % 3;\n var k = (i + 2) % 3;\n\n s = _Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);\n out[i] = 0.5 * fRoot;\n s = 0.5 / fRoot;\n this.w = (m[j * 3 + k] - m[k * 3 + j]) * s;\n out[j] = (m[j * 3 + i] + m[i * 3 + j]) * s;\n out[k] = (m[k * 3 + i] + m[i * 3 + k]) * s;\n\n this.x = out[1];\n this.y = out[2];\n this.z = out[3];\n }\n\n return this;\n },\n\n toArray: function (array, offset) {\n\n offset = offset || 0;\n\n array[offset] = this.x;\n array[offset + 1] = this.y;\n array[offset + 2] = this.z;\n array[offset + 3] = this.w;\n },\n\n fromArray: function (array, offset) {\n\n offset = offset || 0;\n this.set(array[offset], array[offset + 1], array[offset + 2], array[offset + 3]);\n return this;\n }\n\n});\n\nfunction Mat33(e00, e01, e02, e10, e11, e12, e20, e21, e22) {\n\n this.elements = [1, 0, 0, 0, 1, 0, 0, 0, 1];\n\n if (arguments.length > 0) {\n\n console.error('OIMO.Mat33: the constructor no longer reads arguments. use .set() instead.');\n }\n}\n\nObject.assign(Mat33.prototype, {\n\n Mat33: true,\n\n set: function (e00, e01, e02, e10, e11, e12, e20, e21, e22) {\n\n var te = this.elements;\n te[0] = e00;te[1] = e01;te[2] = e02;\n te[3] = e10;te[4] = e11;te[5] = e12;\n te[6] = e20;te[7] = e21;te[8] = e22;\n return this;\n },\n\n add: function (a, b) {\n\n if (b !== undefined) return this.addMatrixs(a, b);\n\n var e = this.elements,\n te = a.elements;\n e[0] += te[0];e[1] += te[1];e[2] += te[2];\n e[3] += te[3];e[4] += te[4];e[5] += te[5];\n e[6] += te[6];e[7] += te[7];e[8] += te[8];\n return this;\n },\n\n addMatrixs: function (a, b) {\n\n var te = this.elements,\n tem1 = a.elements,\n tem2 = b.elements;\n te[0] = tem1[0] + tem2[0];te[1] = tem1[1] + tem2[1];te[2] = tem1[2] + tem2[2];\n te[3] = tem1[3] + tem2[3];te[4] = tem1[4] + tem2[4];te[5] = tem1[5] + tem2[5];\n te[6] = tem1[6] + tem2[6];te[7] = tem1[7] + tem2[7];te[8] = tem1[8] + tem2[8];\n return this;\n },\n\n addEqual: function (m) {\n\n var te = this.elements,\n tem = m.elements;\n te[0] += tem[0];te[1] += tem[1];te[2] += tem[2];\n te[3] += tem[3];te[4] += tem[4];te[5] += tem[5];\n te[6] += tem[6];te[7] += tem[7];te[8] += tem[8];\n return this;\n },\n\n sub: function (a, b) {\n\n if (b !== undefined) return this.subMatrixs(a, b);\n\n var e = this.elements,\n te = a.elements;\n e[0] -= te[0];e[1] -= te[1];e[2] -= te[2];\n e[3] -= te[3];e[4] -= te[4];e[5] -= te[5];\n e[6] -= te[6];e[7] -= te[7];e[8] -= te[8];\n return this;\n },\n\n subMatrixs: function (a, b) {\n\n var te = this.elements,\n tem1 = a.elements,\n tem2 = b.elements;\n te[0] = tem1[0] - tem2[0];te[1] = tem1[1] - tem2[1];te[2] = tem1[2] - tem2[2];\n te[3] = tem1[3] - tem2[3];te[4] = tem1[4] - tem2[4];te[5] = tem1[5] - tem2[5];\n te[6] = tem1[6] - tem2[6];te[7] = tem1[7] - tem2[7];te[8] = tem1[8] - tem2[8];\n return this;\n },\n\n subEqual: function (m) {\n\n var te = this.elements,\n tem = m.elements;\n te[0] -= tem[0];te[1] -= tem[1];te[2] -= tem[2];\n te[3] -= tem[3];te[4] -= tem[4];te[5] -= tem[5];\n te[6] -= tem[6];te[7] -= tem[7];te[8] -= tem[8];\n return this;\n },\n\n scale: function (m, s) {\n\n var te = this.elements,\n tm = m.elements;\n te[0] = tm[0] * s;te[1] = tm[1] * s;te[2] = tm[2] * s;\n te[3] = tm[3] * s;te[4] = tm[4] * s;te[5] = tm[5] * s;\n te[6] = tm[6] * s;te[7] = tm[7] * s;te[8] = tm[8] * s;\n return this;\n },\n\n scaleEqual: function (s) {\n // multiplyScalar\n\n var te = this.elements;\n te[0] *= s;te[1] *= s;te[2] *= s;\n te[3] *= s;te[4] *= s;te[5] *= s;\n te[6] *= s;te[7] *= s;te[8] *= s;\n return this;\n },\n\n multiplyMatrices: function (m1, m2, transpose) {\n\n if (transpose) m2 = m2.clone().transpose();\n\n var te = this.elements;\n var tm1 = m1.elements;\n var tm2 = m2.elements;\n\n var a0 = tm1[0],\n a3 = tm1[3],\n a6 = tm1[6];\n var a1 = tm1[1],\n a4 = tm1[4],\n a7 = tm1[7];\n var a2 = tm1[2],\n a5 = tm1[5],\n a8 = tm1[8];\n\n var b0 = tm2[0],\n b3 = tm2[3],\n b6 = tm2[6];\n var b1 = tm2[1],\n b4 = tm2[4],\n b7 = tm2[7];\n var b2 = tm2[2],\n b5 = tm2[5],\n b8 = tm2[8];\n\n te[0] = a0 * b0 + a1 * b3 + a2 * b6;\n te[1] = a0 * b1 + a1 * b4 + a2 * b7;\n te[2] = a0 * b2 + a1 * b5 + a2 * b8;\n te[3] = a3 * b0 + a4 * b3 + a5 * b6;\n te[4] = a3 * b1 + a4 * b4 + a5 * b7;\n te[5] = a3 * b2 + a4 * b5 + a5 * b8;\n te[6] = a6 * b0 + a7 * b3 + a8 * b6;\n te[7] = a6 * b1 + a7 * b4 + a8 * b7;\n te[8] = a6 * b2 + a7 * b5 + a8 * b8;\n\n return this;\n },\n\n /*mul: function ( m1, m2, transpose ) {\r\n if( transpose ) m2 = m2.clone().transpose();\r\n var te = this.elements;\r\n var tm1 = m1.elements;\r\n var tm2 = m2.elements;\r\n //var tmp;\r\n var a0 = tm1[0], a3 = tm1[3], a6 = tm1[6];\r\n var a1 = tm1[1], a4 = tm1[4], a7 = tm1[7];\r\n var a2 = tm1[2], a5 = tm1[5], a8 = tm1[8];\r\n var b0 = tm2[0], b3 = tm2[3], b6 = tm2[6];\r\n var b1 = tm2[1], b4 = tm2[4], b7 = tm2[7];\r\n var b2 = tm2[2], b5 = tm2[5], b8 = tm2[8];\r\n /*if( transpose ){\r\n tmp = b1; b1 = b3; b3 = tmp;\r\n tmp = b2; b2 = b6; b6 = tmp;\r\n tmp = b5; b5 = b7; b7 = tmp;\r\n }\r\n te[0] = a0*b0 + a1*b3 + a2*b6;\r\n te[1] = a0*b1 + a1*b4 + a2*b7;\r\n te[2] = a0*b2 + a1*b5 + a2*b8;\r\n te[3] = a3*b0 + a4*b3 + a5*b6;\r\n te[4] = a3*b1 + a4*b4 + a5*b7;\r\n te[5] = a3*b2 + a4*b5 + a5*b8;\r\n te[6] = a6*b0 + a7*b3 + a8*b6;\r\n te[7] = a6*b1 + a7*b4 + a8*b7;\r\n te[8] = a6*b2 + a7*b5 + a8*b8;\r\n return this;\r\n },*/\n\n transpose: function (m) {\n\n if (m !== undefined) {\n var a = m.elements;\n this.set(a[0], a[3], a[6], a[1], a[4], a[7], a[2], a[5], a[8]);\n return this;\n }\n\n var te = this.elements;\n var a01 = te[1],\n a02 = te[2],\n a12 = te[5];\n te[1] = te[3];\n te[2] = te[6];\n te[3] = a01;\n te[5] = te[7];\n te[6] = a02;\n te[7] = a12;\n return this;\n },\n\n /*mulScale: function ( m, sx, sy, sz, Prepend ) {\r\n var prepend = Prepend || false;\r\n var te = this.elements, tm = m.elements;\r\n if(prepend){\r\n te[0] = sx*tm[0]; te[1] = sx*tm[1]; te[2] = sx*tm[2];\r\n te[3] = sy*tm[3]; te[4] = sy*tm[4]; te[5] = sy*tm[5];\r\n te[6] = sz*tm[6]; te[7] = sz*tm[7]; te[8] = sz*tm[8];\r\n }else{\r\n te[0] = tm[0]*sx; te[1] = tm[1]*sy; te[2] = tm[2]*sz;\r\n te[3] = tm[3]*sx; te[4] = tm[4]*sy; te[5] = tm[5]*sz;\r\n te[6] = tm[6]*sx; te[7] = tm[7]*sy; te[8] = tm[8]*sz;\r\n }\r\n return this;\r\n },\r\n transpose: function ( m ) {\r\n var te = this.elements, tm = m.elements;\r\n te[0] = tm[0]; te[1] = tm[3]; te[2] = tm[6];\r\n te[3] = tm[1]; te[4] = tm[4]; te[5] = tm[7];\r\n te[6] = tm[2]; te[7] = tm[5]; te[8] = tm[8];\r\n return this;\r\n },*/\n\n setQuat: function (q) {\n\n var te = this.elements;\n var x = q.x,\n y = q.y,\n z = q.z,\n w = q.w;\n var x2 = x + x,\n y2 = y + y,\n z2 = z + z;\n var xx = x * x2,\n xy = x * y2,\n xz = x * z2;\n var yy = y * y2,\n yz = y * z2,\n zz = z * z2;\n var wx = w * x2,\n wy = w * y2,\n wz = w * z2;\n\n te[0] = 1 - (yy + zz);\n te[1] = xy - wz;\n te[2] = xz + wy;\n\n te[3] = xy + wz;\n te[4] = 1 - (xx + zz);\n te[5] = yz - wx;\n\n te[6] = xz - wy;\n te[7] = yz + wx;\n te[8] = 1 - (xx + yy);\n\n return this;\n },\n\n invert: function (m) {\n\n var te = this.elements,\n tm = m.elements,\n a00 = tm[0],\n a10 = tm[3],\n a20 = tm[6],\n a01 = tm[1],\n a11 = tm[4],\n a21 = tm[7],\n a02 = tm[2],\n a12 = tm[5],\n a22 = tm[8],\n b01 = a22 * a11 - a12 * a21,\n b11 = -a22 * a10 + a12 * a20,\n b21 = a21 * a10 - a11 * a20,\n det = a00 * b01 + a01 * b11 + a02 * b21;\n\n if (det === 0) {\n console.log(\"can't invert matrix, determinant is 0\");\n return this.identity();\n }\n\n det = 1.0 / det;\n te[0] = b01 * det;\n te[1] = (-a22 * a01 + a02 * a21) * det;\n te[2] = (a12 * a01 - a02 * a11) * det;\n te[3] = b11 * det;\n te[4] = (a22 * a00 - a02 * a20) * det;\n te[5] = (-a12 * a00 + a02 * a10) * det;\n te[6] = b21 * det;\n te[7] = (-a21 * a00 + a01 * a20) * det;\n te[8] = (a11 * a00 - a01 * a10) * det;\n return this;\n },\n\n addOffset: function (m, v) {\n\n var relX = v.x;\n var relY = v.y;\n var relZ = v.z;\n\n var te = this.elements;\n te[0] += m * (relY * relY + relZ * relZ);\n te[4] += m * (relX * relX + relZ * relZ);\n te[8] += m * (relX * relX + relY * relY);\n var xy = m * relX * relY;\n var yz = m * relY * relZ;\n var zx = m * relZ * relX;\n te[1] -= xy;\n te[3] -= xy;\n te[2] -= yz;\n te[6] -= yz;\n te[5] -= zx;\n te[7] -= zx;\n return this;\n },\n\n subOffset: function (m, v) {\n\n var relX = v.x;\n var relY = v.y;\n var relZ = v.z;\n\n var te = this.elements;\n te[0] -= m * (relY * relY + relZ * relZ);\n te[4] -= m * (relX * relX + relZ * relZ);\n te[8] -= m * (relX * relX + relY * relY);\n var xy = m * relX * relY;\n var yz = m * relY * relZ;\n var zx = m * relZ * relX;\n te[1] += xy;\n te[3] += xy;\n te[2] += yz;\n te[6] += yz;\n te[5] += zx;\n te[7] += zx;\n return this;\n },\n\n // OK \n\n multiplyScalar: function (s) {\n\n var te = this.elements;\n\n te[0] *= s;te[3] *= s;te[6] *= s;\n te[1] *= s;te[4] *= s;te[7] *= s;\n te[2] *= s;te[5] *= s;te[8] *= s;\n\n return this;\n },\n\n identity: function () {\n\n this.set(1, 0, 0, 0, 1, 0, 0, 0, 1);\n return this;\n },\n\n clone: function () {\n\n return new Mat33().fromArray(this.elements);\n },\n\n copy: function (m) {\n\n for (var i = 0; i < 9; i++) this.elements[i] = m.elements[i];\n return this;\n },\n\n determinant: function () {\n\n var te = this.elements;\n var a = te[0],\n b = te[1],\n c = te[2],\n d = te[3],\n e = te[4],\n f = te[5],\n g = te[6],\n h = te[7],\n i = te[8];\n\n return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;\n },\n\n fromArray: function (array, offset) {\n\n if (offset === undefined) offset = 0;\n\n for (var i = 0; i < 9; i++) {\n\n this.elements[i] = array[i + offset];\n }\n\n return this;\n },\n\n toArray: function (array, offset) {\n\n if (array === undefined) array = [];\n if (offset === undefined) offset = 0;\n\n var te = this.elements;\n\n array[offset] = te[0];\n array[offset + 1] = te[1];\n array[offset + 2] = te[2];\n\n array[offset + 3] = te[3];\n array[offset + 4] = te[4];\n array[offset + 5] = te[5];\n\n array[offset + 6] = te[6];\n array[offset + 7] = te[7];\n array[offset + 8] = te[8];\n\n return array;\n }\n\n});\n\n/**\r\n * An axis-aligned bounding box.\r\n *\r\n * @author saharan\r\n * @author lo-th\r\n */\n\nfunction AABB(minX, maxX, minY, maxY, minZ, maxZ) {\n\n this.elements = new Float32Array(6);\n var te = this.elements;\n\n te[0] = minX || 0;te[1] = minY || 0;te[2] = minZ || 0;\n te[3] = maxX || 0;te[4] = maxY || 0;te[5] = maxZ || 0;\n}\n\nObject.assign(AABB.prototype, {\n\n AABB: true,\n\n set: function (minX, maxX, minY, maxY, minZ, maxZ) {\n\n var te = this.elements;\n te[0] = minX;\n te[3] = maxX;\n te[1] = minY;\n te[4] = maxY;\n te[2] = minZ;\n te[5] = maxZ;\n return this;\n },\n\n intersectTest: function (aabb) {\n\n var te = this.elements;\n var ue = aabb.elements;\n return te[0] > ue[3] || te[1] > ue[4] || te[2] > ue[5] || te[3] < ue[0] || te[4] < ue[1] || te[5] < ue[2] ? true : false;\n },\n\n intersectTestTwo: function (aabb) {\n\n var te = this.elements;\n var ue = aabb.elements;\n return te[0] < ue[0] || te[1] < ue[1] || te[2] < ue[2] || te[3] > ue[3] || te[4] > ue[4] || te[5] > ue[5] ? true : false;\n },\n\n clone: function () {\n\n return new this.constructor().fromArray(this.elements);\n },\n\n copy: function (aabb, margin) {\n\n var m = margin || 0;\n var me = aabb.elements;\n this.set(me[0] - m, me[3] + m, me[1] - m, me[4] + m, me[2] - m, me[5] + m);\n return this;\n },\n\n fromArray: function (array) {\n\n this.elements.set(array);\n return this;\n },\n\n // Set this AABB to the combined AABB of aabb1 and aabb2.\n\n combine: function (aabb1, aabb2) {\n\n var a = aabb1.elements;\n var b = aabb2.elements;\n var te = this.elements;\n\n te[0] = a[0] < b[0] ? a[0] : b[0];\n te[1] = a[1] < b[1] ? a[1] : b[1];\n te[2] = a[2] < b[2] ? a[2] : b[2];\n\n te[3] = a[3] > b[3] ? a[3] : b[3];\n te[4] = a[4] > b[4] ? a[4] : b[4];\n te[5] = a[5] > b[5] ? a[5] : b[5];\n\n return this;\n },\n\n // Get the surface area.\n\n surfaceArea: function () {\n\n var te = this.elements;\n var a = te[3] - te[0];\n var h = te[4] - te[1];\n var d = te[5] - te[2];\n return 2 * (a * (h + d) + h * d);\n },\n\n // Get whether the AABB intersects with the point or not.\n\n intersectsWithPoint: function (x, y, z) {\n\n var te = this.elements;\n return x >= te[0] && x <= te[3] && y >= te[1] && y <= te[4] && z >= te[2] && z <= te[5];\n },\n\n /**\r\n * Set the AABB from an array\r\n * of vertices. From THREE.\r\n * @author WestLangley\r\n * @author xprogram\r\n */\n\n setFromPoints: function (arr) {\n this.makeEmpty();\n for (var i = 0; i < arr.length; i++) {\n this.expandByPoint(arr[i]);\n }\n },\n\n makeEmpty: function () {\n this.set(-Infinity, -Infinity, -Infinity, Infinity, Infinity, Infinity);\n },\n\n expandByPoint: function (pt) {\n var te = this.elements;\n this.set(_Math.min(te[0], pt.x), _Math.min(te[1], pt.y), _Math.min(te[2], pt.z), _Math.max(te[3], pt.x), _Math.max(te[4], pt.y), _Math.max(te[5], pt.z));\n },\n\n expandByScalar: function (s) {\n\n var te = this.elements;\n te[0] += -s;\n te[1] += -s;\n te[2] += -s;\n te[3] += s;\n te[4] += s;\n te[5] += s;\n }\n\n});\n\nvar count = 0;\nfunction ShapeIdCount() {\n return count++;\n}\n\n/**\r\n * A shape is used to detect collisions of rigid bodies.\r\n *\r\n * @author saharan\r\n * @author lo-th\r\n */\n\nfunction Shape(config) {\n\n this.type = SHAPE_NULL;\n\n // global identification of the shape should be unique to the shape.\n this.id = ShapeIdCount();\n\n // previous shape in parent rigid body. Used for fast interations.\n this.prev = null;\n\n // next shape in parent rigid body. Used for fast interations.\n this.next = null;\n\n // proxy of the shape used for broad-phase collision detection.\n this.proxy = null;\n\n // parent rigid body of the shape.\n this.parent = null;\n\n // linked list of the contacts with the shape.\n this.contactLink = null;\n\n // number of the contacts with the shape.\n this.numContacts = 0;\n\n // center of gravity of the shape in world coordinate system.\n this.position = new Vec3();\n\n // rotation matrix of the shape in world coordinate system.\n this.rotation = new Mat33();\n\n // position of the shape in parent's coordinate system.\n this.relativePosition = new Vec3().copy(config.relativePosition);\n\n // rotation matrix of the shape in parent's coordinate system.\n this.relativeRotation = new Mat33().copy(config.relativeRotation);\n\n // axis-aligned bounding box of the shape.\n this.aabb = new AABB();\n\n // density of the shape.\n this.density = config.density;\n\n // coefficient of friction of the shape.\n this.friction = config.friction;\n\n // coefficient of restitution of the shape.\n this.restitution = config.restitution;\n\n // bits of the collision groups to which the shape belongs.\n this.belongsTo = config.belongsTo;\n\n // bits of the collision groups with which the shape collides.\n this.collidesWith = config.collidesWith;\n}\n\nObject.assign(Shape.prototype, {\n\n Shape: true,\n\n // Calculate the mass information of the shape.\n\n calculateMassInfo: function (out) {\n\n printError(\"Shape\", \"Inheritance error.\");\n },\n\n // Update the proxy of the shape.\n\n updateProxy: function () {\n\n printError(\"Shape\", \"Inheritance error.\");\n }\n\n});\n\n/**\r\n * Box shape.\r\n * @author saharan\r\n * @author lo-th\r\n */\n\nfunction Box(config, Width, Height, Depth) {\n\n Shape.call(this, config);\n\n this.type = SHAPE_BOX;\n\n this.width = Width;\n this.height = Height;\n this.depth = Depth;\n\n this.halfWidth = Width * 0.5;\n this.halfHeight = Height * 0.5;\n this.halfDepth = Depth * 0.5;\n\n this.dimentions = new Float32Array(18);\n this.elements = new Float32Array(24);\n}\n\nBox.prototype = Object.assign(Object.create(Shape.prototype), {\n\n constructor: Box,\n\n calculateMassInfo: function (out) {\n\n var mass = this.width * this.height * this.depth * this.density;\n var divid = 1 / 12;\n out.mass = mass;\n out.inertia.set(mass * (this.height * this.height + this.depth * this.depth) * divid, 0, 0, 0, mass * (this.width * this.width + this.depth * this.depth) * divid, 0, 0, 0, mass * (this.width * this.width + this.height * this.height) * divid);\n },\n\n updateProxy: function () {\n\n var te = this.rotation.elements;\n var di = this.dimentions;\n // Width\n di[0] = te[0];\n di[1] = te[3];\n di[2] = te[6];\n // Height\n di[3] = te[1];\n di[4] = te[4];\n di[5] = te[7];\n // Depth\n di[6] = te[2];\n di[7] = te[5];\n di[8] = te[8];\n // half Width\n di[9] = te[0] * this.halfWidth;\n di[10] = te[3] * this.halfWidth;\n di[11] = te[6] * this.halfWidth;\n // half Height\n di[12] = te[1] * this.halfHeight;\n di[13] = te[4] * this.halfHeight;\n di[14] = te[7] * this.halfHeight;\n // half Depth\n di[15] = te[2] * this.halfDepth;\n di[16] = te[5] * this.halfDepth;\n di[17] = te[8] * this.halfDepth;\n\n var wx = di[9];\n var wy = di[10];\n var wz = di[11];\n var hx = di[12];\n var hy = di[13];\n var hz = di[14];\n var dx = di[15];\n var dy = di[16];\n var dz = di[17];\n\n var x = this.position.x;\n var y = this.position.y;\n var z = this.position.z;\n\n var v = this.elements;\n //v1\n v[0] = x + wx + hx + dx;\n v[1] = y + wy + hy + dy;\n v[2] = z + wz + hz + dz;\n //v2\n v[3] = x + wx + hx - dx;\n v[4] = y + wy + hy - dy;\n v[5] = z + wz + hz - dz;\n //v3\n v[6] = x + wx - hx + dx;\n v[7] = y + wy - hy + dy;\n v[8] = z + wz - hz + dz;\n //v4\n v[9] = x + wx - hx - dx;\n v[10] = y + wy - hy - dy;\n v[11] = z + wz - hz - dz;\n //v5\n v[12] = x - wx + hx + dx;\n v[13] = y - wy + hy + dy;\n v[14] = z - wz + hz + dz;\n //v6\n v[15] = x - wx + hx - dx;\n v[16] = y - wy + hy - dy;\n v[17] = z - wz + hz - dz;\n //v7\n v[18] = x - wx - hx + dx;\n v[19] = y - wy - hy + dy;\n v[20] = z - wz - hz + dz;\n //v8\n v[21] = x - wx - hx - dx;\n v[22] = y - wy - hy - dy;\n v[23] = z - wz - hz - dz;\n\n var w = di[9] < 0 ? -di[9] : di[9];\n var h = di[10] < 0 ? -di[10] : di[10];\n var d = di[11] < 0 ? -di[11] : di[11];\n\n w = di[12] < 0 ? w - di[12] : w + di[12];\n h = di[13] < 0 ? h - di[13] : h + di[13];\n d = di[14] < 0 ? d - di[14] : d + di[14];\n\n w = di[15] < 0 ? w - di[15] : w + di[15];\n h = di[16] < 0 ? h - di[16] : h + di[16];\n d = di[17] < 0 ? d - di[17] : d + di[17];\n\n var p = AABB_PROX;\n\n this.aabb.set(this.position.x - w - p, this.position.x + w + p, this.position.y - h - p, this.position.y + h + p, this.position.z - d - p, this.position.z + d + p);\n\n if (this.proxy != null) this.proxy.update();\n }\n});\n\n/**\r\n * Sphere shape\r\n * @author saharan\r\n * @author lo-th\r\n */\n\nfunction Sphere(config, radius) {\n\n Shape.call(this, config);\n\n this.type = SHAPE_SPHERE;\n\n // radius of the shape.\n this.radius = radius;\n}\n\nSphere.prototype = Object.assign(Object.create(Shape.prototype), {\n\n constructor: Sphere,\n\n volume: function () {\n\n return _Math.PI * this.radius * 1.333333;\n },\n\n calculateMassInfo: function (out) {\n\n var mass = this.volume() * this.radius * this.radius * this.density; //1.333 * _Math.PI * this.radius * this.radius * this.radius * this.density;\n out.mass = mass;\n var inertia = mass * this.radius * this.radius * 0.4;\n out.inertia.set(inertia, 0, 0, 0, inertia, 0, 0, 0, inertia);\n },\n\n updateProxy: function () {\n\n var p = AABB_PROX;\n\n this.aabb.set(this.position.x - this.radius - p, this.position.x + this.radius + p, this.position.y - this.radius - p, this.position.y + this.radius + p, this.position.z - this.radius - p, this.position.z + this.radius + p);\n\n if (this.proxy != null) this.proxy.update();\n }\n\n});\n\n/**\r\n * Cylinder shape\r\n * @author saharan\r\n * @author lo-th\r\n */\n\nfunction Cylinder(config, radius, height) {\n\n Shape.call(this, config);\n\n this.type = SHAPE_CYLINDER;\n\n this.radius = radius;\n this.height = height;\n this.halfHeight = height * 0.5;\n\n this.normalDirection = new Vec3();\n this.halfDirection = new Vec3();\n}\n\nCylinder.prototype = Object.assign(Object.create(Shape.prototype), {\n\n constructor: Cylinder,\n\n calculateMassInfo: function (out) {\n\n var rsq = this.radius * this.radius;\n var mass = _Math.PI * rsq * this.height * this.density;\n var inertiaXZ = (0.25 * rsq + 0.0833 * this.height * this.height) * mass;\n var inertiaY = 0.5 * rsq;\n out.mass = mass;\n out.inertia.set(inertiaXZ, 0, 0, 0, inertiaY, 0, 0, 0, inertiaXZ);\n },\n\n updateProxy: function () {\n\n var te = this.rotation.elements;\n var len, wx, hy, dz, xx, yy, zz, w, h, d, p;\n\n xx = te[1] * te[1];\n yy = te[4] * te[4];\n zz = te[7] * te[7];\n\n this.normalDirection.set(te[1], te[4], te[7]);\n this.halfDirection.scale(this.normalDirection, this.halfHeight);\n\n wx = 1 - xx;\n len = _Math.sqrt(wx * wx + xx * yy + xx * zz);\n if (len > 0) len = this.radius / len;\n wx *= len;\n hy = 1 - yy;\n len = _Math.sqrt(yy * xx + hy * hy + yy * zz);\n if (len > 0) len = this.radius / len;\n hy *= len;\n dz = 1 - zz;\n len = _Math.sqrt(zz * xx + zz * yy + dz * dz);\n if (len > 0) len = this.radius / len;\n dz *= len;\n\n w = this.halfDirection.x < 0 ? -this.halfDirection.x : this.halfDirection.x;\n h = this.halfDirection.y < 0 ? -this.halfDirection.y : this.halfDirection.y;\n d = this.halfDirection.z < 0 ? -this.halfDirection.z : this.halfDirection.z;\n\n w = wx < 0 ? w - wx : w + wx;\n h = hy < 0 ? h - hy : h + hy;\n