diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..b58b603f
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/3D_Game.iml b/.idea/3D_Game.iml
new file mode 100644
index 00000000..24643cc3
--- /dev/null
+++ b/.idea/3D_Game.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml
new file mode 100644
index 00000000..f7fd3ba6
--- /dev/null
+++ b/.idea/material_theme_project_new.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..30bab2ab
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..1f5e32da
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..35eb1ddf
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dist/996e0c1b19b93e0bdcfb.js b/dist/996e0c1b19b93e0bdcfb.js
new file mode 100644
index 00000000..d5e49d57
--- /dev/null
+++ b/dist/996e0c1b19b93e0bdcfb.js
@@ -0,0 +1,66 @@
+/*
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
+ * This devtool is neither made for production nor for readable output files.
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
+ * or disable the default devtool with "devtool: false".
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
+ */
+/******/(function () {
+ // webpackBootstrap
+ /******/
+ "use strict";
+
+ /******/
+ var __webpack_modules__ = {
+ /***/"./src/index.js": (
+ /*!**********************!*\
+ !*** ./src/index.js ***!
+ \**********************/
+ /***/
+ function _src_indexJs(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+ eval("__webpack_require__.r(__webpack_exports__);\nObject(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());\nObject(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three/examples/jsm/controls/PointerLockControls.js'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());\nObject(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());\nObject(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three/examples/jsm/libs/stats.module.js'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());\n\n\n\n\nvar isGameRunning = false; // Track if the game is running\nvar paused = false; // Track if the game is paused\n\ndocument.addEventListener('DOMContentLoaded', function () {\n var mainButton = document.getElementById('mainButton');\n if (mainButton) {\n mainButton.onclick = function () {\n if (isGameRunning) {\n resumeGame(); // Resume the game if already started and paused\n } else {\n startGame(); // Start the game for the first time\n }\n };\n } else {\n console.error(\"Main button not found!\");\n }\n});\nfunction startGame() {\n controls.lock(); // Lock the pointer for the first time\n isGameRunning = true;\n paused = false;\n document.getElementById('mainButton').innerText = 'Resume Game'; // Change button to 'Resume Game' after start\n document.getElementById('menu').style.display = 'none'; // Hide the menu\n animate(); // Start the game animation loop\n}\nfunction resumeGame() {\n controls.lock(); // Lock the pointer again to resume\n paused = false;\n document.getElementById('menu').style.display = 'none'; // Hide the menu\n animate(); // Resume the animation loop\n}\nfunction pauseGame() {\n paused = true;\n document.getElementById('menu').style.display = 'block'; // Show the menu when paused\n}\nvar scene = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\nvar renderer = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n antialias: true\n});\nrenderer.setSize(window.innerWidth, window.innerHeight);\nrenderer.shadowMap.enabled = true;\nrenderer.shadowMap.type = Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());\ndocument.body.appendChild(renderer.domElement);\n\n// FPS Counter (Stats.js)\nvar stats = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three/examples/jsm/libs/stats.module.js'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\ndocument.body.appendChild(stats.dom);\nvar camera = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(75, window.innerWidth / window.innerHeight, 0.1, 1000);\ncamera.position.set(0, 1.8, 5);\nvar controls = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three/examples/jsm/controls/PointerLockControls.js'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(camera, document.body);\ndocument.body.addEventListener('click', function () {\n if (!isGameRunning) return; // Prevent locking controls before the game starts\n controls.lock();\n});\ncontrols.addEventListener('lock', function () {\n if (!paused) document.getElementById('menu').style.display = 'none'; // Hide the menu when the pointer is locked\n});\ncontrols.addEventListener('unlock', function () {\n if (isGameRunning) pauseGame(); // Show the menu when the pointer is unlocked and the game is running\n});\nwindow.addEventListener('resize', function () {\n renderer.setSize(window.innerWidth, window.innerHeight);\n camera.aspect = window.innerWidth / window.innerHeight;\n camera.updateProjectionMatrix();\n});\n\n// Load Babylon.js online skybox textures using CubeTextureLoader\nvar skyboxLoader = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\nvar skyboxTexture = skyboxLoader.load(['https://playground.babylonjs.com/textures/skybox_px.jpg', 'https://playground.babylonjs.com/textures/skybox_nx.jpg', 'https://playground.babylonjs.com/textures/skybox_py.jpg', 'https://playground.babylonjs.com/textures/skybox_ny.jpg', 'https://playground.babylonjs.com/textures/skybox_pz.jpg', 'https://playground.babylonjs.com/textures/skybox_nz.jpg']);\nscene.background = skyboxTexture;\n\n// Physics world\nvar world = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\nworld.gravity.set(0, -9.82, 0);\nworld.broadphase = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\nworld.solver.iterations = 10;\nvar fixedTimeStep = 1 / 120;\nvar maxSubSteps = 3;\n\n// Ground Physics\nvar groundBody = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n type: Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }()).STATIC,\n shape: new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())()\n});\ngroundBody.quaternion.setFromEuler(-Math.PI / 2, 0, 0);\nworld.addBody(groundBody);\n\n// Ground Mesh\nvar textureLoader = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\nvar groundTexture = textureLoader.load('https://threejsfundamentals.org/threejs/resources/images/checker.png');\ngroundTexture.wrapS = groundTexture.wrapT = Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }());\ngroundTexture.repeat.set(10, 10);\nvar groundMaterial = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n map: groundTexture,\n metalness: 0.3,\n roughness: 0.7\n});\nvar ground = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(50, 50), groundMaterial);\nground.rotation.x = -Math.PI / 2;\nground.receiveShadow = true;\nscene.add(ground);\n\n// Wall texture\nvar wallTexture = textureLoader.load('https://dl.polyhaven.org/file/ph-assets/Textures/jpg/2k/brick_wall_006/brick_wall_006_diff_2k.jpg');\nvar wallMaterial = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n map: wallTexture,\n metalness: 0.0,\n roughness: 0.8\n});\n\n// Create walls\nvar wall1 = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(10, 5, 1), wallMaterial);\nwall1.position.set(0, 2.5, -5);\nwall1.castShadow = true;\nwall1.receiveShadow = true;\nscene.add(wall1);\nvar wall1Body = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n mass: 0,\n shape: new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(5, 2.5, 0.5))\n});\nwall1Body.position.set(0, 2.5, -5);\nworld.addBody(wall1Body);\nvar wall2 = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(10, 5, 1), wallMaterial);\nwall2.position.set(-5, 2.5, 0);\nwall2.rotation.y = Math.PI / 2;\nwall2.castShadow = true;\nwall2.receiveShadow = true;\nscene.add(wall2);\nvar wall2Body = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n mass: 0,\n shape: new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(5, 2.5, 0.5))\n});\nwall2Body.position.set(-5, 2.5, 0);\nwall2Body.quaternion.setFromEuler(0, Math.PI / 2, 0);\nworld.addBody(wall2Body);\n\n// Light setup\nvar hemisphereLight = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(0xddeeff, 0x0f0e0d, 1);\nscene.add(hemisphereLight);\nvar directionalLight = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(0xffffff, 1.5);\ndirectionalLight.position.set(10, 20, 10);\ndirectionalLight.castShadow = true;\nscene.add(directionalLight);\n\n// Cube object with dynamic physics\nvar cubeMaterial = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n color: 0xff0000\n});\nvar cube = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(1, 1, 1), cubeMaterial);\ncube.position.set(0, 1, 0);\ncube.castShadow = true;\nscene.add(cube);\nvar cubeBody = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n mass: 2,\n shape: new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(0.5, 0.5, 0.5))\n});\ncubeBody.position.set(0, 1, 0);\nworld.addBody(cubeBody);\n\n// Sphere object with dynamic physics\nvar sphere = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(0.5, 32, 32), new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n color: 0x00ff00\n}));\nsphere.position.set(3, 1, 0);\nsphere.castShadow = true;\nscene.add(sphere);\nvar sphereBody = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n mass: 2,\n shape: new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(0.5)\n});\nsphereBody.position.set(3, 1, 0);\nworld.addBody(sphereBody);\n\n// Player Physics\nvar playerBody = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())({\n mass: 5,\n shape: new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(1)\n});\nplayerBody.position.set(0, 1, 10);\nworld.addBody(playerBody);\nvar moveForward = false,\n moveBackward = false,\n moveLeft = false,\n moveRight = false;\nvar canJump = false;\nvar isSprinting = false;\nvar baseMoveSpeed = 100;\nvar sprintMultiplier = 2;\nvar velocity = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\nvar heldObject = null;\nvar holder = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\nvar pickupDistance = 2.5;\n\n// Event listener for collisions to enable jumping\nplayerBody.addEventListener('collide', function (event) {\n if (event.body === groundBody) {\n canJump = true;\n }\n});\n\n// Input controls\ndocument.addEventListener('keydown', function (event) {\n switch (event.code) {\n case 'KeyW':\n moveForward = true;\n break;\n case 'KeyS':\n moveBackward = true;\n break;\n case 'KeyA':\n moveLeft = true;\n break;\n case 'KeyD':\n moveRight = true;\n break;\n case 'ControlLeft':\n isSprinting = true;\n break;\n case 'Space':\n if (canJump) {\n playerBody.velocity.y = 10;\n canJump = false;\n }\n break;\n case 'KeyE':\n if (heldObject) {\n releaseObject();\n } else {\n pickUpObject();\n }\n break;\n case 'KeyF':\n if (heldObject) {\n throwObject();\n }\n break;\n }\n});\ndocument.addEventListener('keyup', function (event) {\n switch (event.code) {\n case 'KeyW':\n moveForward = false;\n break;\n case 'KeyS':\n moveBackward = false;\n break;\n case 'KeyA':\n moveLeft = false;\n break;\n case 'KeyD':\n moveRight = false;\n break;\n case 'ControlLeft':\n isSprinting = false;\n break;\n }\n});\n\n// Picking up objects and making them kinematic\nfunction pickUpObject() {\n var raycaster = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\n raycaster.setFromCamera(new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())(0, 0), camera);\n var intersects = raycaster.intersectObjects([cube, sphere]);\n if (intersects.length > 0) {\n var intersectedObject = intersects[0].object;\n var body;\n if (intersectedObject === cube) {\n body = cubeBody;\n } else if (intersectedObject === sphere) {\n body = sphereBody;\n }\n var distance = playerBody.position.distanceTo(intersectedObject.position);\n if (distance <= pickupDistance) {\n heldObject = body;\n heldObject.angularVelocity.set(0, 0, 0);\n heldObject.angularDamping = 1;\n\n // Disable gravity and set kinematic so the object doesn't affect the player\n heldObject.type = Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }()).KINEMATIC;\n heldObject.allowSleep = false;\n heldObject.gravityScale = 0;\n\n // Adjust object position smoothly to prevent passing through walls\n heldObject.collisionResponse = false;\n }\n }\n}\n\n// Release held object and make it dynamic again\nfunction releaseObject() {\n if (heldObject) {\n heldObject.type = Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }()).DYNAMIC;\n heldObject.gravityScale = 1;\n heldObject.angularDamping = 0.1;\n heldObject.collisionResponse = true;\n heldObject = null;\n }\n}\n\n// Throw object with velocity\nfunction throwObject() {\n if (heldObject) {\n var throwVelocity = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'cannon-es'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\n var cameraDirection = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\n camera.getWorldDirection(cameraDirection);\n throwVelocity.set(cameraDirection.x * 20, cameraDirection.y * 20, cameraDirection.z * 20);\n heldObject.velocity.copy(throwVelocity);\n releaseObject();\n }\n}\n\n// Movement logic and restrictions\nfunction updatePlayerMovement(delta) {\n velocity.set(0, 0, 0);\n var moveSpeed = isSprinting ? baseMoveSpeed * sprintMultiplier : baseMoveSpeed;\n var forward = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\n camera.getWorldDirection(forward);\n var right = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\n right.crossVectors(forward, camera.up).normalize();\n if (moveForward) velocity.add(forward.multiplyScalar(moveSpeed * delta));\n if (moveBackward) velocity.add(forward.multiplyScalar(-moveSpeed * delta));\n if (moveLeft) velocity.add(right.multiplyScalar(-moveSpeed * delta));\n if (moveRight) velocity.add(right.multiplyScalar(moveSpeed * delta));\n playerBody.velocity.x = velocity.x;\n playerBody.velocity.z = velocity.z;\n camera.position.copy(playerBody.position);\n controls.object.position.copy(playerBody.position);\n\n // Move held object smoothly with the player\n if (heldObject) {\n var cameraDirection = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\n camera.getWorldDirection(cameraDirection);\n cameraDirection.normalize();\n holder.copy(camera.position).add(cameraDirection.multiplyScalar(2));\n heldObject.position.set(holder.x, holder.y, holder.z);\n }\n}\n\n// Animation loop\nvar clock = new Object(function webpackMissingModule() { var e = new Error(\"Cannot find module 'three'\"); e.code = 'MODULE_NOT_FOUND'; throw e; }())();\nfunction animate() {\n if (paused) return; // Stop the loop if paused\n\n var delta = clock.getDelta();\n world.step(fixedTimeStep, delta, maxSubSteps);\n updatePlayerMovement(delta);\n wall1.position.copy(wall1Body.position);\n wall1.quaternion.copy(wall1Body.quaternion);\n wall2.position.copy(wall2Body.position);\n wall2.quaternion.copy(wall2Body.quaternion);\n cube.position.copy(cubeBody.position);\n cube.quaternion.copy(cubeBody.quaternion);\n sphere.position.copy(sphereBody.position);\n sphere.quaternion.copy(sphereBody.quaternion);\n stats.update();\n renderer.render(scene, camera);\n requestAnimationFrame(animate);\n}\nanimate();\n\n//# sourceURL=webpack://3d_game/./src/index.js?");
+
+ /***/
+ })
+
+ /******/
+ };
+ /************************************************************************/
+ /******/ // The require scope
+ /******/
+ var __webpack_require__ = {};
+ /******/
+ /************************************************************************/
+ /******/ /* webpack/runtime/make namespace object */
+ /******/
+ (function () {
+ /******/ // define __esModule on exports
+ /******/__webpack_require__.r = function (exports) {
+ /******/if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
+ /******/Object.defineProperty(exports, Symbol.toStringTag, {
+ value: 'Module'
+ });
+ /******/
+ }
+ /******/
+ Object.defineProperty(exports, '__esModule', {
+ value: true
+ });
+ /******/
+ };
+ /******/
+ })();
+ /******/
+ /************************************************************************/
+ /******/
+ /******/ // startup
+ /******/ // Load entry module and return exports
+ /******/ // This entry module can't be inlined because the eval devtool is used.
+ /******/
+ var __webpack_exports__ = {};
+ /******/
+ __webpack_modules__["./src/index.js"](0, __webpack_exports__, __webpack_require__);
+ /******/
+ /******/
+})();
\ No newline at end of file
diff --git a/dist/a708c87fa8616c003655.js b/dist/a708c87fa8616c003655.js
new file mode 100644
index 00000000..e3a89072
--- /dev/null
+++ b/dist/a708c87fa8616c003655.js
@@ -0,0 +1,2 @@
+/*! For license information please see a708c87fa8616c003655.js.LICENSE.txt */
+(function(){"use strict";var __webpack_modules__={"./src/index.js":function _src_indexJs(__unused_webpack_module,__webpack_exports__,__webpack_require__){eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var three__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! three */ \"./node_modules/three/build/three.module.js\");\n/* harmony import */ var three_examples_jsm_controls_PointerLockControls_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! three/examples/jsm/controls/PointerLockControls.js */ \"./node_modules/three/examples/jsm/controls/PointerLockControls.js\");\n/* harmony import */ var cannon_es__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! cannon-es */ \"./node_modules/cannon-es/dist/cannon-es.js\");\n/* harmony import */ var three_examples_jsm_libs_stats_module_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! three/examples/jsm/libs/stats.module.js */ \"./node_modules/three/examples/jsm/libs/stats.module.js\");\n\n\n\n\nvar isGameRunning = false; // Track if the game is running\nvar paused = false; // Track if the game is paused\n\ndocument.addEventListener('DOMContentLoaded', function () {\n var mainButton = document.getElementById('mainButton');\n if (mainButton) {\n mainButton.onclick = function () {\n if (isGameRunning) {\n resumeGame(); // Resume the game if already started and paused\n } else {\n startGame(); // Start the game for the first time\n }\n };\n } else {\n console.error(\"Main button not found!\");\n }\n});\nfunction startGame() {\n controls.lock(); // Lock the pointer for the first time\n isGameRunning = true;\n paused = false;\n document.getElementById('mainButton').innerText = 'Resume Game'; // Change button to 'Resume Game' after start\n document.getElementById('menu').style.display = 'none'; // Hide the menu\n animate(); // Start the game animation loop\n}\nfunction resumeGame() {\n controls.lock(); // Lock the pointer again to resume\n paused = false;\n document.getElementById('menu').style.display = 'none'; // Hide the menu\n animate(); // Resume the animation loop\n}\nfunction pauseGame() {\n paused = true;\n document.getElementById('menu').style.display = 'block'; // Show the menu when paused\n}\nvar scene = new three__WEBPACK_IMPORTED_MODULE_0__.Scene();\nvar renderer = new three__WEBPACK_IMPORTED_MODULE_0__.WebGLRenderer({\n antialias: true\n});\nrenderer.setSize(window.innerWidth, window.innerHeight);\nrenderer.shadowMap.enabled = true;\nrenderer.shadowMap.type = three__WEBPACK_IMPORTED_MODULE_0__.PCFSoftShadowMap;\ndocument.body.appendChild(renderer.domElement);\n\n// FPS Counter (Stats.js)\nvar stats = new three_examples_jsm_libs_stats_module_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"]();\ndocument.body.appendChild(stats.dom);\nvar camera = new three__WEBPACK_IMPORTED_MODULE_0__.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);\ncamera.position.set(0, 1.8, 5);\nvar controls = new three_examples_jsm_controls_PointerLockControls_js__WEBPACK_IMPORTED_MODULE_2__.PointerLockControls(camera, document.body);\ndocument.body.addEventListener('click', function () {\n if (!isGameRunning) return; // Prevent locking controls before the game starts\n controls.lock();\n});\ncontrols.addEventListener('lock', function () {\n if (!paused) document.getElementById('menu').style.display = 'none'; // Hide the menu when the pointer is locked\n});\ncontrols.addEventListener('unlock', function () {\n if (isGameRunning) pauseGame(); // Show the menu when the pointer is unlocked and the game is running\n});\nwindow.addEventListener('resize', function () {\n renderer.setSize(window.innerWidth, window.innerHeight);\n camera.aspect = window.innerWidth / window.innerHeight;\n camera.updateProjectionMatrix();\n});\n\n// Load Babylon.js online skybox textures using CubeTextureLoader\nvar skyboxLoader = new three__WEBPACK_IMPORTED_MODULE_0__.CubeTextureLoader();\nvar skyboxTexture = skyboxLoader.load(['https://playground.babylonjs.com/textures/skybox_px.jpg', 'https://playground.babylonjs.com/textures/skybox_nx.jpg', 'https://playground.babylonjs.com/textures/skybox_py.jpg', 'https://playground.babylonjs.com/textures/skybox_ny.jpg', 'https://playground.babylonjs.com/textures/skybox_pz.jpg', 'https://playground.babylonjs.com/textures/skybox_nz.jpg']);\nscene.background = skyboxTexture;\n\n// Physics world\nvar world = new cannon_es__WEBPACK_IMPORTED_MODULE_3__.World();\nworld.gravity.set(0, -9.82, 0);\nworld.broadphase = new cannon_es__WEBPACK_IMPORTED_MODULE_3__.NaiveBroadphase();\nworld.solver.iterations = 10;\nvar fixedTimeStep = 1 / 120;\nvar maxSubSteps = 3;\n\n// Ground Physics\nvar groundBody = new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Body({\n type: cannon_es__WEBPACK_IMPORTED_MODULE_3__.Body.STATIC,\n shape: new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Plane()\n});\ngroundBody.quaternion.setFromEuler(-Math.PI / 2, 0, 0);\nworld.addBody(groundBody);\n\n// Ground Mesh\nvar textureLoader = new three__WEBPACK_IMPORTED_MODULE_0__.TextureLoader();\nvar groundTexture = textureLoader.load('https://threejsfundamentals.org/threejs/resources/images/checker.png');\ngroundTexture.wrapS = groundTexture.wrapT = three__WEBPACK_IMPORTED_MODULE_0__.RepeatWrapping;\ngroundTexture.repeat.set(10, 10);\nvar groundMaterial = new three__WEBPACK_IMPORTED_MODULE_0__.MeshStandardMaterial({\n map: groundTexture,\n metalness: 0.3,\n roughness: 0.7\n});\nvar ground = new three__WEBPACK_IMPORTED_MODULE_0__.Mesh(new three__WEBPACK_IMPORTED_MODULE_0__.PlaneGeometry(50, 50), groundMaterial);\nground.rotation.x = -Math.PI / 2;\nground.receiveShadow = true;\nscene.add(ground);\n\n// Wall texture\nvar wallTexture = textureLoader.load('https://dl.polyhaven.org/file/ph-assets/Textures/jpg/2k/brick_wall_006/brick_wall_006_diff_2k.jpg');\nvar wallMaterial = new three__WEBPACK_IMPORTED_MODULE_0__.MeshStandardMaterial({\n map: wallTexture,\n metalness: 0.0,\n roughness: 0.8\n});\n\n// Create walls\nvar wall1 = new three__WEBPACK_IMPORTED_MODULE_0__.Mesh(new three__WEBPACK_IMPORTED_MODULE_0__.BoxGeometry(10, 5, 1), wallMaterial);\nwall1.position.set(0, 2.5, -5);\nwall1.castShadow = true;\nwall1.receiveShadow = true;\nscene.add(wall1);\nvar wall1Body = new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Body({\n mass: 0,\n shape: new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Box(new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Vec3(5, 2.5, 0.5))\n});\nwall1Body.position.set(0, 2.5, -5);\nworld.addBody(wall1Body);\nvar wall2 = new three__WEBPACK_IMPORTED_MODULE_0__.Mesh(new three__WEBPACK_IMPORTED_MODULE_0__.BoxGeometry(10, 5, 1), wallMaterial);\nwall2.position.set(-5, 2.5, 0);\nwall2.rotation.y = Math.PI / 2;\nwall2.castShadow = true;\nwall2.receiveShadow = true;\nscene.add(wall2);\nvar wall2Body = new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Body({\n mass: 0,\n shape: new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Box(new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Vec3(5, 2.5, 0.5))\n});\nwall2Body.position.set(-5, 2.5, 0);\nwall2Body.quaternion.setFromEuler(0, Math.PI / 2, 0);\nworld.addBody(wall2Body);\n\n// Light setup\nvar hemisphereLight = new three__WEBPACK_IMPORTED_MODULE_0__.HemisphereLight(0xddeeff, 0x0f0e0d, 1);\nscene.add(hemisphereLight);\nvar directionalLight = new three__WEBPACK_IMPORTED_MODULE_0__.DirectionalLight(0xffffff, 1.5);\ndirectionalLight.position.set(10, 20, 10);\ndirectionalLight.castShadow = true;\nscene.add(directionalLight);\n\n// Cube object with dynamic physics\nvar cubeMaterial = new three__WEBPACK_IMPORTED_MODULE_0__.MeshStandardMaterial({\n color: 0xff0000\n});\nvar cube = new three__WEBPACK_IMPORTED_MODULE_0__.Mesh(new three__WEBPACK_IMPORTED_MODULE_0__.BoxGeometry(1, 1, 1), cubeMaterial);\ncube.position.set(0, 1, 0);\ncube.castShadow = true;\nscene.add(cube);\nvar cubeBody = new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Body({\n mass: 2,\n shape: new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Box(new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Vec3(0.5, 0.5, 0.5))\n});\ncubeBody.position.set(0, 1, 0);\nworld.addBody(cubeBody);\n\n// Sphere object with dynamic physics\nvar sphere = new three__WEBPACK_IMPORTED_MODULE_0__.Mesh(new three__WEBPACK_IMPORTED_MODULE_0__.SphereGeometry(0.5, 32, 32), new three__WEBPACK_IMPORTED_MODULE_0__.MeshStandardMaterial({\n color: 0x00ff00\n}));\nsphere.position.set(3, 1, 0);\nsphere.castShadow = true;\nscene.add(sphere);\nvar sphereBody = new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Body({\n mass: 2,\n shape: new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Sphere(0.5)\n});\nsphereBody.position.set(3, 1, 0);\nworld.addBody(sphereBody);\n\n// Player Physics\nvar playerBody = new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Body({\n mass: 5,\n shape: new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Sphere(1)\n});\nplayerBody.position.set(0, 1, 10);\nworld.addBody(playerBody);\nvar moveForward = false,\n moveBackward = false,\n moveLeft = false,\n moveRight = false;\nvar canJump = false;\nvar isSprinting = false;\nvar baseMoveSpeed = 100;\nvar sprintMultiplier = 2;\nvar velocity = new three__WEBPACK_IMPORTED_MODULE_0__.Vector3();\nvar heldObject = null;\nvar holder = new three__WEBPACK_IMPORTED_MODULE_0__.Vector3();\nvar pickupDistance = 2.5;\n\n// Event listener for collisions to enable jumping\nplayerBody.addEventListener('collide', function (event) {\n if (event.body === groundBody) {\n canJump = true;\n }\n});\n\n// Input controls\ndocument.addEventListener('keydown', function (event) {\n switch (event.code) {\n case 'KeyW':\n moveForward = true;\n break;\n case 'KeyS':\n moveBackward = true;\n break;\n case 'KeyA':\n moveLeft = true;\n break;\n case 'KeyD':\n moveRight = true;\n break;\n case 'ControlLeft':\n isSprinting = true;\n break;\n case 'Space':\n if (canJump) {\n playerBody.velocity.y = 10;\n canJump = false;\n }\n break;\n case 'KeyE':\n if (heldObject) {\n releaseObject();\n } else {\n pickUpObject();\n }\n break;\n case 'KeyF':\n if (heldObject) {\n throwObject();\n }\n break;\n }\n});\ndocument.addEventListener('keyup', function (event) {\n switch (event.code) {\n case 'KeyW':\n moveForward = false;\n break;\n case 'KeyS':\n moveBackward = false;\n break;\n case 'KeyA':\n moveLeft = false;\n break;\n case 'KeyD':\n moveRight = false;\n break;\n case 'ControlLeft':\n isSprinting = false;\n break;\n }\n});\n\n// Picking up objects and making them kinematic\nfunction pickUpObject() {\n var raycaster = new three__WEBPACK_IMPORTED_MODULE_0__.Raycaster();\n raycaster.setFromCamera(new three__WEBPACK_IMPORTED_MODULE_0__.Vector2(0, 0), camera);\n var intersects = raycaster.intersectObjects([cube, sphere]);\n if (intersects.length > 0) {\n var intersectedObject = intersects[0].object;\n var body;\n if (intersectedObject === cube) {\n body = cubeBody;\n } else if (intersectedObject === sphere) {\n body = sphereBody;\n }\n var distance = playerBody.position.distanceTo(intersectedObject.position);\n if (distance <= pickupDistance) {\n heldObject = body;\n heldObject.angularVelocity.set(0, 0, 0);\n heldObject.angularDamping = 1;\n\n // Disable gravity and set kinematic so the object doesn't affect the player\n heldObject.type = cannon_es__WEBPACK_IMPORTED_MODULE_3__.Body.KINEMATIC;\n heldObject.allowSleep = false;\n heldObject.gravityScale = 0;\n\n // Adjust object position smoothly to prevent passing through walls\n heldObject.collisionResponse = false;\n }\n }\n}\n\n// Release held object and make it dynamic again\nfunction releaseObject() {\n if (heldObject) {\n heldObject.type = cannon_es__WEBPACK_IMPORTED_MODULE_3__.Body.DYNAMIC;\n heldObject.gravityScale = 1;\n heldObject.angularDamping = 0.1;\n heldObject.collisionResponse = true;\n heldObject = null;\n }\n}\n\n// Throw object with velocity\nfunction throwObject() {\n if (heldObject) {\n var throwVelocity = new cannon_es__WEBPACK_IMPORTED_MODULE_3__.Vec3();\n var cameraDirection = new three__WEBPACK_IMPORTED_MODULE_0__.Vector3();\n camera.getWorldDirection(cameraDirection);\n throwVelocity.set(cameraDirection.x * 20, cameraDirection.y * 20, cameraDirection.z * 20);\n heldObject.velocity.copy(throwVelocity);\n releaseObject();\n }\n}\n\n// Movement logic and restrictions\nfunction updatePlayerMovement(delta) {\n velocity.set(0, 0, 0);\n var moveSpeed = isSprinting ? baseMoveSpeed * sprintMultiplier : baseMoveSpeed;\n var forward = new three__WEBPACK_IMPORTED_MODULE_0__.Vector3();\n camera.getWorldDirection(forward);\n var right = new three__WEBPACK_IMPORTED_MODULE_0__.Vector3();\n right.crossVectors(forward, camera.up).normalize();\n if (moveForward) velocity.add(forward.multiplyScalar(moveSpeed * delta));\n if (moveBackward) velocity.add(forward.multiplyScalar(-moveSpeed * delta));\n if (moveLeft) velocity.add(right.multiplyScalar(-moveSpeed * delta));\n if (moveRight) velocity.add(right.multiplyScalar(moveSpeed * delta));\n playerBody.velocity.x = velocity.x;\n playerBody.velocity.z = velocity.z;\n camera.position.copy(playerBody.position);\n controls.object.position.copy(playerBody.position);\n\n // Move held object smoothly with the player\n if (heldObject) {\n var cameraDirection = new three__WEBPACK_IMPORTED_MODULE_0__.Vector3();\n camera.getWorldDirection(cameraDirection);\n cameraDirection.normalize();\n holder.copy(camera.position).add(cameraDirection.multiplyScalar(2));\n heldObject.position.set(holder.x, holder.y, holder.z);\n }\n}\n\n// Animation loop\nvar clock = new three__WEBPACK_IMPORTED_MODULE_0__.Clock();\nfunction animate() {\n if (paused) return; // Stop the loop if paused\n\n var delta = clock.getDelta();\n world.step(fixedTimeStep, delta, maxSubSteps);\n updatePlayerMovement(delta);\n wall1.position.copy(wall1Body.position);\n wall1.quaternion.copy(wall1Body.quaternion);\n wall2.position.copy(wall2Body.position);\n wall2.quaternion.copy(wall2Body.quaternion);\n cube.position.copy(cubeBody.position);\n cube.quaternion.copy(cubeBody.quaternion);\n sphere.position.copy(sphereBody.position);\n sphere.quaternion.copy(sphereBody.quaternion);\n stats.update();\n renderer.render(scene, camera);\n requestAnimationFrame(animate);\n}\nanimate();\n\n//# sourceURL=webpack://3d_game/./src/index.js?")},"./node_modules/cannon-es/dist/cannon-es.js":function _node_modules_cannonEs_dist_cannonEsJs(__unused_webpack_module,__webpack_exports__,__webpack_require__){eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ AABB: () => (/* binding */ AABB),\n/* harmony export */ ArrayCollisionMatrix: () => (/* binding */ ArrayCollisionMatrix),\n/* harmony export */ BODY_SLEEP_STATES: () => (/* binding */ BODY_SLEEP_STATES),\n/* harmony export */ BODY_TYPES: () => (/* binding */ BODY_TYPES),\n/* harmony export */ Body: () => (/* binding */ Body),\n/* harmony export */ Box: () => (/* binding */ Box),\n/* harmony export */ Broadphase: () => (/* binding */ Broadphase),\n/* harmony export */ COLLISION_TYPES: () => (/* binding */ COLLISION_TYPES),\n/* harmony export */ ConeTwistConstraint: () => (/* binding */ ConeTwistConstraint),\n/* harmony export */ Constraint: () => (/* binding */ Constraint),\n/* harmony export */ ContactEquation: () => (/* binding */ ContactEquation),\n/* harmony export */ ContactMaterial: () => (/* binding */ ContactMaterial),\n/* harmony export */ ConvexPolyhedron: () => (/* binding */ ConvexPolyhedron),\n/* harmony export */ Cylinder: () => (/* binding */ Cylinder),\n/* harmony export */ DistanceConstraint: () => (/* binding */ DistanceConstraint),\n/* harmony export */ Equation: () => (/* binding */ Equation),\n/* harmony export */ EventTarget: () => (/* binding */ EventTarget),\n/* harmony export */ FrictionEquation: () => (/* binding */ FrictionEquation),\n/* harmony export */ GSSolver: () => (/* binding */ GSSolver),\n/* harmony export */ GridBroadphase: () => (/* binding */ GridBroadphase),\n/* harmony export */ Heightfield: () => (/* binding */ Heightfield),\n/* harmony export */ HingeConstraint: () => (/* binding */ HingeConstraint),\n/* harmony export */ JacobianElement: () => (/* binding */ JacobianElement),\n/* harmony export */ LockConstraint: () => (/* binding */ LockConstraint),\n/* harmony export */ Mat3: () => (/* binding */ Mat3),\n/* harmony export */ Material: () => (/* binding */ Material),\n/* harmony export */ NaiveBroadphase: () => (/* binding */ NaiveBroadphase),\n/* harmony export */ Narrowphase: () => (/* binding */ Narrowphase),\n/* harmony export */ ObjectCollisionMatrix: () => (/* binding */ ObjectCollisionMatrix),\n/* harmony export */ Particle: () => (/* binding */ Particle),\n/* harmony export */ Plane: () => (/* binding */ Plane),\n/* harmony export */ PointToPointConstraint: () => (/* binding */ PointToPointConstraint),\n/* harmony export */ Pool: () => (/* binding */ Pool),\n/* harmony export */ Quaternion: () => (/* binding */ Quaternion),\n/* harmony export */ RAY_MODES: () => (/* binding */ RAY_MODES),\n/* harmony export */ Ray: () => (/* binding */ Ray),\n/* harmony export */ RaycastResult: () => (/* binding */ RaycastResult),\n/* harmony export */ RaycastVehicle: () => (/* binding */ RaycastVehicle),\n/* harmony export */ RigidVehicle: () => (/* binding */ RigidVehicle),\n/* harmony export */ RotationalEquation: () => (/* binding */ RotationalEquation),\n/* harmony export */ RotationalMotorEquation: () => (/* binding */ RotationalMotorEquation),\n/* harmony export */ SAPBroadphase: () => (/* binding */ SAPBroadphase),\n/* harmony export */ SHAPE_TYPES: () => (/* binding */ SHAPE_TYPES),\n/* harmony export */ SPHSystem: () => (/* binding */ SPHSystem),\n/* harmony export */ Shape: () => (/* binding */ Shape),\n/* harmony export */ Solver: () => (/* binding */ Solver),\n/* harmony export */ Sphere: () => (/* binding */ Sphere),\n/* harmony export */ SplitSolver: () => (/* binding */ SplitSolver),\n/* harmony export */ Spring: () => (/* binding */ Spring),\n/* harmony export */ Transform: () => (/* binding */ Transform),\n/* harmony export */ Trimesh: () => (/* binding */ Trimesh),\n/* harmony export */ Vec3: () => (/* binding */ Vec3),\n/* harmony export */ Vec3Pool: () => (/* binding */ Vec3Pool),\n/* harmony export */ WheelInfo: () => (/* binding */ WheelInfo),\n/* harmony export */ World: () => (/* binding */ World)\n/* harmony export */ });\n/**\n * Records what objects are colliding with each other\n */\nclass ObjectCollisionMatrix {\n /**\n * The matrix storage.\n */\n\n /**\n * @todo Remove useless constructor\n */\n constructor() {\n this.matrix = {};\n }\n /**\n * get\n */\n\n\n get(bi, bj) {\n let {\n id: i\n } = bi;\n let {\n id: j\n } = bj;\n\n if (j > i) {\n const temp = j;\n j = i;\n i = temp;\n }\n\n return `${i}-${j}` in this.matrix;\n }\n /**\n * set\n */\n\n\n set(bi, bj, value) {\n let {\n id: i\n } = bi;\n let {\n id: j\n } = bj;\n\n if (j > i) {\n const temp = j;\n j = i;\n i = temp;\n }\n\n if (value) {\n this.matrix[`${i}-${j}`] = true;\n } else {\n delete this.matrix[`${i}-${j}`];\n }\n }\n /**\n * Empty the matrix\n */\n\n\n reset() {\n this.matrix = {};\n }\n /**\n * Set max number of objects\n */\n\n\n setNumObjects(n) {}\n\n}\n\n/**\n * A 3x3 matrix.\n * Authored by {@link http://github.com/schteppe/ schteppe}\n */\nclass Mat3 {\n /**\n * A vector of length 9, containing all matrix elements.\n */\n\n /**\n * @param elements A vector of length 9, containing all matrix elements.\n */\n constructor(elements) {\n if (elements === void 0) {\n elements = [0, 0, 0, 0, 0, 0, 0, 0, 0];\n }\n\n this.elements = elements;\n }\n /**\n * Sets the matrix to identity\n * @todo Should perhaps be renamed to `setIdentity()` to be more clear.\n * @todo Create another function that immediately creates an identity matrix eg. `eye()`\n */\n\n\n identity() {\n const e = this.elements;\n e[0] = 1;\n e[1] = 0;\n e[2] = 0;\n e[3] = 0;\n e[4] = 1;\n e[5] = 0;\n e[6] = 0;\n e[7] = 0;\n e[8] = 1;\n }\n /**\n * Set all elements to zero\n */\n\n\n setZero() {\n const e = this.elements;\n e[0] = 0;\n e[1] = 0;\n e[2] = 0;\n e[3] = 0;\n e[4] = 0;\n e[5] = 0;\n e[6] = 0;\n e[7] = 0;\n e[8] = 0;\n }\n /**\n * Sets the matrix diagonal elements from a Vec3\n */\n\n\n setTrace(vector) {\n const e = this.elements;\n e[0] = vector.x;\n e[4] = vector.y;\n e[8] = vector.z;\n }\n /**\n * Gets the matrix diagonal elements\n */\n\n\n getTrace(target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n const e = this.elements;\n target.x = e[0];\n target.y = e[4];\n target.z = e[8];\n return target;\n }\n /**\n * Matrix-Vector multiplication\n * @param v The vector to multiply with\n * @param target Optional, target to save the result in.\n */\n\n\n vmult(v, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n const e = this.elements;\n const x = v.x;\n const y = v.y;\n const z = v.z;\n target.x = e[0] * x + e[1] * y + e[2] * z;\n target.y = e[3] * x + e[4] * y + e[5] * z;\n target.z = e[6] * x + e[7] * y + e[8] * z;\n return target;\n }\n /**\n * Matrix-scalar multiplication\n */\n\n\n smult(s) {\n for (let i = 0; i < this.elements.length; i++) {\n this.elements[i] *= s;\n }\n }\n /**\n * Matrix multiplication\n * @param matrix Matrix to multiply with from left side.\n */\n\n\n mmult(matrix, target) {\n if (target === void 0) {\n target = new Mat3();\n }\n\n const A = this.elements;\n const B = matrix.elements;\n const T = target.elements;\n const a11 = A[0],\n a12 = A[1],\n a13 = A[2],\n a21 = A[3],\n a22 = A[4],\n a23 = A[5],\n a31 = A[6],\n a32 = A[7],\n a33 = A[8];\n const b11 = B[0],\n b12 = B[1],\n b13 = B[2],\n b21 = B[3],\n b22 = B[4],\n b23 = B[5],\n b31 = B[6],\n b32 = B[7],\n b33 = B[8];\n T[0] = a11 * b11 + a12 * b21 + a13 * b31;\n T[1] = a11 * b12 + a12 * b22 + a13 * b32;\n T[2] = a11 * b13 + a12 * b23 + a13 * b33;\n T[3] = a21 * b11 + a22 * b21 + a23 * b31;\n T[4] = a21 * b12 + a22 * b22 + a23 * b32;\n T[5] = a21 * b13 + a22 * b23 + a23 * b33;\n T[6] = a31 * b11 + a32 * b21 + a33 * b31;\n T[7] = a31 * b12 + a32 * b22 + a33 * b32;\n T[8] = a31 * b13 + a32 * b23 + a33 * b33;\n return target;\n }\n /**\n * Scale each column of the matrix\n */\n\n\n scale(vector, target) {\n if (target === void 0) {\n target = new Mat3();\n }\n\n const e = this.elements;\n const t = target.elements;\n\n for (let i = 0; i !== 3; i++) {\n t[3 * i + 0] = vector.x * e[3 * i + 0];\n t[3 * i + 1] = vector.y * e[3 * i + 1];\n t[3 * i + 2] = vector.z * e[3 * i + 2];\n }\n\n return target;\n }\n /**\n * Solve Ax=b\n * @param b The right hand side\n * @param target Optional. Target vector to save in.\n * @return The solution x\n * @todo should reuse arrays\n */\n\n\n solve(b, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n // Construct equations\n const nr = 3; // num rows\n\n const nc = 4; // num cols\n\n const eqns = [];\n let i;\n let j;\n\n for (i = 0; i < nr * nc; i++) {\n eqns.push(0);\n }\n\n for (i = 0; i < 3; i++) {\n for (j = 0; j < 3; j++) {\n eqns[i + nc * j] = this.elements[i + 3 * j];\n }\n }\n\n eqns[3 + 4 * 0] = b.x;\n eqns[3 + 4 * 1] = b.y;\n eqns[3 + 4 * 2] = b.z; // Compute right upper triangular version of the matrix - Gauss elimination\n\n let n = 3;\n const k = n;\n let np;\n const kp = 4; // num rows\n\n let p;\n\n do {\n i = k - n;\n\n if (eqns[i + nc * i] === 0) {\n // the pivot is null, swap lines\n for (j = i + 1; j < k; j++) {\n if (eqns[i + nc * j] !== 0) {\n np = kp;\n\n do {\n // do ligne( i ) = ligne( i ) + ligne( k )\n p = kp - np;\n eqns[p + nc * i] += eqns[p + nc * j];\n } while (--np);\n\n break;\n }\n }\n }\n\n if (eqns[i + nc * i] !== 0) {\n for (j = i + 1; j < k; j++) {\n const multiplier = eqns[i + nc * j] / eqns[i + nc * i];\n np = kp;\n\n do {\n // do ligne( k ) = ligne( k ) - multiplier * ligne( i )\n p = kp - np;\n eqns[p + nc * j] = p <= i ? 0 : eqns[p + nc * j] - eqns[p + nc * i] * multiplier;\n } while (--np);\n }\n }\n } while (--n); // Get the solution\n\n\n target.z = eqns[2 * nc + 3] / eqns[2 * nc + 2];\n target.y = (eqns[1 * nc + 3] - eqns[1 * nc + 2] * target.z) / eqns[1 * nc + 1];\n target.x = (eqns[0 * nc + 3] - eqns[0 * nc + 2] * target.z - eqns[0 * nc + 1] * target.y) / eqns[0 * nc + 0];\n\n if (isNaN(target.x) || isNaN(target.y) || isNaN(target.z) || target.x === Infinity || target.y === Infinity || target.z === Infinity) {\n throw `Could not solve equation! Got x=[${target.toString()}], b=[${b.toString()}], A=[${this.toString()}]`;\n }\n\n return target;\n }\n /**\n * Get an element in the matrix by index. Index starts at 0, not 1!!!\n * @param value If provided, the matrix element will be set to this value.\n */\n\n\n e(row, column, value) {\n if (value === undefined) {\n return this.elements[column + 3 * row];\n } else {\n // Set value\n this.elements[column + 3 * row] = value;\n }\n }\n /**\n * Copy another matrix into this matrix object.\n */\n\n\n copy(matrix) {\n for (let i = 0; i < matrix.elements.length; i++) {\n this.elements[i] = matrix.elements[i];\n }\n\n return this;\n }\n /**\n * Returns a string representation of the matrix.\n */\n\n\n toString() {\n let r = '';\n const sep = ',';\n\n for (let i = 0; i < 9; i++) {\n r += this.elements[i] + sep;\n }\n\n return r;\n }\n /**\n * reverse the matrix\n * @param target Target matrix to save in.\n * @return The solution x\n */\n\n\n reverse(target) {\n if (target === void 0) {\n target = new Mat3();\n }\n\n // Construct equations\n const nr = 3; // num rows\n\n const nc = 6; // num cols\n\n const eqns = reverse_eqns;\n let i;\n let j;\n\n for (i = 0; i < 3; i++) {\n for (j = 0; j < 3; j++) {\n eqns[i + nc * j] = this.elements[i + 3 * j];\n }\n }\n\n eqns[3 + 6 * 0] = 1;\n eqns[3 + 6 * 1] = 0;\n eqns[3 + 6 * 2] = 0;\n eqns[4 + 6 * 0] = 0;\n eqns[4 + 6 * 1] = 1;\n eqns[4 + 6 * 2] = 0;\n eqns[5 + 6 * 0] = 0;\n eqns[5 + 6 * 1] = 0;\n eqns[5 + 6 * 2] = 1; // Compute right upper triangular version of the matrix - Gauss elimination\n\n let n = 3;\n const k = n;\n let np;\n const kp = nc; // num rows\n\n let p;\n\n do {\n i = k - n;\n\n if (eqns[i + nc * i] === 0) {\n // the pivot is null, swap lines\n for (j = i + 1; j < k; j++) {\n if (eqns[i + nc * j] !== 0) {\n np = kp;\n\n do {\n // do line( i ) = line( i ) + line( k )\n p = kp - np;\n eqns[p + nc * i] += eqns[p + nc * j];\n } while (--np);\n\n break;\n }\n }\n }\n\n if (eqns[i + nc * i] !== 0) {\n for (j = i + 1; j < k; j++) {\n const multiplier = eqns[i + nc * j] / eqns[i + nc * i];\n np = kp;\n\n do {\n // do line( k ) = line( k ) - multiplier * line( i )\n p = kp - np;\n eqns[p + nc * j] = p <= i ? 0 : eqns[p + nc * j] - eqns[p + nc * i] * multiplier;\n } while (--np);\n }\n }\n } while (--n); // eliminate the upper left triangle of the matrix\n\n\n i = 2;\n\n do {\n j = i - 1;\n\n do {\n const multiplier = eqns[i + nc * j] / eqns[i + nc * i];\n np = nc;\n\n do {\n p = nc - np;\n eqns[p + nc * j] = eqns[p + nc * j] - eqns[p + nc * i] * multiplier;\n } while (--np);\n } while (j--);\n } while (--i); // operations on the diagonal\n\n\n i = 2;\n\n do {\n const multiplier = 1 / eqns[i + nc * i];\n np = nc;\n\n do {\n p = nc - np;\n eqns[p + nc * i] = eqns[p + nc * i] * multiplier;\n } while (--np);\n } while (i--);\n\n i = 2;\n\n do {\n j = 2;\n\n do {\n p = eqns[nr + j + nc * i];\n\n if (isNaN(p) || p === Infinity) {\n throw `Could not reverse! A=[${this.toString()}]`;\n }\n\n target.e(i, j, p);\n } while (j--);\n } while (i--);\n\n return target;\n }\n /**\n * Set the matrix from a quaterion\n */\n\n\n setRotationFromQuaternion(q) {\n const x = q.x;\n const y = q.y;\n const z = q.z;\n const w = q.w;\n const x2 = x + x;\n const y2 = y + y;\n const z2 = z + z;\n const xx = x * x2;\n const xy = x * y2;\n const xz = x * z2;\n const yy = y * y2;\n const yz = y * z2;\n const zz = z * z2;\n const wx = w * x2;\n const wy = w * y2;\n const wz = w * z2;\n const e = this.elements;\n e[3 * 0 + 0] = 1 - (yy + zz);\n e[3 * 0 + 1] = xy - wz;\n e[3 * 0 + 2] = xz + wy;\n e[3 * 1 + 0] = xy + wz;\n e[3 * 1 + 1] = 1 - (xx + zz);\n e[3 * 1 + 2] = yz - wx;\n e[3 * 2 + 0] = xz - wy;\n e[3 * 2 + 1] = yz + wx;\n e[3 * 2 + 2] = 1 - (xx + yy);\n return this;\n }\n /**\n * Transpose the matrix\n * @param target Optional. Where to store the result.\n * @return The target Mat3, or a new Mat3 if target was omitted.\n */\n\n\n transpose(target) {\n if (target === void 0) {\n target = new Mat3();\n }\n\n const M = this.elements;\n const T = target.elements;\n let tmp; //Set diagonals\n\n T[0] = M[0];\n T[4] = M[4];\n T[8] = M[8];\n tmp = M[1];\n T[1] = M[3];\n T[3] = tmp;\n tmp = M[2];\n T[2] = M[6];\n T[6] = tmp;\n tmp = M[5];\n T[5] = M[7];\n T[7] = tmp;\n return target;\n }\n\n}\nconst reverse_eqns = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];\n\n/**\n * 3-dimensional vector\n * @example\n * const v = new Vec3(1, 2, 3)\n * console.log('x=' + v.x) // x=1\n */\n\nclass Vec3 {\n constructor(x, y, z) {\n if (x === void 0) {\n x = 0.0;\n }\n\n if (y === void 0) {\n y = 0.0;\n }\n\n if (z === void 0) {\n z = 0.0;\n }\n\n this.x = x;\n this.y = y;\n this.z = z;\n }\n /**\n * Vector cross product\n * @param target Optional target to save in.\n */\n\n\n cross(vector, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n const vx = vector.x;\n const vy = vector.y;\n const vz = vector.z;\n const x = this.x;\n const y = this.y;\n const z = this.z;\n target.x = y * vz - z * vy;\n target.y = z * vx - x * vz;\n target.z = x * vy - y * vx;\n return target;\n }\n /**\n * Set the vectors' 3 elements\n */\n\n\n set(x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n return this;\n }\n /**\n * Set all components of the vector to zero.\n */\n\n\n setZero() {\n this.x = this.y = this.z = 0;\n }\n /**\n * Vector addition\n */\n\n\n vadd(vector, target) {\n if (target) {\n target.x = vector.x + this.x;\n target.y = vector.y + this.y;\n target.z = vector.z + this.z;\n } else {\n return new Vec3(this.x + vector.x, this.y + vector.y, this.z + vector.z);\n }\n }\n /**\n * Vector subtraction\n * @param target Optional target to save in.\n */\n\n\n vsub(vector, target) {\n if (target) {\n target.x = this.x - vector.x;\n target.y = this.y - vector.y;\n target.z = this.z - vector.z;\n } else {\n return new Vec3(this.x - vector.x, this.y - vector.y, this.z - vector.z);\n }\n }\n /**\n * Get the cross product matrix a_cross from a vector, such that a x b = a_cross * b = c\n *\n * See {@link https://www8.cs.umu.se/kurser/TDBD24/VT06/lectures/Lecture6.pdf UmeƄ University Lecture}\n */\n\n\n crossmat() {\n return new Mat3([0, -this.z, this.y, this.z, 0, -this.x, -this.y, this.x, 0]);\n }\n /**\n * Normalize the vector. Note that this changes the values in the vector.\n * @return Returns the norm of the vector\n */\n\n\n normalize() {\n const x = this.x;\n const y = this.y;\n const z = this.z;\n const n = Math.sqrt(x * x + y * y + z * z);\n\n if (n > 0.0) {\n const invN = 1 / n;\n this.x *= invN;\n this.y *= invN;\n this.z *= invN;\n } else {\n // Make something up\n this.x = 0;\n this.y = 0;\n this.z = 0;\n }\n\n return n;\n }\n /**\n * Get the version of this vector that is of length 1.\n * @param target Optional target to save in\n * @return Returns the unit vector\n */\n\n\n unit(target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n const x = this.x;\n const y = this.y;\n const z = this.z;\n let ninv = Math.sqrt(x * x + y * y + z * z);\n\n if (ninv > 0.0) {\n ninv = 1.0 / ninv;\n target.x = x * ninv;\n target.y = y * ninv;\n target.z = z * ninv;\n } else {\n target.x = 1;\n target.y = 0;\n target.z = 0;\n }\n\n return target;\n }\n /**\n * Get the length of the vector\n */\n\n\n length() {\n const x = this.x;\n const y = this.y;\n const z = this.z;\n return Math.sqrt(x * x + y * y + z * z);\n }\n /**\n * Get the squared length of the vector.\n */\n\n\n lengthSquared() {\n return this.dot(this);\n }\n /**\n * Get distance from this point to another point\n */\n\n\n distanceTo(p) {\n const x = this.x;\n const y = this.y;\n const z = this.z;\n const px = p.x;\n const py = p.y;\n const pz = p.z;\n return Math.sqrt((px - x) * (px - x) + (py - y) * (py - y) + (pz - z) * (pz - z));\n }\n /**\n * Get squared distance from this point to another point\n */\n\n\n distanceSquared(p) {\n const x = this.x;\n const y = this.y;\n const z = this.z;\n const px = p.x;\n const py = p.y;\n const pz = p.z;\n return (px - x) * (px - x) + (py - y) * (py - y) + (pz - z) * (pz - z);\n }\n /**\n * Multiply all the components of the vector with a scalar.\n * @param target The vector to save the result in.\n */\n\n\n scale(scalar, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n const x = this.x;\n const y = this.y;\n const z = this.z;\n target.x = scalar * x;\n target.y = scalar * y;\n target.z = scalar * z;\n return target;\n }\n /**\n * Multiply the vector with an other vector, component-wise.\n * @param target The vector to save the result in.\n */\n\n\n vmul(vector, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n target.x = vector.x * this.x;\n target.y = vector.y * this.y;\n target.z = vector.z * this.z;\n return target;\n }\n /**\n * Scale a vector and add it to this vector. Save the result in \"target\". (target = this + vector * scalar)\n * @param target The vector to save the result in.\n */\n\n\n addScaledVector(scalar, vector, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n target.x = this.x + scalar * vector.x;\n target.y = this.y + scalar * vector.y;\n target.z = this.z + scalar * vector.z;\n return target;\n }\n /**\n * Calculate dot product\n * @param vector\n */\n\n\n dot(vector) {\n return this.x * vector.x + this.y * vector.y + this.z * vector.z;\n }\n\n isZero() {\n return this.x === 0 && this.y === 0 && this.z === 0;\n }\n /**\n * Make the vector point in the opposite direction.\n * @param target Optional target to save in\n */\n\n\n negate(target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n target.x = -this.x;\n target.y = -this.y;\n target.z = -this.z;\n return target;\n }\n /**\n * Compute two artificial tangents to the vector\n * @param t1 Vector object to save the first tangent in\n * @param t2 Vector object to save the second tangent in\n */\n\n\n tangents(t1, t2) {\n const norm = this.length();\n\n if (norm > 0.0) {\n const n = Vec3_tangents_n;\n const inorm = 1 / norm;\n n.set(this.x * inorm, this.y * inorm, this.z * inorm);\n const randVec = Vec3_tangents_randVec;\n\n if (Math.abs(n.x) < 0.9) {\n randVec.set(1, 0, 0);\n n.cross(randVec, t1);\n } else {\n randVec.set(0, 1, 0);\n n.cross(randVec, t1);\n }\n\n n.cross(t1, t2);\n } else {\n // The normal length is zero, make something up\n t1.set(1, 0, 0);\n t2.set(0, 1, 0);\n }\n }\n /**\n * Converts to a more readable format\n */\n\n\n toString() {\n return `${this.x},${this.y},${this.z}`;\n }\n /**\n * Converts to an array\n */\n\n\n toArray() {\n return [this.x, this.y, this.z];\n }\n /**\n * Copies value of source to this vector.\n */\n\n\n copy(vector) {\n this.x = vector.x;\n this.y = vector.y;\n this.z = vector.z;\n return this;\n }\n /**\n * Do a linear interpolation between two vectors\n * @param t A number between 0 and 1. 0 will make this function return u, and 1 will make it return v. Numbers in between will generate a vector in between them.\n */\n\n\n lerp(vector, t, target) {\n const x = this.x;\n const y = this.y;\n const z = this.z;\n target.x = x + (vector.x - x) * t;\n target.y = y + (vector.y - y) * t;\n target.z = z + (vector.z - z) * t;\n }\n /**\n * Check if a vector equals is almost equal to another one.\n */\n\n\n almostEquals(vector, precision) {\n if (precision === void 0) {\n precision = 1e-6;\n }\n\n if (Math.abs(this.x - vector.x) > precision || Math.abs(this.y - vector.y) > precision || Math.abs(this.z - vector.z) > precision) {\n return false;\n }\n\n return true;\n }\n /**\n * Check if a vector is almost zero\n */\n\n\n almostZero(precision) {\n if (precision === void 0) {\n precision = 1e-6;\n }\n\n if (Math.abs(this.x) > precision || Math.abs(this.y) > precision || Math.abs(this.z) > precision) {\n return false;\n }\n\n return true;\n }\n /**\n * Check if the vector is anti-parallel to another vector.\n * @param precision Set to zero for exact comparisons\n */\n\n\n isAntiparallelTo(vector, precision) {\n this.negate(antip_neg);\n return antip_neg.almostEquals(vector, precision);\n }\n /**\n * Clone the vector\n */\n\n\n clone() {\n return new Vec3(this.x, this.y, this.z);\n }\n\n}\nVec3.ZERO = new Vec3(0, 0, 0);\nVec3.UNIT_X = new Vec3(1, 0, 0);\nVec3.UNIT_Y = new Vec3(0, 1, 0);\nVec3.UNIT_Z = new Vec3(0, 0, 1);\nconst Vec3_tangents_n = new Vec3();\nconst Vec3_tangents_randVec = new Vec3();\nconst antip_neg = new Vec3();\n\n/**\n * Axis aligned bounding box class.\n */\nclass AABB {\n /**\n * The lower bound of the bounding box\n */\n\n /**\n * The upper bound of the bounding box\n */\n constructor(options) {\n if (options === void 0) {\n options = {};\n }\n\n this.lowerBound = new Vec3();\n this.upperBound = new Vec3();\n\n if (options.lowerBound) {\n this.lowerBound.copy(options.lowerBound);\n }\n\n if (options.upperBound) {\n this.upperBound.copy(options.upperBound);\n }\n }\n /**\n * Set the AABB bounds from a set of points.\n * @param points An array of Vec3's.\n * @return The self object\n */\n\n\n setFromPoints(points, position, quaternion, skinSize) {\n const l = this.lowerBound;\n const u = this.upperBound;\n const q = quaternion; // Set to the first point\n\n l.copy(points[0]);\n\n if (q) {\n q.vmult(l, l);\n }\n\n u.copy(l);\n\n for (let i = 1; i < points.length; i++) {\n let p = points[i];\n\n if (q) {\n q.vmult(p, tmp$1);\n p = tmp$1;\n }\n\n if (p.x > u.x) {\n u.x = p.x;\n }\n\n if (p.x < l.x) {\n l.x = p.x;\n }\n\n if (p.y > u.y) {\n u.y = p.y;\n }\n\n if (p.y < l.y) {\n l.y = p.y;\n }\n\n if (p.z > u.z) {\n u.z = p.z;\n }\n\n if (p.z < l.z) {\n l.z = p.z;\n }\n } // Add offset\n\n\n if (position) {\n position.vadd(l, l);\n position.vadd(u, u);\n }\n\n if (skinSize) {\n l.x -= skinSize;\n l.y -= skinSize;\n l.z -= skinSize;\n u.x += skinSize;\n u.y += skinSize;\n u.z += skinSize;\n }\n\n return this;\n }\n /**\n * Copy bounds from an AABB to this AABB\n * @param aabb Source to copy from\n * @return The this object, for chainability\n */\n\n\n copy(aabb) {\n this.lowerBound.copy(aabb.lowerBound);\n this.upperBound.copy(aabb.upperBound);\n return this;\n }\n /**\n * Clone an AABB\n */\n\n\n clone() {\n return new AABB().copy(this);\n }\n /**\n * Extend this AABB so that it covers the given AABB too.\n */\n\n\n extend(aabb) {\n this.lowerBound.x = Math.min(this.lowerBound.x, aabb.lowerBound.x);\n this.upperBound.x = Math.max(this.upperBound.x, aabb.upperBound.x);\n this.lowerBound.y = Math.min(this.lowerBound.y, aabb.lowerBound.y);\n this.upperBound.y = Math.max(this.upperBound.y, aabb.upperBound.y);\n this.lowerBound.z = Math.min(this.lowerBound.z, aabb.lowerBound.z);\n this.upperBound.z = Math.max(this.upperBound.z, aabb.upperBound.z);\n }\n /**\n * Returns true if the given AABB overlaps this AABB.\n */\n\n\n overlaps(aabb) {\n const l1 = this.lowerBound;\n const u1 = this.upperBound;\n const l2 = aabb.lowerBound;\n const u2 = aabb.upperBound; // l2 u2\n // |---------|\n // |--------|\n // l1 u1\n\n const overlapsX = l2.x <= u1.x && u1.x <= u2.x || l1.x <= u2.x && u2.x <= u1.x;\n const overlapsY = l2.y <= u1.y && u1.y <= u2.y || l1.y <= u2.y && u2.y <= u1.y;\n const overlapsZ = l2.z <= u1.z && u1.z <= u2.z || l1.z <= u2.z && u2.z <= u1.z;\n return overlapsX && overlapsY && overlapsZ;\n } // Mostly for debugging\n\n\n volume() {\n const l = this.lowerBound;\n const u = this.upperBound;\n return (u.x - l.x) * (u.y - l.y) * (u.z - l.z);\n }\n /**\n * Returns true if the given AABB is fully contained in this AABB.\n */\n\n\n contains(aabb) {\n const l1 = this.lowerBound;\n const u1 = this.upperBound;\n const l2 = aabb.lowerBound;\n const u2 = aabb.upperBound; // l2 u2\n // |---------|\n // |---------------|\n // l1 u1\n\n return l1.x <= l2.x && u1.x >= u2.x && l1.y <= l2.y && u1.y >= u2.y && l1.z <= l2.z && u1.z >= u2.z;\n }\n\n getCorners(a, b, c, d, e, f, g, h) {\n const l = this.lowerBound;\n const u = this.upperBound;\n a.copy(l);\n b.set(u.x, l.y, l.z);\n c.set(u.x, u.y, l.z);\n d.set(l.x, u.y, u.z);\n e.set(u.x, l.y, u.z);\n f.set(l.x, u.y, l.z);\n g.set(l.x, l.y, u.z);\n h.copy(u);\n }\n /**\n * Get the representation of an AABB in another frame.\n * @return The \"target\" AABB object.\n */\n\n\n toLocalFrame(frame, target) {\n const corners = transformIntoFrame_corners;\n const a = corners[0];\n const b = corners[1];\n const c = corners[2];\n const d = corners[3];\n const e = corners[4];\n const f = corners[5];\n const g = corners[6];\n const h = corners[7]; // Get corners in current frame\n\n this.getCorners(a, b, c, d, e, f, g, h); // Transform them to new local frame\n\n for (let i = 0; i !== 8; i++) {\n const corner = corners[i];\n frame.pointToLocal(corner, corner);\n }\n\n return target.setFromPoints(corners);\n }\n /**\n * Get the representation of an AABB in the global frame.\n * @return The \"target\" AABB object.\n */\n\n\n toWorldFrame(frame, target) {\n const corners = transformIntoFrame_corners;\n const a = corners[0];\n const b = corners[1];\n const c = corners[2];\n const d = corners[3];\n const e = corners[4];\n const f = corners[5];\n const g = corners[6];\n const h = corners[7]; // Get corners in current frame\n\n this.getCorners(a, b, c, d, e, f, g, h); // Transform them to new local frame\n\n for (let i = 0; i !== 8; i++) {\n const corner = corners[i];\n frame.pointToWorld(corner, corner);\n }\n\n return target.setFromPoints(corners);\n }\n /**\n * Check if the AABB is hit by a ray.\n */\n\n\n overlapsRay(ray) {\n const {\n direction,\n from\n } = ray; // const t = 0\n // ray.direction is unit direction vector of ray\n\n const dirFracX = 1 / direction.x;\n const dirFracY = 1 / direction.y;\n const dirFracZ = 1 / direction.z; // this.lowerBound is the corner of AABB with minimal coordinates - left bottom, rt is maximal corner\n\n const t1 = (this.lowerBound.x - from.x) * dirFracX;\n const t2 = (this.upperBound.x - from.x) * dirFracX;\n const t3 = (this.lowerBound.y - from.y) * dirFracY;\n const t4 = (this.upperBound.y - from.y) * dirFracY;\n const t5 = (this.lowerBound.z - from.z) * dirFracZ;\n const t6 = (this.upperBound.z - from.z) * dirFracZ; // const tmin = Math.max(Math.max(Math.min(t1, t2), Math.min(t3, t4)));\n // const tmax = Math.min(Math.min(Math.max(t1, t2), Math.max(t3, t4)));\n\n const tmin = Math.max(Math.max(Math.min(t1, t2), Math.min(t3, t4)), Math.min(t5, t6));\n const tmax = Math.min(Math.min(Math.max(t1, t2), Math.max(t3, t4)), Math.max(t5, t6)); // if tmax < 0, ray (line) is intersecting AABB, but whole AABB is behing us\n\n if (tmax < 0) {\n //t = tmax;\n return false;\n } // if tmin > tmax, ray doesn't intersect AABB\n\n\n if (tmin > tmax) {\n //t = tmax;\n return false;\n }\n\n return true;\n }\n\n}\nconst tmp$1 = new Vec3();\nconst transformIntoFrame_corners = [new Vec3(), new Vec3(), new Vec3(), new Vec3(), new Vec3(), new Vec3(), new Vec3(), new Vec3()];\n\n/**\n * Collision \"matrix\".\n * It's actually a triangular-shaped array of whether two bodies are touching this step, for reference next step\n */\nclass ArrayCollisionMatrix {\n /**\n * The matrix storage.\n */\n constructor() {\n this.matrix = [];\n }\n /**\n * Get an element\n */\n\n\n get(bi, bj) {\n let {\n index: i\n } = bi;\n let {\n index: j\n } = bj;\n\n if (j > i) {\n const temp = j;\n j = i;\n i = temp;\n }\n\n return this.matrix[(i * (i + 1) >> 1) + j - 1];\n }\n /**\n * Set an element\n */\n\n\n set(bi, bj, value) {\n let {\n index: i\n } = bi;\n let {\n index: j\n } = bj;\n\n if (j > i) {\n const temp = j;\n j = i;\n i = temp;\n }\n\n this.matrix[(i * (i + 1) >> 1) + j - 1] = value ? 1 : 0;\n }\n /**\n * Sets all elements to zero\n */\n\n\n reset() {\n for (let i = 0, l = this.matrix.length; i !== l; i++) {\n this.matrix[i] = 0;\n }\n }\n /**\n * Sets the max number of objects\n */\n\n\n setNumObjects(n) {\n this.matrix.length = n * (n - 1) >> 1;\n }\n\n}\n\n/**\n * Base class for objects that dispatches events.\n */\nclass EventTarget {\n /**\n * Add an event listener\n * @return The self object, for chainability.\n */\n addEventListener(type, listener) {\n if (this._listeners === undefined) {\n this._listeners = {};\n }\n\n const listeners = this._listeners;\n\n if (listeners[type] === undefined) {\n listeners[type] = [];\n }\n\n if (!listeners[type].includes(listener)) {\n listeners[type].push(listener);\n }\n\n return this;\n }\n /**\n * Check if an event listener is added\n */\n\n\n hasEventListener(type, listener) {\n if (this._listeners === undefined) {\n return false;\n }\n\n const listeners = this._listeners;\n\n if (listeners[type] !== undefined && listeners[type].includes(listener)) {\n return true;\n }\n\n return false;\n }\n /**\n * Check if any event listener of the given type is added\n */\n\n\n hasAnyEventListener(type) {\n if (this._listeners === undefined) {\n return false;\n }\n\n const listeners = this._listeners;\n return listeners[type] !== undefined;\n }\n /**\n * Remove an event listener\n * @return The self object, for chainability.\n */\n\n\n removeEventListener(type, listener) {\n if (this._listeners === undefined) {\n return this;\n }\n\n const listeners = this._listeners;\n\n if (listeners[type] === undefined) {\n return this;\n }\n\n const index = listeners[type].indexOf(listener);\n\n if (index !== -1) {\n listeners[type].splice(index, 1);\n }\n\n return this;\n }\n /**\n * Emit an event.\n * @return The self object, for chainability.\n */\n\n\n dispatchEvent(event) {\n if (this._listeners === undefined) {\n return this;\n }\n\n const listeners = this._listeners;\n const listenerArray = listeners[event.type];\n\n if (listenerArray !== undefined) {\n event.target = this;\n\n for (let i = 0, l = listenerArray.length; i < l; i++) {\n listenerArray[i].call(this, event);\n }\n }\n\n return this;\n }\n\n}\n\n/**\n * A Quaternion describes a rotation in 3D space. The Quaternion is mathematically defined as Q = x*i + y*j + z*k + w, where (i,j,k) are imaginary basis vectors. (x,y,z) can be seen as a vector related to the axis of rotation, while the real multiplier, w, is related to the amount of rotation.\n * @param x Multiplier of the imaginary basis vector i.\n * @param y Multiplier of the imaginary basis vector j.\n * @param z Multiplier of the imaginary basis vector k.\n * @param w Multiplier of the real part.\n * @see http://en.wikipedia.org/wiki/Quaternion\n */\n\nclass Quaternion {\n constructor(x, y, z, w) {\n if (x === void 0) {\n x = 0;\n }\n\n if (y === void 0) {\n y = 0;\n }\n\n if (z === void 0) {\n z = 0;\n }\n\n if (w === void 0) {\n w = 1;\n }\n\n this.x = x;\n this.y = y;\n this.z = z;\n this.w = w;\n }\n /**\n * Set the value of the quaternion.\n */\n\n\n set(x, y, z, w) {\n this.x = x;\n this.y = y;\n this.z = z;\n this.w = w;\n return this;\n }\n /**\n * Convert to a readable format\n * @return \"x,y,z,w\"\n */\n\n\n toString() {\n return `${this.x},${this.y},${this.z},${this.w}`;\n }\n /**\n * Convert to an Array\n * @return [x, y, z, w]\n */\n\n\n toArray() {\n return [this.x, this.y, this.z, this.w];\n }\n /**\n * Set the quaternion components given an axis and an angle in radians.\n */\n\n\n setFromAxisAngle(vector, angle) {\n const s = Math.sin(angle * 0.5);\n this.x = vector.x * s;\n this.y = vector.y * s;\n this.z = vector.z * s;\n this.w = Math.cos(angle * 0.5);\n return this;\n }\n /**\n * Converts the quaternion to [ axis, angle ] representation.\n * @param targetAxis A vector object to reuse for storing the axis.\n * @return An array, first element is the axis and the second is the angle in radians.\n */\n\n\n toAxisAngle(targetAxis) {\n if (targetAxis === void 0) {\n targetAxis = new Vec3();\n }\n\n this.normalize(); // if w>1 acos and sqrt will produce errors, this cant happen if quaternion is normalised\n\n const angle = 2 * Math.acos(this.w);\n const s = Math.sqrt(1 - this.w * this.w); // assuming quaternion normalised then w is less than 1, so term always positive.\n\n if (s < 0.001) {\n // test to avoid divide by zero, s is always positive due to sqrt\n // if s close to zero then direction of axis not important\n targetAxis.x = this.x; // if it is important that axis is normalised then replace with x=1; y=z=0;\n\n targetAxis.y = this.y;\n targetAxis.z = this.z;\n } else {\n targetAxis.x = this.x / s; // normalise axis\n\n targetAxis.y = this.y / s;\n targetAxis.z = this.z / s;\n }\n\n return [targetAxis, angle];\n }\n /**\n * Set the quaternion value given two vectors. The resulting rotation will be the needed rotation to rotate u to v.\n */\n\n\n setFromVectors(u, v) {\n if (u.isAntiparallelTo(v)) {\n const t1 = sfv_t1;\n const t2 = sfv_t2;\n u.tangents(t1, t2);\n this.setFromAxisAngle(t1, Math.PI);\n } else {\n const a = u.cross(v);\n this.x = a.x;\n this.y = a.y;\n this.z = a.z;\n this.w = Math.sqrt(u.length() ** 2 * v.length() ** 2) + u.dot(v);\n this.normalize();\n }\n\n return this;\n }\n /**\n * Multiply the quaternion with an other quaternion.\n */\n\n\n mult(quat, target) {\n if (target === void 0) {\n target = new Quaternion();\n }\n\n const ax = this.x;\n const ay = this.y;\n const az = this.z;\n const aw = this.w;\n const bx = quat.x;\n const by = quat.y;\n const bz = quat.z;\n const bw = quat.w;\n target.x = ax * bw + aw * bx + ay * bz - az * by;\n target.y = ay * bw + aw * by + az * bx - ax * bz;\n target.z = az * bw + aw * bz + ax * by - ay * bx;\n target.w = aw * bw - ax * bx - ay * by - az * bz;\n return target;\n }\n /**\n * Get the inverse quaternion rotation.\n */\n\n\n inverse(target) {\n if (target === void 0) {\n target = new Quaternion();\n }\n\n const x = this.x;\n const y = this.y;\n const z = this.z;\n const w = this.w;\n this.conjugate(target);\n const inorm2 = 1 / (x * x + y * y + z * z + w * w);\n target.x *= inorm2;\n target.y *= inorm2;\n target.z *= inorm2;\n target.w *= inorm2;\n return target;\n }\n /**\n * Get the quaternion conjugate\n */\n\n\n conjugate(target) {\n if (target === void 0) {\n target = new Quaternion();\n }\n\n target.x = -this.x;\n target.y = -this.y;\n target.z = -this.z;\n target.w = this.w;\n return target;\n }\n /**\n * Normalize the quaternion. Note that this changes the values of the quaternion.\n */\n\n\n normalize() {\n let l = Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w);\n\n if (l === 0) {\n this.x = 0;\n this.y = 0;\n this.z = 0;\n this.w = 0;\n } else {\n l = 1 / l;\n this.x *= l;\n this.y *= l;\n this.z *= l;\n this.w *= l;\n }\n\n return this;\n }\n /**\n * Approximation of quaternion normalization. Works best when quat is already almost-normalized.\n * @author unphased, https://github.com/unphased\n */\n\n\n normalizeFast() {\n const f = (3.0 - (this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w)) / 2.0;\n\n if (f === 0) {\n this.x = 0;\n this.y = 0;\n this.z = 0;\n this.w = 0;\n } else {\n this.x *= f;\n this.y *= f;\n this.z *= f;\n this.w *= f;\n }\n\n return this;\n }\n /**\n * Multiply the quaternion by a vector\n */\n\n\n vmult(v, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n const x = v.x;\n const y = v.y;\n const z = v.z;\n const qx = this.x;\n const qy = this.y;\n const qz = this.z;\n const qw = this.w; // q*v\n\n const ix = qw * x + qy * z - qz * y;\n const iy = qw * y + qz * x - qx * z;\n const iz = qw * z + qx * y - qy * x;\n const iw = -qx * x - qy * y - qz * z;\n target.x = ix * qw + iw * -qx + iy * -qz - iz * -qy;\n target.y = iy * qw + iw * -qy + iz * -qx - ix * -qz;\n target.z = iz * qw + iw * -qz + ix * -qy - iy * -qx;\n return target;\n }\n /**\n * Copies value of source to this quaternion.\n * @return this\n */\n\n\n copy(quat) {\n this.x = quat.x;\n this.y = quat.y;\n this.z = quat.z;\n this.w = quat.w;\n return this;\n }\n /**\n * Convert the quaternion to euler angle representation. Order: YZX, as this page describes: https://www.euclideanspace.com/maths/standards/index.htm\n * @param order Three-character string, defaults to \"YZX\"\n */\n\n\n toEuler(target, order) {\n if (order === void 0) {\n order = 'YZX';\n }\n\n let heading;\n let attitude;\n let bank;\n const x = this.x;\n const y = this.y;\n const z = this.z;\n const w = this.w;\n\n switch (order) {\n case 'YZX':\n const test = x * y + z * w;\n\n if (test > 0.499) {\n // singularity at north pole\n heading = 2 * Math.atan2(x, w);\n attitude = Math.PI / 2;\n bank = 0;\n }\n\n if (test < -0.499) {\n // singularity at south pole\n heading = -2 * Math.atan2(x, w);\n attitude = -Math.PI / 2;\n bank = 0;\n }\n\n if (heading === undefined) {\n const sqx = x * x;\n const sqy = y * y;\n const sqz = z * z;\n heading = Math.atan2(2 * y * w - 2 * x * z, 1 - 2 * sqy - 2 * sqz); // Heading\n\n attitude = Math.asin(2 * test); // attitude\n\n bank = Math.atan2(2 * x * w - 2 * y * z, 1 - 2 * sqx - 2 * sqz); // bank\n }\n\n break;\n\n default:\n throw new Error(`Euler order ${order} not supported yet.`);\n }\n\n target.y = heading;\n target.z = attitude;\n target.x = bank;\n }\n /**\n * Set the quaternion components given Euler angle representation.\n *\n * @param order The order to apply angles: 'XYZ' or 'YXZ' or any other combination.\n *\n * See {@link https://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors MathWorks} reference\n */\n\n\n setFromEuler(x, y, z, order) {\n if (order === void 0) {\n order = 'XYZ';\n }\n\n const c1 = Math.cos(x / 2);\n const c2 = Math.cos(y / 2);\n const c3 = Math.cos(z / 2);\n const s1 = Math.sin(x / 2);\n const s2 = Math.sin(y / 2);\n const s3 = Math.sin(z / 2);\n\n if (order === '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 } else if (order === 'YXZ') {\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 } else if (order === 'ZXY') {\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 } else if (order === 'ZYX') {\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 } else if (order === 'YZX') {\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 } else if (order === 'XZY') {\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\n return this;\n }\n\n clone() {\n return new Quaternion(this.x, this.y, this.z, this.w);\n }\n /**\n * Performs a spherical linear interpolation between two quat\n *\n * @param toQuat second operand\n * @param t interpolation amount between the self quaternion and toQuat\n * @param target A quaternion to store the result in. If not provided, a new one will be created.\n * @returns {Quaternion} The \"target\" object\n */\n\n\n slerp(toQuat, t, target) {\n if (target === void 0) {\n target = new Quaternion();\n }\n\n const ax = this.x;\n const ay = this.y;\n const az = this.z;\n const aw = this.w;\n let bx = toQuat.x;\n let by = toQuat.y;\n let bz = toQuat.z;\n let bw = toQuat.w;\n let omega;\n let cosom;\n let sinom;\n let scale0;\n let 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 > 0.000001) {\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 target.x = scale0 * ax + scale1 * bx;\n target.y = scale0 * ay + scale1 * by;\n target.z = scale0 * az + scale1 * bz;\n target.w = scale0 * aw + scale1 * bw;\n return target;\n }\n /**\n * Rotate an absolute orientation quaternion given an angular velocity and a time step.\n */\n\n\n integrate(angularVelocity, dt, angularFactor, target) {\n if (target === void 0) {\n target = new Quaternion();\n }\n\n const ax = angularVelocity.x * angularFactor.x,\n ay = angularVelocity.y * angularFactor.y,\n az = angularVelocity.z * angularFactor.z,\n bx = this.x,\n by = this.y,\n bz = this.z,\n bw = this.w;\n const half_dt = dt * 0.5;\n target.x += half_dt * (ax * bw + ay * bz - az * by);\n target.y += half_dt * (ay * bw + az * bx - ax * bz);\n target.z += half_dt * (az * bw + ax * by - ay * bx);\n target.w += half_dt * (-ax * bx - ay * by - az * bz);\n return target;\n }\n\n}\nconst sfv_t1 = new Vec3();\nconst sfv_t2 = new Vec3();\n\n/**\n * The available shape types.\n */\nconst SHAPE_TYPES = {\n /** SPHERE */\n SPHERE: 1,\n\n /** PLANE */\n PLANE: 2,\n\n /** BOX */\n BOX: 4,\n\n /** COMPOUND */\n COMPOUND: 8,\n\n /** CONVEXPOLYHEDRON */\n CONVEXPOLYHEDRON: 16,\n\n /** HEIGHTFIELD */\n HEIGHTFIELD: 32,\n\n /** PARTICLE */\n PARTICLE: 64,\n\n /** CYLINDER */\n CYLINDER: 128,\n\n /** TRIMESH */\n TRIMESH: 256\n};\n/**\n * ShapeType\n */\n\n/**\n * Base class for shapes\n */\nclass Shape {\n /**\n * Identifier of the Shape.\n */\n\n /**\n * The type of this shape. Must be set to an int > 0 by subclasses.\n */\n\n /**\n * The local bounding sphere radius of this shape.\n */\n\n /**\n * Whether to produce contact forces when in contact with other bodies. Note that contacts will be generated, but they will be disabled.\n * @default true\n */\n\n /**\n * @default 1\n */\n\n /**\n * @default -1\n */\n\n /**\n * Optional material of the shape that regulates contact properties.\n */\n\n /**\n * The body to which the shape is added to.\n */\n\n /**\n * All the Shape types.\n */\n constructor(options) {\n if (options === void 0) {\n options = {};\n }\n\n this.id = Shape.idCounter++;\n this.type = options.type || 0;\n this.boundingSphereRadius = 0;\n this.collisionResponse = options.collisionResponse ? options.collisionResponse : true;\n this.collisionFilterGroup = options.collisionFilterGroup !== undefined ? options.collisionFilterGroup : 1;\n this.collisionFilterMask = options.collisionFilterMask !== undefined ? options.collisionFilterMask : -1;\n this.material = options.material ? options.material : null;\n this.body = null;\n }\n /**\n * Computes the bounding sphere radius.\n * The result is stored in the property `.boundingSphereRadius`\n */\n\n\n updateBoundingSphereRadius() {\n throw `computeBoundingSphereRadius() not implemented for shape type ${this.type}`;\n }\n /**\n * Get the volume of this shape\n */\n\n\n volume() {\n throw `volume() not implemented for shape type ${this.type}`;\n }\n /**\n * Calculates the inertia in the local frame for this shape.\n * @see http://en.wikipedia.org/wiki/List_of_moments_of_inertia\n */\n\n\n calculateLocalInertia(mass, target) {\n throw `calculateLocalInertia() not implemented for shape type ${this.type}`;\n }\n /**\n * @todo use abstract for these kind of methods\n */\n\n\n calculateWorldAABB(pos, quat, min, max) {\n throw `calculateWorldAABB() not implemented for shape type ${this.type}`;\n }\n\n}\nShape.idCounter = 0;\nShape.types = SHAPE_TYPES;\n\n/**\n * Transformation utilities.\n */\nclass Transform {\n /**\n * position\n */\n\n /**\n * quaternion\n */\n constructor(options) {\n if (options === void 0) {\n options = {};\n }\n\n this.position = new Vec3();\n this.quaternion = new Quaternion();\n\n if (options.position) {\n this.position.copy(options.position);\n }\n\n if (options.quaternion) {\n this.quaternion.copy(options.quaternion);\n }\n }\n /**\n * Get a global point in local transform coordinates.\n */\n\n\n pointToLocal(worldPoint, result) {\n return Transform.pointToLocalFrame(this.position, this.quaternion, worldPoint, result);\n }\n /**\n * Get a local point in global transform coordinates.\n */\n\n\n pointToWorld(localPoint, result) {\n return Transform.pointToWorldFrame(this.position, this.quaternion, localPoint, result);\n }\n /**\n * vectorToWorldFrame\n */\n\n\n vectorToWorldFrame(localVector, result) {\n if (result === void 0) {\n result = new Vec3();\n }\n\n this.quaternion.vmult(localVector, result);\n return result;\n }\n /**\n * pointToLocalFrame\n */\n\n\n static pointToLocalFrame(position, quaternion, worldPoint, result) {\n if (result === void 0) {\n result = new Vec3();\n }\n\n worldPoint.vsub(position, result);\n quaternion.conjugate(tmpQuat$1);\n tmpQuat$1.vmult(result, result);\n return result;\n }\n /**\n * pointToWorldFrame\n */\n\n\n static pointToWorldFrame(position, quaternion, localPoint, result) {\n if (result === void 0) {\n result = new Vec3();\n }\n\n quaternion.vmult(localPoint, result);\n result.vadd(position, result);\n return result;\n }\n /**\n * vectorToWorldFrame\n */\n\n\n static vectorToWorldFrame(quaternion, localVector, result) {\n if (result === void 0) {\n result = new Vec3();\n }\n\n quaternion.vmult(localVector, result);\n return result;\n }\n /**\n * vectorToLocalFrame\n */\n\n\n static vectorToLocalFrame(position, quaternion, worldVector, result) {\n if (result === void 0) {\n result = new Vec3();\n }\n\n quaternion.w *= -1;\n quaternion.vmult(worldVector, result);\n quaternion.w *= -1;\n return result;\n }\n\n}\nconst tmpQuat$1 = new Quaternion();\n\n/**\n * A set of polygons describing a convex shape.\n *\n * The shape MUST be convex for the code to work properly. No polygons may be coplanar (contained\n * in the same 3D plane), instead these should be merged into one polygon.\n *\n * @author qiao / https://github.com/qiao (original author, see https://github.com/qiao/three.js/commit/85026f0c769e4000148a67d45a9e9b9c5108836f)\n * @author schteppe / https://github.com/schteppe\n * @see https://www.altdevblogaday.com/2011/05/13/contact-generation-between-3d-convex-meshes/\n *\n * @todo Move the clipping functions to ContactGenerator?\n * @todo Automatically merge coplanar polygons in constructor.\n * @example\n * const convexShape = new CANNON.ConvexPolyhedron({ vertices, faces })\n * const convexBody = new CANNON.Body({ mass: 1, shape: convexShape })\n * world.addBody(convexBody)\n */\nclass ConvexPolyhedron extends Shape {\n /** vertices */\n\n /**\n * Array of integer arrays, indicating which vertices each face consists of\n */\n\n /** faceNormals */\n\n /** worldVertices */\n\n /** worldVerticesNeedsUpdate */\n\n /** worldFaceNormals */\n\n /** worldFaceNormalsNeedsUpdate */\n\n /**\n * If given, these locally defined, normalized axes are the only ones being checked when doing separating axis check.\n */\n\n /** uniqueEdges */\n\n /**\n * @param vertices An array of Vec3's\n * @param faces Array of integer arrays, describing which vertices that is included in each face.\n */\n constructor(props) {\n if (props === void 0) {\n props = {};\n }\n\n const {\n vertices = [],\n faces = [],\n normals = [],\n axes,\n boundingSphereRadius\n } = props;\n super({\n type: Shape.types.CONVEXPOLYHEDRON\n });\n this.vertices = vertices;\n this.faces = faces;\n this.faceNormals = normals;\n\n if (this.faceNormals.length === 0) {\n this.computeNormals();\n }\n\n if (!boundingSphereRadius) {\n this.updateBoundingSphereRadius();\n } else {\n this.boundingSphereRadius = boundingSphereRadius;\n }\n\n this.worldVertices = []; // World transformed version of .vertices\n\n this.worldVerticesNeedsUpdate = true;\n this.worldFaceNormals = []; // World transformed version of .faceNormals\n\n this.worldFaceNormalsNeedsUpdate = true;\n this.uniqueAxes = axes ? axes.slice() : null;\n this.uniqueEdges = [];\n this.computeEdges();\n }\n /**\n * Computes uniqueEdges\n */\n\n\n computeEdges() {\n const faces = this.faces;\n const vertices = this.vertices;\n const edges = this.uniqueEdges;\n edges.length = 0;\n const edge = new Vec3();\n\n for (let i = 0; i !== faces.length; i++) {\n const face = faces[i];\n const numVertices = face.length;\n\n for (let j = 0; j !== numVertices; j++) {\n const k = (j + 1) % numVertices;\n vertices[face[j]].vsub(vertices[face[k]], edge);\n edge.normalize();\n let found = false;\n\n for (let p = 0; p !== edges.length; p++) {\n if (edges[p].almostEquals(edge) || edges[p].almostEquals(edge)) {\n found = true;\n break;\n }\n }\n\n if (!found) {\n edges.push(edge.clone());\n }\n }\n }\n }\n /**\n * Compute the normals of the faces.\n * Will reuse existing Vec3 objects in the `faceNormals` array if they exist.\n */\n\n\n computeNormals() {\n this.faceNormals.length = this.faces.length; // Generate normals\n\n for (let i = 0; i < this.faces.length; i++) {\n // Check so all vertices exists for this face\n for (let j = 0; j < this.faces[i].length; j++) {\n if (!this.vertices[this.faces[i][j]]) {\n throw new Error(`Vertex ${this.faces[i][j]} not found!`);\n }\n }\n\n const n = this.faceNormals[i] || new Vec3();\n this.getFaceNormal(i, n);\n n.negate(n);\n this.faceNormals[i] = n;\n const vertex = this.vertices[this.faces[i][0]];\n\n if (n.dot(vertex) < 0) {\n console.error(`.faceNormals[${i}] = Vec3(${n.toString()}) looks like it points into the shape? The vertices follow. Make sure they are ordered CCW around the normal, using the right hand rule.`);\n\n for (let j = 0; j < this.faces[i].length; j++) {\n console.warn(`.vertices[${this.faces[i][j]}] = Vec3(${this.vertices[this.faces[i][j]].toString()})`);\n }\n }\n }\n }\n /**\n * Compute the normal of a face from its vertices\n */\n\n\n getFaceNormal(i, target) {\n const f = this.faces[i];\n const va = this.vertices[f[0]];\n const vb = this.vertices[f[1]];\n const vc = this.vertices[f[2]];\n ConvexPolyhedron.computeNormal(va, vb, vc, target);\n }\n /**\n * Get face normal given 3 vertices\n */\n\n\n static computeNormal(va, vb, vc, target) {\n const cb = new Vec3();\n const ab = new Vec3();\n vb.vsub(va, ab);\n vc.vsub(vb, cb);\n cb.cross(ab, target);\n\n if (!target.isZero()) {\n target.normalize();\n }\n }\n /**\n * @param minDist Clamp distance\n * @param result The an array of contact point objects, see clipFaceAgainstHull\n */\n\n\n clipAgainstHull(posA, quatA, hullB, posB, quatB, separatingNormal, minDist, maxDist, result) {\n const WorldNormal = new Vec3();\n let closestFaceB = -1;\n let dmax = -Number.MAX_VALUE;\n\n for (let face = 0; face < hullB.faces.length; face++) {\n WorldNormal.copy(hullB.faceNormals[face]);\n quatB.vmult(WorldNormal, WorldNormal);\n const d = WorldNormal.dot(separatingNormal);\n\n if (d > dmax) {\n dmax = d;\n closestFaceB = face;\n }\n }\n\n const worldVertsB1 = [];\n\n for (let i = 0; i < hullB.faces[closestFaceB].length; i++) {\n const b = hullB.vertices[hullB.faces[closestFaceB][i]];\n const worldb = new Vec3();\n worldb.copy(b);\n quatB.vmult(worldb, worldb);\n posB.vadd(worldb, worldb);\n worldVertsB1.push(worldb);\n }\n\n if (closestFaceB >= 0) {\n this.clipFaceAgainstHull(separatingNormal, posA, quatA, worldVertsB1, minDist, maxDist, result);\n }\n }\n /**\n * Find the separating axis between this hull and another\n * @param target The target vector to save the axis in\n * @return Returns false if a separation is found, else true\n */\n\n\n findSeparatingAxis(hullB, posA, quatA, posB, quatB, target, faceListA, faceListB) {\n const faceANormalWS3 = new Vec3();\n const Worldnormal1 = new Vec3();\n const deltaC = new Vec3();\n const worldEdge0 = new Vec3();\n const worldEdge1 = new Vec3();\n const Cross = new Vec3();\n let dmin = Number.MAX_VALUE;\n const hullA = this;\n\n if (!hullA.uniqueAxes) {\n const numFacesA = faceListA ? faceListA.length : hullA.faces.length; // Test face normals from hullA\n\n for (let i = 0; i < numFacesA; i++) {\n const fi = faceListA ? faceListA[i] : i; // Get world face normal\n\n faceANormalWS3.copy(hullA.faceNormals[fi]);\n quatA.vmult(faceANormalWS3, faceANormalWS3);\n const d = hullA.testSepAxis(faceANormalWS3, hullB, posA, quatA, posB, quatB);\n\n if (d === false) {\n return false;\n }\n\n if (d < dmin) {\n dmin = d;\n target.copy(faceANormalWS3);\n }\n }\n } else {\n // Test unique axes\n for (let i = 0; i !== hullA.uniqueAxes.length; i++) {\n // Get world axis\n quatA.vmult(hullA.uniqueAxes[i], faceANormalWS3);\n const d = hullA.testSepAxis(faceANormalWS3, hullB, posA, quatA, posB, quatB);\n\n if (d === false) {\n return false;\n }\n\n if (d < dmin) {\n dmin = d;\n target.copy(faceANormalWS3);\n }\n }\n }\n\n if (!hullB.uniqueAxes) {\n // Test face normals from hullB\n const numFacesB = faceListB ? faceListB.length : hullB.faces.length;\n\n for (let i = 0; i < numFacesB; i++) {\n const fi = faceListB ? faceListB[i] : i;\n Worldnormal1.copy(hullB.faceNormals[fi]);\n quatB.vmult(Worldnormal1, Worldnormal1);\n const d = hullA.testSepAxis(Worldnormal1, hullB, posA, quatA, posB, quatB);\n\n if (d === false) {\n return false;\n }\n\n if (d < dmin) {\n dmin = d;\n target.copy(Worldnormal1);\n }\n }\n } else {\n // Test unique axes in B\n for (let i = 0; i !== hullB.uniqueAxes.length; i++) {\n quatB.vmult(hullB.uniqueAxes[i], Worldnormal1);\n const d = hullA.testSepAxis(Worldnormal1, hullB, posA, quatA, posB, quatB);\n\n if (d === false) {\n return false;\n }\n\n if (d < dmin) {\n dmin = d;\n target.copy(Worldnormal1);\n }\n }\n } // Test edges\n\n\n for (let e0 = 0; e0 !== hullA.uniqueEdges.length; e0++) {\n // Get world edge\n quatA.vmult(hullA.uniqueEdges[e0], worldEdge0);\n\n for (let e1 = 0; e1 !== hullB.uniqueEdges.length; e1++) {\n // Get world edge 2\n quatB.vmult(hullB.uniqueEdges[e1], worldEdge1);\n worldEdge0.cross(worldEdge1, Cross);\n\n if (!Cross.almostZero()) {\n Cross.normalize();\n const dist = hullA.testSepAxis(Cross, hullB, posA, quatA, posB, quatB);\n\n if (dist === false) {\n return false;\n }\n\n if (dist < dmin) {\n dmin = dist;\n target.copy(Cross);\n }\n }\n }\n }\n\n posB.vsub(posA, deltaC);\n\n if (deltaC.dot(target) > 0.0) {\n target.negate(target);\n }\n\n return true;\n }\n /**\n * Test separating axis against two hulls. Both hulls are projected onto the axis and the overlap size is returned if there is one.\n * @return The overlap depth, or FALSE if no penetration.\n */\n\n\n testSepAxis(axis, hullB, posA, quatA, posB, quatB) {\n const hullA = this;\n ConvexPolyhedron.project(hullA, axis, posA, quatA, maxminA);\n ConvexPolyhedron.project(hullB, axis, posB, quatB, maxminB);\n const maxA = maxminA[0];\n const minA = maxminA[1];\n const maxB = maxminB[0];\n const minB = maxminB[1];\n\n if (maxA < minB || maxB < minA) {\n return false; // Separated\n }\n\n const d0 = maxA - minB;\n const d1 = maxB - minA;\n const depth = d0 < d1 ? d0 : d1;\n return depth;\n }\n /**\n * calculateLocalInertia\n */\n\n\n calculateLocalInertia(mass, target) {\n // Approximate with box inertia\n // Exact inertia calculation is overkill, but see http://geometrictools.com/Documentation/PolyhedralMassProperties.pdf for the correct way to do it\n const aabbmax = new Vec3();\n const aabbmin = new Vec3();\n this.computeLocalAABB(aabbmin, aabbmax);\n const x = aabbmax.x - aabbmin.x;\n const y = aabbmax.y - aabbmin.y;\n const z = aabbmax.z - aabbmin.z;\n target.x = 1.0 / 12.0 * mass * (2 * y * 2 * y + 2 * z * 2 * z);\n target.y = 1.0 / 12.0 * mass * (2 * x * 2 * x + 2 * z * 2 * z);\n target.z = 1.0 / 12.0 * mass * (2 * y * 2 * y + 2 * x * 2 * x);\n }\n /**\n * @param face_i Index of the face\n */\n\n\n getPlaneConstantOfFace(face_i) {\n const f = this.faces[face_i];\n const n = this.faceNormals[face_i];\n const v = this.vertices[f[0]];\n const c = -n.dot(v);\n return c;\n }\n /**\n * Clip a face against a hull.\n * @param worldVertsB1 An array of Vec3 with vertices in the world frame.\n * @param minDist Distance clamping\n * @param Array result Array to store resulting contact points in. Will be objects with properties: point, depth, normal. These are represented in world coordinates.\n */\n\n\n clipFaceAgainstHull(separatingNormal, posA, quatA, worldVertsB1, minDist, maxDist, result) {\n const faceANormalWS = new Vec3();\n const edge0 = new Vec3();\n const WorldEdge0 = new Vec3();\n const worldPlaneAnormal1 = new Vec3();\n const planeNormalWS1 = new Vec3();\n const worldA1 = new Vec3();\n const localPlaneNormal = new Vec3();\n const planeNormalWS = new Vec3();\n const hullA = this;\n const worldVertsB2 = [];\n const pVtxIn = worldVertsB1;\n const pVtxOut = worldVertsB2;\n let closestFaceA = -1;\n let dmin = Number.MAX_VALUE; // Find the face with normal closest to the separating axis\n\n for (let face = 0; face < hullA.faces.length; face++) {\n faceANormalWS.copy(hullA.faceNormals[face]);\n quatA.vmult(faceANormalWS, faceANormalWS);\n const d = faceANormalWS.dot(separatingNormal);\n\n if (d < dmin) {\n dmin = d;\n closestFaceA = face;\n }\n }\n\n if (closestFaceA < 0) {\n return;\n } // Get the face and construct connected faces\n\n\n const polyA = hullA.faces[closestFaceA];\n polyA.connectedFaces = [];\n\n for (let i = 0; i < hullA.faces.length; i++) {\n for (let j = 0; j < hullA.faces[i].length; j++) {\n if (\n /* Sharing a vertex*/\n polyA.indexOf(hullA.faces[i][j]) !== -1 &&\n /* Not the one we are looking for connections from */\n i !== closestFaceA &&\n /* Not already added */\n polyA.connectedFaces.indexOf(i) === -1) {\n polyA.connectedFaces.push(i);\n }\n }\n } // Clip the polygon to the back of the planes of all faces of hull A,\n // that are adjacent to the witness face\n\n\n const numVerticesA = polyA.length;\n\n for (let i = 0; i < numVerticesA; i++) {\n const a = hullA.vertices[polyA[i]];\n const b = hullA.vertices[polyA[(i + 1) % numVerticesA]];\n a.vsub(b, edge0);\n WorldEdge0.copy(edge0);\n quatA.vmult(WorldEdge0, WorldEdge0);\n posA.vadd(WorldEdge0, WorldEdge0);\n worldPlaneAnormal1.copy(this.faceNormals[closestFaceA]);\n quatA.vmult(worldPlaneAnormal1, worldPlaneAnormal1);\n posA.vadd(worldPlaneAnormal1, worldPlaneAnormal1);\n WorldEdge0.cross(worldPlaneAnormal1, planeNormalWS1);\n planeNormalWS1.negate(planeNormalWS1);\n worldA1.copy(a);\n quatA.vmult(worldA1, worldA1);\n posA.vadd(worldA1, worldA1);\n const otherFace = polyA.connectedFaces[i];\n localPlaneNormal.copy(this.faceNormals[otherFace]);\n const localPlaneEq = this.getPlaneConstantOfFace(otherFace);\n planeNormalWS.copy(localPlaneNormal);\n quatA.vmult(planeNormalWS, planeNormalWS);\n const planeEqWS = localPlaneEq - planeNormalWS.dot(posA); // Clip face against our constructed plane\n\n this.clipFaceAgainstPlane(pVtxIn, pVtxOut, planeNormalWS, planeEqWS); // Throw away all clipped points, but save the remaining until next clip\n\n while (pVtxIn.length) {\n pVtxIn.shift();\n }\n\n while (pVtxOut.length) {\n pVtxIn.push(pVtxOut.shift());\n }\n } // only keep contact points that are behind the witness face\n\n\n localPlaneNormal.copy(this.faceNormals[closestFaceA]);\n const localPlaneEq = this.getPlaneConstantOfFace(closestFaceA);\n planeNormalWS.copy(localPlaneNormal);\n quatA.vmult(planeNormalWS, planeNormalWS);\n const planeEqWS = localPlaneEq - planeNormalWS.dot(posA);\n\n for (let i = 0; i < pVtxIn.length; i++) {\n let depth = planeNormalWS.dot(pVtxIn[i]) + planeEqWS; // ???\n\n if (depth <= minDist) {\n console.log(`clamped: depth=${depth} to minDist=${minDist}`);\n depth = minDist;\n }\n\n if (depth <= maxDist) {\n const point = pVtxIn[i];\n\n if (depth <= 1e-6) {\n const p = {\n point,\n normal: planeNormalWS,\n depth\n };\n result.push(p);\n }\n }\n }\n }\n /**\n * Clip a face in a hull against the back of a plane.\n * @param planeConstant The constant in the mathematical plane equation\n */\n\n\n clipFaceAgainstPlane(inVertices, outVertices, planeNormal, planeConstant) {\n let n_dot_first;\n let n_dot_last;\n const numVerts = inVertices.length;\n\n if (numVerts < 2) {\n return outVertices;\n }\n\n let firstVertex = inVertices[inVertices.length - 1];\n let lastVertex = inVertices[0];\n n_dot_first = planeNormal.dot(firstVertex) + planeConstant;\n\n for (let vi = 0; vi < numVerts; vi++) {\n lastVertex = inVertices[vi];\n n_dot_last = planeNormal.dot(lastVertex) + planeConstant;\n\n if (n_dot_first < 0) {\n if (n_dot_last < 0) {\n // Start < 0, end < 0, so output lastVertex\n const newv = new Vec3();\n newv.copy(lastVertex);\n outVertices.push(newv);\n } else {\n // Start < 0, end >= 0, so output intersection\n const newv = new Vec3();\n firstVertex.lerp(lastVertex, n_dot_first / (n_dot_first - n_dot_last), newv);\n outVertices.push(newv);\n }\n } else {\n if (n_dot_last < 0) {\n // Start >= 0, end < 0 so output intersection and end\n const newv = new Vec3();\n firstVertex.lerp(lastVertex, n_dot_first / (n_dot_first - n_dot_last), newv);\n outVertices.push(newv);\n outVertices.push(lastVertex);\n }\n }\n\n firstVertex = lastVertex;\n n_dot_first = n_dot_last;\n }\n\n return outVertices;\n }\n /**\n * Updates `.worldVertices` and sets `.worldVerticesNeedsUpdate` to false.\n */\n\n\n computeWorldVertices(position, quat) {\n while (this.worldVertices.length < this.vertices.length) {\n this.worldVertices.push(new Vec3());\n }\n\n const verts = this.vertices;\n const worldVerts = this.worldVertices;\n\n for (let i = 0; i !== this.vertices.length; i++) {\n quat.vmult(verts[i], worldVerts[i]);\n position.vadd(worldVerts[i], worldVerts[i]);\n }\n\n this.worldVerticesNeedsUpdate = false;\n }\n\n computeLocalAABB(aabbmin, aabbmax) {\n const vertices = this.vertices;\n aabbmin.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n aabbmax.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n\n for (let i = 0; i < this.vertices.length; i++) {\n const v = vertices[i];\n\n if (v.x < aabbmin.x) {\n aabbmin.x = v.x;\n } else if (v.x > aabbmax.x) {\n aabbmax.x = v.x;\n }\n\n if (v.y < aabbmin.y) {\n aabbmin.y = v.y;\n } else if (v.y > aabbmax.y) {\n aabbmax.y = v.y;\n }\n\n if (v.z < aabbmin.z) {\n aabbmin.z = v.z;\n } else if (v.z > aabbmax.z) {\n aabbmax.z = v.z;\n }\n }\n }\n /**\n * Updates `worldVertices` and sets `worldVerticesNeedsUpdate` to false.\n */\n\n\n computeWorldFaceNormals(quat) {\n const N = this.faceNormals.length;\n\n while (this.worldFaceNormals.length < N) {\n this.worldFaceNormals.push(new Vec3());\n }\n\n const normals = this.faceNormals;\n const worldNormals = this.worldFaceNormals;\n\n for (let i = 0; i !== N; i++) {\n quat.vmult(normals[i], worldNormals[i]);\n }\n\n this.worldFaceNormalsNeedsUpdate = false;\n }\n /**\n * updateBoundingSphereRadius\n */\n\n\n updateBoundingSphereRadius() {\n // Assume points are distributed with local (0,0,0) as center\n let max2 = 0;\n const verts = this.vertices;\n\n for (let i = 0; i !== verts.length; i++) {\n const norm2 = verts[i].lengthSquared();\n\n if (norm2 > max2) {\n max2 = norm2;\n }\n }\n\n this.boundingSphereRadius = Math.sqrt(max2);\n }\n /**\n * calculateWorldAABB\n */\n\n\n calculateWorldAABB(pos, quat, min, max) {\n const verts = this.vertices;\n let minx;\n let miny;\n let minz;\n let maxx;\n let maxy;\n let maxz;\n let tempWorldVertex = new Vec3();\n\n for (let i = 0; i < verts.length; i++) {\n tempWorldVertex.copy(verts[i]);\n quat.vmult(tempWorldVertex, tempWorldVertex);\n pos.vadd(tempWorldVertex, tempWorldVertex);\n const v = tempWorldVertex;\n\n if (minx === undefined || v.x < minx) {\n minx = v.x;\n }\n\n if (maxx === undefined || v.x > maxx) {\n maxx = v.x;\n }\n\n if (miny === undefined || v.y < miny) {\n miny = v.y;\n }\n\n if (maxy === undefined || v.y > maxy) {\n maxy = v.y;\n }\n\n if (minz === undefined || v.z < minz) {\n minz = v.z;\n }\n\n if (maxz === undefined || v.z > maxz) {\n maxz = v.z;\n }\n }\n\n min.set(minx, miny, minz);\n max.set(maxx, maxy, maxz);\n }\n /**\n * Get approximate convex volume\n */\n\n\n volume() {\n return 4.0 * Math.PI * this.boundingSphereRadius / 3.0;\n }\n /**\n * Get an average of all the vertices positions\n */\n\n\n getAveragePointLocal(target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n const verts = this.vertices;\n\n for (let i = 0; i < verts.length; i++) {\n target.vadd(verts[i], target);\n }\n\n target.scale(1 / verts.length, target);\n return target;\n }\n /**\n * Transform all local points. Will change the .vertices\n */\n\n\n transformAllPoints(offset, quat) {\n const n = this.vertices.length;\n const verts = this.vertices; // Apply rotation\n\n if (quat) {\n // Rotate vertices\n for (let i = 0; i < n; i++) {\n const v = verts[i];\n quat.vmult(v, v);\n } // Rotate face normals\n\n\n for (let i = 0; i < this.faceNormals.length; i++) {\n const v = this.faceNormals[i];\n quat.vmult(v, v);\n }\n /*\n // Rotate edges\n for(let i=0; i 0 || r1 > 0 && r2 < 0) {\n return false; // Encountered some other sign. Exit.\n }\n } // If we got here, all dot products were of the same sign.\n\n\n return positiveResult ? 1 : -1;\n }\n /**\n * Get max and min dot product of a convex hull at position (pos,quat) projected onto an axis.\n * Results are saved in the array maxmin.\n * @param result result[0] and result[1] will be set to maximum and minimum, respectively.\n */\n\n\n static project(shape, axis, pos, quat, result) {\n const n = shape.vertices.length;\n project_worldVertex;\n const localAxis = project_localAxis;\n let max = 0;\n let min = 0;\n const localOrigin = project_localOrigin;\n const vs = shape.vertices;\n localOrigin.setZero(); // Transform the axis to local\n\n Transform.vectorToLocalFrame(pos, quat, axis, localAxis);\n Transform.pointToLocalFrame(pos, quat, localOrigin, localOrigin);\n const add = localOrigin.dot(localAxis);\n min = max = vs[0].dot(localAxis);\n\n for (let i = 1; i < n; i++) {\n const val = vs[i].dot(localAxis);\n\n if (val > max) {\n max = val;\n }\n\n if (val < min) {\n min = val;\n }\n }\n\n min -= add;\n max -= add;\n\n if (min > max) {\n // Inconsistent - swap\n const temp = min;\n min = max;\n max = temp;\n } // Output\n\n\n result[0] = max;\n result[1] = min;\n }\n\n}\nconst maxminA = [];\nconst maxminB = [];\nconst project_worldVertex = new Vec3();\nconst project_localAxis = new Vec3();\nconst project_localOrigin = new Vec3();\n\n/**\n * A 3d box shape.\n * @example\n * const size = 1\n * const halfExtents = new CANNON.Vec3(size, size, size)\n * const boxShape = new CANNON.Box(halfExtents)\n * const boxBody = new CANNON.Body({ mass: 1, shape: boxShape })\n * world.addBody(boxBody)\n */\nclass Box extends Shape {\n /**\n * The half extents of the box.\n */\n\n /**\n * Used by the contact generator to make contacts with other convex polyhedra for example.\n */\n constructor(halfExtents) {\n super({\n type: Shape.types.BOX\n });\n this.halfExtents = halfExtents;\n this.convexPolyhedronRepresentation = null;\n this.updateConvexPolyhedronRepresentation();\n this.updateBoundingSphereRadius();\n }\n /**\n * Updates the local convex polyhedron representation used for some collisions.\n */\n\n\n updateConvexPolyhedronRepresentation() {\n const sx = this.halfExtents.x;\n const sy = this.halfExtents.y;\n const sz = this.halfExtents.z;\n const V = Vec3;\n const vertices = [new V(-sx, -sy, -sz), new V(sx, -sy, -sz), new V(sx, sy, -sz), new V(-sx, sy, -sz), new V(-sx, -sy, sz), new V(sx, -sy, sz), new V(sx, sy, sz), new V(-sx, sy, sz)];\n const faces = [[3, 2, 1, 0], // -z\n [4, 5, 6, 7], // +z\n [5, 4, 0, 1], // -y\n [2, 3, 7, 6], // +y\n [0, 4, 7, 3], // -x\n [1, 2, 6, 5] // +x\n ];\n const axes = [new V(0, 0, 1), new V(0, 1, 0), new V(1, 0, 0)];\n const h = new ConvexPolyhedron({\n vertices,\n faces,\n axes\n });\n this.convexPolyhedronRepresentation = h;\n h.material = this.material;\n }\n /**\n * Calculate the inertia of the box.\n */\n\n\n calculateLocalInertia(mass, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n Box.calculateInertia(this.halfExtents, mass, target);\n return target;\n }\n\n static calculateInertia(halfExtents, mass, target) {\n const e = halfExtents;\n target.x = 1.0 / 12.0 * mass * (2 * e.y * 2 * e.y + 2 * e.z * 2 * e.z);\n target.y = 1.0 / 12.0 * mass * (2 * e.x * 2 * e.x + 2 * e.z * 2 * e.z);\n target.z = 1.0 / 12.0 * mass * (2 * e.y * 2 * e.y + 2 * e.x * 2 * e.x);\n }\n /**\n * Get the box 6 side normals\n * @param sixTargetVectors An array of 6 vectors, to store the resulting side normals in.\n * @param quat Orientation to apply to the normal vectors. If not provided, the vectors will be in respect to the local frame.\n */\n\n\n getSideNormals(sixTargetVectors, quat) {\n const sides = sixTargetVectors;\n const ex = this.halfExtents;\n sides[0].set(ex.x, 0, 0);\n sides[1].set(0, ex.y, 0);\n sides[2].set(0, 0, ex.z);\n sides[3].set(-ex.x, 0, 0);\n sides[4].set(0, -ex.y, 0);\n sides[5].set(0, 0, -ex.z);\n\n if (quat !== undefined) {\n for (let i = 0; i !== sides.length; i++) {\n quat.vmult(sides[i], sides[i]);\n }\n }\n\n return sides;\n }\n /**\n * Returns the volume of the box.\n */\n\n\n volume() {\n return 8.0 * this.halfExtents.x * this.halfExtents.y * this.halfExtents.z;\n }\n /**\n * updateBoundingSphereRadius\n */\n\n\n updateBoundingSphereRadius() {\n this.boundingSphereRadius = this.halfExtents.length();\n }\n /**\n * forEachWorldCorner\n */\n\n\n forEachWorldCorner(pos, quat, callback) {\n const e = this.halfExtents;\n const corners = [[e.x, e.y, e.z], [-e.x, e.y, e.z], [-e.x, -e.y, e.z], [-e.x, -e.y, -e.z], [e.x, -e.y, -e.z], [e.x, e.y, -e.z], [-e.x, e.y, -e.z], [e.x, -e.y, e.z]];\n\n for (let i = 0; i < corners.length; i++) {\n worldCornerTempPos.set(corners[i][0], corners[i][1], corners[i][2]);\n quat.vmult(worldCornerTempPos, worldCornerTempPos);\n pos.vadd(worldCornerTempPos, worldCornerTempPos);\n callback(worldCornerTempPos.x, worldCornerTempPos.y, worldCornerTempPos.z);\n }\n }\n /**\n * calculateWorldAABB\n */\n\n\n calculateWorldAABB(pos, quat, min, max) {\n const e = this.halfExtents;\n worldCornersTemp[0].set(e.x, e.y, e.z);\n worldCornersTemp[1].set(-e.x, e.y, e.z);\n worldCornersTemp[2].set(-e.x, -e.y, e.z);\n worldCornersTemp[3].set(-e.x, -e.y, -e.z);\n worldCornersTemp[4].set(e.x, -e.y, -e.z);\n worldCornersTemp[5].set(e.x, e.y, -e.z);\n worldCornersTemp[6].set(-e.x, e.y, -e.z);\n worldCornersTemp[7].set(e.x, -e.y, e.z);\n const wc = worldCornersTemp[0];\n quat.vmult(wc, wc);\n pos.vadd(wc, wc);\n max.copy(wc);\n min.copy(wc);\n\n for (let i = 1; i < 8; i++) {\n const wc = worldCornersTemp[i];\n quat.vmult(wc, wc);\n pos.vadd(wc, wc);\n const x = wc.x;\n const y = wc.y;\n const z = wc.z;\n\n if (x > max.x) {\n max.x = x;\n }\n\n if (y > max.y) {\n max.y = y;\n }\n\n if (z > max.z) {\n max.z = z;\n }\n\n if (x < min.x) {\n min.x = x;\n }\n\n if (y < min.y) {\n min.y = y;\n }\n\n if (z < min.z) {\n min.z = z;\n }\n } // Get each axis max\n // min.set(Infinity,Infinity,Infinity);\n // max.set(-Infinity,-Infinity,-Infinity);\n // this.forEachWorldCorner(pos,quat,function(x,y,z){\n // if(x > max.x){\n // max.x = x;\n // }\n // if(y > max.y){\n // max.y = y;\n // }\n // if(z > max.z){\n // max.z = z;\n // }\n // if(x < min.x){\n // min.x = x;\n // }\n // if(y < min.y){\n // min.y = y;\n // }\n // if(z < min.z){\n // min.z = z;\n // }\n // });\n\n }\n\n}\nconst worldCornerTempPos = new Vec3();\nconst worldCornersTemp = [new Vec3(), new Vec3(), new Vec3(), new Vec3(), new Vec3(), new Vec3(), new Vec3(), new Vec3()];\n\n/**\n * BODY_TYPES\n */\nconst BODY_TYPES = {\n /** DYNAMIC */\n DYNAMIC: 1,\n\n /** STATIC */\n STATIC: 2,\n\n /** KINEMATIC */\n KINEMATIC: 4\n};\n/**\n * BodyType\n */\n\n/**\n * BODY_SLEEP_STATES\n */\nconst BODY_SLEEP_STATES = {\n /** AWAKE */\n AWAKE: 0,\n\n /** SLEEPY */\n SLEEPY: 1,\n\n /** SLEEPING */\n SLEEPING: 2\n};\n/**\n * BodySleepState\n */\n\n/**\n * Base class for all body types.\n * @example\n * const shape = new CANNON.Sphere(1)\n * const body = new CANNON.Body({\n * mass: 1,\n * shape,\n * })\n * world.addBody(body)\n */\nclass Body extends EventTarget {\n /**\n * Dispatched after two bodies collide. This event is dispatched on each\n * of the two bodies involved in the collision.\n * @event collide\n * @param body The body that was involved in the collision.\n * @param contact The details of the collision.\n */\n\n /**\n * A dynamic body is fully simulated. Can be moved manually by the user, but normally they move according to forces. A dynamic body can collide with all body types. A dynamic body always has finite, non-zero mass.\n */\n\n /**\n * A static body does not move during simulation and behaves as if it has infinite mass. Static bodies can be moved manually by setting the position of the body. The velocity of a static body is always zero. Static bodies do not collide with other static or kinematic bodies.\n */\n\n /**\n * A kinematic body moves under simulation according to its velocity. They do not respond to forces. They can be moved manually, but normally a kinematic body is moved by setting its velocity. A kinematic body behaves as if it has infinite mass. Kinematic bodies do not collide with other static or kinematic bodies.\n */\n\n /**\n * AWAKE\n */\n\n /**\n * SLEEPY\n */\n\n /**\n * SLEEPING\n */\n\n /**\n * Dispatched after a sleeping body has woken up.\n * @event wakeup\n */\n\n /**\n * Dispatched after a body has gone in to the sleepy state.\n * @event sleepy\n */\n\n /**\n * Dispatched after a body has fallen asleep.\n * @event sleep\n */\n constructor(options) {\n if (options === void 0) {\n options = {};\n }\n\n super();\n this.id = Body.idCounter++;\n this.index = -1;\n this.world = null;\n this.vlambda = new Vec3();\n this.collisionFilterGroup = typeof options.collisionFilterGroup === 'number' ? options.collisionFilterGroup : 1;\n this.collisionFilterMask = typeof options.collisionFilterMask === 'number' ? options.collisionFilterMask : -1;\n this.collisionResponse = typeof options.collisionResponse === 'boolean' ? options.collisionResponse : true;\n this.position = new Vec3();\n this.previousPosition = new Vec3();\n this.interpolatedPosition = new Vec3();\n this.initPosition = new Vec3();\n\n if (options.position) {\n this.position.copy(options.position);\n this.previousPosition.copy(options.position);\n this.interpolatedPosition.copy(options.position);\n this.initPosition.copy(options.position);\n }\n\n this.velocity = new Vec3();\n\n if (options.velocity) {\n this.velocity.copy(options.velocity);\n }\n\n this.initVelocity = new Vec3();\n this.force = new Vec3();\n const mass = typeof options.mass === 'number' ? options.mass : 0;\n this.mass = mass;\n this.invMass = mass > 0 ? 1.0 / mass : 0;\n this.material = options.material || null;\n this.linearDamping = typeof options.linearDamping === 'number' ? options.linearDamping : 0.01;\n this.type = mass <= 0.0 ? Body.STATIC : Body.DYNAMIC;\n\n if (typeof options.type === typeof Body.STATIC) {\n this.type = options.type;\n }\n\n this.allowSleep = typeof options.allowSleep !== 'undefined' ? options.allowSleep : true;\n this.sleepState = Body.AWAKE;\n this.sleepSpeedLimit = typeof options.sleepSpeedLimit !== 'undefined' ? options.sleepSpeedLimit : 0.1;\n this.sleepTimeLimit = typeof options.sleepTimeLimit !== 'undefined' ? options.sleepTimeLimit : 1;\n this.timeLastSleepy = 0;\n this.wakeUpAfterNarrowphase = false;\n this.torque = new Vec3();\n this.quaternion = new Quaternion();\n this.initQuaternion = new Quaternion();\n this.previousQuaternion = new Quaternion();\n this.interpolatedQuaternion = new Quaternion();\n\n if (options.quaternion) {\n this.quaternion.copy(options.quaternion);\n this.initQuaternion.copy(options.quaternion);\n this.previousQuaternion.copy(options.quaternion);\n this.interpolatedQuaternion.copy(options.quaternion);\n }\n\n this.angularVelocity = new Vec3();\n\n if (options.angularVelocity) {\n this.angularVelocity.copy(options.angularVelocity);\n }\n\n this.initAngularVelocity = new Vec3();\n this.shapes = [];\n this.shapeOffsets = [];\n this.shapeOrientations = [];\n this.inertia = new Vec3();\n this.invInertia = new Vec3();\n this.invInertiaWorld = new Mat3();\n this.invMassSolve = 0;\n this.invInertiaSolve = new Vec3();\n this.invInertiaWorldSolve = new Mat3();\n this.fixedRotation = typeof options.fixedRotation !== 'undefined' ? options.fixedRotation : false;\n this.angularDamping = typeof options.angularDamping !== 'undefined' ? options.angularDamping : 0.01;\n this.linearFactor = new Vec3(1, 1, 1);\n\n if (options.linearFactor) {\n this.linearFactor.copy(options.linearFactor);\n }\n\n this.angularFactor = new Vec3(1, 1, 1);\n\n if (options.angularFactor) {\n this.angularFactor.copy(options.angularFactor);\n }\n\n this.aabb = new AABB();\n this.aabbNeedsUpdate = true;\n this.boundingRadius = 0;\n this.wlambda = new Vec3();\n this.isTrigger = Boolean(options.isTrigger);\n\n if (options.shape) {\n this.addShape(options.shape);\n }\n\n this.updateMassProperties();\n }\n /**\n * Wake the body up.\n */\n\n\n wakeUp() {\n const prevState = this.sleepState;\n this.sleepState = Body.AWAKE;\n this.wakeUpAfterNarrowphase = false;\n\n if (prevState === Body.SLEEPING) {\n this.dispatchEvent(Body.wakeupEvent);\n }\n }\n /**\n * Force body sleep\n */\n\n\n sleep() {\n this.sleepState = Body.SLEEPING;\n this.velocity.set(0, 0, 0);\n this.angularVelocity.set(0, 0, 0);\n this.wakeUpAfterNarrowphase = false;\n }\n /**\n * Called every timestep to update internal sleep timer and change sleep state if needed.\n * @param time The world time in seconds\n */\n\n\n sleepTick(time) {\n if (this.allowSleep) {\n const sleepState = this.sleepState;\n const speedSquared = this.velocity.lengthSquared() + this.angularVelocity.lengthSquared();\n const speedLimitSquared = this.sleepSpeedLimit ** 2;\n\n if (sleepState === Body.AWAKE && speedSquared < speedLimitSquared) {\n this.sleepState = Body.SLEEPY; // Sleepy\n\n this.timeLastSleepy = time;\n this.dispatchEvent(Body.sleepyEvent);\n } else if (sleepState === Body.SLEEPY && speedSquared > speedLimitSquared) {\n this.wakeUp(); // Wake up\n } else if (sleepState === Body.SLEEPY && time - this.timeLastSleepy > this.sleepTimeLimit) {\n this.sleep(); // Sleeping\n\n this.dispatchEvent(Body.sleepEvent);\n }\n }\n }\n /**\n * If the body is sleeping, it should be immovable / have infinite mass during solve. We solve it by having a separate \"solve mass\".\n */\n\n\n updateSolveMassProperties() {\n if (this.sleepState === Body.SLEEPING || this.type === Body.KINEMATIC) {\n this.invMassSolve = 0;\n this.invInertiaSolve.setZero();\n this.invInertiaWorldSolve.setZero();\n } else {\n this.invMassSolve = this.invMass;\n this.invInertiaSolve.copy(this.invInertia);\n this.invInertiaWorldSolve.copy(this.invInertiaWorld);\n }\n }\n /**\n * Convert a world point to local body frame.\n */\n\n\n pointToLocalFrame(worldPoint, result) {\n if (result === void 0) {\n result = new Vec3();\n }\n\n worldPoint.vsub(this.position, result);\n this.quaternion.conjugate().vmult(result, result);\n return result;\n }\n /**\n * Convert a world vector to local body frame.\n */\n\n\n vectorToLocalFrame(worldVector, result) {\n if (result === void 0) {\n result = new Vec3();\n }\n\n this.quaternion.conjugate().vmult(worldVector, result);\n return result;\n }\n /**\n * Convert a local body point to world frame.\n */\n\n\n pointToWorldFrame(localPoint, result) {\n if (result === void 0) {\n result = new Vec3();\n }\n\n this.quaternion.vmult(localPoint, result);\n result.vadd(this.position, result);\n return result;\n }\n /**\n * Convert a local body point to world frame.\n */\n\n\n vectorToWorldFrame(localVector, result) {\n if (result === void 0) {\n result = new Vec3();\n }\n\n this.quaternion.vmult(localVector, result);\n return result;\n }\n /**\n * Add a shape to the body with a local offset and orientation.\n * @return The body object, for chainability.\n */\n\n\n addShape(shape, _offset, _orientation) {\n const offset = new Vec3();\n const orientation = new Quaternion();\n\n if (_offset) {\n offset.copy(_offset);\n }\n\n if (_orientation) {\n orientation.copy(_orientation);\n }\n\n this.shapes.push(shape);\n this.shapeOffsets.push(offset);\n this.shapeOrientations.push(orientation);\n this.updateMassProperties();\n this.updateBoundingRadius();\n this.aabbNeedsUpdate = true;\n shape.body = this;\n return this;\n }\n /**\n * Remove a shape from the body.\n * @return The body object, for chainability.\n */\n\n\n removeShape(shape) {\n const index = this.shapes.indexOf(shape);\n\n if (index === -1) {\n console.warn('Shape does not belong to the body');\n return this;\n }\n\n this.shapes.splice(index, 1);\n this.shapeOffsets.splice(index, 1);\n this.shapeOrientations.splice(index, 1);\n this.updateMassProperties();\n this.updateBoundingRadius();\n this.aabbNeedsUpdate = true;\n shape.body = null;\n return this;\n }\n /**\n * Update the bounding radius of the body. Should be done if any of the shapes are changed.\n */\n\n\n updateBoundingRadius() {\n const shapes = this.shapes;\n const shapeOffsets = this.shapeOffsets;\n const N = shapes.length;\n let radius = 0;\n\n for (let i = 0; i !== N; i++) {\n const shape = shapes[i];\n shape.updateBoundingSphereRadius();\n const offset = shapeOffsets[i].length();\n const r = shape.boundingSphereRadius;\n\n if (offset + r > radius) {\n radius = offset + r;\n }\n }\n\n this.boundingRadius = radius;\n }\n /**\n * Updates the .aabb\n */\n\n\n updateAABB() {\n const shapes = this.shapes;\n const shapeOffsets = this.shapeOffsets;\n const shapeOrientations = this.shapeOrientations;\n const N = shapes.length;\n const offset = tmpVec;\n const orientation = tmpQuat;\n const bodyQuat = this.quaternion;\n const aabb = this.aabb;\n const shapeAABB = updateAABB_shapeAABB;\n\n for (let i = 0; i !== N; i++) {\n const shape = shapes[i]; // Get shape world position\n\n bodyQuat.vmult(shapeOffsets[i], offset);\n offset.vadd(this.position, offset); // Get shape world quaternion\n\n bodyQuat.mult(shapeOrientations[i], orientation); // Get shape AABB\n\n shape.calculateWorldAABB(offset, orientation, shapeAABB.lowerBound, shapeAABB.upperBound);\n\n if (i === 0) {\n aabb.copy(shapeAABB);\n } else {\n aabb.extend(shapeAABB);\n }\n }\n\n this.aabbNeedsUpdate = false;\n }\n /**\n * Update `.inertiaWorld` and `.invInertiaWorld`\n */\n\n\n updateInertiaWorld(force) {\n const I = this.invInertia;\n\n if (I.x === I.y && I.y === I.z && !force) ; else {\n const m1 = uiw_m1;\n const m2 = uiw_m2;\n uiw_m3;\n m1.setRotationFromQuaternion(this.quaternion);\n m1.transpose(m2);\n m1.scale(I, m1);\n m1.mmult(m2, this.invInertiaWorld);\n }\n }\n /**\n * Apply force to a point of the body. This could for example be a point on the Body surface.\n * Applying force this way will add to Body.force and Body.torque.\n * @param force The amount of force to add.\n * @param relativePoint A point relative to the center of mass to apply the force on.\n */\n\n\n applyForce(force, relativePoint) {\n if (relativePoint === void 0) {\n relativePoint = new Vec3();\n }\n\n // Needed?\n if (this.type !== Body.DYNAMIC) {\n return;\n }\n\n if (this.sleepState === Body.SLEEPING) {\n this.wakeUp();\n } // Compute produced rotational force\n\n\n const rotForce = Body_applyForce_rotForce;\n relativePoint.cross(force, rotForce); // Add linear force\n\n this.force.vadd(force, this.force); // Add rotational force\n\n this.torque.vadd(rotForce, this.torque);\n }\n /**\n * Apply force to a local point in the body.\n * @param force The force vector to apply, defined locally in the body frame.\n * @param localPoint A local point in the body to apply the force on.\n */\n\n\n applyLocalForce(localForce, localPoint) {\n if (localPoint === void 0) {\n localPoint = new Vec3();\n }\n\n if (this.type !== Body.DYNAMIC) {\n return;\n }\n\n const worldForce = Body_applyLocalForce_worldForce;\n const relativePointWorld = Body_applyLocalForce_relativePointWorld; // Transform the force vector to world space\n\n this.vectorToWorldFrame(localForce, worldForce);\n this.vectorToWorldFrame(localPoint, relativePointWorld);\n this.applyForce(worldForce, relativePointWorld);\n }\n /**\n * Apply torque to the body.\n * @param torque The amount of torque to add.\n */\n\n\n applyTorque(torque) {\n if (this.type !== Body.DYNAMIC) {\n return;\n }\n\n if (this.sleepState === Body.SLEEPING) {\n this.wakeUp();\n } // Add rotational force\n\n\n this.torque.vadd(torque, this.torque);\n }\n /**\n * Apply impulse to a point of the body. This could for example be a point on the Body surface.\n * An impulse is a force added to a body during a short period of time (impulse = force * time).\n * Impulses will be added to Body.velocity and Body.angularVelocity.\n * @param impulse The amount of impulse to add.\n * @param relativePoint A point relative to the center of mass to apply the force on.\n */\n\n\n applyImpulse(impulse, relativePoint) {\n if (relativePoint === void 0) {\n relativePoint = new Vec3();\n }\n\n if (this.type !== Body.DYNAMIC) {\n return;\n }\n\n if (this.sleepState === Body.SLEEPING) {\n this.wakeUp();\n } // Compute point position relative to the body center\n\n\n const r = relativePoint; // Compute produced central impulse velocity\n\n const velo = Body_applyImpulse_velo;\n velo.copy(impulse);\n velo.scale(this.invMass, velo); // Add linear impulse\n\n this.velocity.vadd(velo, this.velocity); // Compute produced rotational impulse velocity\n\n const rotVelo = Body_applyImpulse_rotVelo;\n r.cross(impulse, rotVelo);\n /*\n rotVelo.x *= this.invInertia.x;\n rotVelo.y *= this.invInertia.y;\n rotVelo.z *= this.invInertia.z;\n */\n\n this.invInertiaWorld.vmult(rotVelo, rotVelo); // Add rotational Impulse\n\n this.angularVelocity.vadd(rotVelo, this.angularVelocity);\n }\n /**\n * Apply locally-defined impulse to a local point in the body.\n * @param force The force vector to apply, defined locally in the body frame.\n * @param localPoint A local point in the body to apply the force on.\n */\n\n\n applyLocalImpulse(localImpulse, localPoint) {\n if (localPoint === void 0) {\n localPoint = new Vec3();\n }\n\n if (this.type !== Body.DYNAMIC) {\n return;\n }\n\n const worldImpulse = Body_applyLocalImpulse_worldImpulse;\n const relativePointWorld = Body_applyLocalImpulse_relativePoint; // Transform the force vector to world space\n\n this.vectorToWorldFrame(localImpulse, worldImpulse);\n this.vectorToWorldFrame(localPoint, relativePointWorld);\n this.applyImpulse(worldImpulse, relativePointWorld);\n }\n /**\n * Should be called whenever you change the body shape or mass.\n */\n\n\n updateMassProperties() {\n const halfExtents = Body_updateMassProperties_halfExtents;\n this.invMass = this.mass > 0 ? 1.0 / this.mass : 0;\n const I = this.inertia;\n const fixed = this.fixedRotation; // Approximate with AABB box\n\n this.updateAABB();\n halfExtents.set((this.aabb.upperBound.x - this.aabb.lowerBound.x) / 2, (this.aabb.upperBound.y - this.aabb.lowerBound.y) / 2, (this.aabb.upperBound.z - this.aabb.lowerBound.z) / 2);\n Box.calculateInertia(halfExtents, this.mass, I);\n this.invInertia.set(I.x > 0 && !fixed ? 1.0 / I.x : 0, I.y > 0 && !fixed ? 1.0 / I.y : 0, I.z > 0 && !fixed ? 1.0 / I.z : 0);\n this.updateInertiaWorld(true);\n }\n /**\n * Get world velocity of a point in the body.\n * @param worldPoint\n * @param result\n * @return The result vector.\n */\n\n\n getVelocityAtWorldPoint(worldPoint, result) {\n const r = new Vec3();\n worldPoint.vsub(this.position, r);\n this.angularVelocity.cross(r, result);\n this.velocity.vadd(result, result);\n return result;\n }\n /**\n * Move the body forward in time.\n * @param dt Time step\n * @param quatNormalize Set to true to normalize the body quaternion\n * @param quatNormalizeFast If the quaternion should be normalized using \"fast\" quaternion normalization\n */\n\n\n integrate(dt, quatNormalize, quatNormalizeFast) {\n // Save previous position\n this.previousPosition.copy(this.position);\n this.previousQuaternion.copy(this.quaternion);\n\n if (!(this.type === Body.DYNAMIC || this.type === Body.KINEMATIC) || this.sleepState === Body.SLEEPING) {\n // Only for dynamic\n return;\n }\n\n const velo = this.velocity;\n const angularVelo = this.angularVelocity;\n const pos = this.position;\n const force = this.force;\n const torque = this.torque;\n const quat = this.quaternion;\n const invMass = this.invMass;\n const invInertia = this.invInertiaWorld;\n const linearFactor = this.linearFactor;\n const iMdt = invMass * dt;\n velo.x += force.x * iMdt * linearFactor.x;\n velo.y += force.y * iMdt * linearFactor.y;\n velo.z += force.z * iMdt * linearFactor.z;\n const e = invInertia.elements;\n const angularFactor = this.angularFactor;\n const tx = torque.x * angularFactor.x;\n const ty = torque.y * angularFactor.y;\n const tz = torque.z * angularFactor.z;\n angularVelo.x += dt * (e[0] * tx + e[1] * ty + e[2] * tz);\n angularVelo.y += dt * (e[3] * tx + e[4] * ty + e[5] * tz);\n angularVelo.z += dt * (e[6] * tx + e[7] * ty + e[8] * tz); // Use new velocity - leap frog\n\n pos.x += velo.x * dt;\n pos.y += velo.y * dt;\n pos.z += velo.z * dt;\n quat.integrate(this.angularVelocity, dt, this.angularFactor, quat);\n\n if (quatNormalize) {\n if (quatNormalizeFast) {\n quat.normalizeFast();\n } else {\n quat.normalize();\n }\n }\n\n this.aabbNeedsUpdate = true; // Update world inertia\n\n this.updateInertiaWorld();\n }\n\n}\nBody.idCounter = 0;\nBody.COLLIDE_EVENT_NAME = 'collide';\nBody.DYNAMIC = BODY_TYPES.DYNAMIC;\nBody.STATIC = BODY_TYPES.STATIC;\nBody.KINEMATIC = BODY_TYPES.KINEMATIC;\nBody.AWAKE = BODY_SLEEP_STATES.AWAKE;\nBody.SLEEPY = BODY_SLEEP_STATES.SLEEPY;\nBody.SLEEPING = BODY_SLEEP_STATES.SLEEPING;\nBody.wakeupEvent = {\n type: 'wakeup'\n};\nBody.sleepyEvent = {\n type: 'sleepy'\n};\nBody.sleepEvent = {\n type: 'sleep'\n};\nconst tmpVec = new Vec3();\nconst tmpQuat = new Quaternion();\nconst updateAABB_shapeAABB = new AABB();\nconst uiw_m1 = new Mat3();\nconst uiw_m2 = new Mat3();\nconst uiw_m3 = new Mat3();\nconst Body_applyForce_rotForce = new Vec3();\nconst Body_applyLocalForce_worldForce = new Vec3();\nconst Body_applyLocalForce_relativePointWorld = new Vec3();\nconst Body_applyImpulse_velo = new Vec3();\nconst Body_applyImpulse_rotVelo = new Vec3();\nconst Body_applyLocalImpulse_worldImpulse = new Vec3();\nconst Body_applyLocalImpulse_relativePoint = new Vec3();\nconst Body_updateMassProperties_halfExtents = new Vec3();\n\n/**\n * Base class for broadphase implementations\n * @author schteppe\n */\nclass Broadphase {\n /**\n * The world to search for collisions in.\n */\n\n /**\n * If set to true, the broadphase uses bounding boxes for intersection tests, else it uses bounding spheres.\n */\n\n /**\n * Set to true if the objects in the world moved.\n */\n constructor() {\n this.world = null;\n this.useBoundingBoxes = false;\n this.dirty = true;\n }\n /**\n * Get the collision pairs from the world\n * @param world The world to search in\n * @param p1 Empty array to be filled with body objects\n * @param p2 Empty array to be filled with body objects\n */\n\n\n collisionPairs(world, p1, p2) {\n throw new Error('collisionPairs not implemented for this BroadPhase class!');\n }\n /**\n * Check if a body pair needs to be intersection tested at all.\n */\n\n\n needBroadphaseCollision(bodyA, bodyB) {\n // Check collision filter masks\n if ((bodyA.collisionFilterGroup & bodyB.collisionFilterMask) === 0 || (bodyB.collisionFilterGroup & bodyA.collisionFilterMask) === 0) {\n return false;\n } // Check types\n\n\n if (((bodyA.type & Body.STATIC) !== 0 || bodyA.sleepState === Body.SLEEPING) && ((bodyB.type & Body.STATIC) !== 0 || bodyB.sleepState === Body.SLEEPING)) {\n // Both bodies are static or sleeping. Skip.\n return false;\n }\n\n return true;\n }\n /**\n * Check if the bounding volumes of two bodies intersect.\n */\n\n\n intersectionTest(bodyA, bodyB, pairs1, pairs2) {\n if (this.useBoundingBoxes) {\n this.doBoundingBoxBroadphase(bodyA, bodyB, pairs1, pairs2);\n } else {\n this.doBoundingSphereBroadphase(bodyA, bodyB, pairs1, pairs2);\n }\n }\n /**\n * Check if the bounding spheres of two bodies are intersecting.\n * @param pairs1 bodyA is appended to this array if intersection\n * @param pairs2 bodyB is appended to this array if intersection\n */\n\n\n doBoundingSphereBroadphase(bodyA, bodyB, pairs1, pairs2) {\n const r = Broadphase_collisionPairs_r;\n bodyB.position.vsub(bodyA.position, r);\n const boundingRadiusSum2 = (bodyA.boundingRadius + bodyB.boundingRadius) ** 2;\n const norm2 = r.lengthSquared();\n\n if (norm2 < boundingRadiusSum2) {\n pairs1.push(bodyA);\n pairs2.push(bodyB);\n }\n }\n /**\n * Check if the bounding boxes of two bodies are intersecting.\n */\n\n\n doBoundingBoxBroadphase(bodyA, bodyB, pairs1, pairs2) {\n if (bodyA.aabbNeedsUpdate) {\n bodyA.updateAABB();\n }\n\n if (bodyB.aabbNeedsUpdate) {\n bodyB.updateAABB();\n } // Check AABB / AABB\n\n\n if (bodyA.aabb.overlaps(bodyB.aabb)) {\n pairs1.push(bodyA);\n pairs2.push(bodyB);\n }\n }\n /**\n * Removes duplicate pairs from the pair arrays.\n */\n\n\n makePairsUnique(pairs1, pairs2) {\n const t = Broadphase_makePairsUnique_temp;\n const p1 = Broadphase_makePairsUnique_p1;\n const p2 = Broadphase_makePairsUnique_p2;\n const N = pairs1.length;\n\n for (let i = 0; i !== N; i++) {\n p1[i] = pairs1[i];\n p2[i] = pairs2[i];\n }\n\n pairs1.length = 0;\n pairs2.length = 0;\n\n for (let i = 0; i !== N; i++) {\n const id1 = p1[i].id;\n const id2 = p2[i].id;\n const key = id1 < id2 ? `${id1},${id2}` : `${id2},${id1}`;\n t[key] = i;\n t.keys.push(key);\n }\n\n for (let i = 0; i !== t.keys.length; i++) {\n const key = t.keys.pop();\n const pairIndex = t[key];\n pairs1.push(p1[pairIndex]);\n pairs2.push(p2[pairIndex]);\n delete t[key];\n }\n }\n /**\n * To be implemented by subcasses\n */\n\n\n setWorld(world) {}\n /**\n * Check if the bounding spheres of two bodies overlap.\n */\n\n\n static boundingSphereCheck(bodyA, bodyB) {\n const dist = new Vec3(); // bsc_dist;\n\n bodyA.position.vsub(bodyB.position, dist);\n const sa = bodyA.shapes[0];\n const sb = bodyB.shapes[0];\n return Math.pow(sa.boundingSphereRadius + sb.boundingSphereRadius, 2) > dist.lengthSquared();\n }\n /**\n * Returns all the bodies within the AABB.\n */\n\n\n aabbQuery(world, aabb, result) {\n console.warn('.aabbQuery is not implemented in this Broadphase subclass.');\n return [];\n }\n\n} // Temp objects\n\nconst Broadphase_collisionPairs_r = new Vec3();\nnew Vec3();\nnew Quaternion();\nnew Vec3();\nconst Broadphase_makePairsUnique_temp = {\n keys: []\n};\nconst Broadphase_makePairsUnique_p1 = [];\nconst Broadphase_makePairsUnique_p2 = [];\nnew Vec3();\n\n/**\n * Axis aligned uniform grid broadphase.\n * @todo Needs support for more than just planes and spheres.\n */\nclass GridBroadphase extends Broadphase {\n /**\n * Number of boxes along x\n */\n\n /**\n * Number of boxes along y\n */\n\n /**\n * Number of boxes along z\n */\n\n /**\n * aabbMin\n */\n\n /**\n * aabbMax\n */\n\n /**\n * bins\n */\n\n /**\n * binLengths\n */\n\n /**\n * @param nx Number of boxes along x.\n * @param ny Number of boxes along y.\n * @param nz Number of boxes along z.\n */\n constructor(aabbMin, aabbMax, nx, ny, nz) {\n if (aabbMin === void 0) {\n aabbMin = new Vec3(100, 100, 100);\n }\n\n if (aabbMax === void 0) {\n aabbMax = new Vec3(-100, -100, -100);\n }\n\n if (nx === void 0) {\n nx = 10;\n }\n\n if (ny === void 0) {\n ny = 10;\n }\n\n if (nz === void 0) {\n nz = 10;\n }\n\n super();\n this.nx = nx;\n this.ny = ny;\n this.nz = nz;\n this.aabbMin = aabbMin;\n this.aabbMax = aabbMax;\n const nbins = this.nx * this.ny * this.nz;\n\n if (nbins <= 0) {\n throw \"GridBroadphase: Each dimension's n must be >0\";\n }\n\n this.bins = [];\n this.binLengths = []; // Rather than continually resizing arrays (thrashing the memory), just record length and allow them to grow\n\n this.bins.length = nbins;\n this.binLengths.length = nbins;\n\n for (let i = 0; i < nbins; i++) {\n this.bins[i] = [];\n this.binLengths[i] = 0;\n }\n }\n /**\n * Get all the collision pairs in the physics world\n */\n\n\n collisionPairs(world, pairs1, pairs2) {\n const N = world.bodies.length;\n const bodies = world.bodies;\n const max = this.aabbMax;\n const min = this.aabbMin;\n const nx = this.nx;\n const ny = this.ny;\n const nz = this.nz;\n const xstep = ny * nz;\n const ystep = nz;\n const zstep = 1;\n const xmax = max.x;\n const ymax = max.y;\n const zmax = max.z;\n const xmin = min.x;\n const ymin = min.y;\n const zmin = min.z;\n const xmult = nx / (xmax - xmin);\n const ymult = ny / (ymax - ymin);\n const zmult = nz / (zmax - zmin);\n const binsizeX = (xmax - xmin) / nx;\n const binsizeY = (ymax - ymin) / ny;\n const binsizeZ = (zmax - zmin) / nz;\n const binRadius = Math.sqrt(binsizeX * binsizeX + binsizeY * binsizeY + binsizeZ * binsizeZ) * 0.5;\n const types = Shape.types;\n const SPHERE = types.SPHERE;\n const PLANE = types.PLANE;\n types.BOX;\n types.COMPOUND;\n types.CONVEXPOLYHEDRON;\n const bins = this.bins;\n const binLengths = this.binLengths;\n const Nbins = this.bins.length; // Reset bins\n\n for (let i = 0; i !== Nbins; i++) {\n binLengths[i] = 0;\n }\n\n const ceil = Math.ceil;\n\n function addBoxToBins(x0, y0, z0, x1, y1, z1, bi) {\n let xoff0 = (x0 - xmin) * xmult | 0;\n let yoff0 = (y0 - ymin) * ymult | 0;\n let zoff0 = (z0 - zmin) * zmult | 0;\n let xoff1 = ceil((x1 - xmin) * xmult);\n let yoff1 = ceil((y1 - ymin) * ymult);\n let zoff1 = ceil((z1 - zmin) * zmult);\n\n if (xoff0 < 0) {\n xoff0 = 0;\n } else if (xoff0 >= nx) {\n xoff0 = nx - 1;\n }\n\n if (yoff0 < 0) {\n yoff0 = 0;\n } else if (yoff0 >= ny) {\n yoff0 = ny - 1;\n }\n\n if (zoff0 < 0) {\n zoff0 = 0;\n } else if (zoff0 >= nz) {\n zoff0 = nz - 1;\n }\n\n if (xoff1 < 0) {\n xoff1 = 0;\n } else if (xoff1 >= nx) {\n xoff1 = nx - 1;\n }\n\n if (yoff1 < 0) {\n yoff1 = 0;\n } else if (yoff1 >= ny) {\n yoff1 = ny - 1;\n }\n\n if (zoff1 < 0) {\n zoff1 = 0;\n } else if (zoff1 >= nz) {\n zoff1 = nz - 1;\n }\n\n xoff0 *= xstep;\n yoff0 *= ystep;\n zoff0 *= zstep;\n xoff1 *= xstep;\n yoff1 *= ystep;\n zoff1 *= zstep;\n\n for (let xoff = xoff0; xoff <= xoff1; xoff += xstep) {\n for (let yoff = yoff0; yoff <= yoff1; yoff += ystep) {\n for (let zoff = zoff0; zoff <= zoff1; zoff += zstep) {\n const idx = xoff + yoff + zoff;\n bins[idx][binLengths[idx]++] = bi;\n }\n }\n }\n } // Put all bodies into the bins\n\n\n for (let i = 0; i !== N; i++) {\n const bi = bodies[i];\n const si = bi.shapes[0];\n\n switch (si.type) {\n case SPHERE:\n {\n const shape = si; // Put in bin\n // check if overlap with other bins\n\n const x = bi.position.x;\n const y = bi.position.y;\n const z = bi.position.z;\n const r = shape.radius;\n addBoxToBins(x - r, y - r, z - r, x + r, y + r, z + r, bi);\n break;\n }\n\n case PLANE:\n {\n const shape = si;\n\n if (shape.worldNormalNeedsUpdate) {\n shape.computeWorldNormal(bi.quaternion);\n }\n\n const planeNormal = shape.worldNormal; //Relative position from origin of plane object to the first bin\n //Incremented as we iterate through the bins\n\n const xreset = xmin + binsizeX * 0.5 - bi.position.x;\n const yreset = ymin + binsizeY * 0.5 - bi.position.y;\n const zreset = zmin + binsizeZ * 0.5 - bi.position.z;\n const d = GridBroadphase_collisionPairs_d;\n d.set(xreset, yreset, zreset);\n\n for (let xi = 0, xoff = 0; xi !== nx; xi++, xoff += xstep, d.y = yreset, d.x += binsizeX) {\n for (let yi = 0, yoff = 0; yi !== ny; yi++, yoff += ystep, d.z = zreset, d.y += binsizeY) {\n for (let zi = 0, zoff = 0; zi !== nz; zi++, zoff += zstep, d.z += binsizeZ) {\n if (d.dot(planeNormal) < binRadius) {\n const idx = xoff + yoff + zoff;\n bins[idx][binLengths[idx]++] = bi;\n }\n }\n }\n }\n\n break;\n }\n\n default:\n {\n if (bi.aabbNeedsUpdate) {\n bi.updateAABB();\n }\n\n addBoxToBins(bi.aabb.lowerBound.x, bi.aabb.lowerBound.y, bi.aabb.lowerBound.z, bi.aabb.upperBound.x, bi.aabb.upperBound.y, bi.aabb.upperBound.z, bi);\n break;\n }\n }\n } // Check each bin\n\n\n for (let i = 0; i !== Nbins; i++) {\n const binLength = binLengths[i]; //Skip bins with no potential collisions\n\n if (binLength > 1) {\n const bin = bins[i]; // Do N^2 broadphase inside\n\n for (let xi = 0; xi !== binLength; xi++) {\n const bi = bin[xi];\n\n for (let yi = 0; yi !== xi; yi++) {\n const bj = bin[yi];\n\n if (this.needBroadphaseCollision(bi, bj)) {\n this.intersectionTest(bi, bj, pairs1, pairs2);\n }\n }\n }\n }\n } //\tfor (let zi = 0, zoff=0; zi < nz; zi++, zoff+= zstep) {\n //\t\tconsole.log(\"layer \"+zi);\n //\t\tfor (let yi = 0, yoff=0; yi < ny; yi++, yoff += ystep) {\n //\t\t\tconst row = '';\n //\t\t\tfor (let xi = 0, xoff=0; xi < nx; xi++, xoff += xstep) {\n //\t\t\t\tconst idx = xoff + yoff + zoff;\n //\t\t\t\trow += ' ' + binLengths[idx];\n //\t\t\t}\n //\t\t\tconsole.log(row);\n //\t\t}\n //\t}\n\n\n this.makePairsUnique(pairs1, pairs2);\n }\n\n}\nconst GridBroadphase_collisionPairs_d = new Vec3();\nnew Vec3();\n\n/**\n * Naive broadphase implementation, used in lack of better ones.\n *\n * The naive broadphase looks at all possible pairs without restriction, therefore it has complexity N^2 _(which is bad)_\n */\nclass NaiveBroadphase extends Broadphase {\n /**\n * @todo Remove useless constructor\n */\n constructor() {\n super();\n }\n /**\n * Get all the collision pairs in the physics world\n */\n\n\n collisionPairs(world, pairs1, pairs2) {\n const bodies = world.bodies;\n const n = bodies.length;\n let bi;\n let bj; // Naive N^2 ftw!\n\n for (let i = 0; i !== n; i++) {\n for (let j = 0; j !== i; j++) {\n bi = bodies[i];\n bj = bodies[j];\n\n if (!this.needBroadphaseCollision(bi, bj)) {\n continue;\n }\n\n this.intersectionTest(bi, bj, pairs1, pairs2);\n }\n }\n }\n /**\n * Returns all the bodies within an AABB.\n * @param result An array to store resulting bodies in.\n */\n\n\n aabbQuery(world, aabb, result) {\n if (result === void 0) {\n result = [];\n }\n\n for (let i = 0; i < world.bodies.length; i++) {\n const b = world.bodies[i];\n\n if (b.aabbNeedsUpdate) {\n b.updateAABB();\n } // Ugly hack until Body gets aabb\n\n\n if (b.aabb.overlaps(aabb)) {\n result.push(b);\n }\n }\n\n return result;\n }\n\n}\n\n/**\n * Storage for Ray casting data\n */\nclass RaycastResult {\n /**\n * rayFromWorld\n */\n\n /**\n * rayToWorld\n */\n\n /**\n * hitNormalWorld\n */\n\n /**\n * hitPointWorld\n */\n\n /**\n * hasHit\n */\n\n /**\n * shape\n */\n\n /**\n * body\n */\n\n /**\n * The index of the hit triangle, if the hit shape was a trimesh\n */\n\n /**\n * Distance to the hit. Will be set to -1 if there was no hit\n */\n\n /**\n * If the ray should stop traversing the bodies\n */\n constructor() {\n this.rayFromWorld = new Vec3();\n this.rayToWorld = new Vec3();\n this.hitNormalWorld = new Vec3();\n this.hitPointWorld = new Vec3();\n this.hasHit = false;\n this.shape = null;\n this.body = null;\n this.hitFaceIndex = -1;\n this.distance = -1;\n this.shouldStop = false;\n }\n /**\n * Reset all result data.\n */\n\n\n reset() {\n this.rayFromWorld.setZero();\n this.rayToWorld.setZero();\n this.hitNormalWorld.setZero();\n this.hitPointWorld.setZero();\n this.hasHit = false;\n this.shape = null;\n this.body = null;\n this.hitFaceIndex = -1;\n this.distance = -1;\n this.shouldStop = false;\n }\n /**\n * abort\n */\n\n\n abort() {\n this.shouldStop = true;\n }\n /**\n * Set result data.\n */\n\n\n set(rayFromWorld, rayToWorld, hitNormalWorld, hitPointWorld, shape, body, distance) {\n this.rayFromWorld.copy(rayFromWorld);\n this.rayToWorld.copy(rayToWorld);\n this.hitNormalWorld.copy(hitNormalWorld);\n this.hitPointWorld.copy(hitPointWorld);\n this.shape = shape;\n this.body = body;\n this.distance = distance;\n }\n\n}\n\nlet _Shape$types$SPHERE, _Shape$types$PLANE, _Shape$types$BOX, _Shape$types$CYLINDER, _Shape$types$CONVEXPO, _Shape$types$HEIGHTFI, _Shape$types$TRIMESH;\n\n/**\n * RAY_MODES\n */\nconst RAY_MODES = {\n /** CLOSEST */\n CLOSEST: 1,\n\n /** ANY */\n ANY: 2,\n\n /** ALL */\n ALL: 4\n};\n/**\n * RayMode\n */\n\n_Shape$types$SPHERE = Shape.types.SPHERE;\n_Shape$types$PLANE = Shape.types.PLANE;\n_Shape$types$BOX = Shape.types.BOX;\n_Shape$types$CYLINDER = Shape.types.CYLINDER;\n_Shape$types$CONVEXPO = Shape.types.CONVEXPOLYHEDRON;\n_Shape$types$HEIGHTFI = Shape.types.HEIGHTFIELD;\n_Shape$types$TRIMESH = Shape.types.TRIMESH;\n\n/**\n * A line in 3D space that intersects bodies and return points.\n */\nclass Ray {\n /**\n * from\n */\n\n /**\n * to\n */\n\n /**\n * direction\n */\n\n /**\n * The precision of the ray. Used when checking parallelity etc.\n * @default 0.0001\n */\n\n /**\n * Set to `false` if you don't want the Ray to take `collisionResponse` flags into account on bodies and shapes.\n * @default true\n */\n\n /**\n * If set to `true`, the ray skips any hits with normal.dot(rayDirection) < 0.\n * @default false\n */\n\n /**\n * collisionFilterMask\n * @default -1\n */\n\n /**\n * collisionFilterGroup\n * @default -1\n */\n\n /**\n * The intersection mode. Should be Ray.ANY, Ray.ALL or Ray.CLOSEST.\n * @default RAY.ANY\n */\n\n /**\n * Current result object.\n */\n\n /**\n * Will be set to `true` during intersectWorld() if the ray hit anything.\n */\n\n /**\n * User-provided result callback. Will be used if mode is Ray.ALL.\n */\n\n /**\n * CLOSEST\n */\n\n /**\n * ANY\n */\n\n /**\n * ALL\n */\n get [_Shape$types$SPHERE]() {\n return this._intersectSphere;\n }\n\n get [_Shape$types$PLANE]() {\n return this._intersectPlane;\n }\n\n get [_Shape$types$BOX]() {\n return this._intersectBox;\n }\n\n get [_Shape$types$CYLINDER]() {\n return this._intersectConvex;\n }\n\n get [_Shape$types$CONVEXPO]() {\n return this._intersectConvex;\n }\n\n get [_Shape$types$HEIGHTFI]() {\n return this._intersectHeightfield;\n }\n\n get [_Shape$types$TRIMESH]() {\n return this._intersectTrimesh;\n }\n\n constructor(from, to) {\n if (from === void 0) {\n from = new Vec3();\n }\n\n if (to === void 0) {\n to = new Vec3();\n }\n\n this.from = from.clone();\n this.to = to.clone();\n this.direction = new Vec3();\n this.precision = 0.0001;\n this.checkCollisionResponse = true;\n this.skipBackfaces = false;\n this.collisionFilterMask = -1;\n this.collisionFilterGroup = -1;\n this.mode = Ray.ANY;\n this.result = new RaycastResult();\n this.hasHit = false;\n\n this.callback = result => {};\n }\n /**\n * Do itersection against all bodies in the given World.\n * @return True if the ray hit anything, otherwise false.\n */\n\n\n intersectWorld(world, options) {\n this.mode = options.mode || Ray.ANY;\n this.result = options.result || new RaycastResult();\n this.skipBackfaces = !!options.skipBackfaces;\n this.collisionFilterMask = typeof options.collisionFilterMask !== 'undefined' ? options.collisionFilterMask : -1;\n this.collisionFilterGroup = typeof options.collisionFilterGroup !== 'undefined' ? options.collisionFilterGroup : -1;\n this.checkCollisionResponse = typeof options.checkCollisionResponse !== 'undefined' ? options.checkCollisionResponse : true;\n\n if (options.from) {\n this.from.copy(options.from);\n }\n\n if (options.to) {\n this.to.copy(options.to);\n }\n\n this.callback = options.callback || (() => {});\n\n this.hasHit = false;\n this.result.reset();\n this.updateDirection();\n this.getAABB(tmpAABB$1);\n tmpArray.length = 0;\n world.broadphase.aabbQuery(world, tmpAABB$1, tmpArray);\n this.intersectBodies(tmpArray);\n return this.hasHit;\n }\n /**\n * Shoot a ray at a body, get back information about the hit.\n * @deprecated @param result set the result property of the Ray instead.\n */\n\n\n intersectBody(body, result) {\n if (result) {\n this.result = result;\n this.updateDirection();\n }\n\n const checkCollisionResponse = this.checkCollisionResponse;\n\n if (checkCollisionResponse && !body.collisionResponse) {\n return;\n }\n\n if ((this.collisionFilterGroup & body.collisionFilterMask) === 0 || (body.collisionFilterGroup & this.collisionFilterMask) === 0) {\n return;\n }\n\n const xi = intersectBody_xi;\n const qi = intersectBody_qi;\n\n for (let i = 0, N = body.shapes.length; i < N; i++) {\n const shape = body.shapes[i];\n\n if (checkCollisionResponse && !shape.collisionResponse) {\n continue; // Skip\n }\n\n body.quaternion.mult(body.shapeOrientations[i], qi);\n body.quaternion.vmult(body.shapeOffsets[i], xi);\n xi.vadd(body.position, xi);\n this.intersectShape(shape, qi, xi, body);\n\n if (this.result.shouldStop) {\n break;\n }\n }\n }\n /**\n * Shoot a ray at an array bodies, get back information about the hit.\n * @param bodies An array of Body objects.\n * @deprecated @param result set the result property of the Ray instead.\n *\n */\n\n\n intersectBodies(bodies, result) {\n if (result) {\n this.result = result;\n this.updateDirection();\n }\n\n for (let i = 0, l = bodies.length; !this.result.shouldStop && i < l; i++) {\n this.intersectBody(bodies[i]);\n }\n }\n /**\n * Updates the direction vector.\n */\n\n\n updateDirection() {\n this.to.vsub(this.from, this.direction);\n this.direction.normalize();\n }\n\n intersectShape(shape, quat, position, body) {\n const from = this.from; // Checking boundingSphere\n\n const distance = distanceFromIntersection(from, this.direction, position);\n\n if (distance > shape.boundingSphereRadius) {\n return;\n }\n\n const intersectMethod = this[shape.type];\n\n if (intersectMethod) {\n intersectMethod.call(this, shape, quat, position, body, shape);\n }\n }\n\n _intersectBox(box, quat, position, body, reportedShape) {\n return this._intersectConvex(box.convexPolyhedronRepresentation, quat, position, body, reportedShape);\n }\n\n _intersectPlane(shape, quat, position, body, reportedShape) {\n const from = this.from;\n const to = this.to;\n const direction = this.direction; // Get plane normal\n\n const worldNormal = new Vec3(0, 0, 1);\n quat.vmult(worldNormal, worldNormal);\n const len = new Vec3();\n from.vsub(position, len);\n const planeToFrom = len.dot(worldNormal);\n to.vsub(position, len);\n const planeToTo = len.dot(worldNormal);\n\n if (planeToFrom * planeToTo > 0) {\n // \"from\" and \"to\" are on the same side of the plane... bail out\n return;\n }\n\n if (from.distanceTo(to) < planeToFrom) {\n return;\n }\n\n const n_dot_dir = worldNormal.dot(direction);\n\n if (Math.abs(n_dot_dir) < this.precision) {\n // No intersection\n return;\n }\n\n const planePointToFrom = new Vec3();\n const dir_scaled_with_t = new Vec3();\n const hitPointWorld = new Vec3();\n from.vsub(position, planePointToFrom);\n const t = -worldNormal.dot(planePointToFrom) / n_dot_dir;\n direction.scale(t, dir_scaled_with_t);\n from.vadd(dir_scaled_with_t, hitPointWorld);\n this.reportIntersection(worldNormal, hitPointWorld, reportedShape, body, -1);\n }\n /**\n * Get the world AABB of the ray.\n */\n\n\n getAABB(aabb) {\n const {\n lowerBound,\n upperBound\n } = aabb;\n const to = this.to;\n const from = this.from;\n lowerBound.x = Math.min(to.x, from.x);\n lowerBound.y = Math.min(to.y, from.y);\n lowerBound.z = Math.min(to.z, from.z);\n upperBound.x = Math.max(to.x, from.x);\n upperBound.y = Math.max(to.y, from.y);\n upperBound.z = Math.max(to.z, from.z);\n }\n\n _intersectHeightfield(shape, quat, position, body, reportedShape) {\n shape.data;\n shape.elementSize; // Convert the ray to local heightfield coordinates\n\n const localRay = intersectHeightfield_localRay; //new Ray(this.from, this.to);\n\n localRay.from.copy(this.from);\n localRay.to.copy(this.to);\n Transform.pointToLocalFrame(position, quat, localRay.from, localRay.from);\n Transform.pointToLocalFrame(position, quat, localRay.to, localRay.to);\n localRay.updateDirection(); // Get the index of the data points to test against\n\n const index = intersectHeightfield_index;\n let iMinX;\n let iMinY;\n let iMaxX;\n let iMaxY; // Set to max\n\n iMinX = iMinY = 0;\n iMaxX = iMaxY = shape.data.length - 1;\n const aabb = new AABB();\n localRay.getAABB(aabb);\n shape.getIndexOfPosition(aabb.lowerBound.x, aabb.lowerBound.y, index, true);\n iMinX = Math.max(iMinX, index[0]);\n iMinY = Math.max(iMinY, index[1]);\n shape.getIndexOfPosition(aabb.upperBound.x, aabb.upperBound.y, index, true);\n iMaxX = Math.min(iMaxX, index[0] + 1);\n iMaxY = Math.min(iMaxY, index[1] + 1);\n\n for (let i = iMinX; i < iMaxX; i++) {\n for (let j = iMinY; j < iMaxY; j++) {\n if (this.result.shouldStop) {\n return;\n }\n\n shape.getAabbAtIndex(i, j, aabb);\n\n if (!aabb.overlapsRay(localRay)) {\n continue;\n } // Lower triangle\n\n\n shape.getConvexTrianglePillar(i, j, false);\n Transform.pointToWorldFrame(position, quat, shape.pillarOffset, worldPillarOffset);\n\n this._intersectConvex(shape.pillarConvex, quat, worldPillarOffset, body, reportedShape, intersectConvexOptions);\n\n if (this.result.shouldStop) {\n return;\n } // Upper triangle\n\n\n shape.getConvexTrianglePillar(i, j, true);\n Transform.pointToWorldFrame(position, quat, shape.pillarOffset, worldPillarOffset);\n\n this._intersectConvex(shape.pillarConvex, quat, worldPillarOffset, body, reportedShape, intersectConvexOptions);\n }\n }\n }\n\n _intersectSphere(sphere, quat, position, body, reportedShape) {\n const from = this.from;\n const to = this.to;\n const r = sphere.radius;\n const a = (to.x - from.x) ** 2 + (to.y - from.y) ** 2 + (to.z - from.z) ** 2;\n const b = 2 * ((to.x - from.x) * (from.x - position.x) + (to.y - from.y) * (from.y - position.y) + (to.z - from.z) * (from.z - position.z));\n const c = (from.x - position.x) ** 2 + (from.y - position.y) ** 2 + (from.z - position.z) ** 2 - r ** 2;\n const delta = b ** 2 - 4 * a * c;\n const intersectionPoint = Ray_intersectSphere_intersectionPoint;\n const normal = Ray_intersectSphere_normal;\n\n if (delta < 0) {\n // No intersection\n return;\n } else if (delta === 0) {\n // single intersection point\n from.lerp(to, delta, intersectionPoint);\n intersectionPoint.vsub(position, normal);\n normal.normalize();\n this.reportIntersection(normal, intersectionPoint, reportedShape, body, -1);\n } else {\n const d1 = (-b - Math.sqrt(delta)) / (2 * a);\n const d2 = (-b + Math.sqrt(delta)) / (2 * a);\n\n if (d1 >= 0 && d1 <= 1) {\n from.lerp(to, d1, intersectionPoint);\n intersectionPoint.vsub(position, normal);\n normal.normalize();\n this.reportIntersection(normal, intersectionPoint, reportedShape, body, -1);\n }\n\n if (this.result.shouldStop) {\n return;\n }\n\n if (d2 >= 0 && d2 <= 1) {\n from.lerp(to, d2, intersectionPoint);\n intersectionPoint.vsub(position, normal);\n normal.normalize();\n this.reportIntersection(normal, intersectionPoint, reportedShape, body, -1);\n }\n }\n }\n\n _intersectConvex(shape, quat, position, body, reportedShape, options) {\n intersectConvex_minDistNormal;\n const normal = intersectConvex_normal;\n const vector = intersectConvex_vector;\n intersectConvex_minDistIntersect;\n const faceList = options && options.faceList || null; // Checking faces\n\n const faces = shape.faces;\n const vertices = shape.vertices;\n const normals = shape.faceNormals;\n const direction = this.direction;\n const from = this.from;\n const to = this.to;\n const fromToDistance = from.distanceTo(to);\n const Nfaces = faceList ? faceList.length : faces.length;\n const result = this.result;\n\n for (let j = 0; !result.shouldStop && j < Nfaces; j++) {\n const fi = faceList ? faceList[j] : j;\n const face = faces[fi];\n const faceNormal = normals[fi];\n const q = quat;\n const x = position; // determine if ray intersects the plane of the face\n // note: this works regardless of the direction of the face normal\n // Get plane point in world coordinates...\n\n vector.copy(vertices[face[0]]);\n q.vmult(vector, vector);\n vector.vadd(x, vector); // ...but make it relative to the ray from. We'll fix this later.\n\n vector.vsub(from, vector); // Get plane normal\n\n q.vmult(faceNormal, normal); // If this dot product is negative, we have something interesting\n\n const dot = direction.dot(normal); // Bail out if ray and plane are parallel\n\n if (Math.abs(dot) < this.precision) {\n continue;\n } // calc distance to plane\n\n\n const scalar = normal.dot(vector) / dot; // if negative distance, then plane is behind ray\n\n if (scalar < 0) {\n continue;\n } // if (dot < 0) {\n // Intersection point is from + direction * scalar\n\n\n direction.scale(scalar, intersectPoint);\n intersectPoint.vadd(from, intersectPoint); // a is the point we compare points b and c with.\n\n a.copy(vertices[face[0]]);\n q.vmult(a, a);\n x.vadd(a, a);\n\n for (let i = 1; !result.shouldStop && i < face.length - 1; i++) {\n // Transform 3 vertices to world coords\n b.copy(vertices[face[i]]);\n c.copy(vertices[face[i + 1]]);\n q.vmult(b, b);\n q.vmult(c, c);\n x.vadd(b, b);\n x.vadd(c, c);\n const distance = intersectPoint.distanceTo(from);\n\n if (!(Ray.pointInTriangle(intersectPoint, a, b, c) || Ray.pointInTriangle(intersectPoint, b, a, c)) || distance > fromToDistance) {\n continue;\n }\n\n this.reportIntersection(normal, intersectPoint, reportedShape, body, fi);\n } // }\n\n }\n }\n /**\n * @todo Optimize by transforming the world to local space first.\n * @todo Use Octree lookup\n */\n\n\n _intersectTrimesh(mesh, quat, position, body, reportedShape, options) {\n const normal = intersectTrimesh_normal;\n const triangles = intersectTrimesh_triangles;\n const treeTransform = intersectTrimesh_treeTransform;\n const vector = intersectConvex_vector;\n const localDirection = intersectTrimesh_localDirection;\n const localFrom = intersectTrimesh_localFrom;\n const localTo = intersectTrimesh_localTo;\n const worldIntersectPoint = intersectTrimesh_worldIntersectPoint;\n const worldNormal = intersectTrimesh_worldNormal; // Checking faces\n\n const indices = mesh.indices;\n mesh.vertices; // const normals = mesh.faceNormals\n\n const from = this.from;\n const to = this.to;\n const direction = this.direction;\n treeTransform.position.copy(position);\n treeTransform.quaternion.copy(quat); // Transform ray to local space!\n\n Transform.vectorToLocalFrame(position, quat, direction, localDirection);\n Transform.pointToLocalFrame(position, quat, from, localFrom);\n Transform.pointToLocalFrame(position, quat, to, localTo);\n localTo.x *= mesh.scale.x;\n localTo.y *= mesh.scale.y;\n localTo.z *= mesh.scale.z;\n localFrom.x *= mesh.scale.x;\n localFrom.y *= mesh.scale.y;\n localFrom.z *= mesh.scale.z;\n localTo.vsub(localFrom, localDirection);\n localDirection.normalize();\n const fromToDistanceSquared = localFrom.distanceSquared(localTo);\n mesh.tree.rayQuery(this, treeTransform, triangles);\n\n for (let i = 0, N = triangles.length; !this.result.shouldStop && i !== N; i++) {\n const trianglesIndex = triangles[i];\n mesh.getNormal(trianglesIndex, normal); // determine if ray intersects the plane of the face\n // note: this works regardless of the direction of the face normal\n // Get plane point in world coordinates...\n\n mesh.getVertex(indices[trianglesIndex * 3], a); // ...but make it relative to the ray from. We'll fix this later.\n\n a.vsub(localFrom, vector); // If this dot product is negative, we have something interesting\n\n const dot = localDirection.dot(normal); // Bail out if ray and plane are parallel\n // if (Math.abs( dot ) < this.precision){\n // continue;\n // }\n // calc distance to plane\n\n const scalar = normal.dot(vector) / dot; // if negative distance, then plane is behind ray\n\n if (scalar < 0) {\n continue;\n } // Intersection point is from + direction * scalar\n\n\n localDirection.scale(scalar, intersectPoint);\n intersectPoint.vadd(localFrom, intersectPoint); // Get triangle vertices\n\n mesh.getVertex(indices[trianglesIndex * 3 + 1], b);\n mesh.getVertex(indices[trianglesIndex * 3 + 2], c);\n const squaredDistance = intersectPoint.distanceSquared(localFrom);\n\n if (!(Ray.pointInTriangle(intersectPoint, b, a, c) || Ray.pointInTriangle(intersectPoint, a, b, c)) || squaredDistance > fromToDistanceSquared) {\n continue;\n } // transform intersectpoint and normal to world\n\n\n Transform.vectorToWorldFrame(quat, normal, worldNormal);\n Transform.pointToWorldFrame(position, quat, intersectPoint, worldIntersectPoint);\n this.reportIntersection(worldNormal, worldIntersectPoint, reportedShape, body, trianglesIndex);\n }\n\n triangles.length = 0;\n }\n /**\n * @return True if the intersections should continue\n */\n\n\n reportIntersection(normal, hitPointWorld, shape, body, hitFaceIndex) {\n const from = this.from;\n const to = this.to;\n const distance = from.distanceTo(hitPointWorld);\n const result = this.result; // Skip back faces?\n\n if (this.skipBackfaces && normal.dot(this.direction) > 0) {\n return;\n }\n\n result.hitFaceIndex = typeof hitFaceIndex !== 'undefined' ? hitFaceIndex : -1;\n\n switch (this.mode) {\n case Ray.ALL:\n this.hasHit = true;\n result.set(from, to, normal, hitPointWorld, shape, body, distance);\n result.hasHit = true;\n this.callback(result);\n break;\n\n case Ray.CLOSEST:\n // Store if closer than current closest\n if (distance < result.distance || !result.hasHit) {\n this.hasHit = true;\n result.hasHit = true;\n result.set(from, to, normal, hitPointWorld, shape, body, distance);\n }\n\n break;\n\n case Ray.ANY:\n // Report and stop.\n this.hasHit = true;\n result.hasHit = true;\n result.set(from, to, normal, hitPointWorld, shape, body, distance);\n result.shouldStop = true;\n break;\n }\n }\n /**\n * As per \"Barycentric Technique\" as named\n * {@link https://www.blackpawn.com/texts/pointinpoly/default.html here} but without the division\n */\n\n\n static pointInTriangle(p, a, b, c) {\n c.vsub(a, v0);\n b.vsub(a, v1);\n p.vsub(a, v2);\n const dot00 = v0.dot(v0);\n const dot01 = v0.dot(v1);\n const dot02 = v0.dot(v2);\n const dot11 = v1.dot(v1);\n const dot12 = v1.dot(v2);\n let u;\n let v;\n return (u = dot11 * dot02 - dot01 * dot12) >= 0 && (v = dot00 * dot12 - dot01 * dot02) >= 0 && u + v < dot00 * dot11 - dot01 * dot01;\n }\n\n}\nRay.CLOSEST = RAY_MODES.CLOSEST;\nRay.ANY = RAY_MODES.ANY;\nRay.ALL = RAY_MODES.ALL;\nconst tmpAABB$1 = new AABB();\nconst tmpArray = [];\nconst v1 = new Vec3();\nconst v2 = new Vec3();\nconst intersectBody_xi = new Vec3();\nconst intersectBody_qi = new Quaternion();\nconst intersectPoint = new Vec3();\nconst a = new Vec3();\nconst b = new Vec3();\nconst c = new Vec3();\nnew Vec3();\nnew RaycastResult();\nconst intersectConvexOptions = {\n faceList: [0]\n};\nconst worldPillarOffset = new Vec3();\nconst intersectHeightfield_localRay = new Ray();\nconst intersectHeightfield_index = [];\nconst Ray_intersectSphere_intersectionPoint = new Vec3();\nconst Ray_intersectSphere_normal = new Vec3();\nconst intersectConvex_normal = new Vec3();\nconst intersectConvex_minDistNormal = new Vec3();\nconst intersectConvex_minDistIntersect = new Vec3();\nconst intersectConvex_vector = new Vec3();\nconst intersectTrimesh_normal = new Vec3();\nconst intersectTrimesh_localDirection = new Vec3();\nconst intersectTrimesh_localFrom = new Vec3();\nconst intersectTrimesh_localTo = new Vec3();\nconst intersectTrimesh_worldNormal = new Vec3();\nconst intersectTrimesh_worldIntersectPoint = new Vec3();\nnew AABB();\nconst intersectTrimesh_triangles = [];\nconst intersectTrimesh_treeTransform = new Transform();\nconst v0 = new Vec3();\nconst intersect = new Vec3();\n\nfunction distanceFromIntersection(from, direction, position) {\n // v0 is vector from from to position\n position.vsub(from, v0);\n const dot = v0.dot(direction); // intersect = direction*dot + from\n\n direction.scale(dot, intersect);\n intersect.vadd(from, intersect);\n const distance = position.distanceTo(intersect);\n return distance;\n}\n\n/**\n * Sweep and prune broadphase along one axis.\n */\nclass SAPBroadphase extends Broadphase {\n /**\n * List of bodies currently in the broadphase.\n */\n\n /**\n * The world to search in.\n */\n\n /**\n * Axis to sort the bodies along.\n * Set to 0 for x axis, and 1 for y axis.\n * For best performance, pick the axis where bodies are most distributed.\n */\n\n /**\n * Check if the bounds of two bodies overlap, along the given SAP axis.\n */\n static checkBounds(bi, bj, axisIndex) {\n let biPos;\n let bjPos;\n\n if (axisIndex === 0) {\n biPos = bi.position.x;\n bjPos = bj.position.x;\n } else if (axisIndex === 1) {\n biPos = bi.position.y;\n bjPos = bj.position.y;\n } else if (axisIndex === 2) {\n biPos = bi.position.z;\n bjPos = bj.position.z;\n }\n\n const ri = bi.boundingRadius,\n rj = bj.boundingRadius,\n boundA2 = biPos + ri,\n boundB1 = bjPos - rj;\n return boundB1 < boundA2;\n } // Note: these are identical, save for x/y/z lowerbound\n\n /**\n * insertionSortX\n */\n\n\n static insertionSortX(a) {\n for (let i = 1, l = a.length; i < l; i++) {\n const v = a[i];\n let j;\n\n for (j = i - 1; j >= 0; j--) {\n if (a[j].aabb.lowerBound.x <= v.aabb.lowerBound.x) {\n break;\n }\n\n a[j + 1] = a[j];\n }\n\n a[j + 1] = v;\n }\n\n return a;\n }\n /**\n * insertionSortY\n */\n\n\n static insertionSortY(a) {\n for (let i = 1, l = a.length; i < l; i++) {\n const v = a[i];\n let j;\n\n for (j = i - 1; j >= 0; j--) {\n if (a[j].aabb.lowerBound.y <= v.aabb.lowerBound.y) {\n break;\n }\n\n a[j + 1] = a[j];\n }\n\n a[j + 1] = v;\n }\n\n return a;\n }\n /**\n * insertionSortZ\n */\n\n\n static insertionSortZ(a) {\n for (let i = 1, l = a.length; i < l; i++) {\n const v = a[i];\n let j;\n\n for (j = i - 1; j >= 0; j--) {\n if (a[j].aabb.lowerBound.z <= v.aabb.lowerBound.z) {\n break;\n }\n\n a[j + 1] = a[j];\n }\n\n a[j + 1] = v;\n }\n\n return a;\n }\n\n constructor(world) {\n super();\n this.axisList = [];\n this.world = null;\n this.axisIndex = 0;\n const axisList = this.axisList;\n\n this._addBodyHandler = event => {\n axisList.push(event.body);\n };\n\n this._removeBodyHandler = event => {\n const idx = axisList.indexOf(event.body);\n\n if (idx !== -1) {\n axisList.splice(idx, 1);\n }\n };\n\n if (world) {\n this.setWorld(world);\n }\n }\n /**\n * Change the world\n */\n\n\n setWorld(world) {\n // Clear the old axis array\n this.axisList.length = 0; // Add all bodies from the new world\n\n for (let i = 0; i < world.bodies.length; i++) {\n this.axisList.push(world.bodies[i]);\n } // Remove old handlers, if any\n\n\n world.removeEventListener('addBody', this._addBodyHandler);\n world.removeEventListener('removeBody', this._removeBodyHandler); // Add handlers to update the list of bodies.\n\n world.addEventListener('addBody', this._addBodyHandler);\n world.addEventListener('removeBody', this._removeBodyHandler);\n this.world = world;\n this.dirty = true;\n }\n /**\n * Collect all collision pairs\n */\n\n\n collisionPairs(world, p1, p2) {\n const bodies = this.axisList;\n const N = bodies.length;\n const axisIndex = this.axisIndex;\n let i;\n let j;\n\n if (this.dirty) {\n this.sortList();\n this.dirty = false;\n } // Look through the list\n\n\n for (i = 0; i !== N; i++) {\n const bi = bodies[i];\n\n for (j = i + 1; j < N; j++) {\n const bj = bodies[j];\n\n if (!this.needBroadphaseCollision(bi, bj)) {\n continue;\n }\n\n if (!SAPBroadphase.checkBounds(bi, bj, axisIndex)) {\n break;\n }\n\n this.intersectionTest(bi, bj, p1, p2);\n }\n }\n }\n\n sortList() {\n const axisList = this.axisList;\n const axisIndex = this.axisIndex;\n const N = axisList.length; // Update AABBs\n\n for (let i = 0; i !== N; i++) {\n const bi = axisList[i];\n\n if (bi.aabbNeedsUpdate) {\n bi.updateAABB();\n }\n } // Sort the list\n\n\n if (axisIndex === 0) {\n SAPBroadphase.insertionSortX(axisList);\n } else if (axisIndex === 1) {\n SAPBroadphase.insertionSortY(axisList);\n } else if (axisIndex === 2) {\n SAPBroadphase.insertionSortZ(axisList);\n }\n }\n /**\n * Computes the variance of the body positions and estimates the best axis to use.\n * Will automatically set property `axisIndex`.\n */\n\n\n autoDetectAxis() {\n let sumX = 0;\n let sumX2 = 0;\n let sumY = 0;\n let sumY2 = 0;\n let sumZ = 0;\n let sumZ2 = 0;\n const bodies = this.axisList;\n const N = bodies.length;\n const invN = 1 / N;\n\n for (let i = 0; i !== N; i++) {\n const b = bodies[i];\n const centerX = b.position.x;\n sumX += centerX;\n sumX2 += centerX * centerX;\n const centerY = b.position.y;\n sumY += centerY;\n sumY2 += centerY * centerY;\n const centerZ = b.position.z;\n sumZ += centerZ;\n sumZ2 += centerZ * centerZ;\n }\n\n const varianceX = sumX2 - sumX * sumX * invN;\n const varianceY = sumY2 - sumY * sumY * invN;\n const varianceZ = sumZ2 - sumZ * sumZ * invN;\n\n if (varianceX > varianceY) {\n if (varianceX > varianceZ) {\n this.axisIndex = 0;\n } else {\n this.axisIndex = 2;\n }\n } else if (varianceY > varianceZ) {\n this.axisIndex = 1;\n } else {\n this.axisIndex = 2;\n }\n }\n /**\n * Returns all the bodies within an AABB.\n * @param result An array to store resulting bodies in.\n */\n\n\n aabbQuery(world, aabb, result) {\n if (result === void 0) {\n result = [];\n }\n\n if (this.dirty) {\n this.sortList();\n this.dirty = false;\n }\n\n const axisIndex = this.axisIndex;\n let axis = 'x';\n\n if (axisIndex === 1) {\n axis = 'y';\n }\n\n if (axisIndex === 2) {\n axis = 'z';\n }\n\n const axisList = this.axisList;\n aabb.lowerBound[axis];\n aabb.upperBound[axis];\n\n for (let i = 0; i < axisList.length; i++) {\n const b = axisList[i];\n\n if (b.aabbNeedsUpdate) {\n b.updateAABB();\n }\n\n if (b.aabb.overlaps(aabb)) {\n result.push(b);\n }\n }\n\n return result;\n }\n\n}\n\nclass Utils {\n /**\n * Extend an options object with default values.\n * @param options The options object. May be falsy: in this case, a new object is created and returned.\n * @param defaults An object containing default values.\n * @return The modified options object.\n */\n static defaults(options, defaults) {\n if (options === void 0) {\n options = {};\n }\n\n for (let key in defaults) {\n if (!(key in options)) {\n options[key] = defaults[key];\n }\n }\n\n return options;\n }\n\n}\n\n/**\n * Constraint base class\n */\nclass Constraint {\n /**\n * Equations to be solved in this constraint.\n */\n\n /**\n * Body A.\n */\n\n /**\n * Body B.\n */\n\n /**\n * Set to false if you don't want the bodies to collide when they are connected.\n */\n constructor(bodyA, bodyB, options) {\n if (options === void 0) {\n options = {};\n }\n\n options = Utils.defaults(options, {\n collideConnected: true,\n wakeUpBodies: true\n });\n this.equations = [];\n this.bodyA = bodyA;\n this.bodyB = bodyB;\n this.id = Constraint.idCounter++;\n this.collideConnected = options.collideConnected;\n\n if (options.wakeUpBodies) {\n if (bodyA) {\n bodyA.wakeUp();\n }\n\n if (bodyB) {\n bodyB.wakeUp();\n }\n }\n }\n /**\n * Update all the equations with data.\n */\n\n\n update() {\n throw new Error('method update() not implmemented in this Constraint subclass!');\n }\n /**\n * Enables all equations in the constraint.\n */\n\n\n enable() {\n const eqs = this.equations;\n\n for (let i = 0; i < eqs.length; i++) {\n eqs[i].enabled = true;\n }\n }\n /**\n * Disables all equations in the constraint.\n */\n\n\n disable() {\n const eqs = this.equations;\n\n for (let i = 0; i < eqs.length; i++) {\n eqs[i].enabled = false;\n }\n }\n\n}\nConstraint.idCounter = 0;\n\n/**\n * An element containing 6 entries, 3 spatial and 3 rotational degrees of freedom.\n */\n\nclass JacobianElement {\n /**\n * spatial\n */\n\n /**\n * rotational\n */\n constructor() {\n this.spatial = new Vec3();\n this.rotational = new Vec3();\n }\n /**\n * Multiply with other JacobianElement\n */\n\n\n multiplyElement(element) {\n return element.spatial.dot(this.spatial) + element.rotational.dot(this.rotational);\n }\n /**\n * Multiply with two vectors\n */\n\n\n multiplyVectors(spatial, rotational) {\n return spatial.dot(this.spatial) + rotational.dot(this.rotational);\n }\n\n}\n\n/**\n * Equation base class.\n *\n * `a`, `b` and `eps` are {@link https://www8.cs.umu.se/kurser/5DV058/VT15/lectures/SPOOKlabnotes.pdf SPOOK} parameters that default to `0.0`. See {@link https://github.com/schteppe/cannon.js/issues/238#issuecomment-147172327 this exchange} for more details on Cannon's physics implementation.\n */\nclass Equation {\n /**\n * Minimum (read: negative max) force to be applied by the constraint.\n */\n\n /**\n * Maximum (read: positive max) force to be applied by the constraint.\n */\n\n /**\n * SPOOK parameter\n */\n\n /**\n * SPOOK parameter\n */\n\n /**\n * SPOOK parameter\n */\n\n /**\n * A number, proportional to the force added to the bodies.\n */\n constructor(bi, bj, minForce, maxForce) {\n if (minForce === void 0) {\n minForce = -1e6;\n }\n\n if (maxForce === void 0) {\n maxForce = 1e6;\n }\n\n this.id = Equation.idCounter++;\n this.minForce = minForce;\n this.maxForce = maxForce;\n this.bi = bi;\n this.bj = bj;\n this.a = 0.0; // SPOOK parameter\n\n this.b = 0.0; // SPOOK parameter\n\n this.eps = 0.0; // SPOOK parameter\n\n this.jacobianElementA = new JacobianElement();\n this.jacobianElementB = new JacobianElement();\n this.enabled = true;\n this.multiplier = 0;\n this.setSpookParams(1e7, 4, 1 / 60); // Set typical spook params\n }\n /**\n * Recalculates a, b, and eps.\n *\n * The Equation constructor sets typical SPOOK parameters as such:\n * * `stiffness` = 1e7\n * * `relaxation` = 4\n * * `timeStep`= 1 / 60, _note the hardcoded refresh rate._\n */\n\n\n setSpookParams(stiffness, relaxation, timeStep) {\n const d = relaxation;\n const k = stiffness;\n const h = timeStep;\n this.a = 4.0 / (h * (1 + 4 * d));\n this.b = 4.0 * d / (1 + 4 * d);\n this.eps = 4.0 / (h * h * k * (1 + 4 * d));\n }\n /**\n * Computes the right hand side of the SPOOK equation\n */\n\n\n computeB(a, b, h) {\n const GW = this.computeGW();\n const Gq = this.computeGq();\n const GiMf = this.computeGiMf();\n return -Gq * a - GW * b - GiMf * h;\n }\n /**\n * Computes G*q, where q are the generalized body coordinates\n */\n\n\n computeGq() {\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB;\n const bi = this.bi;\n const bj = this.bj;\n const xi = bi.position;\n const xj = bj.position;\n return GA.spatial.dot(xi) + GB.spatial.dot(xj);\n }\n /**\n * Computes G*W, where W are the body velocities\n */\n\n\n computeGW() {\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB;\n const bi = this.bi;\n const bj = this.bj;\n const vi = bi.velocity;\n const vj = bj.velocity;\n const wi = bi.angularVelocity;\n const wj = bj.angularVelocity;\n return GA.multiplyVectors(vi, wi) + GB.multiplyVectors(vj, wj);\n }\n /**\n * Computes G*Wlambda, where W are the body velocities\n */\n\n\n computeGWlambda() {\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB;\n const bi = this.bi;\n const bj = this.bj;\n const vi = bi.vlambda;\n const vj = bj.vlambda;\n const wi = bi.wlambda;\n const wj = bj.wlambda;\n return GA.multiplyVectors(vi, wi) + GB.multiplyVectors(vj, wj);\n }\n /**\n * Computes G*inv(M)*f, where M is the mass matrix with diagonal blocks for each body, and f are the forces on the bodies.\n */\n\n\n computeGiMf() {\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB;\n const bi = this.bi;\n const bj = this.bj;\n const fi = bi.force;\n const ti = bi.torque;\n const fj = bj.force;\n const tj = bj.torque;\n const invMassi = bi.invMassSolve;\n const invMassj = bj.invMassSolve;\n fi.scale(invMassi, iMfi);\n fj.scale(invMassj, iMfj);\n bi.invInertiaWorldSolve.vmult(ti, invIi_vmult_taui);\n bj.invInertiaWorldSolve.vmult(tj, invIj_vmult_tauj);\n return GA.multiplyVectors(iMfi, invIi_vmult_taui) + GB.multiplyVectors(iMfj, invIj_vmult_tauj);\n }\n /**\n * Computes G*inv(M)*G'\n */\n\n\n computeGiMGt() {\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB;\n const bi = this.bi;\n const bj = this.bj;\n const invMassi = bi.invMassSolve;\n const invMassj = bj.invMassSolve;\n const invIi = bi.invInertiaWorldSolve;\n const invIj = bj.invInertiaWorldSolve;\n let result = invMassi + invMassj;\n invIi.vmult(GA.rotational, tmp);\n result += tmp.dot(GA.rotational);\n invIj.vmult(GB.rotational, tmp);\n result += tmp.dot(GB.rotational);\n return result;\n }\n /**\n * Add constraint velocity to the bodies.\n */\n\n\n addToWlambda(deltalambda) {\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB;\n const bi = this.bi;\n const bj = this.bj;\n const temp = addToWlambda_temp; // Add to linear velocity\n // v_lambda += inv(M) * delta_lamba * G\n\n bi.vlambda.addScaledVector(bi.invMassSolve * deltalambda, GA.spatial, bi.vlambda);\n bj.vlambda.addScaledVector(bj.invMassSolve * deltalambda, GB.spatial, bj.vlambda); // Add to angular velocity\n\n bi.invInertiaWorldSolve.vmult(GA.rotational, temp);\n bi.wlambda.addScaledVector(deltalambda, temp, bi.wlambda);\n bj.invInertiaWorldSolve.vmult(GB.rotational, temp);\n bj.wlambda.addScaledVector(deltalambda, temp, bj.wlambda);\n }\n /**\n * Compute the denominator part of the SPOOK equation: C = G*inv(M)*G' + eps\n */\n\n\n computeC() {\n return this.computeGiMGt() + this.eps;\n }\n\n}\nEquation.idCounter = 0;\nconst iMfi = new Vec3();\nconst iMfj = new Vec3();\nconst invIi_vmult_taui = new Vec3();\nconst invIj_vmult_tauj = new Vec3();\nconst tmp = new Vec3();\nconst addToWlambda_temp = new Vec3();\n\n/**\n * Contact/non-penetration constraint equation\n */\nclass ContactEquation extends Equation {\n /**\n * \"bounciness\": u1 = -e*u0\n */\n\n /**\n * World-oriented vector that goes from the center of bi to the contact point.\n */\n\n /**\n * World-oriented vector that starts in body j position and goes to the contact point.\n */\n\n /**\n * Contact normal, pointing out of body i.\n */\n constructor(bodyA, bodyB, maxForce) {\n if (maxForce === void 0) {\n maxForce = 1e6;\n }\n\n super(bodyA, bodyB, 0, maxForce);\n this.restitution = 0.0;\n this.ri = new Vec3();\n this.rj = new Vec3();\n this.ni = new Vec3();\n }\n\n computeB(h) {\n const a = this.a;\n const b = this.b;\n const bi = this.bi;\n const bj = this.bj;\n const ri = this.ri;\n const rj = this.rj;\n const rixn = ContactEquation_computeB_temp1;\n const rjxn = ContactEquation_computeB_temp2;\n const vi = bi.velocity;\n const wi = bi.angularVelocity;\n bi.force;\n bi.torque;\n const vj = bj.velocity;\n const wj = bj.angularVelocity;\n bj.force;\n bj.torque;\n const penetrationVec = ContactEquation_computeB_temp3;\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB;\n const n = this.ni; // Caluclate cross products\n\n ri.cross(n, rixn);\n rj.cross(n, rjxn); // g = xj+rj -(xi+ri)\n // G = [ -ni -rixn ni rjxn ]\n\n n.negate(GA.spatial);\n rixn.negate(GA.rotational);\n GB.spatial.copy(n);\n GB.rotational.copy(rjxn); // Calculate the penetration vector\n\n penetrationVec.copy(bj.position);\n penetrationVec.vadd(rj, penetrationVec);\n penetrationVec.vsub(bi.position, penetrationVec);\n penetrationVec.vsub(ri, penetrationVec);\n const g = n.dot(penetrationVec); // Compute iteration\n\n const ePlusOne = this.restitution + 1;\n const GW = ePlusOne * vj.dot(n) - ePlusOne * vi.dot(n) + wj.dot(rjxn) - wi.dot(rixn);\n const GiMf = this.computeGiMf();\n const B = -g * a - GW * b - h * GiMf;\n return B;\n }\n /**\n * Get the current relative velocity in the contact point.\n */\n\n\n getImpactVelocityAlongNormal() {\n const vi = ContactEquation_getImpactVelocityAlongNormal_vi;\n const vj = ContactEquation_getImpactVelocityAlongNormal_vj;\n const xi = ContactEquation_getImpactVelocityAlongNormal_xi;\n const xj = ContactEquation_getImpactVelocityAlongNormal_xj;\n const relVel = ContactEquation_getImpactVelocityAlongNormal_relVel;\n this.bi.position.vadd(this.ri, xi);\n this.bj.position.vadd(this.rj, xj);\n this.bi.getVelocityAtWorldPoint(xi, vi);\n this.bj.getVelocityAtWorldPoint(xj, vj);\n vi.vsub(vj, relVel);\n return this.ni.dot(relVel);\n }\n\n}\nconst ContactEquation_computeB_temp1 = new Vec3(); // Temp vectors\n\nconst ContactEquation_computeB_temp2 = new Vec3();\nconst ContactEquation_computeB_temp3 = new Vec3();\nconst ContactEquation_getImpactVelocityAlongNormal_vi = new Vec3();\nconst ContactEquation_getImpactVelocityAlongNormal_vj = new Vec3();\nconst ContactEquation_getImpactVelocityAlongNormal_xi = new Vec3();\nconst ContactEquation_getImpactVelocityAlongNormal_xj = new Vec3();\nconst ContactEquation_getImpactVelocityAlongNormal_relVel = new Vec3();\n\n/**\n * Connects two bodies at given offset points.\n * @example\n * const bodyA = new Body({ mass: 1 })\n * const bodyB = new Body({ mass: 1 })\n * bodyA.position.set(-1, 0, 0)\n * bodyB.position.set(1, 0, 0)\n * bodyA.addShape(shapeA)\n * bodyB.addShape(shapeB)\n * world.addBody(bodyA)\n * world.addBody(bodyB)\n * const localPivotA = new Vec3(1, 0, 0)\n * const localPivotB = new Vec3(-1, 0, 0)\n * const constraint = new PointToPointConstraint(bodyA, localPivotA, bodyB, localPivotB)\n * world.addConstraint(constraint)\n */\nclass PointToPointConstraint extends Constraint {\n /**\n * Pivot, defined locally in bodyA.\n */\n\n /**\n * Pivot, defined locally in bodyB.\n */\n\n /**\n * @param pivotA The point relative to the center of mass of bodyA which bodyA is constrained to.\n * @param bodyB Body that will be constrained in a similar way to the same point as bodyA. We will therefore get a link between bodyA and bodyB. If not specified, bodyA will be constrained to a static point.\n * @param pivotB The point relative to the center of mass of bodyB which bodyB is constrained to.\n * @param maxForce The maximum force that should be applied to constrain the bodies.\n */\n constructor(bodyA, pivotA, bodyB, pivotB, maxForce) {\n if (pivotA === void 0) {\n pivotA = new Vec3();\n }\n\n if (pivotB === void 0) {\n pivotB = new Vec3();\n }\n\n if (maxForce === void 0) {\n maxForce = 1e6;\n }\n\n super(bodyA, bodyB);\n this.pivotA = pivotA.clone();\n this.pivotB = pivotB.clone();\n const x = this.equationX = new ContactEquation(bodyA, bodyB);\n const y = this.equationY = new ContactEquation(bodyA, bodyB);\n const z = this.equationZ = new ContactEquation(bodyA, bodyB); // Equations to be fed to the solver\n\n this.equations.push(x, y, z); // Make the equations bidirectional\n\n x.minForce = y.minForce = z.minForce = -maxForce;\n x.maxForce = y.maxForce = z.maxForce = maxForce;\n x.ni.set(1, 0, 0);\n y.ni.set(0, 1, 0);\n z.ni.set(0, 0, 1);\n }\n\n update() {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const x = this.equationX;\n const y = this.equationY;\n const z = this.equationZ; // Rotate the pivots to world space\n\n bodyA.quaternion.vmult(this.pivotA, x.ri);\n bodyB.quaternion.vmult(this.pivotB, x.rj);\n y.ri.copy(x.ri);\n y.rj.copy(x.rj);\n z.ri.copy(x.ri);\n z.rj.copy(x.rj);\n }\n\n}\n\n/**\n * Cone equation. Works to keep the given body world vectors aligned, or tilted within a given angle from each other.\n */\nclass ConeEquation extends Equation {\n /**\n * Local axis in A\n */\n\n /**\n * Local axis in B\n */\n\n /**\n * The \"cone angle\" to keep\n */\n constructor(bodyA, bodyB, options) {\n if (options === void 0) {\n options = {};\n }\n\n const maxForce = typeof options.maxForce !== 'undefined' ? options.maxForce : 1e6;\n super(bodyA, bodyB, -maxForce, maxForce);\n this.axisA = options.axisA ? options.axisA.clone() : new Vec3(1, 0, 0);\n this.axisB = options.axisB ? options.axisB.clone() : new Vec3(0, 1, 0);\n this.angle = typeof options.angle !== 'undefined' ? options.angle : 0;\n }\n\n computeB(h) {\n const a = this.a;\n const b = this.b;\n const ni = this.axisA;\n const nj = this.axisB;\n const nixnj = tmpVec1$2;\n const njxni = tmpVec2$2;\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB; // Caluclate cross products\n\n ni.cross(nj, nixnj);\n nj.cross(ni, njxni); // The angle between two vector is:\n // cos(theta) = a * b / (length(a) * length(b) = { len(a) = len(b) = 1 } = a * b\n // g = a * b\n // gdot = (b x a) * wi + (a x b) * wj\n // G = [0 bxa 0 axb]\n // W = [vi wi vj wj]\n\n GA.rotational.copy(njxni);\n GB.rotational.copy(nixnj);\n const g = Math.cos(this.angle) - ni.dot(nj);\n const GW = this.computeGW();\n const GiMf = this.computeGiMf();\n const B = -g * a - GW * b - h * GiMf;\n return B;\n }\n\n}\nconst tmpVec1$2 = new Vec3();\nconst tmpVec2$2 = new Vec3();\n\n/**\n * Rotational constraint. Works to keep the local vectors orthogonal to each other in world space.\n */\nclass RotationalEquation extends Equation {\n /**\n * World oriented rotational axis.\n */\n\n /**\n * World oriented rotational axis.\n */\n\n /**\n * maxAngle\n */\n constructor(bodyA, bodyB, options) {\n if (options === void 0) {\n options = {};\n }\n\n const maxForce = typeof options.maxForce !== 'undefined' ? options.maxForce : 1e6;\n super(bodyA, bodyB, -maxForce, maxForce);\n this.axisA = options.axisA ? options.axisA.clone() : new Vec3(1, 0, 0);\n this.axisB = options.axisB ? options.axisB.clone() : new Vec3(0, 1, 0);\n this.maxAngle = Math.PI / 2;\n }\n\n computeB(h) {\n const a = this.a;\n const b = this.b;\n const ni = this.axisA;\n const nj = this.axisB;\n const nixnj = tmpVec1$1;\n const njxni = tmpVec2$1;\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB; // Caluclate cross products\n\n ni.cross(nj, nixnj);\n nj.cross(ni, njxni); // g = ni * nj\n // gdot = (nj x ni) * wi + (ni x nj) * wj\n // G = [0 njxni 0 nixnj]\n // W = [vi wi vj wj]\n\n GA.rotational.copy(njxni);\n GB.rotational.copy(nixnj);\n const g = Math.cos(this.maxAngle) - ni.dot(nj);\n const GW = this.computeGW();\n const GiMf = this.computeGiMf();\n const B = -g * a - GW * b - h * GiMf;\n return B;\n }\n\n}\nconst tmpVec1$1 = new Vec3();\nconst tmpVec2$1 = new Vec3();\n\n/**\n * A Cone Twist constraint, useful for ragdolls.\n */\nclass ConeTwistConstraint extends PointToPointConstraint {\n /**\n * The axis direction for the constraint of the body A.\n */\n\n /**\n * The axis direction for the constraint of the body B.\n */\n\n /**\n * The aperture angle of the cone.\n */\n\n /**\n * The twist angle of the joint.\n */\n constructor(bodyA, bodyB, options) {\n if (options === void 0) {\n options = {};\n }\n\n const maxForce = typeof options.maxForce !== 'undefined' ? options.maxForce : 1e6; // Set pivot point in between\n\n const pivotA = options.pivotA ? options.pivotA.clone() : new Vec3();\n const pivotB = options.pivotB ? options.pivotB.clone() : new Vec3();\n super(bodyA, pivotA, bodyB, pivotB, maxForce);\n this.axisA = options.axisA ? options.axisA.clone() : new Vec3();\n this.axisB = options.axisB ? options.axisB.clone() : new Vec3();\n this.collideConnected = !!options.collideConnected;\n this.angle = typeof options.angle !== 'undefined' ? options.angle : 0;\n const c = this.coneEquation = new ConeEquation(bodyA, bodyB, options);\n const t = this.twistEquation = new RotationalEquation(bodyA, bodyB, options);\n this.twistAngle = typeof options.twistAngle !== 'undefined' ? options.twistAngle : 0; // Make the cone equation push the bodies toward the cone axis, not outward\n\n c.maxForce = 0;\n c.minForce = -maxForce; // Make the twist equation add torque toward the initial position\n\n t.maxForce = 0;\n t.minForce = -maxForce;\n this.equations.push(c, t);\n }\n\n update() {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const cone = this.coneEquation;\n const twist = this.twistEquation;\n super.update(); // Update the axes to the cone constraint\n\n bodyA.vectorToWorldFrame(this.axisA, cone.axisA);\n bodyB.vectorToWorldFrame(this.axisB, cone.axisB); // Update the world axes in the twist constraint\n\n this.axisA.tangents(twist.axisA, twist.axisA);\n bodyA.vectorToWorldFrame(twist.axisA, twist.axisA);\n this.axisB.tangents(twist.axisB, twist.axisB);\n bodyB.vectorToWorldFrame(twist.axisB, twist.axisB);\n cone.angle = this.angle;\n twist.maxAngle = this.twistAngle;\n }\n\n}\nnew Vec3();\nnew Vec3();\n\n/**\n * Constrains two bodies to be at a constant distance from each others center of mass.\n */\nclass DistanceConstraint extends Constraint {\n /**\n * The distance to keep. If undefined, it will be set to the current distance between bodyA and bodyB\n */\n\n /**\n * @param distance The distance to keep. If undefined, it will be set to the current distance between bodyA and bodyB.\n * @param maxForce The maximum force that should be applied to constrain the bodies.\n */\n constructor(bodyA, bodyB, distance, maxForce) {\n if (maxForce === void 0) {\n maxForce = 1e6;\n }\n\n super(bodyA, bodyB);\n\n if (typeof distance === 'undefined') {\n distance = bodyA.position.distanceTo(bodyB.position);\n }\n\n this.distance = distance;\n const eq = this.distanceEquation = new ContactEquation(bodyA, bodyB);\n this.equations.push(eq); // Make it bidirectional\n\n eq.minForce = -maxForce;\n eq.maxForce = maxForce;\n }\n /**\n * update\n */\n\n\n update() {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const eq = this.distanceEquation;\n const halfDist = this.distance * 0.5;\n const normal = eq.ni;\n bodyB.position.vsub(bodyA.position, normal);\n normal.normalize();\n normal.scale(halfDist, eq.ri);\n normal.scale(-halfDist, eq.rj);\n }\n\n}\n\n/**\n * Lock constraint. Will remove all degrees of freedom between the bodies.\n */\nclass LockConstraint extends PointToPointConstraint {\n constructor(bodyA, bodyB, options) {\n if (options === void 0) {\n options = {};\n }\n\n const maxForce = typeof options.maxForce !== 'undefined' ? options.maxForce : 1e6; // Set pivot point in between\n\n const pivotA = new Vec3();\n const pivotB = new Vec3();\n const halfWay = new Vec3();\n bodyA.position.vadd(bodyB.position, halfWay);\n halfWay.scale(0.5, halfWay);\n bodyB.pointToLocalFrame(halfWay, pivotB);\n bodyA.pointToLocalFrame(halfWay, pivotA); // The point-to-point constraint will keep a point shared between the bodies\n\n super(bodyA, pivotA, bodyB, pivotB, maxForce); // Store initial rotation of the bodies as unit vectors in the local body spaces\n\n this.xA = bodyA.vectorToLocalFrame(Vec3.UNIT_X);\n this.xB = bodyB.vectorToLocalFrame(Vec3.UNIT_X);\n this.yA = bodyA.vectorToLocalFrame(Vec3.UNIT_Y);\n this.yB = bodyB.vectorToLocalFrame(Vec3.UNIT_Y);\n this.zA = bodyA.vectorToLocalFrame(Vec3.UNIT_Z);\n this.zB = bodyB.vectorToLocalFrame(Vec3.UNIT_Z); // ...and the following rotational equations will keep all rotational DOF's in place\n\n const r1 = this.rotationalEquation1 = new RotationalEquation(bodyA, bodyB, options);\n const r2 = this.rotationalEquation2 = new RotationalEquation(bodyA, bodyB, options);\n const r3 = this.rotationalEquation3 = new RotationalEquation(bodyA, bodyB, options);\n this.equations.push(r1, r2, r3);\n }\n /**\n * update\n */\n\n\n update() {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n this.motorEquation;\n const r1 = this.rotationalEquation1;\n const r2 = this.rotationalEquation2;\n const r3 = this.rotationalEquation3;\n LockConstraint_update_tmpVec1;\n LockConstraint_update_tmpVec2;\n super.update(); // These vector pairs must be orthogonal\n\n bodyA.vectorToWorldFrame(this.xA, r1.axisA);\n bodyB.vectorToWorldFrame(this.yB, r1.axisB);\n bodyA.vectorToWorldFrame(this.yA, r2.axisA);\n bodyB.vectorToWorldFrame(this.zB, r2.axisB);\n bodyA.vectorToWorldFrame(this.zA, r3.axisA);\n bodyB.vectorToWorldFrame(this.xB, r3.axisB);\n }\n\n}\nconst LockConstraint_update_tmpVec1 = new Vec3();\nconst LockConstraint_update_tmpVec2 = new Vec3();\n\n/**\n * Rotational motor constraint. Tries to keep the relative angular velocity of the bodies to a given value.\n */\nclass RotationalMotorEquation extends Equation {\n /**\n * World oriented rotational axis.\n */\n\n /**\n * World oriented rotational axis.\n */\n\n /**\n * Motor velocity.\n */\n constructor(bodyA, bodyB, maxForce) {\n if (maxForce === void 0) {\n maxForce = 1e6;\n }\n\n super(bodyA, bodyB, -maxForce, maxForce);\n this.axisA = new Vec3();\n this.axisB = new Vec3();\n this.targetVelocity = 0;\n }\n\n computeB(h) {\n this.a;\n const b = this.b;\n this.bi;\n this.bj;\n const axisA = this.axisA;\n const axisB = this.axisB;\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB; // g = 0\n // gdot = axisA * wi - axisB * wj\n // gdot = G * W = G * [vi wi vj wj]\n // =>\n // G = [0 axisA 0 -axisB]\n\n GA.rotational.copy(axisA);\n axisB.negate(GB.rotational);\n const GW = this.computeGW() - this.targetVelocity;\n const GiMf = this.computeGiMf();\n const B = -GW * b - h * GiMf;\n return B;\n }\n\n}\n\n/**\n * Hinge constraint. Think of it as a door hinge. It tries to keep the door in the correct place and with the correct orientation.\n */\nclass HingeConstraint extends PointToPointConstraint {\n /**\n * Rotation axis, defined locally in bodyA.\n */\n\n /**\n * Rotation axis, defined locally in bodyB.\n */\n constructor(bodyA, bodyB, options) {\n if (options === void 0) {\n options = {};\n }\n\n const maxForce = typeof options.maxForce !== 'undefined' ? options.maxForce : 1e6;\n const pivotA = options.pivotA ? options.pivotA.clone() : new Vec3();\n const pivotB = options.pivotB ? options.pivotB.clone() : new Vec3();\n super(bodyA, pivotA, bodyB, pivotB, maxForce);\n const axisA = this.axisA = options.axisA ? options.axisA.clone() : new Vec3(1, 0, 0);\n axisA.normalize();\n const axisB = this.axisB = options.axisB ? options.axisB.clone() : new Vec3(1, 0, 0);\n axisB.normalize();\n this.collideConnected = !!options.collideConnected;\n const rotational1 = this.rotationalEquation1 = new RotationalEquation(bodyA, bodyB, options);\n const rotational2 = this.rotationalEquation2 = new RotationalEquation(bodyA, bodyB, options);\n const motor = this.motorEquation = new RotationalMotorEquation(bodyA, bodyB, maxForce);\n motor.enabled = false; // Not enabled by default\n // Equations to be fed to the solver\n\n this.equations.push(rotational1, rotational2, motor);\n }\n /**\n * enableMotor\n */\n\n\n enableMotor() {\n this.motorEquation.enabled = true;\n }\n /**\n * disableMotor\n */\n\n\n disableMotor() {\n this.motorEquation.enabled = false;\n }\n /**\n * setMotorSpeed\n */\n\n\n setMotorSpeed(speed) {\n this.motorEquation.targetVelocity = speed;\n }\n /**\n * setMotorMaxForce\n */\n\n\n setMotorMaxForce(maxForce) {\n this.motorEquation.maxForce = maxForce;\n this.motorEquation.minForce = -maxForce;\n }\n /**\n * update\n */\n\n\n update() {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const motor = this.motorEquation;\n const r1 = this.rotationalEquation1;\n const r2 = this.rotationalEquation2;\n const worldAxisA = HingeConstraint_update_tmpVec1;\n const worldAxisB = HingeConstraint_update_tmpVec2;\n const axisA = this.axisA;\n const axisB = this.axisB;\n super.update(); // Get world axes\n\n bodyA.quaternion.vmult(axisA, worldAxisA);\n bodyB.quaternion.vmult(axisB, worldAxisB);\n worldAxisA.tangents(r1.axisA, r2.axisA);\n r1.axisB.copy(worldAxisB);\n r2.axisB.copy(worldAxisB);\n\n if (this.motorEquation.enabled) {\n bodyA.quaternion.vmult(this.axisA, motor.axisA);\n bodyB.quaternion.vmult(this.axisB, motor.axisB);\n }\n }\n\n}\nconst HingeConstraint_update_tmpVec1 = new Vec3();\nconst HingeConstraint_update_tmpVec2 = new Vec3();\n\n/**\n * Constrains the slipping in a contact along a tangent\n */\nclass FrictionEquation extends Equation {\n // Tangent\n\n /**\n * @param slipForce should be +-F_friction = +-mu * F_normal = +-mu * m * g\n */\n constructor(bodyA, bodyB, slipForce) {\n super(bodyA, bodyB, -slipForce, slipForce);\n this.ri = new Vec3();\n this.rj = new Vec3();\n this.t = new Vec3();\n }\n\n computeB(h) {\n this.a;\n const b = this.b;\n this.bi;\n this.bj;\n const ri = this.ri;\n const rj = this.rj;\n const rixt = FrictionEquation_computeB_temp1;\n const rjxt = FrictionEquation_computeB_temp2;\n const t = this.t; // Caluclate cross products\n\n ri.cross(t, rixt);\n rj.cross(t, rjxt); // G = [-t -rixt t rjxt]\n // And remember, this is a pure velocity constraint, g is always zero!\n\n const GA = this.jacobianElementA;\n const GB = this.jacobianElementB;\n t.negate(GA.spatial);\n rixt.negate(GA.rotational);\n GB.spatial.copy(t);\n GB.rotational.copy(rjxt);\n const GW = this.computeGW();\n const GiMf = this.computeGiMf();\n const B = -GW * b - h * GiMf;\n return B;\n }\n\n}\nconst FrictionEquation_computeB_temp1 = new Vec3();\nconst FrictionEquation_computeB_temp2 = new Vec3();\n\n/**\n * Defines what happens when two materials meet.\n * @todo Refactor materials to materialA and materialB\n */\nclass ContactMaterial {\n /**\n * Identifier of this material.\n */\n\n /**\n * Participating materials.\n */\n\n /**\n * Friction coefficient.\n * @default 0.3\n */\n\n /**\n * Restitution coefficient.\n * @default 0.3\n */\n\n /**\n * Stiffness of the produced contact equations.\n * @default 1e7\n */\n\n /**\n * Relaxation time of the produced contact equations.\n * @default 3\n */\n\n /**\n * Stiffness of the produced friction equations.\n * @default 1e7\n */\n\n /**\n * Relaxation time of the produced friction equations\n * @default 3\n */\n constructor(m1, m2, options) {\n options = Utils.defaults(options, {\n friction: 0.3,\n restitution: 0.3,\n contactEquationStiffness: 1e7,\n contactEquationRelaxation: 3,\n frictionEquationStiffness: 1e7,\n frictionEquationRelaxation: 3\n });\n this.id = ContactMaterial.idCounter++;\n this.materials = [m1, m2];\n this.friction = options.friction;\n this.restitution = options.restitution;\n this.contactEquationStiffness = options.contactEquationStiffness;\n this.contactEquationRelaxation = options.contactEquationRelaxation;\n this.frictionEquationStiffness = options.frictionEquationStiffness;\n this.frictionEquationRelaxation = options.frictionEquationRelaxation;\n }\n\n}\nContactMaterial.idCounter = 0;\n\n/**\n * Defines a physics material.\n */\nclass Material {\n /**\n * Material name.\n * If options is a string, name will be set to that string.\n * @todo Deprecate this\n */\n\n /** Material id. */\n\n /**\n * Friction for this material.\n * If non-negative, it will be used instead of the friction given by ContactMaterials. If there's no matching ContactMaterial, the value from `defaultContactMaterial` in the World will be used.\n */\n\n /**\n * Restitution for this material.\n * If non-negative, it will be used instead of the restitution given by ContactMaterials. If there's no matching ContactMaterial, the value from `defaultContactMaterial` in the World will be used.\n */\n constructor(options) {\n if (options === void 0) {\n options = {};\n }\n\n let name = ''; // Backwards compatibility fix\n\n if (typeof options === 'string') {\n //console.warn(`Passing a string to MaterialOptions is deprecated, and has no effect`)\n name = options;\n options = {};\n }\n\n this.name = name;\n this.id = Material.idCounter++;\n this.friction = typeof options.friction !== 'undefined' ? options.friction : -1;\n this.restitution = typeof options.restitution !== 'undefined' ? options.restitution : -1;\n }\n\n}\nMaterial.idCounter = 0;\n\n/**\n * A spring, connecting two bodies.\n * @example\n * const spring = new Spring(boxBody, sphereBody, {\n * restLength: 0,\n * stiffness: 50,\n * damping: 1,\n * })\n *\n * // Compute the force after each step\n * world.addEventListener('postStep', (event) => {\n * spring.applyForce()\n * })\n */\nclass Spring {\n /**\n * Rest length of the spring. A number > 0.\n * @default 1\n */\n\n /**\n * Stiffness of the spring. A number >= 0.\n * @default 100\n */\n\n /**\n * Damping of the spring. A number >= 0.\n * @default 1\n */\n\n /**\n * First connected body.\n */\n\n /**\n * Second connected body.\n */\n\n /**\n * Anchor for bodyA in local bodyA coordinates.\n * Where to hook the spring to body A, in local body coordinates.\n * @default new Vec3()\n */\n\n /**\n * Anchor for bodyB in local bodyB coordinates.\n * Where to hook the spring to body B, in local body coordinates.\n * @default new Vec3()\n */\n constructor(bodyA, bodyB, options) {\n if (options === void 0) {\n options = {};\n }\n\n this.restLength = typeof options.restLength === 'number' ? options.restLength : 1;\n this.stiffness = options.stiffness || 100;\n this.damping = options.damping || 1;\n this.bodyA = bodyA;\n this.bodyB = bodyB;\n this.localAnchorA = new Vec3();\n this.localAnchorB = new Vec3();\n\n if (options.localAnchorA) {\n this.localAnchorA.copy(options.localAnchorA);\n }\n\n if (options.localAnchorB) {\n this.localAnchorB.copy(options.localAnchorB);\n }\n\n if (options.worldAnchorA) {\n this.setWorldAnchorA(options.worldAnchorA);\n }\n\n if (options.worldAnchorB) {\n this.setWorldAnchorB(options.worldAnchorB);\n }\n }\n /**\n * Set the anchor point on body A, using world coordinates.\n */\n\n\n setWorldAnchorA(worldAnchorA) {\n this.bodyA.pointToLocalFrame(worldAnchorA, this.localAnchorA);\n }\n /**\n * Set the anchor point on body B, using world coordinates.\n */\n\n\n setWorldAnchorB(worldAnchorB) {\n this.bodyB.pointToLocalFrame(worldAnchorB, this.localAnchorB);\n }\n /**\n * Get the anchor point on body A, in world coordinates.\n * @param result The vector to store the result in.\n */\n\n\n getWorldAnchorA(result) {\n this.bodyA.pointToWorldFrame(this.localAnchorA, result);\n }\n /**\n * Get the anchor point on body B, in world coordinates.\n * @param result The vector to store the result in.\n */\n\n\n getWorldAnchorB(result) {\n this.bodyB.pointToWorldFrame(this.localAnchorB, result);\n }\n /**\n * Apply the spring force to the connected bodies.\n */\n\n\n applyForce() {\n const k = this.stiffness;\n const d = this.damping;\n const l = this.restLength;\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const r = applyForce_r;\n const r_unit = applyForce_r_unit;\n const u = applyForce_u;\n const f = applyForce_f;\n const tmp = applyForce_tmp;\n const worldAnchorA = applyForce_worldAnchorA;\n const worldAnchorB = applyForce_worldAnchorB;\n const ri = applyForce_ri;\n const rj = applyForce_rj;\n const ri_x_f = applyForce_ri_x_f;\n const rj_x_f = applyForce_rj_x_f; // Get world anchors\n\n this.getWorldAnchorA(worldAnchorA);\n this.getWorldAnchorB(worldAnchorB); // Get offset points\n\n worldAnchorA.vsub(bodyA.position, ri);\n worldAnchorB.vsub(bodyB.position, rj); // Compute distance vector between world anchor points\n\n worldAnchorB.vsub(worldAnchorA, r);\n const rlen = r.length();\n r_unit.copy(r);\n r_unit.normalize(); // Compute relative velocity of the anchor points, u\n\n bodyB.velocity.vsub(bodyA.velocity, u); // Add rotational velocity\n\n bodyB.angularVelocity.cross(rj, tmp);\n u.vadd(tmp, u);\n bodyA.angularVelocity.cross(ri, tmp);\n u.vsub(tmp, u); // F = - k * ( x - L ) - D * ( u )\n\n r_unit.scale(-k * (rlen - l) - d * u.dot(r_unit), f); // Add forces to bodies\n\n bodyA.force.vsub(f, bodyA.force);\n bodyB.force.vadd(f, bodyB.force); // Angular force\n\n ri.cross(f, ri_x_f);\n rj.cross(f, rj_x_f);\n bodyA.torque.vsub(ri_x_f, bodyA.torque);\n bodyB.torque.vadd(rj_x_f, bodyB.torque);\n }\n\n}\nconst applyForce_r = new Vec3();\nconst applyForce_r_unit = new Vec3();\nconst applyForce_u = new Vec3();\nconst applyForce_f = new Vec3();\nconst applyForce_worldAnchorA = new Vec3();\nconst applyForce_worldAnchorB = new Vec3();\nconst applyForce_ri = new Vec3();\nconst applyForce_rj = new Vec3();\nconst applyForce_ri_x_f = new Vec3();\nconst applyForce_rj_x_f = new Vec3();\nconst applyForce_tmp = new Vec3();\n\n/**\n * WheelInfo\n */\nclass WheelInfo {\n /**\n * Max travel distance of the suspension, in meters.\n * @default 1\n */\n\n /**\n * Speed to apply to the wheel rotation when the wheel is sliding.\n * @default -0.1\n */\n\n /**\n * If the customSlidingRotationalSpeed should be used.\n * @default false\n */\n\n /**\n * sliding\n */\n\n /**\n * Connection point, defined locally in the chassis body frame.\n */\n\n /**\n * chassisConnectionPointWorld\n */\n\n /**\n * directionLocal\n */\n\n /**\n * directionWorld\n */\n\n /**\n * axleLocal\n */\n\n /**\n * axleWorld\n */\n\n /**\n * suspensionRestLength\n * @default 1\n */\n\n /**\n * suspensionMaxLength\n * @default 2\n */\n\n /**\n * radius\n * @default 1\n */\n\n /**\n * suspensionStiffness\n * @default 100\n */\n\n /**\n * dampingCompression\n * @default 10\n */\n\n /**\n * dampingRelaxation\n * @default 10\n */\n\n /**\n * frictionSlip\n * @default 10.5\n */\n\n /** forwardAcceleration */\n\n /** sideAcceleration */\n\n /**\n * steering\n * @default 0\n */\n\n /**\n * Rotation value, in radians.\n * @default 0\n */\n\n /**\n * deltaRotation\n * @default 0\n */\n\n /**\n * rollInfluence\n * @default 0.01\n */\n\n /**\n * maxSuspensionForce\n */\n\n /**\n * engineForce\n */\n\n /**\n * brake\n */\n\n /**\n * isFrontWheel\n * @default true\n */\n\n /**\n * clippedInvContactDotSuspension\n * @default 1\n */\n\n /**\n * suspensionRelativeVelocity\n * @default 0\n */\n\n /**\n * suspensionForce\n * @default 0\n */\n\n /**\n * slipInfo\n */\n\n /**\n * skidInfo\n * @default 0\n */\n\n /**\n * suspensionLength\n * @default 0\n */\n\n /**\n * sideImpulse\n */\n\n /**\n * forwardImpulse\n */\n\n /**\n * The result from raycasting.\n */\n\n /**\n * Wheel world transform.\n */\n\n /**\n * isInContact\n */\n constructor(options) {\n if (options === void 0) {\n options = {};\n }\n\n options = Utils.defaults(options, {\n chassisConnectionPointLocal: new Vec3(),\n chassisConnectionPointWorld: new Vec3(),\n directionLocal: new Vec3(),\n directionWorld: new Vec3(),\n axleLocal: new Vec3(),\n axleWorld: new Vec3(),\n suspensionRestLength: 1,\n suspensionMaxLength: 2,\n radius: 1,\n suspensionStiffness: 100,\n dampingCompression: 10,\n dampingRelaxation: 10,\n frictionSlip: 10.5,\n forwardAcceleration: 1,\n sideAcceleration: 1,\n steering: 0,\n rotation: 0,\n deltaRotation: 0,\n rollInfluence: 0.01,\n maxSuspensionForce: Number.MAX_VALUE,\n isFrontWheel: true,\n clippedInvContactDotSuspension: 1,\n suspensionRelativeVelocity: 0,\n suspensionForce: 0,\n slipInfo: 0,\n skidInfo: 0,\n suspensionLength: 0,\n maxSuspensionTravel: 1,\n useCustomSlidingRotationalSpeed: false,\n customSlidingRotationalSpeed: -0.1\n });\n this.maxSuspensionTravel = options.maxSuspensionTravel;\n this.customSlidingRotationalSpeed = options.customSlidingRotationalSpeed;\n this.useCustomSlidingRotationalSpeed = options.useCustomSlidingRotationalSpeed;\n this.sliding = false;\n this.chassisConnectionPointLocal = options.chassisConnectionPointLocal.clone();\n this.chassisConnectionPointWorld = options.chassisConnectionPointWorld.clone();\n this.directionLocal = options.directionLocal.clone();\n this.directionWorld = options.directionWorld.clone();\n this.axleLocal = options.axleLocal.clone();\n this.axleWorld = options.axleWorld.clone();\n this.suspensionRestLength = options.suspensionRestLength;\n this.suspensionMaxLength = options.suspensionMaxLength;\n this.radius = options.radius;\n this.suspensionStiffness = options.suspensionStiffness;\n this.dampingCompression = options.dampingCompression;\n this.dampingRelaxation = options.dampingRelaxation;\n this.frictionSlip = options.frictionSlip;\n this.forwardAcceleration = options.forwardAcceleration;\n this.sideAcceleration = options.sideAcceleration;\n this.steering = 0;\n this.rotation = 0;\n this.deltaRotation = 0;\n this.rollInfluence = options.rollInfluence;\n this.maxSuspensionForce = options.maxSuspensionForce;\n this.engineForce = 0;\n this.brake = 0;\n this.isFrontWheel = options.isFrontWheel;\n this.clippedInvContactDotSuspension = 1;\n this.suspensionRelativeVelocity = 0;\n this.suspensionForce = 0;\n this.slipInfo = 0;\n this.skidInfo = 0;\n this.suspensionLength = 0;\n this.sideImpulse = 0;\n this.forwardImpulse = 0;\n this.raycastResult = new RaycastResult();\n this.worldTransform = new Transform();\n this.isInContact = false;\n }\n\n updateWheel(chassis) {\n const raycastResult = this.raycastResult;\n\n if (this.isInContact) {\n const project = raycastResult.hitNormalWorld.dot(raycastResult.directionWorld);\n raycastResult.hitPointWorld.vsub(chassis.position, relpos);\n chassis.getVelocityAtWorldPoint(relpos, chassis_velocity_at_contactPoint);\n const projVel = raycastResult.hitNormalWorld.dot(chassis_velocity_at_contactPoint);\n\n if (project >= -0.1) {\n this.suspensionRelativeVelocity = 0.0;\n this.clippedInvContactDotSuspension = 1.0 / 0.1;\n } else {\n const inv = -1 / project;\n this.suspensionRelativeVelocity = projVel * inv;\n this.clippedInvContactDotSuspension = inv;\n }\n } else {\n // Not in contact : position wheel in a nice (rest length) position\n raycastResult.suspensionLength = this.suspensionRestLength;\n this.suspensionRelativeVelocity = 0.0;\n raycastResult.directionWorld.scale(-1, raycastResult.hitNormalWorld);\n this.clippedInvContactDotSuspension = 1.0;\n }\n }\n\n}\nconst chassis_velocity_at_contactPoint = new Vec3();\nconst relpos = new Vec3();\n\n/**\n * Vehicle helper class that casts rays from the wheel positions towards the ground and applies forces.\n */\nclass RaycastVehicle {\n /** The car chassis body. */\n\n /** The wheels. */\n\n /** Will be set to true if the car is sliding. */\n\n /** Index of the right axis. x=0, y=1, z=2 */\n\n /** Index of the forward axis. x=0, y=1, z=2 */\n\n /** Index of the up axis. x=0, y=1, z=2 */\n\n /** The constraints. */\n\n /** Optional pre-step callback. */\n\n /** Number of wheels on the ground. */\n constructor(options) {\n this.chassisBody = options.chassisBody;\n this.wheelInfos = [];\n this.sliding = false;\n this.world = null;\n this.indexRightAxis = typeof options.indexRightAxis !== 'undefined' ? options.indexRightAxis : 2;\n this.indexForwardAxis = typeof options.indexForwardAxis !== 'undefined' ? options.indexForwardAxis : 0;\n this.indexUpAxis = typeof options.indexUpAxis !== 'undefined' ? options.indexUpAxis : 1;\n this.constraints = [];\n\n this.preStepCallback = () => {};\n\n this.currentVehicleSpeedKmHour = 0;\n this.numWheelsOnGround = 0;\n }\n /**\n * Add a wheel. For information about the options, see `WheelInfo`.\n */\n\n\n addWheel(options) {\n if (options === void 0) {\n options = {};\n }\n\n const info = new WheelInfo(options);\n const index = this.wheelInfos.length;\n this.wheelInfos.push(info);\n return index;\n }\n /**\n * Set the steering value of a wheel.\n */\n\n\n setSteeringValue(value, wheelIndex) {\n const wheel = this.wheelInfos[wheelIndex];\n wheel.steering = value;\n }\n /**\n * Set the wheel force to apply on one of the wheels each time step\n */\n\n\n applyEngineForce(value, wheelIndex) {\n this.wheelInfos[wheelIndex].engineForce = value;\n }\n /**\n * Set the braking force of a wheel\n */\n\n\n setBrake(brake, wheelIndex) {\n this.wheelInfos[wheelIndex].brake = brake;\n }\n /**\n * Add the vehicle including its constraints to the world.\n */\n\n\n addToWorld(world) {\n world.addBody(this.chassisBody);\n const that = this;\n\n this.preStepCallback = () => {\n that.updateVehicle(world.dt);\n };\n\n world.addEventListener('preStep', this.preStepCallback);\n this.world = world;\n }\n /**\n * Get one of the wheel axles, world-oriented.\n */\n\n\n getVehicleAxisWorld(axisIndex, result) {\n result.set(axisIndex === 0 ? 1 : 0, axisIndex === 1 ? 1 : 0, axisIndex === 2 ? 1 : 0);\n this.chassisBody.vectorToWorldFrame(result, result);\n }\n\n updateVehicle(timeStep) {\n const wheelInfos = this.wheelInfos;\n const numWheels = wheelInfos.length;\n const chassisBody = this.chassisBody;\n\n for (let i = 0; i < numWheels; i++) {\n this.updateWheelTransform(i);\n }\n\n this.currentVehicleSpeedKmHour = 3.6 * chassisBody.velocity.length();\n const forwardWorld = new Vec3();\n this.getVehicleAxisWorld(this.indexForwardAxis, forwardWorld);\n\n if (forwardWorld.dot(chassisBody.velocity) < 0) {\n this.currentVehicleSpeedKmHour *= -1;\n } // simulate suspension\n\n\n for (let i = 0; i < numWheels; i++) {\n this.castRay(wheelInfos[i]);\n }\n\n this.updateSuspension(timeStep);\n const impulse = new Vec3();\n const relpos = new Vec3();\n\n for (let i = 0; i < numWheels; i++) {\n //apply suspension force\n const wheel = wheelInfos[i];\n let suspensionForce = wheel.suspensionForce;\n\n if (suspensionForce > wheel.maxSuspensionForce) {\n suspensionForce = wheel.maxSuspensionForce;\n }\n\n wheel.raycastResult.hitNormalWorld.scale(suspensionForce * timeStep, impulse);\n wheel.raycastResult.hitPointWorld.vsub(chassisBody.position, relpos);\n chassisBody.applyImpulse(impulse, relpos);\n }\n\n this.updateFriction(timeStep);\n const hitNormalWorldScaledWithProj = new Vec3();\n const fwd = new Vec3();\n const vel = new Vec3();\n\n for (let i = 0; i < numWheels; i++) {\n const wheel = wheelInfos[i]; //const relpos = new Vec3();\n //wheel.chassisConnectionPointWorld.vsub(chassisBody.position, relpos);\n\n chassisBody.getVelocityAtWorldPoint(wheel.chassisConnectionPointWorld, vel); // Hack to get the rotation in the correct direction\n\n let m = 1;\n\n switch (this.indexUpAxis) {\n case 1:\n m = -1;\n break;\n }\n\n if (wheel.isInContact) {\n this.getVehicleAxisWorld(this.indexForwardAxis, fwd);\n const proj = fwd.dot(wheel.raycastResult.hitNormalWorld);\n wheel.raycastResult.hitNormalWorld.scale(proj, hitNormalWorldScaledWithProj);\n fwd.vsub(hitNormalWorldScaledWithProj, fwd);\n const proj2 = fwd.dot(vel);\n wheel.deltaRotation = m * proj2 * timeStep / wheel.radius;\n }\n\n if ((wheel.sliding || !wheel.isInContact) && wheel.engineForce !== 0 && wheel.useCustomSlidingRotationalSpeed) {\n // Apply custom rotation when accelerating and sliding\n wheel.deltaRotation = (wheel.engineForce > 0 ? 1 : -1) * wheel.customSlidingRotationalSpeed * timeStep;\n } // Lock wheels\n\n\n if (Math.abs(wheel.brake) > Math.abs(wheel.engineForce)) {\n wheel.deltaRotation = 0;\n }\n\n wheel.rotation += wheel.deltaRotation; // Use the old value\n\n wheel.deltaRotation *= 0.99; // damping of rotation when not in contact\n }\n }\n\n updateSuspension(deltaTime) {\n const chassisBody = this.chassisBody;\n const chassisMass = chassisBody.mass;\n const wheelInfos = this.wheelInfos;\n const numWheels = wheelInfos.length;\n\n for (let w_it = 0; w_it < numWheels; w_it++) {\n const wheel = wheelInfos[w_it];\n\n if (wheel.isInContact) {\n let force; // Spring\n\n const susp_length = wheel.suspensionRestLength;\n const current_length = wheel.suspensionLength;\n const length_diff = susp_length - current_length;\n force = wheel.suspensionStiffness * length_diff * wheel.clippedInvContactDotSuspension; // Damper\n\n const projected_rel_vel = wheel.suspensionRelativeVelocity;\n let susp_damping;\n\n if (projected_rel_vel < 0) {\n susp_damping = wheel.dampingCompression;\n } else {\n susp_damping = wheel.dampingRelaxation;\n }\n\n force -= susp_damping * projected_rel_vel;\n wheel.suspensionForce = force * chassisMass;\n\n if (wheel.suspensionForce < 0) {\n wheel.suspensionForce = 0;\n }\n } else {\n wheel.suspensionForce = 0;\n }\n }\n }\n /**\n * Remove the vehicle including its constraints from the world.\n */\n\n\n removeFromWorld(world) {\n this.constraints;\n world.removeBody(this.chassisBody);\n world.removeEventListener('preStep', this.preStepCallback);\n this.world = null;\n }\n\n castRay(wheel) {\n const rayvector = castRay_rayvector;\n const target = castRay_target;\n this.updateWheelTransformWorld(wheel);\n const chassisBody = this.chassisBody;\n let depth = -1;\n const raylen = wheel.suspensionRestLength + wheel.radius;\n wheel.directionWorld.scale(raylen, rayvector);\n const source = wheel.chassisConnectionPointWorld;\n source.vadd(rayvector, target);\n const raycastResult = wheel.raycastResult;\n raycastResult.reset(); // Turn off ray collision with the chassis temporarily\n\n const oldState = chassisBody.collisionResponse;\n chassisBody.collisionResponse = false; // Cast ray against world\n\n this.world.rayTest(source, target, raycastResult);\n chassisBody.collisionResponse = oldState;\n const object = raycastResult.body;\n wheel.raycastResult.groundObject = 0;\n\n if (object) {\n depth = raycastResult.distance;\n wheel.raycastResult.hitNormalWorld = raycastResult.hitNormalWorld;\n wheel.isInContact = true;\n const hitDistance = raycastResult.distance;\n wheel.suspensionLength = hitDistance - wheel.radius; // clamp on max suspension travel\n\n const minSuspensionLength = wheel.suspensionRestLength - wheel.maxSuspensionTravel;\n const maxSuspensionLength = wheel.suspensionRestLength + wheel.maxSuspensionTravel;\n\n if (wheel.suspensionLength < minSuspensionLength) {\n wheel.suspensionLength = minSuspensionLength;\n }\n\n if (wheel.suspensionLength > maxSuspensionLength) {\n wheel.suspensionLength = maxSuspensionLength;\n wheel.raycastResult.reset();\n }\n\n const denominator = wheel.raycastResult.hitNormalWorld.dot(wheel.directionWorld);\n const chassis_velocity_at_contactPoint = new Vec3();\n chassisBody.getVelocityAtWorldPoint(wheel.raycastResult.hitPointWorld, chassis_velocity_at_contactPoint);\n const projVel = wheel.raycastResult.hitNormalWorld.dot(chassis_velocity_at_contactPoint);\n\n if (denominator >= -0.1) {\n wheel.suspensionRelativeVelocity = 0;\n wheel.clippedInvContactDotSuspension = 1 / 0.1;\n } else {\n const inv = -1 / denominator;\n wheel.suspensionRelativeVelocity = projVel * inv;\n wheel.clippedInvContactDotSuspension = inv;\n }\n } else {\n //put wheel info as in rest position\n wheel.suspensionLength = wheel.suspensionRestLength + 0 * wheel.maxSuspensionTravel;\n wheel.suspensionRelativeVelocity = 0.0;\n wheel.directionWorld.scale(-1, wheel.raycastResult.hitNormalWorld);\n wheel.clippedInvContactDotSuspension = 1.0;\n }\n\n return depth;\n }\n\n updateWheelTransformWorld(wheel) {\n wheel.isInContact = false;\n const chassisBody = this.chassisBody;\n chassisBody.pointToWorldFrame(wheel.chassisConnectionPointLocal, wheel.chassisConnectionPointWorld);\n chassisBody.vectorToWorldFrame(wheel.directionLocal, wheel.directionWorld);\n chassisBody.vectorToWorldFrame(wheel.axleLocal, wheel.axleWorld);\n }\n /**\n * Update one of the wheel transform.\n * Note when rendering wheels: during each step, wheel transforms are updated BEFORE the chassis; ie. their position becomes invalid after the step. Thus when you render wheels, you must update wheel transforms before rendering them. See raycastVehicle demo for an example.\n * @param wheelIndex The wheel index to update.\n */\n\n\n updateWheelTransform(wheelIndex) {\n const up = tmpVec4;\n const right = tmpVec5;\n const fwd = tmpVec6;\n const wheel = this.wheelInfos[wheelIndex];\n this.updateWheelTransformWorld(wheel);\n wheel.directionLocal.scale(-1, up);\n right.copy(wheel.axleLocal);\n up.cross(right, fwd);\n fwd.normalize();\n right.normalize(); // Rotate around steering over the wheelAxle\n\n const steering = wheel.steering;\n const steeringOrn = new Quaternion();\n steeringOrn.setFromAxisAngle(up, steering);\n const rotatingOrn = new Quaternion();\n rotatingOrn.setFromAxisAngle(right, wheel.rotation); // World rotation of the wheel\n\n const q = wheel.worldTransform.quaternion;\n this.chassisBody.quaternion.mult(steeringOrn, q);\n q.mult(rotatingOrn, q);\n q.normalize(); // world position of the wheel\n\n const p = wheel.worldTransform.position;\n p.copy(wheel.directionWorld);\n p.scale(wheel.suspensionLength, p);\n p.vadd(wheel.chassisConnectionPointWorld, p);\n }\n /**\n * Get the world transform of one of the wheels\n */\n\n\n getWheelTransformWorld(wheelIndex) {\n return this.wheelInfos[wheelIndex].worldTransform;\n }\n\n updateFriction(timeStep) {\n const surfNormalWS_scaled_proj = updateFriction_surfNormalWS_scaled_proj; //calculate the impulse, so that the wheels don't move sidewards\n\n const wheelInfos = this.wheelInfos;\n const numWheels = wheelInfos.length;\n const chassisBody = this.chassisBody;\n const forwardWS = updateFriction_forwardWS;\n const axle = updateFriction_axle;\n this.numWheelsOnGround = 0;\n\n for (let i = 0; i < numWheels; i++) {\n const wheel = wheelInfos[i];\n const groundObject = wheel.raycastResult.body;\n\n if (groundObject) {\n this.numWheelsOnGround++;\n }\n\n wheel.sideImpulse = 0;\n wheel.forwardImpulse = 0;\n\n if (!forwardWS[i]) {\n forwardWS[i] = new Vec3();\n }\n\n if (!axle[i]) {\n axle[i] = new Vec3();\n }\n }\n\n for (let i = 0; i < numWheels; i++) {\n const wheel = wheelInfos[i];\n const groundObject = wheel.raycastResult.body;\n\n if (groundObject) {\n const axlei = axle[i];\n const wheelTrans = this.getWheelTransformWorld(i); // Get world axle\n\n wheelTrans.vectorToWorldFrame(directions[this.indexRightAxis], axlei);\n const surfNormalWS = wheel.raycastResult.hitNormalWorld;\n const proj = axlei.dot(surfNormalWS);\n surfNormalWS.scale(proj, surfNormalWS_scaled_proj);\n axlei.vsub(surfNormalWS_scaled_proj, axlei);\n axlei.normalize();\n surfNormalWS.cross(axlei, forwardWS[i]);\n forwardWS[i].normalize();\n wheel.sideImpulse = resolveSingleBilateral(chassisBody, wheel.raycastResult.hitPointWorld, groundObject, wheel.raycastResult.hitPointWorld, axlei);\n wheel.sideImpulse *= sideFrictionStiffness2;\n }\n }\n\n const sideFactor = 1;\n const fwdFactor = 0.5;\n this.sliding = false;\n\n for (let i = 0; i < numWheels; i++) {\n const wheel = wheelInfos[i];\n const groundObject = wheel.raycastResult.body;\n let rollingFriction = 0;\n wheel.slipInfo = 1;\n\n if (groundObject) {\n const defaultRollingFrictionImpulse = 0;\n const maxImpulse = wheel.brake ? wheel.brake : defaultRollingFrictionImpulse; // btWheelContactPoint contactPt(chassisBody,groundObject,wheelInfraycastInfo.hitPointWorld,forwardWS[wheel],maxImpulse);\n // rollingFriction = calcRollingFriction(contactPt);\n\n rollingFriction = calcRollingFriction(chassisBody, groundObject, wheel.raycastResult.hitPointWorld, forwardWS[i], maxImpulse);\n rollingFriction += wheel.engineForce * timeStep; // rollingFriction = 0;\n\n const factor = maxImpulse / rollingFriction;\n wheel.slipInfo *= factor;\n } //switch between active rolling (throttle), braking and non-active rolling friction (nthrottle/break)\n\n\n wheel.forwardImpulse = 0;\n wheel.skidInfo = 1;\n\n if (groundObject) {\n wheel.skidInfo = 1;\n const maximp = wheel.suspensionForce * timeStep * wheel.frictionSlip;\n const maximpSide = maximp;\n const maximpSquared = maximp * maximpSide;\n wheel.forwardImpulse = rollingFriction; //wheelInfo.engineForce* timeStep;\n\n const x = wheel.forwardImpulse * fwdFactor / wheel.forwardAcceleration;\n const y = wheel.sideImpulse * sideFactor / wheel.sideAcceleration;\n const impulseSquared = x * x + y * y;\n wheel.sliding = false;\n\n if (impulseSquared > maximpSquared) {\n this.sliding = true;\n wheel.sliding = true;\n const factor = maximp / Math.sqrt(impulseSquared);\n wheel.skidInfo *= factor;\n }\n }\n }\n\n if (this.sliding) {\n for (let i = 0; i < numWheels; i++) {\n const wheel = wheelInfos[i];\n\n if (wheel.sideImpulse !== 0) {\n if (wheel.skidInfo < 1) {\n wheel.forwardImpulse *= wheel.skidInfo;\n wheel.sideImpulse *= wheel.skidInfo;\n }\n }\n }\n } // apply the impulses\n\n\n for (let i = 0; i < numWheels; i++) {\n const wheel = wheelInfos[i];\n const rel_pos = new Vec3();\n wheel.raycastResult.hitPointWorld.vsub(chassisBody.position, rel_pos); // cannons applyimpulse is using world coord for the position\n //rel_pos.copy(wheel.raycastResult.hitPointWorld);\n\n if (wheel.forwardImpulse !== 0) {\n const impulse = new Vec3();\n forwardWS[i].scale(wheel.forwardImpulse, impulse);\n chassisBody.applyImpulse(impulse, rel_pos);\n }\n\n if (wheel.sideImpulse !== 0) {\n const groundObject = wheel.raycastResult.body;\n const rel_pos2 = new Vec3();\n wheel.raycastResult.hitPointWorld.vsub(groundObject.position, rel_pos2); //rel_pos2.copy(wheel.raycastResult.hitPointWorld);\n\n const sideImp = new Vec3();\n axle[i].scale(wheel.sideImpulse, sideImp); // Scale the relative position in the up direction with rollInfluence.\n // If rollInfluence is 1, the impulse will be applied on the hitPoint (easy to roll over), if it is zero it will be applied in the same plane as the center of mass (not easy to roll over).\n\n chassisBody.vectorToLocalFrame(rel_pos, rel_pos);\n rel_pos['xyz'[this.indexUpAxis]] *= wheel.rollInfluence;\n chassisBody.vectorToWorldFrame(rel_pos, rel_pos);\n chassisBody.applyImpulse(sideImp, rel_pos); //apply friction impulse on the ground\n\n sideImp.scale(-1, sideImp);\n groundObject.applyImpulse(sideImp, rel_pos2);\n }\n }\n }\n\n}\nnew Vec3();\nnew Vec3();\nnew Vec3();\nconst tmpVec4 = new Vec3();\nconst tmpVec5 = new Vec3();\nconst tmpVec6 = new Vec3();\nnew Ray();\nnew Vec3();\nconst castRay_rayvector = new Vec3();\nconst castRay_target = new Vec3();\nconst directions = [new Vec3(1, 0, 0), new Vec3(0, 1, 0), new Vec3(0, 0, 1)];\nconst updateFriction_surfNormalWS_scaled_proj = new Vec3();\nconst updateFriction_axle = [];\nconst updateFriction_forwardWS = [];\nconst sideFrictionStiffness2 = 1;\nconst calcRollingFriction_vel1 = new Vec3();\nconst calcRollingFriction_vel2 = new Vec3();\nconst calcRollingFriction_vel = new Vec3();\n\nfunction calcRollingFriction(body0, body1, frictionPosWorld, frictionDirectionWorld, maxImpulse) {\n let j1 = 0;\n const contactPosWorld = frictionPosWorld; // const rel_pos1 = new Vec3();\n // const rel_pos2 = new Vec3();\n\n const vel1 = calcRollingFriction_vel1;\n const vel2 = calcRollingFriction_vel2;\n const vel = calcRollingFriction_vel; // contactPosWorld.vsub(body0.position, rel_pos1);\n // contactPosWorld.vsub(body1.position, rel_pos2);\n\n body0.getVelocityAtWorldPoint(contactPosWorld, vel1);\n body1.getVelocityAtWorldPoint(contactPosWorld, vel2);\n vel1.vsub(vel2, vel);\n const vrel = frictionDirectionWorld.dot(vel);\n const denom0 = computeImpulseDenominator(body0, frictionPosWorld, frictionDirectionWorld);\n const denom1 = computeImpulseDenominator(body1, frictionPosWorld, frictionDirectionWorld);\n const relaxation = 1;\n const jacDiagABInv = relaxation / (denom0 + denom1); // calculate j that moves us to zero relative velocity\n\n j1 = -vrel * jacDiagABInv;\n\n if (maxImpulse < j1) {\n j1 = maxImpulse;\n }\n\n if (j1 < -maxImpulse) {\n j1 = -maxImpulse;\n }\n\n return j1;\n}\n\nconst computeImpulseDenominator_r0 = new Vec3();\nconst computeImpulseDenominator_c0 = new Vec3();\nconst computeImpulseDenominator_vec = new Vec3();\nconst computeImpulseDenominator_m = new Vec3();\n\nfunction computeImpulseDenominator(body, pos, normal) {\n const r0 = computeImpulseDenominator_r0;\n const c0 = computeImpulseDenominator_c0;\n const vec = computeImpulseDenominator_vec;\n const m = computeImpulseDenominator_m;\n pos.vsub(body.position, r0);\n r0.cross(normal, c0);\n body.invInertiaWorld.vmult(c0, m);\n m.cross(r0, vec);\n return body.invMass + normal.dot(vec);\n}\n\nconst resolveSingleBilateral_vel1 = new Vec3();\nconst resolveSingleBilateral_vel2 = new Vec3();\nconst resolveSingleBilateral_vel = new Vec3(); // bilateral constraint between two dynamic objects\n\nfunction resolveSingleBilateral(body1, pos1, body2, pos2, normal) {\n const normalLenSqr = normal.lengthSquared();\n\n if (normalLenSqr > 1.1) {\n return 0; // no impulse\n } // const rel_pos1 = new Vec3();\n // const rel_pos2 = new Vec3();\n // pos1.vsub(body1.position, rel_pos1);\n // pos2.vsub(body2.position, rel_pos2);\n\n\n const vel1 = resolveSingleBilateral_vel1;\n const vel2 = resolveSingleBilateral_vel2;\n const vel = resolveSingleBilateral_vel;\n body1.getVelocityAtWorldPoint(pos1, vel1);\n body2.getVelocityAtWorldPoint(pos2, vel2);\n vel1.vsub(vel2, vel);\n const rel_vel = normal.dot(vel);\n const contactDamping = 0.2;\n const massTerm = 1 / (body1.invMass + body2.invMass);\n const impulse = -contactDamping * rel_vel * massTerm;\n return impulse;\n}\n\n/**\n * Spherical shape\n * @example\n * const radius = 1\n * const sphereShape = new CANNON.Sphere(radius)\n * const sphereBody = new CANNON.Body({ mass: 1, shape: sphereShape })\n * world.addBody(sphereBody)\n */\nclass Sphere extends Shape {\n /**\n * The radius of the sphere.\n */\n\n /**\n *\n * @param radius The radius of the sphere, a non-negative number.\n */\n constructor(radius) {\n super({\n type: Shape.types.SPHERE\n });\n this.radius = radius !== undefined ? radius : 1.0;\n\n if (this.radius < 0) {\n throw new Error('The sphere radius cannot be negative.');\n }\n\n this.updateBoundingSphereRadius();\n }\n /** calculateLocalInertia */\n\n\n calculateLocalInertia(mass, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n const I = 2.0 * mass * this.radius * this.radius / 5.0;\n target.x = I;\n target.y = I;\n target.z = I;\n return target;\n }\n /** volume */\n\n\n volume() {\n return 4.0 * Math.PI * Math.pow(this.radius, 3) / 3.0;\n }\n\n updateBoundingSphereRadius() {\n this.boundingSphereRadius = this.radius;\n }\n\n calculateWorldAABB(pos, quat, min, max) {\n const r = this.radius;\n const axes = ['x', 'y', 'z'];\n\n for (let i = 0; i < axes.length; i++) {\n const ax = axes[i];\n min[ax] = pos[ax] - r;\n max[ax] = pos[ax] + r;\n }\n }\n\n}\n\n/**\n * Simple vehicle helper class with spherical rigid body wheels.\n */\nclass RigidVehicle {\n /**\n * The bodies of the wheels.\n */\n\n /**\n * The chassis body.\n */\n\n /**\n * The constraints.\n */\n\n /**\n * The wheel axes.\n */\n\n /**\n * The wheel forces.\n */\n constructor(options) {\n if (options === void 0) {\n options = {};\n }\n\n this.wheelBodies = [];\n this.coordinateSystem = typeof options.coordinateSystem !== 'undefined' ? options.coordinateSystem.clone() : new Vec3(1, 2, 3);\n\n if (options.chassisBody) {\n this.chassisBody = options.chassisBody;\n } else {\n // No chassis body given. Create it!\n this.chassisBody = new Body({\n mass: 1,\n shape: new Box(new Vec3(5, 0.5, 2))\n });\n }\n\n this.constraints = [];\n this.wheelAxes = [];\n this.wheelForces = [];\n }\n /**\n * Add a wheel\n */\n\n\n addWheel(options) {\n if (options === void 0) {\n options = {};\n }\n\n let wheelBody;\n\n if (options.body) {\n wheelBody = options.body;\n } else {\n // No wheel body given. Create it!\n wheelBody = new Body({\n mass: 1,\n shape: new Sphere(1.2)\n });\n }\n\n this.wheelBodies.push(wheelBody);\n this.wheelForces.push(0); // Position constrain wheels\n\n const position = typeof options.position !== 'undefined' ? options.position.clone() : new Vec3(); // Set position locally to the chassis\n\n const worldPosition = new Vec3();\n this.chassisBody.pointToWorldFrame(position, worldPosition);\n wheelBody.position.set(worldPosition.x, worldPosition.y, worldPosition.z); // Constrain wheel\n\n const axis = typeof options.axis !== 'undefined' ? options.axis.clone() : new Vec3(0, 0, 1);\n this.wheelAxes.push(axis);\n const hingeConstraint = new HingeConstraint(this.chassisBody, wheelBody, {\n pivotA: position,\n axisA: axis,\n pivotB: Vec3.ZERO,\n axisB: axis,\n collideConnected: false\n });\n this.constraints.push(hingeConstraint);\n return this.wheelBodies.length - 1;\n }\n /**\n * Set the steering value of a wheel.\n * @todo check coordinateSystem\n */\n\n\n setSteeringValue(value, wheelIndex) {\n // Set angle of the hinge axis\n const axis = this.wheelAxes[wheelIndex];\n const c = Math.cos(value);\n const s = Math.sin(value);\n const x = axis.x;\n const z = axis.z;\n this.constraints[wheelIndex].axisA.set(-c * x + s * z, 0, s * x + c * z);\n }\n /**\n * Set the target rotational speed of the hinge constraint.\n */\n\n\n setMotorSpeed(value, wheelIndex) {\n const hingeConstraint = this.constraints[wheelIndex];\n hingeConstraint.enableMotor();\n hingeConstraint.motorTargetVelocity = value;\n }\n /**\n * Set the target rotational speed of the hinge constraint.\n */\n\n\n disableMotor(wheelIndex) {\n const hingeConstraint = this.constraints[wheelIndex];\n hingeConstraint.disableMotor();\n }\n /**\n * Set the wheel force to apply on one of the wheels each time step\n */\n\n\n setWheelForce(value, wheelIndex) {\n this.wheelForces[wheelIndex] = value;\n }\n /**\n * Apply a torque on one of the wheels.\n */\n\n\n applyWheelForce(value, wheelIndex) {\n const axis = this.wheelAxes[wheelIndex];\n const wheelBody = this.wheelBodies[wheelIndex];\n const bodyTorque = wheelBody.torque;\n axis.scale(value, torque);\n wheelBody.vectorToWorldFrame(torque, torque);\n bodyTorque.vadd(torque, bodyTorque);\n }\n /**\n * Add the vehicle including its constraints to the world.\n */\n\n\n addToWorld(world) {\n const constraints = this.constraints;\n const bodies = this.wheelBodies.concat([this.chassisBody]);\n\n for (let i = 0; i < bodies.length; i++) {\n world.addBody(bodies[i]);\n }\n\n for (let i = 0; i < constraints.length; i++) {\n world.addConstraint(constraints[i]);\n }\n\n world.addEventListener('preStep', this._update.bind(this));\n }\n\n _update() {\n const wheelForces = this.wheelForces;\n\n for (let i = 0; i < wheelForces.length; i++) {\n this.applyWheelForce(wheelForces[i], i);\n }\n }\n /**\n * Remove the vehicle including its constraints from the world.\n */\n\n\n removeFromWorld(world) {\n const constraints = this.constraints;\n const bodies = this.wheelBodies.concat([this.chassisBody]);\n\n for (let i = 0; i < bodies.length; i++) {\n world.removeBody(bodies[i]);\n }\n\n for (let i = 0; i < constraints.length; i++) {\n world.removeConstraint(constraints[i]);\n }\n }\n /**\n * Get current rotational velocity of a wheel\n */\n\n\n getWheelSpeed(wheelIndex) {\n const axis = this.wheelAxes[wheelIndex];\n const wheelBody = this.wheelBodies[wheelIndex];\n const w = wheelBody.angularVelocity;\n this.chassisBody.vectorToWorldFrame(axis, worldAxis);\n return w.dot(worldAxis);\n }\n\n}\nconst torque = new Vec3();\nconst worldAxis = new Vec3();\n\n/**\n * Smoothed-particle hydrodynamics system\n * @todo Make parameters customizable in the constructor\n */\nclass SPHSystem {\n /**\n * The particles array.\n */\n\n /**\n * Density of the system (kg/m3).\n * @default 1\n */\n\n /**\n * Distance below which two particles are considered to be neighbors.\n * It should be adjusted so there are about 15-20 neighbor particles within this radius.\n * @default 1\n */\n\n /**\n * @default 1\n */\n\n /**\n * Viscosity of the system.\n * @default 0.01\n */\n\n /**\n * @default 0.000001\n */\n constructor() {\n this.particles = [];\n this.density = 1;\n this.smoothingRadius = 1;\n this.speedOfSound = 1;\n this.viscosity = 0.01;\n this.eps = 0.000001; // Stuff Computed per particle\n\n this.pressures = [];\n this.densities = [];\n this.neighbors = [];\n }\n /**\n * Add a particle to the system.\n */\n\n\n add(particle) {\n this.particles.push(particle);\n\n if (this.neighbors.length < this.particles.length) {\n this.neighbors.push([]);\n }\n }\n /**\n * Remove a particle from the system.\n */\n\n\n remove(particle) {\n const idx = this.particles.indexOf(particle);\n\n if (idx !== -1) {\n this.particles.splice(idx, 1);\n\n if (this.neighbors.length > this.particles.length) {\n this.neighbors.pop();\n }\n }\n }\n /**\n * Get neighbors within smoothing volume, save in the array neighbors\n */\n\n\n getNeighbors(particle, neighbors) {\n const N = this.particles.length;\n const id = particle.id;\n const R2 = this.smoothingRadius * this.smoothingRadius;\n const dist = SPHSystem_getNeighbors_dist;\n\n for (let i = 0; i !== N; i++) {\n const p = this.particles[i];\n p.position.vsub(particle.position, dist);\n\n if (id !== p.id && dist.lengthSquared() < R2) {\n neighbors.push(p);\n }\n }\n }\n\n update() {\n const N = this.particles.length;\n const dist = SPHSystem_update_dist;\n const cs = this.speedOfSound;\n const eps = this.eps;\n\n for (let i = 0; i !== N; i++) {\n const p = this.particles[i]; // Current particle\n\n const neighbors = this.neighbors[i]; // Get neighbors\n\n neighbors.length = 0;\n this.getNeighbors(p, neighbors);\n neighbors.push(this.particles[i]); // Add current too\n\n const numNeighbors = neighbors.length; // Accumulate density for the particle\n\n let sum = 0.0;\n\n for (let j = 0; j !== numNeighbors; j++) {\n //printf(\"Current particle has position %f %f %f\\n\",objects[id].pos.x(),objects[id].pos.y(),objects[id].pos.z());\n p.position.vsub(neighbors[j].position, dist);\n const len = dist.length();\n const weight = this.w(len);\n sum += neighbors[j].mass * weight;\n } // Save\n\n\n this.densities[i] = sum;\n this.pressures[i] = cs * cs * (this.densities[i] - this.density);\n } // Add forces\n // Sum to these accelerations\n\n\n const a_pressure = SPHSystem_update_a_pressure;\n const a_visc = SPHSystem_update_a_visc;\n const gradW = SPHSystem_update_gradW;\n const r_vec = SPHSystem_update_r_vec;\n const u = SPHSystem_update_u;\n\n for (let i = 0; i !== N; i++) {\n const particle = this.particles[i];\n a_pressure.set(0, 0, 0);\n a_visc.set(0, 0, 0); // Init vars\n\n let Pij;\n let nabla;\n\n const neighbors = this.neighbors[i];\n const numNeighbors = neighbors.length; //printf(\"Neighbors: \");\n\n for (let j = 0; j !== numNeighbors; j++) {\n const neighbor = neighbors[j]; //printf(\"%d \",nj);\n // Get r once for all..\n\n particle.position.vsub(neighbor.position, r_vec);\n const r = r_vec.length(); // Pressure contribution\n\n Pij = -neighbor.mass * (this.pressures[i] / (this.densities[i] * this.densities[i] + eps) + this.pressures[j] / (this.densities[j] * this.densities[j] + eps));\n this.gradw(r_vec, gradW); // Add to pressure acceleration\n\n gradW.scale(Pij, gradW);\n a_pressure.vadd(gradW, a_pressure); // Viscosity contribution\n\n neighbor.velocity.vsub(particle.velocity, u);\n u.scale(1.0 / (0.0001 + this.densities[i] * this.densities[j]) * this.viscosity * neighbor.mass, u);\n nabla = this.nablaw(r);\n u.scale(nabla, u); // Add to viscosity acceleration\n\n a_visc.vadd(u, a_visc);\n } // Calculate force\n\n\n a_visc.scale(particle.mass, a_visc);\n a_pressure.scale(particle.mass, a_pressure); // Add force to particles\n\n particle.force.vadd(a_visc, particle.force);\n particle.force.vadd(a_pressure, particle.force);\n }\n } // Calculate the weight using the W(r) weightfunction\n\n\n w(r) {\n // 315\n const h = this.smoothingRadius;\n return 315.0 / (64.0 * Math.PI * h ** 9) * (h * h - r * r) ** 3;\n } // calculate gradient of the weight function\n\n\n gradw(rVec, resultVec) {\n const r = rVec.length();\n const h = this.smoothingRadius;\n rVec.scale(945.0 / (32.0 * Math.PI * h ** 9) * (h * h - r * r) ** 2, resultVec);\n } // Calculate nabla(W)\n\n\n nablaw(r) {\n const h = this.smoothingRadius;\n const nabla = 945.0 / (32.0 * Math.PI * h ** 9) * (h * h - r * r) * (7 * r * r - 3 * h * h);\n return nabla;\n }\n\n}\nconst SPHSystem_getNeighbors_dist = new Vec3(); // Temp vectors for calculation\n\nconst SPHSystem_update_dist = new Vec3(); // Relative velocity\n\nconst SPHSystem_update_a_pressure = new Vec3();\nconst SPHSystem_update_a_visc = new Vec3();\nconst SPHSystem_update_gradW = new Vec3();\nconst SPHSystem_update_r_vec = new Vec3();\nconst SPHSystem_update_u = new Vec3();\n\n/**\n * Cylinder class.\n * @example\n * const radiusTop = 0.5\n * const radiusBottom = 0.5\n * const height = 2\n * const numSegments = 12\n * const cylinderShape = new CANNON.Cylinder(radiusTop, radiusBottom, height, numSegments)\n * const cylinderBody = new CANNON.Body({ mass: 1, shape: cylinderShape })\n * world.addBody(cylinderBody)\n */\n\nclass Cylinder extends ConvexPolyhedron {\n /** The radius of the top of the Cylinder. */\n\n /** The radius of the bottom of the Cylinder. */\n\n /** The height of the Cylinder. */\n\n /** The number of segments to build the cylinder out of. */\n\n /**\n * @param radiusTop The radius of the top of the Cylinder.\n * @param radiusBottom The radius of the bottom of the Cylinder.\n * @param height The height of the Cylinder.\n * @param numSegments The number of segments to build the cylinder out of.\n */\n constructor(radiusTop, radiusBottom, height, numSegments) {\n if (radiusTop === void 0) {\n radiusTop = 1;\n }\n\n if (radiusBottom === void 0) {\n radiusBottom = 1;\n }\n\n if (height === void 0) {\n height = 1;\n }\n\n if (numSegments === void 0) {\n numSegments = 8;\n }\n\n if (radiusTop < 0) {\n throw new Error('The cylinder radiusTop cannot be negative.');\n }\n\n if (radiusBottom < 0) {\n throw new Error('The cylinder radiusBottom cannot be negative.');\n }\n\n const N = numSegments;\n const vertices = [];\n const axes = [];\n const faces = [];\n const bottomface = [];\n const topface = [];\n const cos = Math.cos;\n const sin = Math.sin; // First bottom point\n\n vertices.push(new Vec3(-radiusBottom * sin(0), -height * 0.5, radiusBottom * cos(0)));\n bottomface.push(0); // First top point\n\n vertices.push(new Vec3(-radiusTop * sin(0), height * 0.5, radiusTop * cos(0)));\n topface.push(1);\n\n for (let i = 0; i < N; i++) {\n const theta = 2 * Math.PI / N * (i + 1);\n const thetaN = 2 * Math.PI / N * (i + 0.5);\n\n if (i < N - 1) {\n // Bottom\n vertices.push(new Vec3(-radiusBottom * sin(theta), -height * 0.5, radiusBottom * cos(theta)));\n bottomface.push(2 * i + 2); // Top\n\n vertices.push(new Vec3(-radiusTop * sin(theta), height * 0.5, radiusTop * cos(theta)));\n topface.push(2 * i + 3); // Face\n\n faces.push([2 * i, 2 * i + 1, 2 * i + 3, 2 * i + 2]);\n } else {\n faces.push([2 * i, 2 * i + 1, 1, 0]); // Connect\n } // Axis: we can cut off half of them if we have even number of segments\n\n\n if (N % 2 === 1 || i < N / 2) {\n axes.push(new Vec3(-sin(thetaN), 0, cos(thetaN)));\n }\n }\n\n faces.push(bottomface);\n axes.push(new Vec3(0, 1, 0)); // Reorder top face\n\n const temp = [];\n\n for (let i = 0; i < topface.length; i++) {\n temp.push(topface[topface.length - i - 1]);\n }\n\n faces.push(temp);\n super({\n vertices,\n faces,\n axes\n });\n this.type = Shape.types.CYLINDER;\n this.radiusTop = radiusTop;\n this.radiusBottom = radiusBottom;\n this.height = height;\n this.numSegments = numSegments;\n }\n\n}\n\n/**\n * Particle shape.\n * @example\n * const particleShape = new CANNON.Particle()\n * const particleBody = new CANNON.Body({ mass: 1, shape: particleShape })\n * world.addBody(particleBody)\n */\nclass Particle extends Shape {\n constructor() {\n super({\n type: Shape.types.PARTICLE\n });\n }\n /**\n * calculateLocalInertia\n */\n\n\n calculateLocalInertia(mass, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n target.set(0, 0, 0);\n return target;\n }\n\n volume() {\n return 0;\n }\n\n updateBoundingSphereRadius() {\n this.boundingSphereRadius = 0;\n }\n\n calculateWorldAABB(pos, quat, min, max) {\n // Get each axis max\n min.copy(pos);\n max.copy(pos);\n }\n\n}\n\n/**\n * A plane, facing in the Z direction. The plane has its surface at z=0 and everything below z=0 is assumed to be solid plane. To make the plane face in some other direction than z, you must put it inside a Body and rotate that body. See the demos.\n * @example\n * const planeShape = new CANNON.Plane()\n * const planeBody = new CANNON.Body({ mass: 0, shape: planeShape })\n * planeBody.quaternion.setFromEuler(-Math.PI / 2, 0, 0) // make it face up\n * world.addBody(planeBody)\n */\nclass Plane extends Shape {\n /** worldNormal */\n\n /** worldNormalNeedsUpdate */\n constructor() {\n super({\n type: Shape.types.PLANE\n }); // World oriented normal\n\n this.worldNormal = new Vec3();\n this.worldNormalNeedsUpdate = true;\n this.boundingSphereRadius = Number.MAX_VALUE;\n }\n /** computeWorldNormal */\n\n\n computeWorldNormal(quat) {\n const n = this.worldNormal;\n n.set(0, 0, 1);\n quat.vmult(n, n);\n this.worldNormalNeedsUpdate = false;\n }\n\n calculateLocalInertia(mass, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n return target;\n }\n\n volume() {\n return (// The plane is infinite...\n Number.MAX_VALUE\n );\n }\n\n calculateWorldAABB(pos, quat, min, max) {\n // The plane AABB is infinite, except if the normal is pointing along any axis\n tempNormal.set(0, 0, 1); // Default plane normal is z\n\n quat.vmult(tempNormal, tempNormal);\n const maxVal = Number.MAX_VALUE;\n min.set(-maxVal, -maxVal, -maxVal);\n max.set(maxVal, maxVal, maxVal);\n\n if (tempNormal.x === 1) {\n max.x = pos.x;\n } else if (tempNormal.x === -1) {\n min.x = pos.x;\n }\n\n if (tempNormal.y === 1) {\n max.y = pos.y;\n } else if (tempNormal.y === -1) {\n min.y = pos.y;\n }\n\n if (tempNormal.z === 1) {\n max.z = pos.z;\n } else if (tempNormal.z === -1) {\n min.z = pos.z;\n }\n }\n\n updateBoundingSphereRadius() {\n this.boundingSphereRadius = Number.MAX_VALUE;\n }\n\n}\nconst tempNormal = new Vec3();\n\n/**\n * Heightfield shape class. Height data is given as an array. These data points are spread out evenly with a given distance.\n * @todo Should be possible to use along all axes, not just y\n * @todo should be possible to scale along all axes\n * @todo Refactor elementSize to elementSizeX and elementSizeY\n *\n * @example\n * // Generate some height data (y-values).\n * const data = []\n * for (let i = 0; i < 1000; i++) {\n * const y = 0.5 * Math.cos(0.2 * i)\n * data.push(y)\n * }\n *\n * // Create the heightfield shape\n * const heightfieldShape = new CANNON.Heightfield(data, {\n * elementSize: 1 // Distance between the data points in X and Y directions\n * })\n * const heightfieldBody = new CANNON.Body({ shape: heightfieldShape })\n * world.addBody(heightfieldBody)\n */\nclass Heightfield extends Shape {\n /**\n * An array of numbers, or height values, that are spread out along the x axis.\n */\n\n /**\n * Max value of the data points in the data array.\n */\n\n /**\n * Minimum value of the data points in the data array.\n */\n\n /**\n * World spacing between the data points in X and Y direction.\n * @todo elementSizeX and Y\n * @default 1\n */\n\n /**\n * @default true\n */\n\n /**\n * @param data An array of numbers, or height values, that are spread out along the x axis.\n */\n constructor(data, options) {\n if (options === void 0) {\n options = {};\n }\n\n options = Utils.defaults(options, {\n maxValue: null,\n minValue: null,\n elementSize: 1\n });\n super({\n type: Shape.types.HEIGHTFIELD\n });\n this.data = data;\n this.maxValue = options.maxValue;\n this.minValue = options.minValue;\n this.elementSize = options.elementSize;\n\n if (options.minValue === null) {\n this.updateMinValue();\n }\n\n if (options.maxValue === null) {\n this.updateMaxValue();\n }\n\n this.cacheEnabled = true;\n this.pillarConvex = new ConvexPolyhedron();\n this.pillarOffset = new Vec3();\n this.updateBoundingSphereRadius(); // \"i_j_isUpper\" => { convex: ..., offset: ... }\n // for example:\n // _cachedPillars[\"0_2_1\"]\n\n this._cachedPillars = {};\n }\n /**\n * Call whenever you change the data array.\n */\n\n\n update() {\n this._cachedPillars = {};\n }\n /**\n * Update the `minValue` property\n */\n\n\n updateMinValue() {\n const data = this.data;\n let minValue = data[0][0];\n\n for (let i = 0; i !== data.length; i++) {\n for (let j = 0; j !== data[i].length; j++) {\n const v = data[i][j];\n\n if (v < minValue) {\n minValue = v;\n }\n }\n }\n\n this.minValue = minValue;\n }\n /**\n * Update the `maxValue` property\n */\n\n\n updateMaxValue() {\n const data = this.data;\n let maxValue = data[0][0];\n\n for (let i = 0; i !== data.length; i++) {\n for (let j = 0; j !== data[i].length; j++) {\n const v = data[i][j];\n\n if (v > maxValue) {\n maxValue = v;\n }\n }\n }\n\n this.maxValue = maxValue;\n }\n /**\n * Set the height value at an index. Don't forget to update maxValue and minValue after you're done.\n */\n\n\n setHeightValueAtIndex(xi, yi, value) {\n const data = this.data;\n data[xi][yi] = value; // Invalidate cache\n\n this.clearCachedConvexTrianglePillar(xi, yi, false);\n\n if (xi > 0) {\n this.clearCachedConvexTrianglePillar(xi - 1, yi, true);\n this.clearCachedConvexTrianglePillar(xi - 1, yi, false);\n }\n\n if (yi > 0) {\n this.clearCachedConvexTrianglePillar(xi, yi - 1, true);\n this.clearCachedConvexTrianglePillar(xi, yi - 1, false);\n }\n\n if (yi > 0 && xi > 0) {\n this.clearCachedConvexTrianglePillar(xi - 1, yi - 1, true);\n }\n }\n /**\n * Get max/min in a rectangle in the matrix data\n * @param result An array to store the results in.\n * @return The result array, if it was passed in. Minimum will be at position 0 and max at 1.\n */\n\n\n getRectMinMax(iMinX, iMinY, iMaxX, iMaxY, result) {\n if (result === void 0) {\n result = [];\n }\n\n // Get max and min of the data\n const data = this.data; // Set first value\n\n let max = this.minValue;\n\n for (let i = iMinX; i <= iMaxX; i++) {\n for (let j = iMinY; j <= iMaxY; j++) {\n const height = data[i][j];\n\n if (height > max) {\n max = height;\n }\n }\n }\n\n result[0] = this.minValue;\n result[1] = max;\n }\n /**\n * Get the index of a local position on the heightfield. The indexes indicate the rectangles, so if your terrain is made of N x N height data points, you will have rectangle indexes ranging from 0 to N-1.\n * @param result Two-element array\n * @param clamp If the position should be clamped to the heightfield edge.\n */\n\n\n getIndexOfPosition(x, y, result, clamp) {\n // Get the index of the data points to test against\n const w = this.elementSize;\n const data = this.data;\n let xi = Math.floor(x / w);\n let yi = Math.floor(y / w);\n result[0] = xi;\n result[1] = yi;\n\n if (clamp) {\n // Clamp index to edges\n if (xi < 0) {\n xi = 0;\n }\n\n if (yi < 0) {\n yi = 0;\n }\n\n if (xi >= data.length - 1) {\n xi = data.length - 1;\n }\n\n if (yi >= data[0].length - 1) {\n yi = data[0].length - 1;\n }\n } // Bail out if we are out of the terrain\n\n\n if (xi < 0 || yi < 0 || xi >= data.length - 1 || yi >= data[0].length - 1) {\n return false;\n }\n\n return true;\n }\n\n getTriangleAt(x, y, edgeClamp, a, b, c) {\n const idx = getHeightAt_idx;\n this.getIndexOfPosition(x, y, idx, edgeClamp);\n let xi = idx[0];\n let yi = idx[1];\n const data = this.data;\n\n if (edgeClamp) {\n xi = Math.min(data.length - 2, Math.max(0, xi));\n yi = Math.min(data[0].length - 2, Math.max(0, yi));\n }\n\n const elementSize = this.elementSize;\n const lowerDist2 = (x / elementSize - xi) ** 2 + (y / elementSize - yi) ** 2;\n const upperDist2 = (x / elementSize - (xi + 1)) ** 2 + (y / elementSize - (yi + 1)) ** 2;\n const upper = lowerDist2 > upperDist2;\n this.getTriangle(xi, yi, upper, a, b, c);\n return upper;\n }\n\n getNormalAt(x, y, edgeClamp, result) {\n const a = getNormalAt_a;\n const b = getNormalAt_b;\n const c = getNormalAt_c;\n const e0 = getNormalAt_e0;\n const e1 = getNormalAt_e1;\n this.getTriangleAt(x, y, edgeClamp, a, b, c);\n b.vsub(a, e0);\n c.vsub(a, e1);\n e0.cross(e1, result);\n result.normalize();\n }\n /**\n * Get an AABB of a square in the heightfield\n * @param xi\n * @param yi\n * @param result\n */\n\n\n getAabbAtIndex(xi, yi, _ref) {\n let {\n lowerBound,\n upperBound\n } = _ref;\n const data = this.data;\n const elementSize = this.elementSize;\n lowerBound.set(xi * elementSize, yi * elementSize, data[xi][yi]);\n upperBound.set((xi + 1) * elementSize, (yi + 1) * elementSize, data[xi + 1][yi + 1]);\n }\n /**\n * Get the height in the heightfield at a given position\n */\n\n\n getHeightAt(x, y, edgeClamp) {\n const data = this.data;\n const a = getHeightAt_a;\n const b = getHeightAt_b;\n const c = getHeightAt_c;\n const idx = getHeightAt_idx;\n this.getIndexOfPosition(x, y, idx, edgeClamp);\n let xi = idx[0];\n let yi = idx[1];\n\n if (edgeClamp) {\n xi = Math.min(data.length - 2, Math.max(0, xi));\n yi = Math.min(data[0].length - 2, Math.max(0, yi));\n }\n\n const upper = this.getTriangleAt(x, y, edgeClamp, a, b, c);\n barycentricWeights(x, y, a.x, a.y, b.x, b.y, c.x, c.y, getHeightAt_weights);\n const w = getHeightAt_weights;\n\n if (upper) {\n // Top triangle verts\n return data[xi + 1][yi + 1] * w.x + data[xi][yi + 1] * w.y + data[xi + 1][yi] * w.z;\n } else {\n // Top triangle verts\n return data[xi][yi] * w.x + data[xi + 1][yi] * w.y + data[xi][yi + 1] * w.z;\n }\n }\n\n getCacheConvexTrianglePillarKey(xi, yi, getUpperTriangle) {\n return `${xi}_${yi}_${getUpperTriangle ? 1 : 0}`;\n }\n\n getCachedConvexTrianglePillar(xi, yi, getUpperTriangle) {\n return this._cachedPillars[this.getCacheConvexTrianglePillarKey(xi, yi, getUpperTriangle)];\n }\n\n setCachedConvexTrianglePillar(xi, yi, getUpperTriangle, convex, offset) {\n this._cachedPillars[this.getCacheConvexTrianglePillarKey(xi, yi, getUpperTriangle)] = {\n convex,\n offset\n };\n }\n\n clearCachedConvexTrianglePillar(xi, yi, getUpperTriangle) {\n delete this._cachedPillars[this.getCacheConvexTrianglePillarKey(xi, yi, getUpperTriangle)];\n }\n /**\n * Get a triangle from the heightfield\n */\n\n\n getTriangle(xi, yi, upper, a, b, c) {\n const data = this.data;\n const elementSize = this.elementSize;\n\n if (upper) {\n // Top triangle verts\n a.set((xi + 1) * elementSize, (yi + 1) * elementSize, data[xi + 1][yi + 1]);\n b.set(xi * elementSize, (yi + 1) * elementSize, data[xi][yi + 1]);\n c.set((xi + 1) * elementSize, yi * elementSize, data[xi + 1][yi]);\n } else {\n // Top triangle verts\n a.set(xi * elementSize, yi * elementSize, data[xi][yi]);\n b.set((xi + 1) * elementSize, yi * elementSize, data[xi + 1][yi]);\n c.set(xi * elementSize, (yi + 1) * elementSize, data[xi][yi + 1]);\n }\n }\n /**\n * Get a triangle in the terrain in the form of a triangular convex shape.\n */\n\n\n getConvexTrianglePillar(xi, yi, getUpperTriangle) {\n let result = this.pillarConvex;\n let offsetResult = this.pillarOffset;\n\n if (this.cacheEnabled) {\n const data = this.getCachedConvexTrianglePillar(xi, yi, getUpperTriangle);\n\n if (data) {\n this.pillarConvex = data.convex;\n this.pillarOffset = data.offset;\n return;\n }\n\n result = new ConvexPolyhedron();\n offsetResult = new Vec3();\n this.pillarConvex = result;\n this.pillarOffset = offsetResult;\n }\n\n const data = this.data;\n const elementSize = this.elementSize;\n const faces = result.faces; // Reuse verts if possible\n\n result.vertices.length = 6;\n\n for (let i = 0; i < 6; i++) {\n if (!result.vertices[i]) {\n result.vertices[i] = new Vec3();\n }\n } // Reuse faces if possible\n\n\n faces.length = 5;\n\n for (let i = 0; i < 5; i++) {\n if (!faces[i]) {\n faces[i] = [];\n }\n }\n\n const verts = result.vertices;\n const h = (Math.min(data[xi][yi], data[xi + 1][yi], data[xi][yi + 1], data[xi + 1][yi + 1]) - this.minValue) / 2 + this.minValue;\n\n if (!getUpperTriangle) {\n // Center of the triangle pillar - all polygons are given relative to this one\n offsetResult.set((xi + 0.25) * elementSize, // sort of center of a triangle\n (yi + 0.25) * elementSize, h // vertical center\n ); // Top triangle verts\n\n verts[0].set(-0.25 * elementSize, -0.25 * elementSize, data[xi][yi] - h);\n verts[1].set(0.75 * elementSize, -0.25 * elementSize, data[xi + 1][yi] - h);\n verts[2].set(-0.25 * elementSize, 0.75 * elementSize, data[xi][yi + 1] - h); // bottom triangle verts\n\n verts[3].set(-0.25 * elementSize, -0.25 * elementSize, -Math.abs(h) - 1);\n verts[4].set(0.75 * elementSize, -0.25 * elementSize, -Math.abs(h) - 1);\n verts[5].set(-0.25 * elementSize, 0.75 * elementSize, -Math.abs(h) - 1); // top triangle\n\n faces[0][0] = 0;\n faces[0][1] = 1;\n faces[0][2] = 2; // bottom triangle\n\n faces[1][0] = 5;\n faces[1][1] = 4;\n faces[1][2] = 3; // -x facing quad\n\n faces[2][0] = 0;\n faces[2][1] = 2;\n faces[2][2] = 5;\n faces[2][3] = 3; // -y facing quad\n\n faces[3][0] = 1;\n faces[3][1] = 0;\n faces[3][2] = 3;\n faces[3][3] = 4; // +xy facing quad\n\n faces[4][0] = 4;\n faces[4][1] = 5;\n faces[4][2] = 2;\n faces[4][3] = 1;\n } else {\n // Center of the triangle pillar - all polygons are given relative to this one\n offsetResult.set((xi + 0.75) * elementSize, // sort of center of a triangle\n (yi + 0.75) * elementSize, h // vertical center\n ); // Top triangle verts\n\n verts[0].set(0.25 * elementSize, 0.25 * elementSize, data[xi + 1][yi + 1] - h);\n verts[1].set(-0.75 * elementSize, 0.25 * elementSize, data[xi][yi + 1] - h);\n verts[2].set(0.25 * elementSize, -0.75 * elementSize, data[xi + 1][yi] - h); // bottom triangle verts\n\n verts[3].set(0.25 * elementSize, 0.25 * elementSize, -Math.abs(h) - 1);\n verts[4].set(-0.75 * elementSize, 0.25 * elementSize, -Math.abs(h) - 1);\n verts[5].set(0.25 * elementSize, -0.75 * elementSize, -Math.abs(h) - 1); // Top triangle\n\n faces[0][0] = 0;\n faces[0][1] = 1;\n faces[0][2] = 2; // bottom triangle\n\n faces[1][0] = 5;\n faces[1][1] = 4;\n faces[1][2] = 3; // +x facing quad\n\n faces[2][0] = 2;\n faces[2][1] = 5;\n faces[2][2] = 3;\n faces[2][3] = 0; // +y facing quad\n\n faces[3][0] = 3;\n faces[3][1] = 4;\n faces[3][2] = 1;\n faces[3][3] = 0; // -xy facing quad\n\n faces[4][0] = 1;\n faces[4][1] = 4;\n faces[4][2] = 5;\n faces[4][3] = 2;\n }\n\n result.computeNormals();\n result.computeEdges();\n result.updateBoundingSphereRadius();\n this.setCachedConvexTrianglePillar(xi, yi, getUpperTriangle, result, offsetResult);\n }\n\n calculateLocalInertia(mass, target) {\n if (target === void 0) {\n target = new Vec3();\n }\n\n target.set(0, 0, 0);\n return target;\n }\n\n volume() {\n return (// The terrain is infinite\n Number.MAX_VALUE\n );\n }\n\n calculateWorldAABB(pos, quat, min, max) {\n /** @TODO do it properly */\n min.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);\n max.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);\n }\n\n updateBoundingSphereRadius() {\n // Use the bounding box of the min/max values\n const data = this.data;\n const s = this.elementSize;\n this.boundingSphereRadius = new Vec3(data.length * s, data[0].length * s, Math.max(Math.abs(this.maxValue), Math.abs(this.minValue))).length();\n }\n /**\n * Sets the height values from an image. Currently only supported in browser.\n */\n\n\n setHeightsFromImage(image, scale) {\n const {\n x,\n z,\n y\n } = scale;\n const canvas = document.createElement('canvas');\n canvas.width = image.width;\n canvas.height = image.height;\n const context = canvas.getContext('2d');\n context.drawImage(image, 0, 0);\n const imageData = context.getImageData(0, 0, image.width, image.height);\n const matrix = this.data;\n matrix.length = 0;\n this.elementSize = Math.abs(x) / imageData.width;\n\n for (let i = 0; i < imageData.height; i++) {\n const row = [];\n\n for (let j = 0; j < imageData.width; j++) {\n const a = imageData.data[(i * imageData.height + j) * 4];\n const b = imageData.data[(i * imageData.height + j) * 4 + 1];\n const c = imageData.data[(i * imageData.height + j) * 4 + 2];\n const height = (a + b + c) / 4 / 255 * z;\n\n if (x < 0) {\n row.push(height);\n } else {\n row.unshift(height);\n }\n }\n\n if (y < 0) {\n matrix.unshift(row);\n } else {\n matrix.push(row);\n }\n }\n\n this.updateMaxValue();\n this.updateMinValue();\n this.update();\n }\n\n}\nconst getHeightAt_idx = [];\nconst getHeightAt_weights = new Vec3();\nconst getHeightAt_a = new Vec3();\nconst getHeightAt_b = new Vec3();\nconst getHeightAt_c = new Vec3();\nconst getNormalAt_a = new Vec3();\nconst getNormalAt_b = new Vec3();\nconst getNormalAt_c = new Vec3();\nconst getNormalAt_e0 = new Vec3();\nconst getNormalAt_e1 = new Vec3(); // from https://en.wikipedia.org/wiki/Barycentric_coordinate_system\n\nfunction barycentricWeights(x, y, ax, ay, bx, by, cx, cy, result) {\n result.x = ((by - cy) * (x - cx) + (cx - bx) * (y - cy)) / ((by - cy) * (ax - cx) + (cx - bx) * (ay - cy));\n result.y = ((cy - ay) * (x - cx) + (ax - cx) * (y - cy)) / ((by - cy) * (ax - cx) + (cx - bx) * (ay - cy));\n result.z = 1 - result.x - result.y;\n}\n\n/**\n * OctreeNode\n */\nclass OctreeNode {\n /** The root node */\n\n /** Boundary of this node */\n\n /** Contained data at the current node level */\n\n /** Children to this node */\n constructor(options) {\n if (options === void 0) {\n options = {};\n }\n\n this.root = options.root || null;\n this.aabb = options.aabb ? options.aabb.clone() : new AABB();\n this.data = [];\n this.children = [];\n }\n /**\n * reset\n */\n\n\n reset() {\n this.children.length = this.data.length = 0;\n }\n /**\n * Insert data into this node\n * @return True if successful, otherwise false\n */\n\n\n insert(aabb, elementData, level) {\n if (level === void 0) {\n level = 0;\n }\n\n const nodeData = this.data; // Ignore objects that do not belong in this node\n\n if (!this.aabb.contains(aabb)) {\n return false; // object cannot be added\n }\n\n const children = this.children;\n const maxDepth = this.maxDepth || this.root.maxDepth;\n\n if (level < maxDepth) {\n // Subdivide if there are no children yet\n let subdivided = false;\n\n if (!children.length) {\n this.subdivide();\n subdivided = true;\n } // add to whichever node will accept it\n\n\n for (let i = 0; i !== 8; i++) {\n if (children[i].insert(aabb, elementData, level + 1)) {\n return true;\n }\n }\n\n if (subdivided) {\n // No children accepted! Might as well just remove em since they contain none\n children.length = 0;\n }\n } // Too deep, or children didnt want it. add it in current node\n\n\n nodeData.push(elementData);\n return true;\n }\n /**\n * Create 8 equally sized children nodes and put them in the `children` array.\n */\n\n\n subdivide() {\n const aabb = this.aabb;\n const l = aabb.lowerBound;\n const u = aabb.upperBound;\n const children = this.children;\n children.push(new OctreeNode({\n aabb: new AABB({\n lowerBound: new Vec3(0, 0, 0)\n })\n }), new OctreeNode({\n aabb: new AABB({\n lowerBound: new Vec3(1, 0, 0)\n })\n }), new OctreeNode({\n aabb: new AABB({\n lowerBound: new Vec3(1, 1, 0)\n })\n }), new OctreeNode({\n aabb: new AABB({\n lowerBound: new Vec3(1, 1, 1)\n })\n }), new OctreeNode({\n aabb: new AABB({\n lowerBound: new Vec3(0, 1, 1)\n })\n }), new OctreeNode({\n aabb: new AABB({\n lowerBound: new Vec3(0, 0, 1)\n })\n }), new OctreeNode({\n aabb: new AABB({\n lowerBound: new Vec3(1, 0, 1)\n })\n }), new OctreeNode({\n aabb: new AABB({\n lowerBound: new Vec3(0, 1, 0)\n })\n }));\n u.vsub(l, halfDiagonal);\n halfDiagonal.scale(0.5, halfDiagonal);\n const root = this.root || this;\n\n for (let i = 0; i !== 8; i++) {\n const child = children[i]; // Set current node as root\n\n child.root = root; // Compute bounds\n\n const lowerBound = child.aabb.lowerBound;\n lowerBound.x *= halfDiagonal.x;\n lowerBound.y *= halfDiagonal.y;\n lowerBound.z *= halfDiagonal.z;\n lowerBound.vadd(l, lowerBound); // Upper bound is always lower bound + halfDiagonal\n\n lowerBound.vadd(halfDiagonal, child.aabb.upperBound);\n }\n }\n /**\n * Get all data, potentially within an AABB\n * @return The \"result\" object\n */\n\n\n aabbQuery(aabb, result) {\n this.data; // abort if the range does not intersect this node\n // if (!this.aabb.overlaps(aabb)){\n // return result;\n // }\n // Add objects at this level\n // Array.prototype.push.apply(result, nodeData);\n // Add child data\n // @todo unwrap recursion into a queue / loop, that's faster in JS\n\n this.children; // for (let i = 0, N = this.children.length; i !== N; i++) {\n // children[i].aabbQuery(aabb, result);\n // }\n\n const queue = [this];\n\n while (queue.length) {\n const node = queue.pop();\n\n if (node.aabb.overlaps(aabb)) {\n Array.prototype.push.apply(result, node.data);\n }\n\n Array.prototype.push.apply(queue, node.children);\n }\n\n return result;\n }\n /**\n * Get all data, potentially intersected by a ray.\n * @return The \"result\" object\n */\n\n\n rayQuery(ray, treeTransform, result) {\n // Use aabb query for now.\n\n /** @todo implement real ray query which needs less lookups */\n ray.getAABB(tmpAABB);\n tmpAABB.toLocalFrame(treeTransform, tmpAABB);\n this.aabbQuery(tmpAABB, result);\n return result;\n }\n /**\n * removeEmptyNodes\n */\n\n\n removeEmptyNodes() {\n for (let i = this.children.length - 1; i >= 0; i--) {\n this.children[i].removeEmptyNodes();\n\n if (!this.children[i].children.length && !this.children[i].data.length) {\n this.children.splice(i, 1);\n }\n }\n }\n\n}\n/**\n * Octree\n */\n\n\nclass Octree extends OctreeNode {\n /**\n * Maximum subdivision depth\n * @default 8\n */\n\n /**\n * @param aabb The total AABB of the tree\n */\n constructor(aabb, options) {\n if (options === void 0) {\n options = {};\n }\n\n super({\n root: null,\n aabb\n });\n this.maxDepth = typeof options.maxDepth !== 'undefined' ? options.maxDepth : 8;\n }\n\n}\nconst halfDiagonal = new Vec3();\nconst tmpAABB = new AABB();\n\n/**\n * Trimesh.\n * @example\n * // How to make a mesh with a single triangle\n * const vertices = [\n * 0, 0, 0, // vertex 0\n * 1, 0, 0, // vertex 1\n * 0, 1, 0 // vertex 2\n * ]\n * const indices = [\n * 0, 1, 2 // triangle 0\n * ]\n * const trimeshShape = new CANNON.Trimesh(vertices, indices)\n */\nclass Trimesh extends Shape {\n /**\n * vertices\n */\n\n /**\n * Array of integers, indicating which vertices each triangle consists of. The length of this array is thus 3 times the number of triangles.\n */\n\n /**\n * The normals data.\n */\n\n /**\n * The local AABB of the mesh.\n */\n\n /**\n * References to vertex pairs, making up all unique edges in the trimesh.\n */\n\n /**\n * Local scaling of the mesh. Use .setScale() to set it.\n */\n\n /**\n * The indexed triangles. Use .updateTree() to update it.\n */\n constructor(vertices, indices) {\n super({\n type: Shape.types.TRIMESH\n });\n this.vertices = new Float32Array(vertices);\n this.indices = new Int16Array(indices);\n this.normals = new Float32Array(indices.length);\n this.aabb = new AABB();\n this.edges = null;\n this.scale = new Vec3(1, 1, 1);\n this.tree = new Octree();\n this.updateEdges();\n this.updateNormals();\n this.updateAABB();\n this.updateBoundingSphereRadius();\n this.updateTree();\n }\n /**\n * updateTree\n */\n\n\n updateTree() {\n const tree = this.tree;\n tree.reset();\n tree.aabb.copy(this.aabb);\n const scale = this.scale; // The local mesh AABB is scaled, but the octree AABB should be unscaled\n\n tree.aabb.lowerBound.x *= 1 / scale.x;\n tree.aabb.lowerBound.y *= 1 / scale.y;\n tree.aabb.lowerBound.z *= 1 / scale.z;\n tree.aabb.upperBound.x *= 1 / scale.x;\n tree.aabb.upperBound.y *= 1 / scale.y;\n tree.aabb.upperBound.z *= 1 / scale.z; // Insert all triangles\n\n const triangleAABB = new AABB();\n const a = new Vec3();\n const b = new Vec3();\n const c = new Vec3();\n const points = [a, b, c];\n\n for (let i = 0; i < this.indices.length / 3; i++) {\n //this.getTriangleVertices(i, a, b, c);\n // Get unscaled triangle verts\n const i3 = i * 3;\n\n this._getUnscaledVertex(this.indices[i3], a);\n\n this._getUnscaledVertex(this.indices[i3 + 1], b);\n\n this._getUnscaledVertex(this.indices[i3 + 2], c);\n\n triangleAABB.setFromPoints(points);\n tree.insert(triangleAABB, i);\n }\n\n tree.removeEmptyNodes();\n }\n /**\n * Get triangles in a local AABB from the trimesh.\n * @param result An array of integers, referencing the queried triangles.\n */\n\n\n getTrianglesInAABB(aabb, result) {\n unscaledAABB.copy(aabb); // Scale it to local\n\n const scale = this.scale;\n const isx = scale.x;\n const isy = scale.y;\n const isz = scale.z;\n const l = unscaledAABB.lowerBound;\n const u = unscaledAABB.upperBound;\n l.x /= isx;\n l.y /= isy;\n l.z /= isz;\n u.x /= isx;\n u.y /= isy;\n u.z /= isz;\n return this.tree.aabbQuery(unscaledAABB, result);\n }\n /**\n * setScale\n */\n\n\n setScale(scale) {\n const wasUniform = this.scale.x === this.scale.y && this.scale.y === this.scale.z;\n const isUniform = scale.x === scale.y && scale.y === scale.z;\n\n if (!(wasUniform && isUniform)) {\n // Non-uniform scaling. Need to update normals.\n this.updateNormals();\n }\n\n this.scale.copy(scale);\n this.updateAABB();\n this.updateBoundingSphereRadius();\n }\n /**\n * Compute the normals of the faces. Will save in the `.normals` array.\n */\n\n\n updateNormals() {\n const n = computeNormals_n; // Generate normals\n\n const normals = this.normals;\n\n for (let i = 0; i < this.indices.length / 3; i++) {\n const i3 = i * 3;\n const a = this.indices[i3];\n const b = this.indices[i3 + 1];\n const c = this.indices[i3 + 2];\n this.getVertex(a, va);\n this.getVertex(b, vb);\n this.getVertex(c, vc);\n Trimesh.computeNormal(vb, va, vc, n);\n normals[i3] = n.x;\n normals[i3 + 1] = n.y;\n normals[i3 + 2] = n.z;\n }\n }\n /**\n * Update the `.edges` property\n */\n\n\n updateEdges() {\n const edges = {};\n\n const add = (a, b) => {\n const key = a < b ? `${a}_${b}` : `${b}_${a}`;\n edges[key] = true;\n };\n\n for (let i = 0; i < this.indices.length / 3; i++) {\n const i3 = i * 3;\n const a = this.indices[i3];\n const b = this.indices[i3 + 1];\n const c = this.indices[i3 + 2];\n add(a, b);\n add(b, c);\n add(c, a);\n }\n\n const keys = Object.keys(edges);\n this.edges = new Int16Array(keys.length * 2);\n\n for (let i = 0; i < keys.length; i++) {\n const indices = keys[i].split('_');\n this.edges[2 * i] = parseInt(indices[0], 10);\n this.edges[2 * i + 1] = parseInt(indices[1], 10);\n }\n }\n /**\n * Get an edge vertex\n * @param firstOrSecond 0 or 1, depending on which one of the vertices you need.\n * @param vertexStore Where to store the result\n */\n\n\n getEdgeVertex(edgeIndex, firstOrSecond, vertexStore) {\n const vertexIndex = this.edges[edgeIndex * 2 + (firstOrSecond ? 1 : 0)];\n this.getVertex(vertexIndex, vertexStore);\n }\n /**\n * Get a vector along an edge.\n */\n\n\n getEdgeVector(edgeIndex, vectorStore) {\n const va = getEdgeVector_va;\n const vb = getEdgeVector_vb;\n this.getEdgeVertex(edgeIndex, 0, va);\n this.getEdgeVertex(edgeIndex, 1, vb);\n vb.vsub(va, vectorStore);\n }\n /**\n * Get face normal given 3 vertices\n */\n\n\n static computeNormal(va, vb, vc, target) {\n vb.vsub(va, ab);\n vc.vsub(vb, cb);\n cb.cross(ab, target);\n\n if (!target.isZero()) {\n target.normalize();\n }\n }\n /**\n * Get vertex i.\n * @return The \"out\" vector object\n */\n\n\n getVertex(i, out) {\n const scale = this.scale;\n\n this._getUnscaledVertex(i, out);\n\n out.x *= scale.x;\n out.y *= scale.y;\n out.z *= scale.z;\n return out;\n }\n /**\n * Get raw vertex i\n * @return The \"out\" vector object\n */\n\n\n _getUnscaledVertex(i, out) {\n const i3 = i * 3;\n const vertices = this.vertices;\n return out.set(vertices[i3], vertices[i3 + 1], vertices[i3 + 2]);\n }\n /**\n * Get a vertex from the trimesh,transformed by the given position and quaternion.\n * @return The \"out\" vector object\n */\n\n\n getWorldVertex(i, pos, quat, out) {\n this.getVertex(i, out);\n Transform.pointToWorldFrame(pos, quat, out, out);\n return out;\n }\n /**\n * Get the three vertices for triangle i.\n */\n\n\n getTriangleVertices(i, a, b, c) {\n const i3 = i * 3;\n this.getVertex(this.indices[i3], a);\n this.getVertex(this.indices[i3 + 1], b);\n this.getVertex(this.indices[i3 + 2], c);\n }\n /**\n * Compute the normal of triangle i.\n * @return The \"target\" vector object\n */\n\n\n getNormal(i, target) {\n const i3 = i * 3;\n return target.set(this.normals[i3], this.normals[i3 + 1], this.normals[i3 + 2]);\n }\n /**\n * @return The \"target\" vector object\n */\n\n\n calculateLocalInertia(mass, target) {\n // Approximate with box inertia\n // Exact inertia calculation is overkill, but see http://geometrictools.com/Documentation/PolyhedralMassProperties.pdf for the correct way to do it\n this.computeLocalAABB(cli_aabb);\n const x = cli_aabb.upperBound.x - cli_aabb.lowerBound.x;\n const y = cli_aabb.upperBound.y - cli_aabb.lowerBound.y;\n const z = cli_aabb.upperBound.z - cli_aabb.lowerBound.z;\n return target.set(1.0 / 12.0 * mass * (2 * y * 2 * y + 2 * z * 2 * z), 1.0 / 12.0 * mass * (2 * x * 2 * x + 2 * z * 2 * z), 1.0 / 12.0 * mass * (2 * y * 2 * y + 2 * x * 2 * x));\n }\n /**\n * Compute the local AABB for the trimesh\n */\n\n\n computeLocalAABB(aabb) {\n const l = aabb.lowerBound;\n const u = aabb.upperBound;\n const n = this.vertices.length;\n this.vertices;\n const v = computeLocalAABB_worldVert;\n this.getVertex(0, v);\n l.copy(v);\n u.copy(v);\n\n for (let i = 0; i !== n; i++) {\n this.getVertex(i, v);\n\n if (v.x < l.x) {\n l.x = v.x;\n } else if (v.x > u.x) {\n u.x = v.x;\n }\n\n if (v.y < l.y) {\n l.y = v.y;\n } else if (v.y > u.y) {\n u.y = v.y;\n }\n\n if (v.z < l.z) {\n l.z = v.z;\n } else if (v.z > u.z) {\n u.z = v.z;\n }\n }\n }\n /**\n * Update the `.aabb` property\n */\n\n\n updateAABB() {\n this.computeLocalAABB(this.aabb);\n }\n /**\n * Will update the `.boundingSphereRadius` property\n */\n\n\n updateBoundingSphereRadius() {\n // Assume points are distributed with local (0,0,0) as center\n let max2 = 0;\n const vertices = this.vertices;\n const v = new Vec3();\n\n for (let i = 0, N = vertices.length / 3; i !== N; i++) {\n this.getVertex(i, v);\n const norm2 = v.lengthSquared();\n\n if (norm2 > max2) {\n max2 = norm2;\n }\n }\n\n this.boundingSphereRadius = Math.sqrt(max2);\n }\n /**\n * calculateWorldAABB\n */\n\n\n calculateWorldAABB(pos, quat, min, max) {\n /*\n const n = this.vertices.length / 3,\n verts = this.vertices;\n const minx,miny,minz,maxx,maxy,maxz;\n const v = tempWorldVertex;\n for(let i=0; i maxx || maxx===undefined){\n maxx = v.x;\n }\n if (v.y < miny || miny===undefined){\n miny = v.y;\n } else if(v.y > maxy || maxy===undefined){\n maxy = v.y;\n }\n if (v.z < minz || minz===undefined){\n minz = v.z;\n } else if(v.z > maxz || maxz===undefined){\n maxz = v.z;\n }\n }\n min.set(minx,miny,minz);\n max.set(maxx,maxy,maxz);\n */\n // Faster approximation using local AABB\n const frame = calculateWorldAABB_frame;\n const result = calculateWorldAABB_aabb;\n frame.position = pos;\n frame.quaternion = quat;\n this.aabb.toWorldFrame(frame, result);\n min.copy(result.lowerBound);\n max.copy(result.upperBound);\n }\n /**\n * Get approximate volume\n */\n\n\n volume() {\n return 4.0 * Math.PI * this.boundingSphereRadius / 3.0;\n }\n /**\n * Create a Trimesh instance, shaped as a torus.\n */\n\n\n static createTorus(radius, tube, radialSegments, tubularSegments, arc) {\n if (radius === void 0) {\n radius = 1;\n }\n\n if (tube === void 0) {\n tube = 0.5;\n }\n\n if (radialSegments === void 0) {\n radialSegments = 8;\n }\n\n if (tubularSegments === void 0) {\n tubularSegments = 6;\n }\n\n if (arc === void 0) {\n arc = Math.PI * 2;\n }\n\n const vertices = [];\n const indices = [];\n\n for (let j = 0; j <= radialSegments; j++) {\n for (let i = 0; i <= tubularSegments; i++) {\n const u = i / tubularSegments * arc;\n const v = j / radialSegments * Math.PI * 2;\n const x = (radius + tube * Math.cos(v)) * Math.cos(u);\n const y = (radius + tube * Math.cos(v)) * Math.sin(u);\n const z = tube * Math.sin(v);\n vertices.push(x, y, z);\n }\n }\n\n for (let j = 1; j <= radialSegments; j++) {\n for (let i = 1; i <= tubularSegments; i++) {\n const a = (tubularSegments + 1) * j + i - 1;\n const b = (tubularSegments + 1) * (j - 1) + i - 1;\n const c = (tubularSegments + 1) * (j - 1) + i;\n const d = (tubularSegments + 1) * j + i;\n indices.push(a, b, d);\n indices.push(b, c, d);\n }\n }\n\n return new Trimesh(vertices, indices);\n }\n\n}\nconst computeNormals_n = new Vec3();\nconst unscaledAABB = new AABB();\nconst getEdgeVector_va = new Vec3();\nconst getEdgeVector_vb = new Vec3();\nconst cb = new Vec3();\nconst ab = new Vec3();\nconst va = new Vec3();\nconst vb = new Vec3();\nconst vc = new Vec3();\nconst cli_aabb = new AABB();\nconst computeLocalAABB_worldVert = new Vec3();\nconst calculateWorldAABB_frame = new Transform();\nconst calculateWorldAABB_aabb = new AABB();\n\n/**\n * Constraint equation solver base class.\n */\nclass Solver {\n /**\n * All equations to be solved\n */\n\n /**\n * @todo remove useless constructor\n */\n constructor() {\n this.equations = [];\n }\n /**\n * Should be implemented in subclasses!\n * @todo use abstract\n * @return number of iterations performed\n */\n\n\n solve(dt, world) {\n return (// Should return the number of iterations done!\n 0\n );\n }\n /**\n * Add an equation\n */\n\n\n addEquation(eq) {\n if (eq.enabled && !eq.bi.isTrigger && !eq.bj.isTrigger) {\n this.equations.push(eq);\n }\n }\n /**\n * Remove an equation\n */\n\n\n removeEquation(eq) {\n const eqs = this.equations;\n const i = eqs.indexOf(eq);\n\n if (i !== -1) {\n eqs.splice(i, 1);\n }\n }\n /**\n * Add all equations\n */\n\n\n removeAllEquations() {\n this.equations.length = 0;\n }\n\n}\n\n/**\n * Constraint equation Gauss-Seidel solver.\n * @todo The spook parameters should be specified for each constraint, not globally.\n * @see https://www8.cs.umu.se/kurser/5DV058/VT09/lectures/spooknotes.pdf\n */\nclass GSSolver extends Solver {\n /**\n * The number of solver iterations determines quality of the constraints in the world.\n * The more iterations, the more correct simulation. More iterations need more computations though. If you have a large gravity force in your world, you will need more iterations.\n */\n\n /**\n * When tolerance is reached, the system is assumed to be converged.\n */\n\n /**\n * @todo remove useless constructor\n */\n constructor() {\n super();\n this.iterations = 10;\n this.tolerance = 1e-7;\n }\n /**\n * Solve\n * @return number of iterations performed\n */\n\n\n solve(dt, world) {\n let iter = 0;\n const maxIter = this.iterations;\n const tolSquared = this.tolerance * this.tolerance;\n const equations = this.equations;\n const Neq = equations.length;\n const bodies = world.bodies;\n const Nbodies = bodies.length;\n const h = dt;\n let B;\n let invC;\n let deltalambda;\n let deltalambdaTot;\n let GWlambda;\n let lambdaj; // Update solve mass\n\n if (Neq !== 0) {\n for (let i = 0; i !== Nbodies; i++) {\n bodies[i].updateSolveMassProperties();\n }\n } // Things that do not change during iteration can be computed once\n\n\n const invCs = GSSolver_solve_invCs;\n const Bs = GSSolver_solve_Bs;\n const lambda = GSSolver_solve_lambda;\n invCs.length = Neq;\n Bs.length = Neq;\n lambda.length = Neq;\n\n for (let i = 0; i !== Neq; i++) {\n const c = equations[i];\n lambda[i] = 0.0;\n Bs[i] = c.computeB(h);\n invCs[i] = 1.0 / c.computeC();\n }\n\n if (Neq !== 0) {\n // Reset vlambda\n for (let i = 0; i !== Nbodies; i++) {\n const b = bodies[i];\n const vlambda = b.vlambda;\n const wlambda = b.wlambda;\n vlambda.set(0, 0, 0);\n wlambda.set(0, 0, 0);\n } // Iterate over equations\n\n\n for (iter = 0; iter !== maxIter; iter++) {\n // Accumulate the total error for each iteration.\n deltalambdaTot = 0.0;\n\n for (let j = 0; j !== Neq; j++) {\n const c = equations[j]; // Compute iteration\n\n B = Bs[j];\n invC = invCs[j];\n lambdaj = lambda[j];\n GWlambda = c.computeGWlambda();\n deltalambda = invC * (B - GWlambda - c.eps * lambdaj); // Clamp if we are not within the min/max interval\n\n if (lambdaj + deltalambda < c.minForce) {\n deltalambda = c.minForce - lambdaj;\n } else if (lambdaj + deltalambda > c.maxForce) {\n deltalambda = c.maxForce - lambdaj;\n }\n\n lambda[j] += deltalambda;\n deltalambdaTot += deltalambda > 0.0 ? deltalambda : -deltalambda; // abs(deltalambda)\n\n c.addToWlambda(deltalambda);\n } // If the total error is small enough - stop iterate\n\n\n if (deltalambdaTot * deltalambdaTot < tolSquared) {\n break;\n }\n } // Add result to velocity\n\n\n for (let i = 0; i !== Nbodies; i++) {\n const b = bodies[i];\n const v = b.velocity;\n const w = b.angularVelocity;\n b.vlambda.vmul(b.linearFactor, b.vlambda);\n v.vadd(b.vlambda, v);\n b.wlambda.vmul(b.angularFactor, b.wlambda);\n w.vadd(b.wlambda, w);\n } // Set the `.multiplier` property of each equation\n\n\n let l = equations.length;\n const invDt = 1 / h;\n\n while (l--) {\n equations[l].multiplier = lambda[l] * invDt;\n }\n }\n\n return iter;\n }\n\n} // Just temporary number holders that we want to reuse each iteration.\n\nconst GSSolver_solve_lambda = [];\nconst GSSolver_solve_invCs = [];\nconst GSSolver_solve_Bs = [];\n\n/**\n * Splits the equations into islands and solves them independently. Can improve performance.\n */\nclass SplitSolver extends Solver {\n /**\n * The number of solver iterations determines quality of the constraints in the world. The more iterations, the more correct simulation. More iterations need more computations though. If you have a large gravity force in your world, you will need more iterations.\n */\n\n /**\n * When tolerance is reached, the system is assumed to be converged.\n */\n\n /** subsolver */\n constructor(subsolver) {\n super();\n this.iterations = 10;\n this.tolerance = 1e-7;\n this.subsolver = subsolver;\n this.nodes = [];\n this.nodePool = []; // Create needed nodes, reuse if possible\n\n while (this.nodePool.length < 128) {\n this.nodePool.push(this.createNode());\n }\n }\n /**\n * createNode\n */\n\n\n createNode() {\n return {\n body: null,\n children: [],\n eqs: [],\n visited: false\n };\n }\n /**\n * Solve the subsystems\n * @return number of iterations performed\n */\n\n\n solve(dt, world) {\n const nodes = SplitSolver_solve_nodes;\n const nodePool = this.nodePool;\n const bodies = world.bodies;\n const equations = this.equations;\n const Neq = equations.length;\n const Nbodies = bodies.length;\n const subsolver = this.subsolver; // Create needed nodes, reuse if possible\n\n while (nodePool.length < Nbodies) {\n nodePool.push(this.createNode());\n }\n\n nodes.length = Nbodies;\n\n for (let i = 0; i < Nbodies; i++) {\n nodes[i] = nodePool[i];\n } // Reset node values\n\n\n for (let i = 0; i !== Nbodies; i++) {\n const node = nodes[i];\n node.body = bodies[i];\n node.children.length = 0;\n node.eqs.length = 0;\n node.visited = false;\n }\n\n for (let k = 0; k !== Neq; k++) {\n const eq = equations[k];\n const i = bodies.indexOf(eq.bi);\n const j = bodies.indexOf(eq.bj);\n const ni = nodes[i];\n const nj = nodes[j];\n ni.children.push(nj);\n ni.eqs.push(eq);\n nj.children.push(ni);\n nj.eqs.push(eq);\n }\n\n let child;\n let n = 0;\n let eqs = SplitSolver_solve_eqs;\n subsolver.tolerance = this.tolerance;\n subsolver.iterations = this.iterations;\n const dummyWorld = SplitSolver_solve_dummyWorld;\n\n while (child = getUnvisitedNode(nodes)) {\n eqs.length = 0;\n dummyWorld.bodies.length = 0;\n bfs(child, visitFunc, dummyWorld.bodies, eqs);\n const Neqs = eqs.length;\n eqs = eqs.sort(sortById);\n\n for (let i = 0; i !== Neqs; i++) {\n subsolver.addEquation(eqs[i]);\n }\n\n subsolver.solve(dt, dummyWorld);\n subsolver.removeAllEquations();\n n++;\n }\n\n return n;\n }\n\n} // Returns the number of subsystems\n\nconst SplitSolver_solve_nodes = []; // All allocated node objects\n\nconst SplitSolver_solve_eqs = []; // Temp array\n\nconst SplitSolver_solve_dummyWorld = {\n bodies: []\n}; // Temp object\n\nconst STATIC = Body.STATIC;\n\nfunction getUnvisitedNode(nodes) {\n const Nnodes = nodes.length;\n\n for (let i = 0; i !== Nnodes; i++) {\n const node = nodes[i];\n\n if (!node.visited && !(node.body.type & STATIC)) {\n return node;\n }\n }\n\n return false;\n}\n\nconst queue = [];\n\nfunction bfs(root, visitFunc, bds, eqs) {\n queue.push(root);\n root.visited = true;\n visitFunc(root, bds, eqs);\n\n while (queue.length) {\n const node = queue.pop(); // Loop over unvisited child nodes\n\n let child;\n\n while (child = getUnvisitedNode(node.children)) {\n child.visited = true;\n visitFunc(child, bds, eqs);\n queue.push(child);\n }\n }\n}\n\nfunction visitFunc(node, bds, eqs) {\n bds.push(node.body);\n const Neqs = node.eqs.length;\n\n for (let i = 0; i !== Neqs; i++) {\n const eq = node.eqs[i];\n\n if (!eqs.includes(eq)) {\n eqs.push(eq);\n }\n }\n}\n\nfunction sortById(a, b) {\n return b.id - a.id;\n}\n\n/**\n * For pooling objects that can be reused.\n */\nclass Pool {\n constructor() {\n this.objects = [];\n this.type = Object;\n }\n\n /**\n * Release an object after use\n */\n release() {\n const Nargs = arguments.length;\n\n for (let i = 0; i !== Nargs; i++) {\n this.objects.push(i < 0 || arguments.length <= i ? undefined : arguments[i]);\n }\n\n return this;\n }\n /**\n * Get an object\n */\n\n\n get() {\n if (this.objects.length === 0) {\n return this.constructObject();\n } else {\n return this.objects.pop();\n }\n }\n /**\n * Construct an object. Should be implemented in each subclass.\n */\n\n\n constructObject() {\n throw new Error('constructObject() not implemented in this Pool subclass yet!');\n }\n /**\n * @return Self, for chaining\n */\n\n\n resize(size) {\n const objects = this.objects;\n\n while (objects.length > size) {\n objects.pop();\n }\n\n while (objects.length < size) {\n objects.push(this.constructObject());\n }\n\n return this;\n }\n\n}\n\n/**\n * Vec3Pool\n */\n\nclass Vec3Pool extends Pool {\n constructor() {\n super(...arguments);\n this.type = Vec3;\n }\n\n /**\n * Construct a vector\n */\n constructObject() {\n return new Vec3();\n }\n\n}\n\n// Naming rule: based of the order in SHAPE_TYPES,\n// the first part of the method is formed by the\n// shape type that comes before, in the second part\n// there is the shape type that comes after in the SHAPE_TYPES list\nconst COLLISION_TYPES = {\n sphereSphere: Shape.types.SPHERE,\n spherePlane: Shape.types.SPHERE | Shape.types.PLANE,\n boxBox: Shape.types.BOX | Shape.types.BOX,\n sphereBox: Shape.types.SPHERE | Shape.types.BOX,\n planeBox: Shape.types.PLANE | Shape.types.BOX,\n convexConvex: Shape.types.CONVEXPOLYHEDRON,\n sphereConvex: Shape.types.SPHERE | Shape.types.CONVEXPOLYHEDRON,\n planeConvex: Shape.types.PLANE | Shape.types.CONVEXPOLYHEDRON,\n boxConvex: Shape.types.BOX | Shape.types.CONVEXPOLYHEDRON,\n sphereHeightfield: Shape.types.SPHERE | Shape.types.HEIGHTFIELD,\n boxHeightfield: Shape.types.BOX | Shape.types.HEIGHTFIELD,\n convexHeightfield: Shape.types.CONVEXPOLYHEDRON | Shape.types.HEIGHTFIELD,\n sphereParticle: Shape.types.PARTICLE | Shape.types.SPHERE,\n planeParticle: Shape.types.PLANE | Shape.types.PARTICLE,\n boxParticle: Shape.types.BOX | Shape.types.PARTICLE,\n convexParticle: Shape.types.PARTICLE | Shape.types.CONVEXPOLYHEDRON,\n cylinderCylinder: Shape.types.CYLINDER,\n sphereCylinder: Shape.types.SPHERE | Shape.types.CYLINDER,\n planeCylinder: Shape.types.PLANE | Shape.types.CYLINDER,\n boxCylinder: Shape.types.BOX | Shape.types.CYLINDER,\n convexCylinder: Shape.types.CONVEXPOLYHEDRON | Shape.types.CYLINDER,\n heightfieldCylinder: Shape.types.HEIGHTFIELD | Shape.types.CYLINDER,\n particleCylinder: Shape.types.PARTICLE | Shape.types.CYLINDER,\n sphereTrimesh: Shape.types.SPHERE | Shape.types.TRIMESH,\n planeTrimesh: Shape.types.PLANE | Shape.types.TRIMESH\n};\n\n/**\n * Helper class for the World. Generates ContactEquations.\n * @todo Sphere-ConvexPolyhedron contacts\n * @todo Contact reduction\n * @todo should move methods to prototype\n */\nclass Narrowphase {\n /**\n * Internal storage of pooled contact points.\n */\n\n /**\n * Pooled vectors.\n */\n get [COLLISION_TYPES.sphereSphere]() {\n return this.sphereSphere;\n }\n\n get [COLLISION_TYPES.spherePlane]() {\n return this.spherePlane;\n }\n\n get [COLLISION_TYPES.boxBox]() {\n return this.boxBox;\n }\n\n get [COLLISION_TYPES.sphereBox]() {\n return this.sphereBox;\n }\n\n get [COLLISION_TYPES.planeBox]() {\n return this.planeBox;\n }\n\n get [COLLISION_TYPES.convexConvex]() {\n return this.convexConvex;\n }\n\n get [COLLISION_TYPES.sphereConvex]() {\n return this.sphereConvex;\n }\n\n get [COLLISION_TYPES.planeConvex]() {\n return this.planeConvex;\n }\n\n get [COLLISION_TYPES.boxConvex]() {\n return this.boxConvex;\n }\n\n get [COLLISION_TYPES.sphereHeightfield]() {\n return this.sphereHeightfield;\n }\n\n get [COLLISION_TYPES.boxHeightfield]() {\n return this.boxHeightfield;\n }\n\n get [COLLISION_TYPES.convexHeightfield]() {\n return this.convexHeightfield;\n }\n\n get [COLLISION_TYPES.sphereParticle]() {\n return this.sphereParticle;\n }\n\n get [COLLISION_TYPES.planeParticle]() {\n return this.planeParticle;\n }\n\n get [COLLISION_TYPES.boxParticle]() {\n return this.boxParticle;\n }\n\n get [COLLISION_TYPES.convexParticle]() {\n return this.convexParticle;\n }\n\n get [COLLISION_TYPES.cylinderCylinder]() {\n return this.convexConvex;\n }\n\n get [COLLISION_TYPES.sphereCylinder]() {\n return this.sphereConvex;\n }\n\n get [COLLISION_TYPES.planeCylinder]() {\n return this.planeConvex;\n }\n\n get [COLLISION_TYPES.boxCylinder]() {\n return this.boxConvex;\n }\n\n get [COLLISION_TYPES.convexCylinder]() {\n return this.convexConvex;\n }\n\n get [COLLISION_TYPES.heightfieldCylinder]() {\n return this.heightfieldCylinder;\n }\n\n get [COLLISION_TYPES.particleCylinder]() {\n return this.particleCylinder;\n }\n\n get [COLLISION_TYPES.sphereTrimesh]() {\n return this.sphereTrimesh;\n }\n\n get [COLLISION_TYPES.planeTrimesh]() {\n return this.planeTrimesh;\n } // get [COLLISION_TYPES.convexTrimesh]() {\n // return this.convexTrimesh\n // }\n\n\n constructor(world) {\n this.contactPointPool = [];\n this.frictionEquationPool = [];\n this.result = [];\n this.frictionResult = [];\n this.v3pool = new Vec3Pool();\n this.world = world;\n this.currentContactMaterial = world.defaultContactMaterial;\n this.enableFrictionReduction = false;\n }\n /**\n * Make a contact object, by using the internal pool or creating a new one.\n */\n\n\n createContactEquation(bi, bj, si, sj, overrideShapeA, overrideShapeB) {\n let c;\n\n if (this.contactPointPool.length) {\n c = this.contactPointPool.pop();\n c.bi = bi;\n c.bj = bj;\n } else {\n c = new ContactEquation(bi, bj);\n }\n\n c.enabled = bi.collisionResponse && bj.collisionResponse && si.collisionResponse && sj.collisionResponse;\n const cm = this.currentContactMaterial;\n c.restitution = cm.restitution;\n c.setSpookParams(cm.contactEquationStiffness, cm.contactEquationRelaxation, this.world.dt);\n const matA = si.material || bi.material;\n const matB = sj.material || bj.material;\n\n if (matA && matB && matA.restitution >= 0 && matB.restitution >= 0) {\n c.restitution = matA.restitution * matB.restitution;\n }\n\n c.si = overrideShapeA || si;\n c.sj = overrideShapeB || sj;\n return c;\n }\n\n createFrictionEquationsFromContact(contactEquation, outArray) {\n const bodyA = contactEquation.bi;\n const bodyB = contactEquation.bj;\n const shapeA = contactEquation.si;\n const shapeB = contactEquation.sj;\n const world = this.world;\n const cm = this.currentContactMaterial; // If friction or restitution were specified in the material, use them\n\n let friction = cm.friction;\n const matA = shapeA.material || bodyA.material;\n const matB = shapeB.material || bodyB.material;\n\n if (matA && matB && matA.friction >= 0 && matB.friction >= 0) {\n friction = matA.friction * matB.friction;\n }\n\n if (friction > 0) {\n // Create 2 tangent equations\n // Users may provide a force different from global gravity to use when computing contact friction.\n const mug = friction * (world.frictionGravity || world.gravity).length();\n let reducedMass = bodyA.invMass + bodyB.invMass;\n\n if (reducedMass > 0) {\n reducedMass = 1 / reducedMass;\n }\n\n const pool = this.frictionEquationPool;\n const c1 = pool.length ? pool.pop() : new FrictionEquation(bodyA, bodyB, mug * reducedMass);\n const c2 = pool.length ? pool.pop() : new FrictionEquation(bodyA, bodyB, mug * reducedMass);\n c1.bi = c2.bi = bodyA;\n c1.bj = c2.bj = bodyB;\n c1.minForce = c2.minForce = -mug * reducedMass;\n c1.maxForce = c2.maxForce = mug * reducedMass; // Copy over the relative vectors\n\n c1.ri.copy(contactEquation.ri);\n c1.rj.copy(contactEquation.rj);\n c2.ri.copy(contactEquation.ri);\n c2.rj.copy(contactEquation.rj); // Construct tangents\n\n contactEquation.ni.tangents(c1.t, c2.t); // Set spook params\n\n c1.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, world.dt);\n c2.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, world.dt);\n c1.enabled = c2.enabled = contactEquation.enabled;\n outArray.push(c1, c2);\n return true;\n }\n\n return false;\n }\n /**\n * Take the average N latest contact point on the plane.\n */\n\n\n createFrictionFromAverage(numContacts) {\n // The last contactEquation\n let c = this.result[this.result.length - 1]; // Create the result: two \"average\" friction equations\n\n if (!this.createFrictionEquationsFromContact(c, this.frictionResult) || numContacts === 1) {\n return;\n }\n\n const f1 = this.frictionResult[this.frictionResult.length - 2];\n const f2 = this.frictionResult[this.frictionResult.length - 1];\n averageNormal.setZero();\n averageContactPointA.setZero();\n averageContactPointB.setZero();\n const bodyA = c.bi;\n c.bj;\n\n for (let i = 0; i !== numContacts; i++) {\n c = this.result[this.result.length - 1 - i];\n\n if (c.bi !== bodyA) {\n averageNormal.vadd(c.ni, averageNormal);\n averageContactPointA.vadd(c.ri, averageContactPointA);\n averageContactPointB.vadd(c.rj, averageContactPointB);\n } else {\n averageNormal.vsub(c.ni, averageNormal);\n averageContactPointA.vadd(c.rj, averageContactPointA);\n averageContactPointB.vadd(c.ri, averageContactPointB);\n }\n }\n\n const invNumContacts = 1 / numContacts;\n averageContactPointA.scale(invNumContacts, f1.ri);\n averageContactPointB.scale(invNumContacts, f1.rj);\n f2.ri.copy(f1.ri); // Should be the same\n\n f2.rj.copy(f1.rj);\n averageNormal.normalize();\n averageNormal.tangents(f1.t, f2.t); // return eq;\n }\n /**\n * Generate all contacts between a list of body pairs\n * @param p1 Array of body indices\n * @param p2 Array of body indices\n * @param result Array to store generated contacts\n * @param oldcontacts Optional. Array of reusable contact objects\n */\n\n\n getContacts(p1, p2, world, result, oldcontacts, frictionResult, frictionPool) {\n // Save old contact objects\n this.contactPointPool = oldcontacts;\n this.frictionEquationPool = frictionPool;\n this.result = result;\n this.frictionResult = frictionResult;\n const qi = tmpQuat1;\n const qj = tmpQuat2;\n const xi = tmpVec1;\n const xj = tmpVec2;\n\n for (let k = 0, N = p1.length; k !== N; k++) {\n // Get current collision bodies\n const bi = p1[k];\n const bj = p2[k]; // Get contact material\n\n let bodyContactMaterial = null;\n\n if (bi.material && bj.material) {\n bodyContactMaterial = world.getContactMaterial(bi.material, bj.material) || null;\n }\n\n const justTest = bi.type & Body.KINEMATIC && bj.type & Body.STATIC || bi.type & Body.STATIC && bj.type & Body.KINEMATIC || bi.type & Body.KINEMATIC && bj.type & Body.KINEMATIC;\n\n for (let i = 0; i < bi.shapes.length; i++) {\n bi.quaternion.mult(bi.shapeOrientations[i], qi);\n bi.quaternion.vmult(bi.shapeOffsets[i], xi);\n xi.vadd(bi.position, xi);\n const si = bi.shapes[i];\n\n for (let j = 0; j < bj.shapes.length; j++) {\n // Compute world transform of shapes\n bj.quaternion.mult(bj.shapeOrientations[j], qj);\n bj.quaternion.vmult(bj.shapeOffsets[j], xj);\n xj.vadd(bj.position, xj);\n const sj = bj.shapes[j];\n\n if (!(si.collisionFilterMask & sj.collisionFilterGroup && sj.collisionFilterMask & si.collisionFilterGroup)) {\n continue;\n }\n\n if (xi.distanceTo(xj) > si.boundingSphereRadius + sj.boundingSphereRadius) {\n continue;\n } // Get collision material\n\n\n let shapeContactMaterial = null;\n\n if (si.material && sj.material) {\n shapeContactMaterial = world.getContactMaterial(si.material, sj.material) || null;\n }\n\n this.currentContactMaterial = shapeContactMaterial || bodyContactMaterial || world.defaultContactMaterial; // Get contacts\n\n const resolverIndex = si.type | sj.type;\n const resolver = this[resolverIndex];\n\n if (resolver) {\n let retval = false; // TO DO: investigate why sphereParticle and convexParticle\n // resolvers expect si and sj shapes to be in reverse order\n // (i.e. larger integer value type first instead of smaller first)\n\n if (si.type < sj.type) {\n retval = resolver.call(this, si, sj, xi, xj, qi, qj, bi, bj, si, sj, justTest);\n } else {\n retval = resolver.call(this, sj, si, xj, xi, qj, qi, bj, bi, si, sj, justTest);\n }\n\n if (retval && justTest) {\n // Register overlap\n world.shapeOverlapKeeper.set(si.id, sj.id);\n world.bodyOverlapKeeper.set(bi.id, bj.id);\n }\n }\n }\n }\n }\n }\n\n sphereSphere(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest) {\n if (justTest) {\n return xi.distanceSquared(xj) < (si.radius + sj.radius) ** 2;\n } // We will have only one contact in this case\n\n\n const contactEq = this.createContactEquation(bi, bj, si, sj, rsi, rsj); // Contact normal\n\n xj.vsub(xi, contactEq.ni);\n contactEq.ni.normalize(); // Contact point locations\n\n contactEq.ri.copy(contactEq.ni);\n contactEq.rj.copy(contactEq.ni);\n contactEq.ri.scale(si.radius, contactEq.ri);\n contactEq.rj.scale(-sj.radius, contactEq.rj);\n contactEq.ri.vadd(xi, contactEq.ri);\n contactEq.ri.vsub(bi.position, contactEq.ri);\n contactEq.rj.vadd(xj, contactEq.rj);\n contactEq.rj.vsub(bj.position, contactEq.rj);\n this.result.push(contactEq);\n this.createFrictionEquationsFromContact(contactEq, this.frictionResult);\n }\n\n spherePlane(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest) {\n // We will have one contact in this case\n const r = this.createContactEquation(bi, bj, si, sj, rsi, rsj); // Contact normal\n\n r.ni.set(0, 0, 1);\n qj.vmult(r.ni, r.ni);\n r.ni.negate(r.ni); // body i is the sphere, flip normal\n\n r.ni.normalize(); // Needed?\n // Vector from sphere center to contact point\n\n r.ni.scale(si.radius, r.ri); // Project down sphere on plane\n\n xi.vsub(xj, point_on_plane_to_sphere);\n r.ni.scale(r.ni.dot(point_on_plane_to_sphere), plane_to_sphere_ortho);\n point_on_plane_to_sphere.vsub(plane_to_sphere_ortho, r.rj); // The sphere position projected to plane\n\n if (-point_on_plane_to_sphere.dot(r.ni) <= si.radius) {\n if (justTest) {\n return true;\n } // Make it relative to the body\n\n\n const ri = r.ri;\n const rj = r.rj;\n ri.vadd(xi, ri);\n ri.vsub(bi.position, ri);\n rj.vadd(xj, rj);\n rj.vsub(bj.position, rj);\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n }\n }\n\n boxBox(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest) {\n si.convexPolyhedronRepresentation.material = si.material;\n sj.convexPolyhedronRepresentation.material = sj.material;\n si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse;\n sj.convexPolyhedronRepresentation.collisionResponse = sj.collisionResponse;\n return this.convexConvex(si.convexPolyhedronRepresentation, sj.convexPolyhedronRepresentation, xi, xj, qi, qj, bi, bj, si, sj, justTest);\n }\n\n sphereBox(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest) {\n const v3pool = this.v3pool; // we refer to the box as body j\n\n const sides = sphereBox_sides;\n xi.vsub(xj, box_to_sphere);\n sj.getSideNormals(sides, qj);\n const R = si.radius;\n\n let found = false; // Store the resulting side penetration info\n\n const side_ns = sphereBox_side_ns;\n const side_ns1 = sphereBox_side_ns1;\n const side_ns2 = sphereBox_side_ns2;\n let side_h = null;\n let side_penetrations = 0;\n let side_dot1 = 0;\n let side_dot2 = 0;\n let side_distance = null;\n\n for (let idx = 0, nsides = sides.length; idx !== nsides && found === false; idx++) {\n // Get the plane side normal (ns)\n const ns = sphereBox_ns;\n ns.copy(sides[idx]);\n const h = ns.length();\n ns.normalize(); // The normal/distance dot product tells which side of the plane we are\n\n const dot = box_to_sphere.dot(ns);\n\n if (dot < h + R && dot > 0) {\n // Intersects plane. Now check the other two dimensions\n const ns1 = sphereBox_ns1;\n const ns2 = sphereBox_ns2;\n ns1.copy(sides[(idx + 1) % 3]);\n ns2.copy(sides[(idx + 2) % 3]);\n const h1 = ns1.length();\n const h2 = ns2.length();\n ns1.normalize();\n ns2.normalize();\n const dot1 = box_to_sphere.dot(ns1);\n const dot2 = box_to_sphere.dot(ns2);\n\n if (dot1 < h1 && dot1 > -h1 && dot2 < h2 && dot2 > -h2) {\n const dist = Math.abs(dot - h - R);\n\n if (side_distance === null || dist < side_distance) {\n side_distance = dist;\n side_dot1 = dot1;\n side_dot2 = dot2;\n side_h = h;\n side_ns.copy(ns);\n side_ns1.copy(ns1);\n side_ns2.copy(ns2);\n side_penetrations++;\n\n if (justTest) {\n return true;\n }\n }\n }\n }\n }\n\n if (side_penetrations) {\n found = true;\n const r = this.createContactEquation(bi, bj, si, sj, rsi, rsj);\n side_ns.scale(-R, r.ri); // Sphere r\n\n r.ni.copy(side_ns);\n r.ni.negate(r.ni); // Normal should be out of sphere\n\n side_ns.scale(side_h, side_ns);\n side_ns1.scale(side_dot1, side_ns1);\n side_ns.vadd(side_ns1, side_ns);\n side_ns2.scale(side_dot2, side_ns2);\n side_ns.vadd(side_ns2, r.rj); // Make relative to bodies\n\n r.ri.vadd(xi, r.ri);\n r.ri.vsub(bi.position, r.ri);\n r.rj.vadd(xj, r.rj);\n r.rj.vsub(bj.position, r.rj);\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n } // Check corners\n\n\n let rj = v3pool.get();\n const sphere_to_corner = sphereBox_sphere_to_corner;\n\n for (let j = 0; j !== 2 && !found; j++) {\n for (let k = 0; k !== 2 && !found; k++) {\n for (let l = 0; l !== 2 && !found; l++) {\n rj.set(0, 0, 0);\n\n if (j) {\n rj.vadd(sides[0], rj);\n } else {\n rj.vsub(sides[0], rj);\n }\n\n if (k) {\n rj.vadd(sides[1], rj);\n } else {\n rj.vsub(sides[1], rj);\n }\n\n if (l) {\n rj.vadd(sides[2], rj);\n } else {\n rj.vsub(sides[2], rj);\n } // World position of corner\n\n\n xj.vadd(rj, sphere_to_corner);\n sphere_to_corner.vsub(xi, sphere_to_corner);\n\n if (sphere_to_corner.lengthSquared() < R * R) {\n if (justTest) {\n return true;\n }\n\n found = true;\n const r = this.createContactEquation(bi, bj, si, sj, rsi, rsj);\n r.ri.copy(sphere_to_corner);\n r.ri.normalize();\n r.ni.copy(r.ri);\n r.ri.scale(R, r.ri);\n r.rj.copy(rj); // Make relative to bodies\n\n r.ri.vadd(xi, r.ri);\n r.ri.vsub(bi.position, r.ri);\n r.rj.vadd(xj, r.rj);\n r.rj.vsub(bj.position, r.rj);\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n }\n }\n }\n }\n\n v3pool.release(rj);\n rj = null; // Check edges\n\n const edgeTangent = v3pool.get();\n const edgeCenter = v3pool.get();\n const r = v3pool.get(); // r = edge center to sphere center\n\n const orthogonal = v3pool.get();\n const dist = v3pool.get();\n const Nsides = sides.length;\n\n for (let j = 0; j !== Nsides && !found; j++) {\n for (let k = 0; k !== Nsides && !found; k++) {\n if (j % 3 !== k % 3) {\n // Get edge tangent\n sides[k].cross(sides[j], edgeTangent);\n edgeTangent.normalize();\n sides[j].vadd(sides[k], edgeCenter);\n r.copy(xi);\n r.vsub(edgeCenter, r);\n r.vsub(xj, r);\n const orthonorm = r.dot(edgeTangent); // distance from edge center to sphere center in the tangent direction\n\n edgeTangent.scale(orthonorm, orthogonal); // Vector from edge center to sphere center in the tangent direction\n // Find the third side orthogonal to this one\n\n let l = 0;\n\n while (l === j % 3 || l === k % 3) {\n l++;\n } // vec from edge center to sphere projected to the plane orthogonal to the edge tangent\n\n\n dist.copy(xi);\n dist.vsub(orthogonal, dist);\n dist.vsub(edgeCenter, dist);\n dist.vsub(xj, dist); // Distances in tangent direction and distance in the plane orthogonal to it\n\n const tdist = Math.abs(orthonorm);\n const ndist = dist.length();\n\n if (tdist < sides[l].length() && ndist < R) {\n if (justTest) {\n return true;\n }\n\n found = true;\n const res = this.createContactEquation(bi, bj, si, sj, rsi, rsj);\n edgeCenter.vadd(orthogonal, res.rj); // box rj\n\n res.rj.copy(res.rj);\n dist.negate(res.ni);\n res.ni.normalize();\n res.ri.copy(res.rj);\n res.ri.vadd(xj, res.ri);\n res.ri.vsub(xi, res.ri);\n res.ri.normalize();\n res.ri.scale(R, res.ri); // Make relative to bodies\n\n res.ri.vadd(xi, res.ri);\n res.ri.vsub(bi.position, res.ri);\n res.rj.vadd(xj, res.rj);\n res.rj.vsub(bj.position, res.rj);\n this.result.push(res);\n this.createFrictionEquationsFromContact(res, this.frictionResult);\n }\n }\n }\n }\n\n v3pool.release(edgeTangent, edgeCenter, r, orthogonal, dist);\n }\n\n planeBox(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest) {\n sj.convexPolyhedronRepresentation.material = sj.material;\n sj.convexPolyhedronRepresentation.collisionResponse = sj.collisionResponse;\n sj.convexPolyhedronRepresentation.id = sj.id;\n return this.planeConvex(si, sj.convexPolyhedronRepresentation, xi, xj, qi, qj, bi, bj, si, sj, justTest);\n }\n\n convexConvex(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest, faceListA, faceListB) {\n const sepAxis = convexConvex_sepAxis;\n\n if (xi.distanceTo(xj) > si.boundingSphereRadius + sj.boundingSphereRadius) {\n return;\n }\n\n if (si.findSeparatingAxis(sj, xi, qi, xj, qj, sepAxis, faceListA, faceListB)) {\n const res = [];\n const q = convexConvex_q;\n si.clipAgainstHull(xi, qi, sj, xj, qj, sepAxis, -100, 100, res);\n let numContacts = 0;\n\n for (let j = 0; j !== res.length; j++) {\n if (justTest) {\n return true;\n }\n\n const r = this.createContactEquation(bi, bj, si, sj, rsi, rsj);\n const ri = r.ri;\n const rj = r.rj;\n sepAxis.negate(r.ni);\n res[j].normal.negate(q);\n q.scale(res[j].depth, q);\n res[j].point.vadd(q, ri);\n rj.copy(res[j].point); // Contact points are in world coordinates. Transform back to relative\n\n ri.vsub(xi, ri);\n rj.vsub(xj, rj); // Make relative to bodies\n\n ri.vadd(xi, ri);\n ri.vsub(bi.position, ri);\n rj.vadd(xj, rj);\n rj.vsub(bj.position, rj);\n this.result.push(r);\n numContacts++;\n\n if (!this.enableFrictionReduction) {\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n }\n }\n\n if (this.enableFrictionReduction && numContacts) {\n this.createFrictionFromAverage(numContacts);\n }\n }\n }\n\n sphereConvex(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest) {\n const v3pool = this.v3pool;\n xi.vsub(xj, convex_to_sphere);\n const normals = sj.faceNormals;\n const faces = sj.faces;\n const verts = sj.vertices;\n const R = si.radius;\n // return;\n // }\n\n let found = false; // Check corners\n\n for (let i = 0; i !== verts.length; i++) {\n const v = verts[i]; // World position of corner\n\n const worldCorner = sphereConvex_worldCorner;\n qj.vmult(v, worldCorner);\n xj.vadd(worldCorner, worldCorner);\n const sphere_to_corner = sphereConvex_sphereToCorner;\n worldCorner.vsub(xi, sphere_to_corner);\n\n if (sphere_to_corner.lengthSquared() < R * R) {\n if (justTest) {\n return true;\n }\n\n found = true;\n const r = this.createContactEquation(bi, bj, si, sj, rsi, rsj);\n r.ri.copy(sphere_to_corner);\n r.ri.normalize();\n r.ni.copy(r.ri);\n r.ri.scale(R, r.ri);\n worldCorner.vsub(xj, r.rj); // Should be relative to the body.\n\n r.ri.vadd(xi, r.ri);\n r.ri.vsub(bi.position, r.ri); // Should be relative to the body.\n\n r.rj.vadd(xj, r.rj);\n r.rj.vsub(bj.position, r.rj);\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n return;\n }\n } // Check side (plane) intersections\n\n\n for (let i = 0, nfaces = faces.length; i !== nfaces && found === false; i++) {\n const normal = normals[i];\n const face = faces[i]; // Get world-transformed normal of the face\n\n const worldNormal = sphereConvex_worldNormal;\n qj.vmult(normal, worldNormal); // Get a world vertex from the face\n\n const worldPoint = sphereConvex_worldPoint;\n qj.vmult(verts[face[0]], worldPoint);\n worldPoint.vadd(xj, worldPoint); // Get a point on the sphere, closest to the face normal\n\n const worldSpherePointClosestToPlane = sphereConvex_worldSpherePointClosestToPlane;\n worldNormal.scale(-R, worldSpherePointClosestToPlane);\n xi.vadd(worldSpherePointClosestToPlane, worldSpherePointClosestToPlane); // Vector from a face point to the closest point on the sphere\n\n const penetrationVec = sphereConvex_penetrationVec;\n worldSpherePointClosestToPlane.vsub(worldPoint, penetrationVec); // The penetration. Negative value means overlap.\n\n const penetration = penetrationVec.dot(worldNormal);\n const worldPointToSphere = sphereConvex_sphereToWorldPoint;\n xi.vsub(worldPoint, worldPointToSphere);\n\n if (penetration < 0 && worldPointToSphere.dot(worldNormal) > 0) {\n // Intersects plane. Now check if the sphere is inside the face polygon\n const faceVerts = []; // Face vertices, in world coords\n\n for (let j = 0, Nverts = face.length; j !== Nverts; j++) {\n const worldVertex = v3pool.get();\n qj.vmult(verts[face[j]], worldVertex);\n xj.vadd(worldVertex, worldVertex);\n faceVerts.push(worldVertex);\n }\n\n if (pointInPolygon(faceVerts, worldNormal, xi)) {\n // Is the sphere center in the face polygon?\n if (justTest) {\n return true;\n }\n\n found = true;\n const r = this.createContactEquation(bi, bj, si, sj, rsi, rsj);\n worldNormal.scale(-R, r.ri); // Contact offset, from sphere center to contact\n\n worldNormal.negate(r.ni); // Normal pointing out of sphere\n\n const penetrationVec2 = v3pool.get();\n worldNormal.scale(-penetration, penetrationVec2);\n const penetrationSpherePoint = v3pool.get();\n worldNormal.scale(-R, penetrationSpherePoint); //xi.vsub(xj).vadd(penetrationSpherePoint).vadd(penetrationVec2 , r.rj);\n\n xi.vsub(xj, r.rj);\n r.rj.vadd(penetrationSpherePoint, r.rj);\n r.rj.vadd(penetrationVec2, r.rj); // Should be relative to the body.\n\n r.rj.vadd(xj, r.rj);\n r.rj.vsub(bj.position, r.rj); // Should be relative to the body.\n\n r.ri.vadd(xi, r.ri);\n r.ri.vsub(bi.position, r.ri);\n v3pool.release(penetrationVec2);\n v3pool.release(penetrationSpherePoint);\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult); // Release world vertices\n\n for (let j = 0, Nfaceverts = faceVerts.length; j !== Nfaceverts; j++) {\n v3pool.release(faceVerts[j]);\n }\n\n return; // We only expect *one* face contact\n } else {\n // Edge?\n for (let j = 0; j !== face.length; j++) {\n // Get two world transformed vertices\n const v1 = v3pool.get();\n const v2 = v3pool.get();\n qj.vmult(verts[face[(j + 1) % face.length]], v1);\n qj.vmult(verts[face[(j + 2) % face.length]], v2);\n xj.vadd(v1, v1);\n xj.vadd(v2, v2); // Construct edge vector\n\n const edge = sphereConvex_edge;\n v2.vsub(v1, edge); // Construct the same vector, but normalized\n\n const edgeUnit = sphereConvex_edgeUnit;\n edge.unit(edgeUnit); // p is xi projected onto the edge\n\n const p = v3pool.get();\n const v1_to_xi = v3pool.get();\n xi.vsub(v1, v1_to_xi);\n const dot = v1_to_xi.dot(edgeUnit);\n edgeUnit.scale(dot, p);\n p.vadd(v1, p); // Compute a vector from p to the center of the sphere\n\n const xi_to_p = v3pool.get();\n p.vsub(xi, xi_to_p); // Collision if the edge-sphere distance is less than the radius\n // AND if p is in between v1 and v2\n\n if (dot > 0 && dot * dot < edge.lengthSquared() && xi_to_p.lengthSquared() < R * R) {\n // Collision if the edge-sphere distance is less than the radius\n // Edge contact!\n if (justTest) {\n return true;\n }\n\n const r = this.createContactEquation(bi, bj, si, sj, rsi, rsj);\n p.vsub(xj, r.rj);\n p.vsub(xi, r.ni);\n r.ni.normalize();\n r.ni.scale(R, r.ri); // Should be relative to the body.\n\n r.rj.vadd(xj, r.rj);\n r.rj.vsub(bj.position, r.rj); // Should be relative to the body.\n\n r.ri.vadd(xi, r.ri);\n r.ri.vsub(bi.position, r.ri);\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult); // Release world vertices\n\n for (let j = 0, Nfaceverts = faceVerts.length; j !== Nfaceverts; j++) {\n v3pool.release(faceVerts[j]);\n }\n\n v3pool.release(v1);\n v3pool.release(v2);\n v3pool.release(p);\n v3pool.release(xi_to_p);\n v3pool.release(v1_to_xi);\n return;\n }\n\n v3pool.release(v1);\n v3pool.release(v2);\n v3pool.release(p);\n v3pool.release(xi_to_p);\n v3pool.release(v1_to_xi);\n }\n } // Release world vertices\n\n\n for (let j = 0, Nfaceverts = faceVerts.length; j !== Nfaceverts; j++) {\n v3pool.release(faceVerts[j]);\n }\n }\n }\n }\n\n planeConvex(planeShape, convexShape, planePosition, convexPosition, planeQuat, convexQuat, planeBody, convexBody, si, sj, justTest) {\n // Simply return the points behind the plane.\n const worldVertex = planeConvex_v;\n const worldNormal = planeConvex_normal;\n worldNormal.set(0, 0, 1);\n planeQuat.vmult(worldNormal, worldNormal); // Turn normal according to plane orientation\n\n let numContacts = 0;\n const relpos = planeConvex_relpos;\n\n for (let i = 0; i !== convexShape.vertices.length; i++) {\n // Get world convex vertex\n worldVertex.copy(convexShape.vertices[i]);\n convexQuat.vmult(worldVertex, worldVertex);\n convexPosition.vadd(worldVertex, worldVertex);\n worldVertex.vsub(planePosition, relpos);\n const dot = worldNormal.dot(relpos);\n\n if (dot <= 0.0) {\n if (justTest) {\n return true;\n }\n\n const r = this.createContactEquation(planeBody, convexBody, planeShape, convexShape, si, sj); // Get vertex position projected on plane\n\n const projected = planeConvex_projected;\n worldNormal.scale(worldNormal.dot(relpos), projected);\n worldVertex.vsub(projected, projected);\n projected.vsub(planePosition, r.ri); // From plane to vertex projected on plane\n\n r.ni.copy(worldNormal); // Contact normal is the plane normal out from plane\n // rj is now just the vector from the convex center to the vertex\n\n worldVertex.vsub(convexPosition, r.rj); // Make it relative to the body\n\n r.ri.vadd(planePosition, r.ri);\n r.ri.vsub(planeBody.position, r.ri);\n r.rj.vadd(convexPosition, r.rj);\n r.rj.vsub(convexBody.position, r.rj);\n this.result.push(r);\n numContacts++;\n\n if (!this.enableFrictionReduction) {\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n }\n }\n }\n\n if (this.enableFrictionReduction && numContacts) {\n this.createFrictionFromAverage(numContacts);\n }\n }\n\n boxConvex(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest) {\n si.convexPolyhedronRepresentation.material = si.material;\n si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse;\n return this.convexConvex(si.convexPolyhedronRepresentation, sj, xi, xj, qi, qj, bi, bj, si, sj, justTest);\n }\n\n sphereHeightfield(sphereShape, hfShape, spherePos, hfPos, sphereQuat, hfQuat, sphereBody, hfBody, rsi, rsj, justTest) {\n const data = hfShape.data;\n const radius = sphereShape.radius;\n const w = hfShape.elementSize;\n const worldPillarOffset = sphereHeightfield_tmp2; // Get sphere position to heightfield local!\n\n const localSpherePos = sphereHeightfield_tmp1;\n Transform.pointToLocalFrame(hfPos, hfQuat, spherePos, localSpherePos); // Get the index of the data points to test against\n\n let iMinX = Math.floor((localSpherePos.x - radius) / w) - 1;\n let iMaxX = Math.ceil((localSpherePos.x + radius) / w) + 1;\n let iMinY = Math.floor((localSpherePos.y - radius) / w) - 1;\n let iMaxY = Math.ceil((localSpherePos.y + radius) / w) + 1; // Bail out if we are out of the terrain\n\n if (iMaxX < 0 || iMaxY < 0 || iMinX > data.length || iMinY > data[0].length) {\n return;\n } // Clamp index to edges\n\n\n if (iMinX < 0) {\n iMinX = 0;\n }\n\n if (iMaxX < 0) {\n iMaxX = 0;\n }\n\n if (iMinY < 0) {\n iMinY = 0;\n }\n\n if (iMaxY < 0) {\n iMaxY = 0;\n }\n\n if (iMinX >= data.length) {\n iMinX = data.length - 1;\n }\n\n if (iMaxX >= data.length) {\n iMaxX = data.length - 1;\n }\n\n if (iMaxY >= data[0].length) {\n iMaxY = data[0].length - 1;\n }\n\n if (iMinY >= data[0].length) {\n iMinY = data[0].length - 1;\n }\n\n const minMax = [];\n hfShape.getRectMinMax(iMinX, iMinY, iMaxX, iMaxY, minMax);\n const min = minMax[0];\n const max = minMax[1]; // Bail out if we can't touch the bounding height box\n\n if (localSpherePos.z - radius > max || localSpherePos.z + radius < min) {\n return;\n }\n\n const result = this.result;\n\n for (let i = iMinX; i < iMaxX; i++) {\n for (let j = iMinY; j < iMaxY; j++) {\n const numContactsBefore = result.length;\n let intersecting = false; // Lower triangle\n\n hfShape.getConvexTrianglePillar(i, j, false);\n Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset);\n\n if (spherePos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + sphereShape.boundingSphereRadius) {\n intersecting = this.sphereConvex(sphereShape, hfShape.pillarConvex, spherePos, worldPillarOffset, sphereQuat, hfQuat, sphereBody, hfBody, sphereShape, hfShape, justTest);\n }\n\n if (justTest && intersecting) {\n return true;\n } // Upper triangle\n\n\n hfShape.getConvexTrianglePillar(i, j, true);\n Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset);\n\n if (spherePos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + sphereShape.boundingSphereRadius) {\n intersecting = this.sphereConvex(sphereShape, hfShape.pillarConvex, spherePos, worldPillarOffset, sphereQuat, hfQuat, sphereBody, hfBody, sphereShape, hfShape, justTest);\n }\n\n if (justTest && intersecting) {\n return true;\n }\n\n const numContacts = result.length - numContactsBefore;\n\n if (numContacts > 2) {\n return;\n }\n /*\n // Skip all but 1\n for (let k = 0; k < numContacts - 1; k++) {\n result.pop();\n }\n */\n\n }\n }\n }\n\n boxHeightfield(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest) {\n si.convexPolyhedronRepresentation.material = si.material;\n si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse;\n return this.convexHeightfield(si.convexPolyhedronRepresentation, sj, xi, xj, qi, qj, bi, bj, si, sj, justTest);\n }\n\n convexHeightfield(convexShape, hfShape, convexPos, hfPos, convexQuat, hfQuat, convexBody, hfBody, rsi, rsj, justTest) {\n const data = hfShape.data;\n const w = hfShape.elementSize;\n const radius = convexShape.boundingSphereRadius;\n const worldPillarOffset = convexHeightfield_tmp2;\n const faceList = convexHeightfield_faceList; // Get sphere position to heightfield local!\n\n const localConvexPos = convexHeightfield_tmp1;\n Transform.pointToLocalFrame(hfPos, hfQuat, convexPos, localConvexPos); // Get the index of the data points to test against\n\n let iMinX = Math.floor((localConvexPos.x - radius) / w) - 1;\n let iMaxX = Math.ceil((localConvexPos.x + radius) / w) + 1;\n let iMinY = Math.floor((localConvexPos.y - radius) / w) - 1;\n let iMaxY = Math.ceil((localConvexPos.y + radius) / w) + 1; // Bail out if we are out of the terrain\n\n if (iMaxX < 0 || iMaxY < 0 || iMinX > data.length || iMinY > data[0].length) {\n return;\n } // Clamp index to edges\n\n\n if (iMinX < 0) {\n iMinX = 0;\n }\n\n if (iMaxX < 0) {\n iMaxX = 0;\n }\n\n if (iMinY < 0) {\n iMinY = 0;\n }\n\n if (iMaxY < 0) {\n iMaxY = 0;\n }\n\n if (iMinX >= data.length) {\n iMinX = data.length - 1;\n }\n\n if (iMaxX >= data.length) {\n iMaxX = data.length - 1;\n }\n\n if (iMaxY >= data[0].length) {\n iMaxY = data[0].length - 1;\n }\n\n if (iMinY >= data[0].length) {\n iMinY = data[0].length - 1;\n }\n\n const minMax = [];\n hfShape.getRectMinMax(iMinX, iMinY, iMaxX, iMaxY, minMax);\n const min = minMax[0];\n const max = minMax[1]; // Bail out if we're cant touch the bounding height box\n\n if (localConvexPos.z - radius > max || localConvexPos.z + radius < min) {\n return;\n }\n\n for (let i = iMinX; i < iMaxX; i++) {\n for (let j = iMinY; j < iMaxY; j++) {\n let intersecting = false; // Lower triangle\n\n hfShape.getConvexTrianglePillar(i, j, false);\n Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset);\n\n if (convexPos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + convexShape.boundingSphereRadius) {\n intersecting = this.convexConvex(convexShape, hfShape.pillarConvex, convexPos, worldPillarOffset, convexQuat, hfQuat, convexBody, hfBody, null, null, justTest, faceList, null);\n }\n\n if (justTest && intersecting) {\n return true;\n } // Upper triangle\n\n\n hfShape.getConvexTrianglePillar(i, j, true);\n Transform.pointToWorldFrame(hfPos, hfQuat, hfShape.pillarOffset, worldPillarOffset);\n\n if (convexPos.distanceTo(worldPillarOffset) < hfShape.pillarConvex.boundingSphereRadius + convexShape.boundingSphereRadius) {\n intersecting = this.convexConvex(convexShape, hfShape.pillarConvex, convexPos, worldPillarOffset, convexQuat, hfQuat, convexBody, hfBody, null, null, justTest, faceList, null);\n }\n\n if (justTest && intersecting) {\n return true;\n }\n }\n }\n }\n\n sphereParticle(sj, si, xj, xi, qj, qi, bj, bi, rsi, rsj, justTest) {\n // The normal is the unit vector from sphere center to particle center\n const normal = particleSphere_normal;\n normal.set(0, 0, 1);\n xi.vsub(xj, normal);\n const lengthSquared = normal.lengthSquared();\n\n if (lengthSquared <= sj.radius * sj.radius) {\n if (justTest) {\n return true;\n }\n\n const r = this.createContactEquation(bi, bj, si, sj, rsi, rsj);\n normal.normalize();\n r.rj.copy(normal);\n r.rj.scale(sj.radius, r.rj);\n r.ni.copy(normal); // Contact normal\n\n r.ni.negate(r.ni);\n r.ri.set(0, 0, 0); // Center of particle\n\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n }\n }\n\n planeParticle(sj, si, xj, xi, qj, qi, bj, bi, rsi, rsj, justTest) {\n const normal = particlePlane_normal;\n normal.set(0, 0, 1);\n bj.quaternion.vmult(normal, normal); // Turn normal according to plane orientation\n\n const relpos = particlePlane_relpos;\n xi.vsub(bj.position, relpos);\n const dot = normal.dot(relpos);\n\n if (dot <= 0.0) {\n if (justTest) {\n return true;\n }\n\n const r = this.createContactEquation(bi, bj, si, sj, rsi, rsj);\n r.ni.copy(normal); // Contact normal is the plane normal\n\n r.ni.negate(r.ni);\n r.ri.set(0, 0, 0); // Center of particle\n // Get particle position projected on plane\n\n const projected = particlePlane_projected;\n normal.scale(normal.dot(xi), projected);\n xi.vsub(projected, projected); //projected.vadd(bj.position,projected);\n // rj is now the projected world position minus plane position\n\n r.rj.copy(projected);\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n }\n }\n\n boxParticle(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest) {\n si.convexPolyhedronRepresentation.material = si.material;\n si.convexPolyhedronRepresentation.collisionResponse = si.collisionResponse;\n return this.convexParticle(si.convexPolyhedronRepresentation, sj, xi, xj, qi, qj, bi, bj, si, sj, justTest);\n }\n\n convexParticle(sj, si, xj, xi, qj, qi, bj, bi, rsi, rsj, justTest) {\n let penetratedFaceIndex = -1;\n const penetratedFaceNormal = convexParticle_penetratedFaceNormal;\n const worldPenetrationVec = convexParticle_worldPenetrationVec;\n let minPenetration = null;\n\n const local = convexParticle_local;\n local.copy(xi);\n local.vsub(xj, local); // Convert position to relative the convex origin\n\n qj.conjugate(cqj);\n cqj.vmult(local, local);\n\n if (sj.pointIsInside(local)) {\n if (sj.worldVerticesNeedsUpdate) {\n sj.computeWorldVertices(xj, qj);\n }\n\n if (sj.worldFaceNormalsNeedsUpdate) {\n sj.computeWorldFaceNormals(qj);\n } // For each world polygon in the polyhedra\n\n\n for (let i = 0, nfaces = sj.faces.length; i !== nfaces; i++) {\n // Construct world face vertices\n const verts = [sj.worldVertices[sj.faces[i][0]]];\n const normal = sj.worldFaceNormals[i]; // Check how much the particle penetrates the polygon plane.\n\n xi.vsub(verts[0], convexParticle_vertexToParticle);\n const penetration = -normal.dot(convexParticle_vertexToParticle);\n\n if (minPenetration === null || Math.abs(penetration) < Math.abs(minPenetration)) {\n if (justTest) {\n return true;\n }\n\n minPenetration = penetration;\n penetratedFaceIndex = i;\n penetratedFaceNormal.copy(normal);\n }\n }\n\n if (penetratedFaceIndex !== -1) {\n // Setup contact\n const r = this.createContactEquation(bi, bj, si, sj, rsi, rsj);\n penetratedFaceNormal.scale(minPenetration, worldPenetrationVec); // rj is the particle position projected to the face\n\n worldPenetrationVec.vadd(xi, worldPenetrationVec);\n worldPenetrationVec.vsub(xj, worldPenetrationVec);\n r.rj.copy(worldPenetrationVec); //const projectedToFace = xi.vsub(xj).vadd(worldPenetrationVec);\n //projectedToFace.copy(r.rj);\n //qj.vmult(r.rj,r.rj);\n\n penetratedFaceNormal.negate(r.ni); // Contact normal\n\n r.ri.set(0, 0, 0); // Center of particle\n\n const ri = r.ri;\n const rj = r.rj; // Make relative to bodies\n\n ri.vadd(xi, ri);\n ri.vsub(bi.position, ri);\n rj.vadd(xj, rj);\n rj.vsub(bj.position, rj);\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n } else {\n console.warn('Point found inside convex, but did not find penetrating face!');\n }\n }\n }\n\n heightfieldCylinder(hfShape, convexShape, hfPos, convexPos, hfQuat, convexQuat, hfBody, convexBody, rsi, rsj, justTest) {\n return this.convexHeightfield(convexShape, hfShape, convexPos, hfPos, convexQuat, hfQuat, convexBody, hfBody, rsi, rsj, justTest);\n }\n\n particleCylinder(si, sj, xi, xj, qi, qj, bi, bj, rsi, rsj, justTest) {\n return this.convexParticle(sj, si, xj, xi, qj, qi, bj, bi, rsi, rsj, justTest);\n }\n\n sphereTrimesh(sphereShape, trimeshShape, spherePos, trimeshPos, sphereQuat, trimeshQuat, sphereBody, trimeshBody, rsi, rsj, justTest) {\n const edgeVertexA = sphereTrimesh_edgeVertexA;\n const edgeVertexB = sphereTrimesh_edgeVertexB;\n const edgeVector = sphereTrimesh_edgeVector;\n const edgeVectorUnit = sphereTrimesh_edgeVectorUnit;\n const localSpherePos = sphereTrimesh_localSpherePos;\n const tmp = sphereTrimesh_tmp;\n const localSphereAABB = sphereTrimesh_localSphereAABB;\n const v2 = sphereTrimesh_v2;\n const relpos = sphereTrimesh_relpos;\n const triangles = sphereTrimesh_triangles; // Convert sphere position to local in the trimesh\n\n Transform.pointToLocalFrame(trimeshPos, trimeshQuat, spherePos, localSpherePos); // Get the aabb of the sphere locally in the trimesh\n\n const sphereRadius = sphereShape.radius;\n localSphereAABB.lowerBound.set(localSpherePos.x - sphereRadius, localSpherePos.y - sphereRadius, localSpherePos.z - sphereRadius);\n localSphereAABB.upperBound.set(localSpherePos.x + sphereRadius, localSpherePos.y + sphereRadius, localSpherePos.z + sphereRadius);\n trimeshShape.getTrianglesInAABB(localSphereAABB, triangles); //for (let i = 0; i < trimeshShape.indices.length / 3; i++) triangles.push(i); // All\n // Vertices\n\n const v = sphereTrimesh_v;\n const radiusSquared = sphereShape.radius * sphereShape.radius;\n\n for (let i = 0; i < triangles.length; i++) {\n for (let j = 0; j < 3; j++) {\n trimeshShape.getVertex(trimeshShape.indices[triangles[i] * 3 + j], v); // Check vertex overlap in sphere\n\n v.vsub(localSpherePos, relpos);\n\n if (relpos.lengthSquared() <= radiusSquared) {\n // Safe up\n v2.copy(v);\n Transform.pointToWorldFrame(trimeshPos, trimeshQuat, v2, v);\n v.vsub(spherePos, relpos);\n\n if (justTest) {\n return true;\n }\n\n let r = this.createContactEquation(sphereBody, trimeshBody, sphereShape, trimeshShape, rsi, rsj);\n r.ni.copy(relpos);\n r.ni.normalize(); // ri is the vector from sphere center to the sphere surface\n\n r.ri.copy(r.ni);\n r.ri.scale(sphereShape.radius, r.ri);\n r.ri.vadd(spherePos, r.ri);\n r.ri.vsub(sphereBody.position, r.ri);\n r.rj.copy(v);\n r.rj.vsub(trimeshBody.position, r.rj); // Store result\n\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n }\n }\n } // Check all edges\n\n\n for (let i = 0; i < triangles.length; i++) {\n for (let j = 0; j < 3; j++) {\n trimeshShape.getVertex(trimeshShape.indices[triangles[i] * 3 + j], edgeVertexA);\n trimeshShape.getVertex(trimeshShape.indices[triangles[i] * 3 + (j + 1) % 3], edgeVertexB);\n edgeVertexB.vsub(edgeVertexA, edgeVector); // Project sphere position to the edge\n\n localSpherePos.vsub(edgeVertexB, tmp);\n const positionAlongEdgeB = tmp.dot(edgeVector);\n localSpherePos.vsub(edgeVertexA, tmp);\n let positionAlongEdgeA = tmp.dot(edgeVector);\n\n if (positionAlongEdgeA > 0 && positionAlongEdgeB < 0) {\n // Now check the orthogonal distance from edge to sphere center\n localSpherePos.vsub(edgeVertexA, tmp);\n edgeVectorUnit.copy(edgeVector);\n edgeVectorUnit.normalize();\n positionAlongEdgeA = tmp.dot(edgeVectorUnit);\n edgeVectorUnit.scale(positionAlongEdgeA, tmp);\n tmp.vadd(edgeVertexA, tmp); // tmp is now the sphere center position projected to the edge, defined locally in the trimesh frame\n\n const dist = tmp.distanceTo(localSpherePos);\n\n if (dist < sphereShape.radius) {\n if (justTest) {\n return true;\n }\n\n const r = this.createContactEquation(sphereBody, trimeshBody, sphereShape, trimeshShape, rsi, rsj);\n tmp.vsub(localSpherePos, r.ni);\n r.ni.normalize();\n r.ni.scale(sphereShape.radius, r.ri);\n r.ri.vadd(spherePos, r.ri);\n r.ri.vsub(sphereBody.position, r.ri);\n Transform.pointToWorldFrame(trimeshPos, trimeshQuat, tmp, tmp);\n tmp.vsub(trimeshBody.position, r.rj);\n Transform.vectorToWorldFrame(trimeshQuat, r.ni, r.ni);\n Transform.vectorToWorldFrame(trimeshQuat, r.ri, r.ri);\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n }\n }\n }\n } // Triangle faces\n\n\n const va = sphereTrimesh_va;\n const vb = sphereTrimesh_vb;\n const vc = sphereTrimesh_vc;\n const normal = sphereTrimesh_normal;\n\n for (let i = 0, N = triangles.length; i !== N; i++) {\n trimeshShape.getTriangleVertices(triangles[i], va, vb, vc);\n trimeshShape.getNormal(triangles[i], normal);\n localSpherePos.vsub(va, tmp);\n let dist = tmp.dot(normal);\n normal.scale(dist, tmp);\n localSpherePos.vsub(tmp, tmp); // tmp is now the sphere position projected to the triangle plane\n\n dist = tmp.distanceTo(localSpherePos);\n\n if (Ray.pointInTriangle(tmp, va, vb, vc) && dist < sphereShape.radius) {\n if (justTest) {\n return true;\n }\n\n let r = this.createContactEquation(sphereBody, trimeshBody, sphereShape, trimeshShape, rsi, rsj);\n tmp.vsub(localSpherePos, r.ni);\n r.ni.normalize();\n r.ni.scale(sphereShape.radius, r.ri);\n r.ri.vadd(spherePos, r.ri);\n r.ri.vsub(sphereBody.position, r.ri);\n Transform.pointToWorldFrame(trimeshPos, trimeshQuat, tmp, tmp);\n tmp.vsub(trimeshBody.position, r.rj);\n Transform.vectorToWorldFrame(trimeshQuat, r.ni, r.ni);\n Transform.vectorToWorldFrame(trimeshQuat, r.ri, r.ri);\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n }\n }\n\n triangles.length = 0;\n }\n\n planeTrimesh(planeShape, trimeshShape, planePos, trimeshPos, planeQuat, trimeshQuat, planeBody, trimeshBody, rsi, rsj, justTest) {\n // Make contacts!\n const v = new Vec3();\n const normal = planeTrimesh_normal;\n normal.set(0, 0, 1);\n planeQuat.vmult(normal, normal); // Turn normal according to plane\n\n for (let i = 0; i < trimeshShape.vertices.length / 3; i++) {\n // Get world vertex from trimesh\n trimeshShape.getVertex(i, v); // Safe up\n\n const v2 = new Vec3();\n v2.copy(v);\n Transform.pointToWorldFrame(trimeshPos, trimeshQuat, v2, v); // Check plane side\n\n const relpos = planeTrimesh_relpos;\n v.vsub(planePos, relpos);\n const dot = normal.dot(relpos);\n\n if (dot <= 0.0) {\n if (justTest) {\n return true;\n }\n\n const r = this.createContactEquation(planeBody, trimeshBody, planeShape, trimeshShape, rsi, rsj);\n r.ni.copy(normal); // Contact normal is the plane normal\n // Get vertex position projected on plane\n\n const projected = planeTrimesh_projected;\n normal.scale(relpos.dot(normal), projected);\n v.vsub(projected, projected); // ri is the projected world position minus plane position\n\n r.ri.copy(projected);\n r.ri.vsub(planeBody.position, r.ri);\n r.rj.copy(v);\n r.rj.vsub(trimeshBody.position, r.rj); // Store result\n\n this.result.push(r);\n this.createFrictionEquationsFromContact(r, this.frictionResult);\n }\n }\n } // convexTrimesh(\n // si: ConvexPolyhedron, sj: Trimesh, xi: Vec3, xj: Vec3, qi: Quaternion, qj: Quaternion,\n // bi: Body, bj: Body, rsi?: Shape | null, rsj?: Shape | null,\n // faceListA?: number[] | null, faceListB?: number[] | null,\n // ) {\n // const sepAxis = convexConvex_sepAxis;\n // if(xi.distanceTo(xj) > si.boundingSphereRadius + sj.boundingSphereRadius){\n // return;\n // }\n // // Construct a temp hull for each triangle\n // const hullB = new ConvexPolyhedron();\n // hullB.faces = [[0,1,2]];\n // const va = new Vec3();\n // const vb = new Vec3();\n // const vc = new Vec3();\n // hullB.vertices = [\n // va,\n // vb,\n // vc\n // ];\n // for (let i = 0; i < sj.indices.length / 3; i++) {\n // const triangleNormal = new Vec3();\n // sj.getNormal(i, triangleNormal);\n // hullB.faceNormals = [triangleNormal];\n // sj.getTriangleVertices(i, va, vb, vc);\n // let d = si.testSepAxis(triangleNormal, hullB, xi, qi, xj, qj);\n // if(!d){\n // triangleNormal.scale(-1, triangleNormal);\n // d = si.testSepAxis(triangleNormal, hullB, xi, qi, xj, qj);\n // if(!d){\n // continue;\n // }\n // }\n // const res: ConvexPolyhedronContactPoint[] = [];\n // const q = convexConvex_q;\n // si.clipAgainstHull(xi,qi,hullB,xj,qj,triangleNormal,-100,100,res);\n // for(let j = 0; j !== res.length; j++){\n // const r = this.createContactEquation(bi,bj,si,sj,rsi,rsj),\n // ri = r.ri,\n // rj = r.rj;\n // r.ni.copy(triangleNormal);\n // r.ni.negate(r.ni);\n // res[j].normal.negate(q);\n // q.mult(res[j].depth, q);\n // res[j].point.vadd(q, ri);\n // rj.copy(res[j].point);\n // // Contact points are in world coordinates. Transform back to relative\n // ri.vsub(xi,ri);\n // rj.vsub(xj,rj);\n // // Make relative to bodies\n // ri.vadd(xi, ri);\n // ri.vsub(bi.position, ri);\n // rj.vadd(xj, rj);\n // rj.vsub(bj.position, rj);\n // result.push(r);\n // }\n // }\n // }\n\n\n}\nconst averageNormal = new Vec3();\nconst averageContactPointA = new Vec3();\nconst averageContactPointB = new Vec3();\nconst tmpVec1 = new Vec3();\nconst tmpVec2 = new Vec3();\nconst tmpQuat1 = new Quaternion();\nconst tmpQuat2 = new Quaternion();\n\nconst planeTrimesh_normal = new Vec3();\nconst planeTrimesh_relpos = new Vec3();\nconst planeTrimesh_projected = new Vec3();\nconst sphereTrimesh_normal = new Vec3();\nconst sphereTrimesh_relpos = new Vec3();\nnew Vec3();\nconst sphereTrimesh_v = new Vec3();\nconst sphereTrimesh_v2 = new Vec3();\nconst sphereTrimesh_edgeVertexA = new Vec3();\nconst sphereTrimesh_edgeVertexB = new Vec3();\nconst sphereTrimesh_edgeVector = new Vec3();\nconst sphereTrimesh_edgeVectorUnit = new Vec3();\nconst sphereTrimesh_localSpherePos = new Vec3();\nconst sphereTrimesh_tmp = new Vec3();\nconst sphereTrimesh_va = new Vec3();\nconst sphereTrimesh_vb = new Vec3();\nconst sphereTrimesh_vc = new Vec3();\nconst sphereTrimesh_localSphereAABB = new AABB();\nconst sphereTrimesh_triangles = [];\nconst point_on_plane_to_sphere = new Vec3();\nconst plane_to_sphere_ortho = new Vec3(); // See http://bulletphysics.com/Bullet/BulletFull/SphereTriangleDetector_8cpp_source.html\n\nconst pointInPolygon_edge = new Vec3();\nconst pointInPolygon_edge_x_normal = new Vec3();\nconst pointInPolygon_vtp = new Vec3();\n\nfunction pointInPolygon(verts, normal, p) {\n let positiveResult = null;\n const N = verts.length;\n\n for (let i = 0; i !== N; i++) {\n const v = verts[i]; // Get edge to the next vertex\n\n const edge = pointInPolygon_edge;\n verts[(i + 1) % N].vsub(v, edge); // Get cross product between polygon normal and the edge\n\n const edge_x_normal = pointInPolygon_edge_x_normal; //const edge_x_normal = new Vec3();\n\n edge.cross(normal, edge_x_normal); // Get vector between point and current vertex\n\n const vertex_to_p = pointInPolygon_vtp;\n p.vsub(v, vertex_to_p); // This dot product determines which side of the edge the point is\n\n const r = edge_x_normal.dot(vertex_to_p); // If all such dot products have same sign, we are inside the polygon.\n\n if (positiveResult === null || r > 0 && positiveResult === true || r <= 0 && positiveResult === false) {\n if (positiveResult === null) {\n positiveResult = r > 0;\n }\n\n continue;\n } else {\n return false; // Encountered some other sign. Exit.\n }\n } // If we got here, all dot products were of the same sign.\n\n\n return true;\n}\n\nconst box_to_sphere = new Vec3();\nconst sphereBox_ns = new Vec3();\nconst sphereBox_ns1 = new Vec3();\nconst sphereBox_ns2 = new Vec3();\nconst sphereBox_sides = [new Vec3(), new Vec3(), new Vec3(), new Vec3(), new Vec3(), new Vec3()];\nconst sphereBox_sphere_to_corner = new Vec3();\nconst sphereBox_side_ns = new Vec3();\nconst sphereBox_side_ns1 = new Vec3();\nconst sphereBox_side_ns2 = new Vec3();\nconst convex_to_sphere = new Vec3();\nconst sphereConvex_edge = new Vec3();\nconst sphereConvex_edgeUnit = new Vec3();\nconst sphereConvex_sphereToCorner = new Vec3();\nconst sphereConvex_worldCorner = new Vec3();\nconst sphereConvex_worldNormal = new Vec3();\nconst sphereConvex_worldPoint = new Vec3();\nconst sphereConvex_worldSpherePointClosestToPlane = new Vec3();\nconst sphereConvex_penetrationVec = new Vec3();\nconst sphereConvex_sphereToWorldPoint = new Vec3();\nnew Vec3();\nnew Vec3();\nconst planeConvex_v = new Vec3();\nconst planeConvex_normal = new Vec3();\nconst planeConvex_relpos = new Vec3();\nconst planeConvex_projected = new Vec3();\nconst convexConvex_sepAxis = new Vec3();\nconst convexConvex_q = new Vec3();\nconst particlePlane_normal = new Vec3();\nconst particlePlane_relpos = new Vec3();\nconst particlePlane_projected = new Vec3();\nconst particleSphere_normal = new Vec3(); // WIP\n\nconst cqj = new Quaternion();\nconst convexParticle_local = new Vec3();\nnew Vec3();\nconst convexParticle_penetratedFaceNormal = new Vec3();\nconst convexParticle_vertexToParticle = new Vec3();\nconst convexParticle_worldPenetrationVec = new Vec3();\nconst convexHeightfield_tmp1 = new Vec3();\nconst convexHeightfield_tmp2 = new Vec3();\nconst convexHeightfield_faceList = [0];\nconst sphereHeightfield_tmp1 = new Vec3();\nconst sphereHeightfield_tmp2 = new Vec3();\n\nclass OverlapKeeper {\n /**\n * @todo Remove useless constructor\n */\n constructor() {\n this.current = [];\n this.previous = [];\n }\n /**\n * getKey\n */\n\n\n getKey(i, j) {\n if (j < i) {\n const temp = j;\n j = i;\n i = temp;\n }\n\n return i << 16 | j;\n }\n /**\n * set\n */\n\n\n set(i, j) {\n // Insertion sort. This way the diff will have linear complexity.\n const key = this.getKey(i, j);\n const current = this.current;\n let index = 0;\n\n while (key > current[index]) {\n index++;\n }\n\n if (key === current[index]) {\n return; // Pair was already added\n }\n\n for (let j = current.length - 1; j >= index; j--) {\n current[j + 1] = current[j];\n }\n\n current[index] = key;\n }\n /**\n * tick\n */\n\n\n tick() {\n const tmp = this.current;\n this.current = this.previous;\n this.previous = tmp;\n this.current.length = 0;\n }\n /**\n * getDiff\n */\n\n\n getDiff(additions, removals) {\n const a = this.current;\n const b = this.previous;\n const al = a.length;\n const bl = b.length;\n let j = 0;\n\n for (let i = 0; i < al; i++) {\n let found = false;\n const keyA = a[i];\n\n while (keyA > b[j]) {\n j++;\n }\n\n found = keyA === b[j];\n\n if (!found) {\n unpackAndPush(additions, keyA);\n }\n }\n\n j = 0;\n\n for (let i = 0; i < bl; i++) {\n let found = false;\n const keyB = b[i];\n\n while (keyB > a[j]) {\n j++;\n }\n\n found = a[j] === keyB;\n\n if (!found) {\n unpackAndPush(removals, keyB);\n }\n }\n }\n\n}\n\nfunction unpackAndPush(array, key) {\n array.push((key & 0xffff0000) >> 16, key & 0x0000ffff);\n}\n\nconst getKey = (i, j) => i < j ? `${i}-${j}` : `${j}-${i}`;\n/**\n * TupleDictionary\n */\n\n\nclass TupleDictionary {\n constructor() {\n this.data = {\n keys: []\n };\n }\n\n /** get */\n get(i, j) {\n const key = getKey(i, j);\n return this.data[key];\n }\n /** set */\n\n\n set(i, j, value) {\n const key = getKey(i, j); // Check if key already exists\n\n if (!this.get(i, j)) {\n this.data.keys.push(key);\n }\n\n this.data[key] = value;\n }\n /** delete */\n\n\n delete(i, j) {\n const key = getKey(i, j);\n const index = this.data.keys.indexOf(key);\n\n if (index !== -1) {\n this.data.keys.splice(index, 1);\n }\n\n delete this.data[key];\n }\n /** reset */\n\n\n reset() {\n const data = this.data;\n const keys = data.keys;\n\n while (keys.length > 0) {\n const key = keys.pop();\n delete data[key];\n }\n }\n\n}\n\n/**\n * The physics world\n */\nclass World extends EventTarget {\n /**\n * Currently / last used timestep. Is set to -1 if not available. This value is updated before each internal step, which means that it is \"fresh\" inside event callbacks.\n */\n\n /**\n * Makes bodies go to sleep when they've been inactive.\n * @default false\n */\n\n /**\n * All the current contacts (instances of ContactEquation) in the world.\n */\n\n /**\n * How often to normalize quaternions. Set to 0 for every step, 1 for every second etc.. A larger value increases performance. If bodies tend to explode, set to a smaller value (zero to be sure nothing can go wrong).\n * @default 0\n */\n\n /**\n * Set to true to use fast quaternion normalization. It is often enough accurate to use.\n * If bodies tend to explode, set to false.\n * @default false\n */\n\n /**\n * The wall-clock time since simulation start.\n */\n\n /**\n * Number of timesteps taken since start.\n */\n\n /**\n * Default and last timestep sizes.\n */\n\n /**\n * The gravity of the world.\n */\n\n /**\n * Gravity to use when approximating the friction max force (mu*mass*gravity).\n * If undefined, global gravity will be used.\n * Use to enable friction in a World with a null gravity vector (no gravity).\n */\n\n /**\n * The broadphase algorithm to use.\n * @default NaiveBroadphase\n */\n\n /**\n * All bodies in this world\n */\n\n /**\n * True if any bodies are not sleeping, false if every body is sleeping.\n */\n\n /**\n * The solver algorithm to use.\n * @default GSSolver\n */\n\n /**\n * collisionMatrix\n */\n\n /**\n * CollisionMatrix from the previous step.\n */\n\n /**\n * All added contactmaterials.\n */\n\n /**\n * Used to look up a ContactMaterial given two instances of Material.\n */\n\n /**\n * The default material of the bodies.\n */\n\n /**\n * This contact material is used if no suitable contactmaterial is found for a contact.\n */\n\n /**\n * Time accumulator for interpolation.\n * @see https://gafferongames.com/game-physics/fix-your-timestep/\n */\n\n /**\n * Dispatched after a body has been added to the world.\n */\n\n /**\n * Dispatched after a body has been removed from the world.\n */\n constructor(options) {\n if (options === void 0) {\n options = {};\n }\n\n super();\n this.dt = -1;\n this.allowSleep = !!options.allowSleep;\n this.contacts = [];\n this.frictionEquations = [];\n this.quatNormalizeSkip = options.quatNormalizeSkip !== undefined ? options.quatNormalizeSkip : 0;\n this.quatNormalizeFast = options.quatNormalizeFast !== undefined ? options.quatNormalizeFast : false;\n this.time = 0.0;\n this.stepnumber = 0;\n this.default_dt = 1 / 60;\n this.nextId = 0;\n this.gravity = new Vec3();\n\n if (options.gravity) {\n this.gravity.copy(options.gravity);\n }\n\n if (options.frictionGravity) {\n this.frictionGravity = new Vec3();\n this.frictionGravity.copy(options.frictionGravity);\n }\n\n this.broadphase = options.broadphase !== undefined ? options.broadphase : new NaiveBroadphase();\n this.bodies = [];\n this.hasActiveBodies = false;\n this.solver = options.solver !== undefined ? options.solver : new GSSolver();\n this.constraints = [];\n this.narrowphase = new Narrowphase(this);\n this.collisionMatrix = new ArrayCollisionMatrix();\n this.collisionMatrixPrevious = new ArrayCollisionMatrix();\n this.bodyOverlapKeeper = new OverlapKeeper();\n this.shapeOverlapKeeper = new OverlapKeeper();\n this.contactmaterials = [];\n this.contactMaterialTable = new TupleDictionary();\n this.defaultMaterial = new Material('default');\n this.defaultContactMaterial = new ContactMaterial(this.defaultMaterial, this.defaultMaterial, {\n friction: 0.3,\n restitution: 0.0\n });\n this.doProfiling = false;\n this.profile = {\n solve: 0,\n makeContactConstraints: 0,\n broadphase: 0,\n integrate: 0,\n narrowphase: 0\n };\n this.accumulator = 0;\n this.subsystems = [];\n this.addBodyEvent = {\n type: 'addBody',\n body: null\n };\n this.removeBodyEvent = {\n type: 'removeBody',\n body: null\n };\n this.idToBodyMap = {};\n this.broadphase.setWorld(this);\n }\n /**\n * Get the contact material between materials m1 and m2\n * @return The contact material if it was found.\n */\n\n\n getContactMaterial(m1, m2) {\n return this.contactMaterialTable.get(m1.id, m2.id);\n }\n /**\n * Store old collision state info\n */\n\n\n collisionMatrixTick() {\n const temp = this.collisionMatrixPrevious;\n this.collisionMatrixPrevious = this.collisionMatrix;\n this.collisionMatrix = temp;\n this.collisionMatrix.reset();\n this.bodyOverlapKeeper.tick();\n this.shapeOverlapKeeper.tick();\n }\n /**\n * Add a constraint to the simulation.\n */\n\n\n addConstraint(c) {\n this.constraints.push(c);\n }\n /**\n * Removes a constraint\n */\n\n\n removeConstraint(c) {\n const idx = this.constraints.indexOf(c);\n\n if (idx !== -1) {\n this.constraints.splice(idx, 1);\n }\n }\n /**\n * Raycast test\n * @deprecated Use .raycastAll, .raycastClosest or .raycastAny instead.\n */\n\n\n rayTest(from, to, result) {\n if (result instanceof RaycastResult) {\n // Do raycastClosest\n this.raycastClosest(from, to, {\n skipBackfaces: true\n }, result);\n } else {\n // Do raycastAll\n this.raycastAll(from, to, {\n skipBackfaces: true\n }, result);\n }\n }\n /**\n * Ray cast against all bodies. The provided callback will be executed for each hit with a RaycastResult as single argument.\n * @return True if any body was hit.\n */\n\n\n raycastAll(from, to, options, callback) {\n if (options === void 0) {\n options = {};\n }\n\n options.mode = Ray.ALL;\n options.from = from;\n options.to = to;\n options.callback = callback;\n return tmpRay.intersectWorld(this, options);\n }\n /**\n * Ray cast, and stop at the first result. Note that the order is random - but the method is fast.\n * @return True if any body was hit.\n */\n\n\n raycastAny(from, to, options, result) {\n if (options === void 0) {\n options = {};\n }\n\n options.mode = Ray.ANY;\n options.from = from;\n options.to = to;\n options.result = result;\n return tmpRay.intersectWorld(this, options);\n }\n /**\n * Ray cast, and return information of the closest hit.\n * @return True if any body was hit.\n */\n\n\n raycastClosest(from, to, options, result) {\n if (options === void 0) {\n options = {};\n }\n\n options.mode = Ray.CLOSEST;\n options.from = from;\n options.to = to;\n options.result = result;\n return tmpRay.intersectWorld(this, options);\n }\n /**\n * Add a rigid body to the simulation.\n * @todo If the simulation has not yet started, why recrete and copy arrays for each body? Accumulate in dynamic arrays in this case.\n * @todo Adding an array of bodies should be possible. This would save some loops too\n */\n\n\n addBody(body) {\n if (this.bodies.includes(body)) {\n return;\n }\n\n body.index = this.bodies.length;\n this.bodies.push(body);\n body.world = this;\n body.initPosition.copy(body.position);\n body.initVelocity.copy(body.velocity);\n body.timeLastSleepy = this.time;\n\n if (body instanceof Body) {\n body.initAngularVelocity.copy(body.angularVelocity);\n body.initQuaternion.copy(body.quaternion);\n }\n\n this.collisionMatrix.setNumObjects(this.bodies.length);\n this.addBodyEvent.body = body;\n this.idToBodyMap[body.id] = body;\n this.dispatchEvent(this.addBodyEvent);\n }\n /**\n * Remove a rigid body from the simulation.\n */\n\n\n removeBody(body) {\n body.world = null;\n const n = this.bodies.length - 1;\n const bodies = this.bodies;\n const idx = bodies.indexOf(body);\n\n if (idx !== -1) {\n bodies.splice(idx, 1); // Todo: should use a garbage free method\n // Recompute index\n\n for (let i = 0; i !== bodies.length; i++) {\n bodies[i].index = i;\n }\n\n this.collisionMatrix.setNumObjects(n);\n this.removeBodyEvent.body = body;\n delete this.idToBodyMap[body.id];\n this.dispatchEvent(this.removeBodyEvent);\n }\n }\n\n getBodyById(id) {\n return this.idToBodyMap[id];\n }\n /**\n * @todo Make a faster map\n */\n\n\n getShapeById(id) {\n const bodies = this.bodies;\n\n for (let i = 0; i < bodies.length; i++) {\n const shapes = bodies[i].shapes;\n\n for (let j = 0; j < shapes.length; j++) {\n const shape = shapes[j];\n\n if (shape.id === id) {\n return shape;\n }\n }\n }\n\n return null;\n }\n /**\n * Adds a contact material to the World\n */\n\n\n addContactMaterial(cmat) {\n // Add contact material\n this.contactmaterials.push(cmat); // Add current contact material to the material table\n\n this.contactMaterialTable.set(cmat.materials[0].id, cmat.materials[1].id, cmat);\n }\n /**\n * Removes a contact material from the World.\n */\n\n\n removeContactMaterial(cmat) {\n const idx = this.contactmaterials.indexOf(cmat);\n\n if (idx === -1) {\n return;\n }\n\n this.contactmaterials.splice(idx, 1);\n this.contactMaterialTable.delete(cmat.materials[0].id, cmat.materials[1].id);\n }\n /**\n * Step the simulation forward keeping track of last called time\n * to be able to step the world at a fixed rate, independently of framerate.\n *\n * @param dt The fixed time step size to use (default: 1 / 60).\n * @param maxSubSteps Maximum number of fixed steps to take per function call (default: 10).\n * @see https://gafferongames.com/post/fix_your_timestep/\n * @example\n * // Run the simulation independently of framerate every 1 / 60 ms\n * world.fixedStep()\n */\n\n\n fixedStep(dt, maxSubSteps) {\n if (dt === void 0) {\n dt = 1 / 60;\n }\n\n if (maxSubSteps === void 0) {\n maxSubSteps = 10;\n }\n\n const time = performance.now() / 1000; // seconds\n\n if (!this.lastCallTime) {\n this.step(dt, undefined, maxSubSteps);\n } else {\n const timeSinceLastCalled = time - this.lastCallTime;\n this.step(dt, timeSinceLastCalled, maxSubSteps);\n }\n\n this.lastCallTime = time;\n }\n /**\n * Step the physics world forward in time.\n *\n * There are two modes. The simple mode is fixed timestepping without interpolation. In this case you only use the first argument. The second case uses interpolation. In that you also provide the time since the function was last used, as well as the maximum fixed timesteps to take.\n *\n * @param dt The fixed time step size to use.\n * @param timeSinceLastCalled The time elapsed since the function was last called.\n * @param maxSubSteps Maximum number of fixed steps to take per function call (default: 10).\n * @see https://web.archive.org/web/20180426154531/http://bulletphysics.org/mediawiki-1.5.8/index.php/Stepping_The_World#What_do_the_parameters_to_btDynamicsWorld::stepSimulation_mean.3F\n * @example\n * // fixed timestepping without interpolation\n * world.step(1 / 60)\n */\n\n\n step(dt, timeSinceLastCalled, maxSubSteps) {\n if (maxSubSteps === void 0) {\n maxSubSteps = 10;\n }\n\n if (timeSinceLastCalled === undefined) {\n // Fixed, simple stepping\n this.internalStep(dt); // Increment time\n\n this.time += dt;\n } else {\n this.accumulator += timeSinceLastCalled;\n const t0 = performance.now();\n let substeps = 0;\n\n while (this.accumulator >= dt && substeps < maxSubSteps) {\n // Do fixed steps to catch up\n this.internalStep(dt);\n this.accumulator -= dt;\n substeps++;\n\n if (performance.now() - t0 > dt * 1000) {\n // The framerate is not interactive anymore.\n // We are below the target framerate.\n // Better bail out.\n break;\n }\n } // Remove the excess accumulator, since we may not\n // have had enough substeps available to catch up\n\n\n this.accumulator = this.accumulator % dt;\n const t = this.accumulator / dt;\n\n for (let j = 0; j !== this.bodies.length; j++) {\n const b = this.bodies[j];\n b.previousPosition.lerp(b.position, t, b.interpolatedPosition);\n b.previousQuaternion.slerp(b.quaternion, t, b.interpolatedQuaternion);\n b.previousQuaternion.normalize();\n }\n\n this.time += timeSinceLastCalled;\n }\n }\n\n internalStep(dt) {\n this.dt = dt;\n const contacts = this.contacts;\n const p1 = World_step_p1;\n const p2 = World_step_p2;\n const N = this.bodies.length;\n const bodies = this.bodies;\n const solver = this.solver;\n const gravity = this.gravity;\n const doProfiling = this.doProfiling;\n const profile = this.profile;\n const DYNAMIC = Body.DYNAMIC;\n let profilingStart = -Infinity;\n const constraints = this.constraints;\n const frictionEquationPool = World_step_frictionEquationPool;\n gravity.length();\n const gx = gravity.x;\n const gy = gravity.y;\n const gz = gravity.z;\n let i = 0;\n\n if (doProfiling) {\n profilingStart = performance.now();\n } // Add gravity to all objects\n\n\n for (i = 0; i !== N; i++) {\n const bi = bodies[i];\n\n if (bi.type === DYNAMIC) {\n // Only for dynamic bodies\n const f = bi.force;\n const m = bi.mass;\n f.x += m * gx;\n f.y += m * gy;\n f.z += m * gz;\n }\n } // Update subsystems\n\n\n for (let i = 0, Nsubsystems = this.subsystems.length; i !== Nsubsystems; i++) {\n this.subsystems[i].update();\n } // Collision detection\n\n\n if (doProfiling) {\n profilingStart = performance.now();\n }\n\n p1.length = 0; // Clean up pair arrays from last step\n\n p2.length = 0;\n this.broadphase.collisionPairs(this, p1, p2);\n\n if (doProfiling) {\n profile.broadphase = performance.now() - profilingStart;\n } // Remove constrained pairs with collideConnected == false\n\n\n let Nconstraints = constraints.length;\n\n for (i = 0; i !== Nconstraints; i++) {\n const c = constraints[i];\n\n if (!c.collideConnected) {\n for (let j = p1.length - 1; j >= 0; j -= 1) {\n if (c.bodyA === p1[j] && c.bodyB === p2[j] || c.bodyB === p1[j] && c.bodyA === p2[j]) {\n p1.splice(j, 1);\n p2.splice(j, 1);\n }\n }\n }\n }\n\n this.collisionMatrixTick(); // Generate contacts\n\n if (doProfiling) {\n profilingStart = performance.now();\n }\n\n const oldcontacts = World_step_oldContacts;\n const NoldContacts = contacts.length;\n\n for (i = 0; i !== NoldContacts; i++) {\n oldcontacts.push(contacts[i]);\n }\n\n contacts.length = 0; // Transfer FrictionEquation from current list to the pool for reuse\n\n const NoldFrictionEquations = this.frictionEquations.length;\n\n for (i = 0; i !== NoldFrictionEquations; i++) {\n frictionEquationPool.push(this.frictionEquations[i]);\n }\n\n this.frictionEquations.length = 0;\n this.narrowphase.getContacts(p1, p2, this, contacts, oldcontacts, // To be reused\n this.frictionEquations, frictionEquationPool);\n\n if (doProfiling) {\n profile.narrowphase = performance.now() - profilingStart;\n } // Loop over all collisions\n\n\n if (doProfiling) {\n profilingStart = performance.now();\n } // Add all friction eqs\n\n\n for (i = 0; i < this.frictionEquations.length; i++) {\n solver.addEquation(this.frictionEquations[i]);\n }\n\n const ncontacts = contacts.length;\n\n for (let k = 0; k !== ncontacts; k++) {\n // Current contact\n const c = contacts[k]; // Get current collision indeces\n\n const bi = c.bi;\n const bj = c.bj;\n const si = c.si;\n const sj = c.sj; // Get collision properties\n\n let cm;\n\n if (bi.material && bj.material) {\n cm = this.getContactMaterial(bi.material, bj.material) || this.defaultContactMaterial;\n } else {\n cm = this.defaultContactMaterial;\n } // c.enabled = bi.collisionResponse && bj.collisionResponse && si.collisionResponse && sj.collisionResponse;\n\n\n cm.friction; // c.restitution = cm.restitution;\n // If friction or restitution were specified in the material, use them\n\n if (bi.material && bj.material) {\n if (bi.material.friction >= 0 && bj.material.friction >= 0) {\n bi.material.friction * bj.material.friction;\n }\n\n if (bi.material.restitution >= 0 && bj.material.restitution >= 0) {\n c.restitution = bi.material.restitution * bj.material.restitution;\n }\n } // c.setSpookParams(\n // cm.contactEquationStiffness,\n // cm.contactEquationRelaxation,\n // dt\n // );\n\n\n solver.addEquation(c); // // Add friction constraint equation\n // if(mu > 0){\n // \t// Create 2 tangent equations\n // \tconst mug = mu * gnorm;\n // \tconst reducedMass = (bi.invMass + bj.invMass);\n // \tif(reducedMass > 0){\n // \t\treducedMass = 1/reducedMass;\n // \t}\n // \tconst pool = frictionEquationPool;\n // \tconst c1 = pool.length ? pool.pop() : new FrictionEquation(bi,bj,mug*reducedMass);\n // \tconst c2 = pool.length ? pool.pop() : new FrictionEquation(bi,bj,mug*reducedMass);\n // \tthis.frictionEquations.push(c1, c2);\n // \tc1.bi = c2.bi = bi;\n // \tc1.bj = c2.bj = bj;\n // \tc1.minForce = c2.minForce = -mug*reducedMass;\n // \tc1.maxForce = c2.maxForce = mug*reducedMass;\n // \t// Copy over the relative vectors\n // \tc1.ri.copy(c.ri);\n // \tc1.rj.copy(c.rj);\n // \tc2.ri.copy(c.ri);\n // \tc2.rj.copy(c.rj);\n // \t// Construct tangents\n // \tc.ni.tangents(c1.t, c2.t);\n // // Set spook params\n // c1.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, dt);\n // c2.setSpookParams(cm.frictionEquationStiffness, cm.frictionEquationRelaxation, dt);\n // c1.enabled = c2.enabled = c.enabled;\n // \t// Add equations to solver\n // \tsolver.addEquation(c1);\n // \tsolver.addEquation(c2);\n // }\n\n if (bi.allowSleep && bi.type === Body.DYNAMIC && bi.sleepState === Body.SLEEPING && bj.sleepState === Body.AWAKE && bj.type !== Body.STATIC) {\n const speedSquaredB = bj.velocity.lengthSquared() + bj.angularVelocity.lengthSquared();\n const speedLimitSquaredB = bj.sleepSpeedLimit ** 2;\n\n if (speedSquaredB >= speedLimitSquaredB * 2) {\n bi.wakeUpAfterNarrowphase = true;\n }\n }\n\n if (bj.allowSleep && bj.type === Body.DYNAMIC && bj.sleepState === Body.SLEEPING && bi.sleepState === Body.AWAKE && bi.type !== Body.STATIC) {\n const speedSquaredA = bi.velocity.lengthSquared() + bi.angularVelocity.lengthSquared();\n const speedLimitSquaredA = bi.sleepSpeedLimit ** 2;\n\n if (speedSquaredA >= speedLimitSquaredA * 2) {\n bj.wakeUpAfterNarrowphase = true;\n }\n } // Now we know that i and j are in contact. Set collision matrix state\n\n\n this.collisionMatrix.set(bi, bj, true);\n\n if (!this.collisionMatrixPrevious.get(bi, bj)) {\n // First contact!\n // We reuse the collideEvent object, otherwise we will end up creating new objects for each new contact, even if there's no event listener attached.\n World_step_collideEvent.body = bj;\n World_step_collideEvent.contact = c;\n bi.dispatchEvent(World_step_collideEvent);\n World_step_collideEvent.body = bi;\n bj.dispatchEvent(World_step_collideEvent);\n }\n\n this.bodyOverlapKeeper.set(bi.id, bj.id);\n this.shapeOverlapKeeper.set(si.id, sj.id);\n }\n\n this.emitContactEvents();\n\n if (doProfiling) {\n profile.makeContactConstraints = performance.now() - profilingStart;\n profilingStart = performance.now();\n } // Wake up bodies\n\n\n for (i = 0; i !== N; i++) {\n const bi = bodies[i];\n\n if (bi.wakeUpAfterNarrowphase) {\n bi.wakeUp();\n bi.wakeUpAfterNarrowphase = false;\n }\n } // Add user-added constraints\n\n\n Nconstraints = constraints.length;\n\n for (i = 0; i !== Nconstraints; i++) {\n const c = constraints[i];\n c.update();\n\n for (let j = 0, Neq = c.equations.length; j !== Neq; j++) {\n const eq = c.equations[j];\n solver.addEquation(eq);\n }\n } // Solve the constrained system\n\n\n solver.solve(dt, this);\n\n if (doProfiling) {\n profile.solve = performance.now() - profilingStart;\n } // Remove all contacts from solver\n\n\n solver.removeAllEquations(); // Apply damping, see http://code.google.com/p/bullet/issues/detail?id=74 for details\n\n const pow = Math.pow;\n\n for (i = 0; i !== N; i++) {\n const bi = bodies[i];\n\n if (bi.type & DYNAMIC) {\n // Only for dynamic bodies\n const ld = pow(1.0 - bi.linearDamping, dt);\n const v = bi.velocity;\n v.scale(ld, v);\n const av = bi.angularVelocity;\n\n if (av) {\n const ad = pow(1.0 - bi.angularDamping, dt);\n av.scale(ad, av);\n }\n }\n }\n\n this.dispatchEvent(World_step_preStepEvent); // Leap frog\n // vnew = v + h*f/m\n // xnew = x + h*vnew\n\n if (doProfiling) {\n profilingStart = performance.now();\n }\n\n const stepnumber = this.stepnumber;\n const quatNormalize = stepnumber % (this.quatNormalizeSkip + 1) === 0;\n const quatNormalizeFast = this.quatNormalizeFast;\n\n for (i = 0; i !== N; i++) {\n bodies[i].integrate(dt, quatNormalize, quatNormalizeFast);\n }\n\n this.clearForces();\n this.broadphase.dirty = true;\n\n if (doProfiling) {\n profile.integrate = performance.now() - profilingStart;\n } // Update step number\n\n\n this.stepnumber += 1;\n this.dispatchEvent(World_step_postStepEvent); // Sleeping update\n\n let hasActiveBodies = true;\n\n if (this.allowSleep) {\n hasActiveBodies = false;\n\n for (i = 0; i !== N; i++) {\n const bi = bodies[i];\n bi.sleepTick(this.time);\n\n if (bi.sleepState !== Body.SLEEPING) {\n hasActiveBodies = true;\n }\n }\n }\n\n this.hasActiveBodies = hasActiveBodies;\n }\n\n emitContactEvents() {\n const hasBeginContact = this.hasAnyEventListener('beginContact');\n const hasEndContact = this.hasAnyEventListener('endContact');\n\n if (hasBeginContact || hasEndContact) {\n this.bodyOverlapKeeper.getDiff(additions, removals);\n }\n\n if (hasBeginContact) {\n for (let i = 0, l = additions.length; i < l; i += 2) {\n beginContactEvent.bodyA = this.getBodyById(additions[i]);\n beginContactEvent.bodyB = this.getBodyById(additions[i + 1]);\n this.dispatchEvent(beginContactEvent);\n }\n\n beginContactEvent.bodyA = beginContactEvent.bodyB = null;\n }\n\n if (hasEndContact) {\n for (let i = 0, l = removals.length; i < l; i += 2) {\n endContactEvent.bodyA = this.getBodyById(removals[i]);\n endContactEvent.bodyB = this.getBodyById(removals[i + 1]);\n this.dispatchEvent(endContactEvent);\n }\n\n endContactEvent.bodyA = endContactEvent.bodyB = null;\n }\n\n additions.length = removals.length = 0;\n const hasBeginShapeContact = this.hasAnyEventListener('beginShapeContact');\n const hasEndShapeContact = this.hasAnyEventListener('endShapeContact');\n\n if (hasBeginShapeContact || hasEndShapeContact) {\n this.shapeOverlapKeeper.getDiff(additions, removals);\n }\n\n if (hasBeginShapeContact) {\n for (let i = 0, l = additions.length; i < l; i += 2) {\n const shapeA = this.getShapeById(additions[i]);\n const shapeB = this.getShapeById(additions[i + 1]);\n beginShapeContactEvent.shapeA = shapeA;\n beginShapeContactEvent.shapeB = shapeB;\n if (shapeA) beginShapeContactEvent.bodyA = shapeA.body;\n if (shapeB) beginShapeContactEvent.bodyB = shapeB.body;\n this.dispatchEvent(beginShapeContactEvent);\n }\n\n beginShapeContactEvent.bodyA = beginShapeContactEvent.bodyB = beginShapeContactEvent.shapeA = beginShapeContactEvent.shapeB = null;\n }\n\n if (hasEndShapeContact) {\n for (let i = 0, l = removals.length; i < l; i += 2) {\n const shapeA = this.getShapeById(removals[i]);\n const shapeB = this.getShapeById(removals[i + 1]);\n endShapeContactEvent.shapeA = shapeA;\n endShapeContactEvent.shapeB = shapeB;\n if (shapeA) endShapeContactEvent.bodyA = shapeA.body;\n if (shapeB) endShapeContactEvent.bodyB = shapeB.body;\n this.dispatchEvent(endShapeContactEvent);\n }\n\n endShapeContactEvent.bodyA = endShapeContactEvent.bodyB = endShapeContactEvent.shapeA = endShapeContactEvent.shapeB = null;\n }\n }\n /**\n * Sets all body forces in the world to zero.\n */\n\n\n clearForces() {\n const bodies = this.bodies;\n const N = bodies.length;\n\n for (let i = 0; i !== N; i++) {\n const b = bodies[i];\n b.force;\n b.torque;\n b.force.set(0, 0, 0);\n b.torque.set(0, 0, 0);\n }\n }\n\n} // Temp stuff\n\nnew AABB();\nconst tmpRay = new Ray(); // performance.now() fallback on Date.now()\n\nconst performance = globalThis.performance || {};\n\nif (!performance.now) {\n let nowOffset = Date.now();\n\n if (performance.timing && performance.timing.navigationStart) {\n nowOffset = performance.timing.navigationStart;\n }\n\n performance.now = () => Date.now() - nowOffset;\n}\n\nnew Vec3(); // Dispatched after the world has stepped forward in time.\n// Reusable event objects to save memory.\n\nconst World_step_postStepEvent = {\n type: 'postStep'\n}; // Dispatched before the world steps forward in time.\n\nconst World_step_preStepEvent = {\n type: 'preStep'\n};\nconst World_step_collideEvent = {\n type: Body.COLLIDE_EVENT_NAME,\n body: null,\n contact: null\n}; // Pools for unused objects\n\nconst World_step_oldContacts = [];\nconst World_step_frictionEquationPool = []; // Reusable arrays for collision pairs\n\nconst World_step_p1 = [];\nconst World_step_p2 = []; // Stuff for emitContactEvents\n\nconst additions = [];\nconst removals = [];\nconst beginContactEvent = {\n type: 'beginContact',\n bodyA: null,\n bodyB: null\n};\nconst endContactEvent = {\n type: 'endContact',\n bodyA: null,\n bodyB: null\n};\nconst beginShapeContactEvent = {\n type: 'beginShapeContact',\n bodyA: null,\n bodyB: null,\n shapeA: null,\n shapeB: null\n};\nconst endShapeContactEvent = {\n type: 'endShapeContact',\n bodyA: null,\n bodyB: null,\n shapeA: null,\n shapeB: null\n};\n\n\n\n\n//# sourceURL=webpack://3d_game/./node_modules/cannon-es/dist/cannon-es.js?")},"./node_modules/three/build/three.module.js":function _node_modules_three_build_threeModuleJs(__unused_webpack___webpack_module__,__webpack_exports__,__webpack_require__){eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ACESFilmicToneMapping: () => (/* binding */ ACESFilmicToneMapping),\n/* harmony export */ AddEquation: () => (/* binding */ AddEquation),\n/* harmony export */ AddOperation: () => (/* binding */ AddOperation),\n/* harmony export */ AdditiveAnimationBlendMode: () => (/* binding */ AdditiveAnimationBlendMode),\n/* harmony export */ AdditiveBlending: () => (/* binding */ AdditiveBlending),\n/* harmony export */ AgXToneMapping: () => (/* binding */ AgXToneMapping),\n/* harmony export */ AlphaFormat: () => (/* binding */ AlphaFormat),\n/* harmony export */ AlwaysCompare: () => (/* binding */ AlwaysCompare),\n/* harmony export */ AlwaysDepth: () => (/* binding */ AlwaysDepth),\n/* harmony export */ AlwaysStencilFunc: () => (/* binding */ AlwaysStencilFunc),\n/* harmony export */ AmbientLight: () => (/* binding */ AmbientLight),\n/* harmony export */ AnimationAction: () => (/* binding */ AnimationAction),\n/* harmony export */ AnimationClip: () => (/* binding */ AnimationClip),\n/* harmony export */ AnimationLoader: () => (/* binding */ AnimationLoader),\n/* harmony export */ AnimationMixer: () => (/* binding */ AnimationMixer),\n/* harmony export */ AnimationObjectGroup: () => (/* binding */ AnimationObjectGroup),\n/* harmony export */ AnimationUtils: () => (/* binding */ AnimationUtils),\n/* harmony export */ ArcCurve: () => (/* binding */ ArcCurve),\n/* harmony export */ ArrayCamera: () => (/* binding */ ArrayCamera),\n/* harmony export */ ArrowHelper: () => (/* binding */ ArrowHelper),\n/* harmony export */ AttachedBindMode: () => (/* binding */ AttachedBindMode),\n/* harmony export */ Audio: () => (/* binding */ Audio),\n/* harmony export */ AudioAnalyser: () => (/* binding */ AudioAnalyser),\n/* harmony export */ AudioContext: () => (/* binding */ AudioContext),\n/* harmony export */ AudioListener: () => (/* binding */ AudioListener),\n/* harmony export */ AudioLoader: () => (/* binding */ AudioLoader),\n/* harmony export */ AxesHelper: () => (/* binding */ AxesHelper),\n/* harmony export */ BackSide: () => (/* binding */ BackSide),\n/* harmony export */ BasicDepthPacking: () => (/* binding */ BasicDepthPacking),\n/* harmony export */ BasicShadowMap: () => (/* binding */ BasicShadowMap),\n/* harmony export */ BatchedMesh: () => (/* binding */ BatchedMesh),\n/* harmony export */ Bone: () => (/* binding */ Bone),\n/* harmony export */ BooleanKeyframeTrack: () => (/* binding */ BooleanKeyframeTrack),\n/* harmony export */ Box2: () => (/* binding */ Box2),\n/* harmony export */ Box3: () => (/* binding */ Box3),\n/* harmony export */ Box3Helper: () => (/* binding */ Box3Helper),\n/* harmony export */ BoxGeometry: () => (/* binding */ BoxGeometry),\n/* harmony export */ BoxHelper: () => (/* binding */ BoxHelper),\n/* harmony export */ BufferAttribute: () => (/* binding */ BufferAttribute),\n/* harmony export */ BufferGeometry: () => (/* binding */ BufferGeometry),\n/* harmony export */ BufferGeometryLoader: () => (/* binding */ BufferGeometryLoader),\n/* harmony export */ ByteType: () => (/* binding */ ByteType),\n/* harmony export */ Cache: () => (/* binding */ Cache),\n/* harmony export */ Camera: () => (/* binding */ Camera),\n/* harmony export */ CameraHelper: () => (/* binding */ CameraHelper),\n/* harmony export */ CanvasTexture: () => (/* binding */ CanvasTexture),\n/* harmony export */ CapsuleGeometry: () => (/* binding */ CapsuleGeometry),\n/* harmony export */ CatmullRomCurve3: () => (/* binding */ CatmullRomCurve3),\n/* harmony export */ CineonToneMapping: () => (/* binding */ CineonToneMapping),\n/* harmony export */ CircleGeometry: () => (/* binding */ CircleGeometry),\n/* harmony export */ ClampToEdgeWrapping: () => (/* binding */ ClampToEdgeWrapping),\n/* harmony export */ Clock: () => (/* binding */ Clock),\n/* harmony export */ Color: () => (/* binding */ Color),\n/* harmony export */ ColorKeyframeTrack: () => (/* binding */ ColorKeyframeTrack),\n/* harmony export */ ColorManagement: () => (/* binding */ ColorManagement),\n/* harmony export */ CompressedArrayTexture: () => (/* binding */ CompressedArrayTexture),\n/* harmony export */ CompressedCubeTexture: () => (/* binding */ CompressedCubeTexture),\n/* harmony export */ CompressedTexture: () => (/* binding */ CompressedTexture),\n/* harmony export */ CompressedTextureLoader: () => (/* binding */ CompressedTextureLoader),\n/* harmony export */ ConeGeometry: () => (/* binding */ ConeGeometry),\n/* harmony export */ ConstantAlphaFactor: () => (/* binding */ ConstantAlphaFactor),\n/* harmony export */ ConstantColorFactor: () => (/* binding */ ConstantColorFactor),\n/* harmony export */ Controls: () => (/* binding */ Controls),\n/* harmony export */ CubeCamera: () => (/* binding */ CubeCamera),\n/* harmony export */ CubeReflectionMapping: () => (/* binding */ CubeReflectionMapping),\n/* harmony export */ CubeRefractionMapping: () => (/* binding */ CubeRefractionMapping),\n/* harmony export */ CubeTexture: () => (/* binding */ CubeTexture),\n/* harmony export */ CubeTextureLoader: () => (/* binding */ CubeTextureLoader),\n/* harmony export */ CubeUVReflectionMapping: () => (/* binding */ CubeUVReflectionMapping),\n/* harmony export */ CubicBezierCurve: () => (/* binding */ CubicBezierCurve),\n/* harmony export */ CubicBezierCurve3: () => (/* binding */ CubicBezierCurve3),\n/* harmony export */ CubicInterpolant: () => (/* binding */ CubicInterpolant),\n/* harmony export */ CullFaceBack: () => (/* binding */ CullFaceBack),\n/* harmony export */ CullFaceFront: () => (/* binding */ CullFaceFront),\n/* harmony export */ CullFaceFrontBack: () => (/* binding */ CullFaceFrontBack),\n/* harmony export */ CullFaceNone: () => (/* binding */ CullFaceNone),\n/* harmony export */ Curve: () => (/* binding */ Curve),\n/* harmony export */ CurvePath: () => (/* binding */ CurvePath),\n/* harmony export */ CustomBlending: () => (/* binding */ CustomBlending),\n/* harmony export */ CustomToneMapping: () => (/* binding */ CustomToneMapping),\n/* harmony export */ CylinderGeometry: () => (/* binding */ CylinderGeometry),\n/* harmony export */ Cylindrical: () => (/* binding */ Cylindrical),\n/* harmony export */ Data3DTexture: () => (/* binding */ Data3DTexture),\n/* harmony export */ DataArrayTexture: () => (/* binding */ DataArrayTexture),\n/* harmony export */ DataTexture: () => (/* binding */ DataTexture),\n/* harmony export */ DataTextureLoader: () => (/* binding */ DataTextureLoader),\n/* harmony export */ DataUtils: () => (/* binding */ DataUtils),\n/* harmony export */ DecrementStencilOp: () => (/* binding */ DecrementStencilOp),\n/* harmony export */ DecrementWrapStencilOp: () => (/* binding */ DecrementWrapStencilOp),\n/* harmony export */ DefaultLoadingManager: () => (/* binding */ DefaultLoadingManager),\n/* harmony export */ DepthFormat: () => (/* binding */ DepthFormat),\n/* harmony export */ DepthStencilFormat: () => (/* binding */ DepthStencilFormat),\n/* harmony export */ DepthTexture: () => (/* binding */ DepthTexture),\n/* harmony export */ DetachedBindMode: () => (/* binding */ DetachedBindMode),\n/* harmony export */ DirectionalLight: () => (/* binding */ DirectionalLight),\n/* harmony export */ DirectionalLightHelper: () => (/* binding */ DirectionalLightHelper),\n/* harmony export */ DiscreteInterpolant: () => (/* binding */ DiscreteInterpolant),\n/* harmony export */ DisplayP3ColorSpace: () => (/* binding */ DisplayP3ColorSpace),\n/* harmony export */ DodecahedronGeometry: () => (/* binding */ DodecahedronGeometry),\n/* harmony export */ DoubleSide: () => (/* binding */ DoubleSide),\n/* harmony export */ DstAlphaFactor: () => (/* binding */ DstAlphaFactor),\n/* harmony export */ DstColorFactor: () => (/* binding */ DstColorFactor),\n/* harmony export */ DynamicCopyUsage: () => (/* binding */ DynamicCopyUsage),\n/* harmony export */ DynamicDrawUsage: () => (/* binding */ DynamicDrawUsage),\n/* harmony export */ DynamicReadUsage: () => (/* binding */ DynamicReadUsage),\n/* harmony export */ EdgesGeometry: () => (/* binding */ EdgesGeometry),\n/* harmony export */ EllipseCurve: () => (/* binding */ EllipseCurve),\n/* harmony export */ EqualCompare: () => (/* binding */ EqualCompare),\n/* harmony export */ EqualDepth: () => (/* binding */ EqualDepth),\n/* harmony export */ EqualStencilFunc: () => (/* binding */ EqualStencilFunc),\n/* harmony export */ EquirectangularReflectionMapping: () => (/* binding */ EquirectangularReflectionMapping),\n/* harmony export */ EquirectangularRefractionMapping: () => (/* binding */ EquirectangularRefractionMapping),\n/* harmony export */ Euler: () => (/* binding */ Euler),\n/* harmony export */ EventDispatcher: () => (/* binding */ EventDispatcher),\n/* harmony export */ ExtrudeGeometry: () => (/* binding */ ExtrudeGeometry),\n/* harmony export */ FileLoader: () => (/* binding */ FileLoader),\n/* harmony export */ Float16BufferAttribute: () => (/* binding */ Float16BufferAttribute),\n/* harmony export */ Float32BufferAttribute: () => (/* binding */ Float32BufferAttribute),\n/* harmony export */ FloatType: () => (/* binding */ FloatType),\n/* harmony export */ Fog: () => (/* binding */ Fog),\n/* harmony export */ FogExp2: () => (/* binding */ FogExp2),\n/* harmony export */ FramebufferTexture: () => (/* binding */ FramebufferTexture),\n/* harmony export */ FrontSide: () => (/* binding */ FrontSide),\n/* harmony export */ Frustum: () => (/* binding */ Frustum),\n/* harmony export */ GLBufferAttribute: () => (/* binding */ GLBufferAttribute),\n/* harmony export */ GLSL1: () => (/* binding */ GLSL1),\n/* harmony export */ GLSL3: () => (/* binding */ GLSL3),\n/* harmony export */ GreaterCompare: () => (/* binding */ GreaterCompare),\n/* harmony export */ GreaterDepth: () => (/* binding */ GreaterDepth),\n/* harmony export */ GreaterEqualCompare: () => (/* binding */ GreaterEqualCompare),\n/* harmony export */ GreaterEqualDepth: () => (/* binding */ GreaterEqualDepth),\n/* harmony export */ GreaterEqualStencilFunc: () => (/* binding */ GreaterEqualStencilFunc),\n/* harmony export */ GreaterStencilFunc: () => (/* binding */ GreaterStencilFunc),\n/* harmony export */ GridHelper: () => (/* binding */ GridHelper),\n/* harmony export */ Group: () => (/* binding */ Group),\n/* harmony export */ HalfFloatType: () => (/* binding */ HalfFloatType),\n/* harmony export */ HemisphereLight: () => (/* binding */ HemisphereLight),\n/* harmony export */ HemisphereLightHelper: () => (/* binding */ HemisphereLightHelper),\n/* harmony export */ IcosahedronGeometry: () => (/* binding */ IcosahedronGeometry),\n/* harmony export */ ImageBitmapLoader: () => (/* binding */ ImageBitmapLoader),\n/* harmony export */ ImageLoader: () => (/* binding */ ImageLoader),\n/* harmony export */ ImageUtils: () => (/* binding */ ImageUtils),\n/* harmony export */ IncrementStencilOp: () => (/* binding */ IncrementStencilOp),\n/* harmony export */ IncrementWrapStencilOp: () => (/* binding */ IncrementWrapStencilOp),\n/* harmony export */ InstancedBufferAttribute: () => (/* binding */ InstancedBufferAttribute),\n/* harmony export */ InstancedBufferGeometry: () => (/* binding */ InstancedBufferGeometry),\n/* harmony export */ InstancedInterleavedBuffer: () => (/* binding */ InstancedInterleavedBuffer),\n/* harmony export */ InstancedMesh: () => (/* binding */ InstancedMesh),\n/* harmony export */ Int16BufferAttribute: () => (/* binding */ Int16BufferAttribute),\n/* harmony export */ Int32BufferAttribute: () => (/* binding */ Int32BufferAttribute),\n/* harmony export */ Int8BufferAttribute: () => (/* binding */ Int8BufferAttribute),\n/* harmony export */ IntType: () => (/* binding */ IntType),\n/* harmony export */ InterleavedBuffer: () => (/* binding */ InterleavedBuffer),\n/* harmony export */ InterleavedBufferAttribute: () => (/* binding */ InterleavedBufferAttribute),\n/* harmony export */ Interpolant: () => (/* binding */ Interpolant),\n/* harmony export */ InterpolateDiscrete: () => (/* binding */ InterpolateDiscrete),\n/* harmony export */ InterpolateLinear: () => (/* binding */ InterpolateLinear),\n/* harmony export */ InterpolateSmooth: () => (/* binding */ InterpolateSmooth),\n/* harmony export */ InvertStencilOp: () => (/* binding */ InvertStencilOp),\n/* harmony export */ KeepStencilOp: () => (/* binding */ KeepStencilOp),\n/* harmony export */ KeyframeTrack: () => (/* binding */ KeyframeTrack),\n/* harmony export */ LOD: () => (/* binding */ LOD),\n/* harmony export */ LatheGeometry: () => (/* binding */ LatheGeometry),\n/* harmony export */ Layers: () => (/* binding */ Layers),\n/* harmony export */ LessCompare: () => (/* binding */ LessCompare),\n/* harmony export */ LessDepth: () => (/* binding */ LessDepth),\n/* harmony export */ LessEqualCompare: () => (/* binding */ LessEqualCompare),\n/* harmony export */ LessEqualDepth: () => (/* binding */ LessEqualDepth),\n/* harmony export */ LessEqualStencilFunc: () => (/* binding */ LessEqualStencilFunc),\n/* harmony export */ LessStencilFunc: () => (/* binding */ LessStencilFunc),\n/* harmony export */ Light: () => (/* binding */ Light),\n/* harmony export */ LightProbe: () => (/* binding */ LightProbe),\n/* harmony export */ Line: () => (/* binding */ Line),\n/* harmony export */ Line3: () => (/* binding */ Line3),\n/* harmony export */ LineBasicMaterial: () => (/* binding */ LineBasicMaterial),\n/* harmony export */ LineCurve: () => (/* binding */ LineCurve),\n/* harmony export */ LineCurve3: () => (/* binding */ LineCurve3),\n/* harmony export */ LineDashedMaterial: () => (/* binding */ LineDashedMaterial),\n/* harmony export */ LineLoop: () => (/* binding */ LineLoop),\n/* harmony export */ LineSegments: () => (/* binding */ LineSegments),\n/* harmony export */ LinearDisplayP3ColorSpace: () => (/* binding */ LinearDisplayP3ColorSpace),\n/* harmony export */ LinearFilter: () => (/* binding */ LinearFilter),\n/* harmony export */ LinearInterpolant: () => (/* binding */ LinearInterpolant),\n/* harmony export */ LinearMipMapLinearFilter: () => (/* binding */ LinearMipMapLinearFilter),\n/* harmony export */ LinearMipMapNearestFilter: () => (/* binding */ LinearMipMapNearestFilter),\n/* harmony export */ LinearMipmapLinearFilter: () => (/* binding */ LinearMipmapLinearFilter),\n/* harmony export */ LinearMipmapNearestFilter: () => (/* binding */ LinearMipmapNearestFilter),\n/* harmony export */ LinearSRGBColorSpace: () => (/* binding */ LinearSRGBColorSpace),\n/* harmony export */ LinearToneMapping: () => (/* binding */ LinearToneMapping),\n/* harmony export */ LinearTransfer: () => (/* binding */ LinearTransfer),\n/* harmony export */ Loader: () => (/* binding */ Loader),\n/* harmony export */ LoaderUtils: () => (/* binding */ LoaderUtils),\n/* harmony export */ LoadingManager: () => (/* binding */ LoadingManager),\n/* harmony export */ LoopOnce: () => (/* binding */ LoopOnce),\n/* harmony export */ LoopPingPong: () => (/* binding */ LoopPingPong),\n/* harmony export */ LoopRepeat: () => (/* binding */ LoopRepeat),\n/* harmony export */ LuminanceAlphaFormat: () => (/* binding */ LuminanceAlphaFormat),\n/* harmony export */ LuminanceFormat: () => (/* binding */ LuminanceFormat),\n/* harmony export */ MOUSE: () => (/* binding */ MOUSE),\n/* harmony export */ Material: () => (/* binding */ Material),\n/* harmony export */ MaterialLoader: () => (/* binding */ MaterialLoader),\n/* harmony export */ MathUtils: () => (/* binding */ MathUtils),\n/* harmony export */ Matrix2: () => (/* binding */ Matrix2),\n/* harmony export */ Matrix3: () => (/* binding */ Matrix3),\n/* harmony export */ Matrix4: () => (/* binding */ Matrix4),\n/* harmony export */ MaxEquation: () => (/* binding */ MaxEquation),\n/* harmony export */ Mesh: () => (/* binding */ Mesh),\n/* harmony export */ MeshBasicMaterial: () => (/* binding */ MeshBasicMaterial),\n/* harmony export */ MeshDepthMaterial: () => (/* binding */ MeshDepthMaterial),\n/* harmony export */ MeshDistanceMaterial: () => (/* binding */ MeshDistanceMaterial),\n/* harmony export */ MeshLambertMaterial: () => (/* binding */ MeshLambertMaterial),\n/* harmony export */ MeshMatcapMaterial: () => (/* binding */ MeshMatcapMaterial),\n/* harmony export */ MeshNormalMaterial: () => (/* binding */ MeshNormalMaterial),\n/* harmony export */ MeshPhongMaterial: () => (/* binding */ MeshPhongMaterial),\n/* harmony export */ MeshPhysicalMaterial: () => (/* binding */ MeshPhysicalMaterial),\n/* harmony export */ MeshStandardMaterial: () => (/* binding */ MeshStandardMaterial),\n/* harmony export */ MeshToonMaterial: () => (/* binding */ MeshToonMaterial),\n/* harmony export */ MinEquation: () => (/* binding */ MinEquation),\n/* harmony export */ MirroredRepeatWrapping: () => (/* binding */ MirroredRepeatWrapping),\n/* harmony export */ MixOperation: () => (/* binding */ MixOperation),\n/* harmony export */ MultiplyBlending: () => (/* binding */ MultiplyBlending),\n/* harmony export */ MultiplyOperation: () => (/* binding */ MultiplyOperation),\n/* harmony export */ NearestFilter: () => (/* binding */ NearestFilter),\n/* harmony export */ NearestMipMapLinearFilter: () => (/* binding */ NearestMipMapLinearFilter),\n/* harmony export */ NearestMipMapNearestFilter: () => (/* binding */ NearestMipMapNearestFilter),\n/* harmony export */ NearestMipmapLinearFilter: () => (/* binding */ NearestMipmapLinearFilter),\n/* harmony export */ NearestMipmapNearestFilter: () => (/* binding */ NearestMipmapNearestFilter),\n/* harmony export */ NeutralToneMapping: () => (/* binding */ NeutralToneMapping),\n/* harmony export */ NeverCompare: () => (/* binding */ NeverCompare),\n/* harmony export */ NeverDepth: () => (/* binding */ NeverDepth),\n/* harmony export */ NeverStencilFunc: () => (/* binding */ NeverStencilFunc),\n/* harmony export */ NoBlending: () => (/* binding */ NoBlending),\n/* harmony export */ NoColorSpace: () => (/* binding */ NoColorSpace),\n/* harmony export */ NoToneMapping: () => (/* binding */ NoToneMapping),\n/* harmony export */ NormalAnimationBlendMode: () => (/* binding */ NormalAnimationBlendMode),\n/* harmony export */ NormalBlending: () => (/* binding */ NormalBlending),\n/* harmony export */ NotEqualCompare: () => (/* binding */ NotEqualCompare),\n/* harmony export */ NotEqualDepth: () => (/* binding */ NotEqualDepth),\n/* harmony export */ NotEqualStencilFunc: () => (/* binding */ NotEqualStencilFunc),\n/* harmony export */ NumberKeyframeTrack: () => (/* binding */ NumberKeyframeTrack),\n/* harmony export */ Object3D: () => (/* binding */ Object3D),\n/* harmony export */ ObjectLoader: () => (/* binding */ ObjectLoader),\n/* harmony export */ ObjectSpaceNormalMap: () => (/* binding */ ObjectSpaceNormalMap),\n/* harmony export */ OctahedronGeometry: () => (/* binding */ OctahedronGeometry),\n/* harmony export */ OneFactor: () => (/* binding */ OneFactor),\n/* harmony export */ OneMinusConstantAlphaFactor: () => (/* binding */ OneMinusConstantAlphaFactor),\n/* harmony export */ OneMinusConstantColorFactor: () => (/* binding */ OneMinusConstantColorFactor),\n/* harmony export */ OneMinusDstAlphaFactor: () => (/* binding */ OneMinusDstAlphaFactor),\n/* harmony export */ OneMinusDstColorFactor: () => (/* binding */ OneMinusDstColorFactor),\n/* harmony export */ OneMinusSrcAlphaFactor: () => (/* binding */ OneMinusSrcAlphaFactor),\n/* harmony export */ OneMinusSrcColorFactor: () => (/* binding */ OneMinusSrcColorFactor),\n/* harmony export */ OrthographicCamera: () => (/* binding */ OrthographicCamera),\n/* harmony export */ P3Primaries: () => (/* binding */ P3Primaries),\n/* harmony export */ PCFShadowMap: () => (/* binding */ PCFShadowMap),\n/* harmony export */ PCFSoftShadowMap: () => (/* binding */ PCFSoftShadowMap),\n/* harmony export */ PMREMGenerator: () => (/* binding */ PMREMGenerator),\n/* harmony export */ Path: () => (/* binding */ Path),\n/* harmony export */ PerspectiveCamera: () => (/* binding */ PerspectiveCamera),\n/* harmony export */ Plane: () => (/* binding */ Plane),\n/* harmony export */ PlaneGeometry: () => (/* binding */ PlaneGeometry),\n/* harmony export */ PlaneHelper: () => (/* binding */ PlaneHelper),\n/* harmony export */ PointLight: () => (/* binding */ PointLight),\n/* harmony export */ PointLightHelper: () => (/* binding */ PointLightHelper),\n/* harmony export */ Points: () => (/* binding */ Points),\n/* harmony export */ PointsMaterial: () => (/* binding */ PointsMaterial),\n/* harmony export */ PolarGridHelper: () => (/* binding */ PolarGridHelper),\n/* harmony export */ PolyhedronGeometry: () => (/* binding */ PolyhedronGeometry),\n/* harmony export */ PositionalAudio: () => (/* binding */ PositionalAudio),\n/* harmony export */ PropertyBinding: () => (/* binding */ PropertyBinding),\n/* harmony export */ PropertyMixer: () => (/* binding */ PropertyMixer),\n/* harmony export */ QuadraticBezierCurve: () => (/* binding */ QuadraticBezierCurve),\n/* harmony export */ QuadraticBezierCurve3: () => (/* binding */ QuadraticBezierCurve3),\n/* harmony export */ Quaternion: () => (/* binding */ Quaternion),\n/* harmony export */ QuaternionKeyframeTrack: () => (/* binding */ QuaternionKeyframeTrack),\n/* harmony export */ QuaternionLinearInterpolant: () => (/* binding */ QuaternionLinearInterpolant),\n/* harmony export */ RED_GREEN_RGTC2_Format: () => (/* binding */ RED_GREEN_RGTC2_Format),\n/* harmony export */ RED_RGTC1_Format: () => (/* binding */ RED_RGTC1_Format),\n/* harmony export */ REVISION: () => (/* binding */ REVISION),\n/* harmony export */ RGBADepthPacking: () => (/* binding */ RGBADepthPacking),\n/* harmony export */ RGBAFormat: () => (/* binding */ RGBAFormat),\n/* harmony export */ RGBAIntegerFormat: () => (/* binding */ RGBAIntegerFormat),\n/* harmony export */ RGBA_ASTC_10x10_Format: () => (/* binding */ RGBA_ASTC_10x10_Format),\n/* harmony export */ RGBA_ASTC_10x5_Format: () => (/* binding */ RGBA_ASTC_10x5_Format),\n/* harmony export */ RGBA_ASTC_10x6_Format: () => (/* binding */ RGBA_ASTC_10x6_Format),\n/* harmony export */ RGBA_ASTC_10x8_Format: () => (/* binding */ RGBA_ASTC_10x8_Format),\n/* harmony export */ RGBA_ASTC_12x10_Format: () => (/* binding */ RGBA_ASTC_12x10_Format),\n/* harmony export */ RGBA_ASTC_12x12_Format: () => (/* binding */ RGBA_ASTC_12x12_Format),\n/* harmony export */ RGBA_ASTC_4x4_Format: () => (/* binding */ RGBA_ASTC_4x4_Format),\n/* harmony export */ RGBA_ASTC_5x4_Format: () => (/* binding */ RGBA_ASTC_5x4_Format),\n/* harmony export */ RGBA_ASTC_5x5_Format: () => (/* binding */ RGBA_ASTC_5x5_Format),\n/* harmony export */ RGBA_ASTC_6x5_Format: () => (/* binding */ RGBA_ASTC_6x5_Format),\n/* harmony export */ RGBA_ASTC_6x6_Format: () => (/* binding */ RGBA_ASTC_6x6_Format),\n/* harmony export */ RGBA_ASTC_8x5_Format: () => (/* binding */ RGBA_ASTC_8x5_Format),\n/* harmony export */ RGBA_ASTC_8x6_Format: () => (/* binding */ RGBA_ASTC_8x6_Format),\n/* harmony export */ RGBA_ASTC_8x8_Format: () => (/* binding */ RGBA_ASTC_8x8_Format),\n/* harmony export */ RGBA_BPTC_Format: () => (/* binding */ RGBA_BPTC_Format),\n/* harmony export */ RGBA_ETC2_EAC_Format: () => (/* binding */ RGBA_ETC2_EAC_Format),\n/* harmony export */ RGBA_PVRTC_2BPPV1_Format: () => (/* binding */ RGBA_PVRTC_2BPPV1_Format),\n/* harmony export */ RGBA_PVRTC_4BPPV1_Format: () => (/* binding */ RGBA_PVRTC_4BPPV1_Format),\n/* harmony export */ RGBA_S3TC_DXT1_Format: () => (/* binding */ RGBA_S3TC_DXT1_Format),\n/* harmony export */ RGBA_S3TC_DXT3_Format: () => (/* binding */ RGBA_S3TC_DXT3_Format),\n/* harmony export */ RGBA_S3TC_DXT5_Format: () => (/* binding */ RGBA_S3TC_DXT5_Format),\n/* harmony export */ RGBDepthPacking: () => (/* binding */ RGBDepthPacking),\n/* harmony export */ RGBFormat: () => (/* binding */ RGBFormat),\n/* harmony export */ RGBIntegerFormat: () => (/* binding */ RGBIntegerFormat),\n/* harmony export */ RGB_BPTC_SIGNED_Format: () => (/* binding */ RGB_BPTC_SIGNED_Format),\n/* harmony export */ RGB_BPTC_UNSIGNED_Format: () => (/* binding */ RGB_BPTC_UNSIGNED_Format),\n/* harmony export */ RGB_ETC1_Format: () => (/* binding */ RGB_ETC1_Format),\n/* harmony export */ RGB_ETC2_Format: () => (/* binding */ RGB_ETC2_Format),\n/* harmony export */ RGB_PVRTC_2BPPV1_Format: () => (/* binding */ RGB_PVRTC_2BPPV1_Format),\n/* harmony export */ RGB_PVRTC_4BPPV1_Format: () => (/* binding */ RGB_PVRTC_4BPPV1_Format),\n/* harmony export */ RGB_S3TC_DXT1_Format: () => (/* binding */ RGB_S3TC_DXT1_Format),\n/* harmony export */ RGDepthPacking: () => (/* binding */ RGDepthPacking),\n/* harmony export */ RGFormat: () => (/* binding */ RGFormat),\n/* harmony export */ RGIntegerFormat: () => (/* binding */ RGIntegerFormat),\n/* harmony export */ RawShaderMaterial: () => (/* binding */ RawShaderMaterial),\n/* harmony export */ Ray: () => (/* binding */ Ray),\n/* harmony export */ Raycaster: () => (/* binding */ Raycaster),\n/* harmony export */ Rec709Primaries: () => (/* binding */ Rec709Primaries),\n/* harmony export */ RectAreaLight: () => (/* binding */ RectAreaLight),\n/* harmony export */ RedFormat: () => (/* binding */ RedFormat),\n/* harmony export */ RedIntegerFormat: () => (/* binding */ RedIntegerFormat),\n/* harmony export */ ReinhardToneMapping: () => (/* binding */ ReinhardToneMapping),\n/* harmony export */ RenderTarget: () => (/* binding */ RenderTarget),\n/* harmony export */ RepeatWrapping: () => (/* binding */ RepeatWrapping),\n/* harmony export */ ReplaceStencilOp: () => (/* binding */ ReplaceStencilOp),\n/* harmony export */ ReverseSubtractEquation: () => (/* binding */ ReverseSubtractEquation),\n/* harmony export */ RingGeometry: () => (/* binding */ RingGeometry),\n/* harmony export */ SIGNED_RED_GREEN_RGTC2_Format: () => (/* binding */ SIGNED_RED_GREEN_RGTC2_Format),\n/* harmony export */ SIGNED_RED_RGTC1_Format: () => (/* binding */ SIGNED_RED_RGTC1_Format),\n/* harmony export */ SRGBColorSpace: () => (/* binding */ SRGBColorSpace),\n/* harmony export */ SRGBTransfer: () => (/* binding */ SRGBTransfer),\n/* harmony export */ Scene: () => (/* binding */ Scene),\n/* harmony export */ ShaderChunk: () => (/* binding */ ShaderChunk),\n/* harmony export */ ShaderLib: () => (/* binding */ ShaderLib),\n/* harmony export */ ShaderMaterial: () => (/* binding */ ShaderMaterial),\n/* harmony export */ ShadowMaterial: () => (/* binding */ ShadowMaterial),\n/* harmony export */ Shape: () => (/* binding */ Shape),\n/* harmony export */ ShapeGeometry: () => (/* binding */ ShapeGeometry),\n/* harmony export */ ShapePath: () => (/* binding */ ShapePath),\n/* harmony export */ ShapeUtils: () => (/* binding */ ShapeUtils),\n/* harmony export */ ShortType: () => (/* binding */ ShortType),\n/* harmony export */ Skeleton: () => (/* binding */ Skeleton),\n/* harmony export */ SkeletonHelper: () => (/* binding */ SkeletonHelper),\n/* harmony export */ SkinnedMesh: () => (/* binding */ SkinnedMesh),\n/* harmony export */ Source: () => (/* binding */ Source),\n/* harmony export */ Sphere: () => (/* binding */ Sphere),\n/* harmony export */ SphereGeometry: () => (/* binding */ SphereGeometry),\n/* harmony export */ Spherical: () => (/* binding */ Spherical),\n/* harmony export */ SphericalHarmonics3: () => (/* binding */ SphericalHarmonics3),\n/* harmony export */ SplineCurve: () => (/* binding */ SplineCurve),\n/* harmony export */ SpotLight: () => (/* binding */ SpotLight),\n/* harmony export */ SpotLightHelper: () => (/* binding */ SpotLightHelper),\n/* harmony export */ Sprite: () => (/* binding */ Sprite),\n/* harmony export */ SpriteMaterial: () => (/* binding */ SpriteMaterial),\n/* harmony export */ SrcAlphaFactor: () => (/* binding */ SrcAlphaFactor),\n/* harmony export */ SrcAlphaSaturateFactor: () => (/* binding */ SrcAlphaSaturateFactor),\n/* harmony export */ SrcColorFactor: () => (/* binding */ SrcColorFactor),\n/* harmony export */ StaticCopyUsage: () => (/* binding */ StaticCopyUsage),\n/* harmony export */ StaticDrawUsage: () => (/* binding */ StaticDrawUsage),\n/* harmony export */ StaticReadUsage: () => (/* binding */ StaticReadUsage),\n/* harmony export */ StereoCamera: () => (/* binding */ StereoCamera),\n/* harmony export */ StreamCopyUsage: () => (/* binding */ StreamCopyUsage),\n/* harmony export */ StreamDrawUsage: () => (/* binding */ StreamDrawUsage),\n/* harmony export */ StreamReadUsage: () => (/* binding */ StreamReadUsage),\n/* harmony export */ StringKeyframeTrack: () => (/* binding */ StringKeyframeTrack),\n/* harmony export */ SubtractEquation: () => (/* binding */ SubtractEquation),\n/* harmony export */ SubtractiveBlending: () => (/* binding */ SubtractiveBlending),\n/* harmony export */ TOUCH: () => (/* binding */ TOUCH),\n/* harmony export */ TangentSpaceNormalMap: () => (/* binding */ TangentSpaceNormalMap),\n/* harmony export */ TetrahedronGeometry: () => (/* binding */ TetrahedronGeometry),\n/* harmony export */ Texture: () => (/* binding */ Texture),\n/* harmony export */ TextureLoader: () => (/* binding */ TextureLoader),\n/* harmony export */ TextureUtils: () => (/* binding */ TextureUtils),\n/* harmony export */ TorusGeometry: () => (/* binding */ TorusGeometry),\n/* harmony export */ TorusKnotGeometry: () => (/* binding */ TorusKnotGeometry),\n/* harmony export */ Triangle: () => (/* binding */ Triangle),\n/* harmony export */ TriangleFanDrawMode: () => (/* binding */ TriangleFanDrawMode),\n/* harmony export */ TriangleStripDrawMode: () => (/* binding */ TriangleStripDrawMode),\n/* harmony export */ TrianglesDrawMode: () => (/* binding */ TrianglesDrawMode),\n/* harmony export */ TubeGeometry: () => (/* binding */ TubeGeometry),\n/* harmony export */ UVMapping: () => (/* binding */ UVMapping),\n/* harmony export */ Uint16BufferAttribute: () => (/* binding */ Uint16BufferAttribute),\n/* harmony export */ Uint32BufferAttribute: () => (/* binding */ Uint32BufferAttribute),\n/* harmony export */ Uint8BufferAttribute: () => (/* binding */ Uint8BufferAttribute),\n/* harmony export */ Uint8ClampedBufferAttribute: () => (/* binding */ Uint8ClampedBufferAttribute),\n/* harmony export */ Uniform: () => (/* binding */ Uniform),\n/* harmony export */ UniformsGroup: () => (/* binding */ UniformsGroup),\n/* harmony export */ UniformsLib: () => (/* binding */ UniformsLib),\n/* harmony export */ UniformsUtils: () => (/* binding */ UniformsUtils),\n/* harmony export */ UnsignedByteType: () => (/* binding */ UnsignedByteType),\n/* harmony export */ UnsignedInt248Type: () => (/* binding */ UnsignedInt248Type),\n/* harmony export */ UnsignedInt5999Type: () => (/* binding */ UnsignedInt5999Type),\n/* harmony export */ UnsignedIntType: () => (/* binding */ UnsignedIntType),\n/* harmony export */ UnsignedShort4444Type: () => (/* binding */ UnsignedShort4444Type),\n/* harmony export */ UnsignedShort5551Type: () => (/* binding */ UnsignedShort5551Type),\n/* harmony export */ UnsignedShortType: () => (/* binding */ UnsignedShortType),\n/* harmony export */ VSMShadowMap: () => (/* binding */ VSMShadowMap),\n/* harmony export */ Vector2: () => (/* binding */ Vector2),\n/* harmony export */ Vector3: () => (/* binding */ Vector3),\n/* harmony export */ Vector4: () => (/* binding */ Vector4),\n/* harmony export */ VectorKeyframeTrack: () => (/* binding */ VectorKeyframeTrack),\n/* harmony export */ VideoTexture: () => (/* binding */ VideoTexture),\n/* harmony export */ WebGL3DRenderTarget: () => (/* binding */ WebGL3DRenderTarget),\n/* harmony export */ WebGLArrayRenderTarget: () => (/* binding */ WebGLArrayRenderTarget),\n/* harmony export */ WebGLCoordinateSystem: () => (/* binding */ WebGLCoordinateSystem),\n/* harmony export */ WebGLCubeRenderTarget: () => (/* binding */ WebGLCubeRenderTarget),\n/* harmony export */ WebGLMultipleRenderTargets: () => (/* binding */ WebGLMultipleRenderTargets),\n/* harmony export */ WebGLRenderTarget: () => (/* binding */ WebGLRenderTarget),\n/* harmony export */ WebGLRenderer: () => (/* binding */ WebGLRenderer),\n/* harmony export */ WebGLUtils: () => (/* binding */ WebGLUtils),\n/* harmony export */ WebGPUCoordinateSystem: () => (/* binding */ WebGPUCoordinateSystem),\n/* harmony export */ WireframeGeometry: () => (/* binding */ WireframeGeometry),\n/* harmony export */ WrapAroundEnding: () => (/* binding */ WrapAroundEnding),\n/* harmony export */ ZeroCurvatureEnding: () => (/* binding */ ZeroCurvatureEnding),\n/* harmony export */ ZeroFactor: () => (/* binding */ ZeroFactor),\n/* harmony export */ ZeroSlopeEnding: () => (/* binding */ ZeroSlopeEnding),\n/* harmony export */ ZeroStencilOp: () => (/* binding */ ZeroStencilOp),\n/* harmony export */ createCanvasElement: () => (/* binding */ createCanvasElement)\n/* harmony export */ });\n/**\n * @license\n * Copyright 2010-2024 Three.js Authors\n * SPDX-License-Identifier: MIT\n */\nconst REVISION = '168';\n\nconst MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };\nconst TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };\nconst CullFaceNone = 0;\nconst CullFaceBack = 1;\nconst CullFaceFront = 2;\nconst CullFaceFrontBack = 3;\nconst BasicShadowMap = 0;\nconst PCFShadowMap = 1;\nconst PCFSoftShadowMap = 2;\nconst VSMShadowMap = 3;\nconst FrontSide = 0;\nconst BackSide = 1;\nconst DoubleSide = 2;\nconst NoBlending = 0;\nconst NormalBlending = 1;\nconst AdditiveBlending = 2;\nconst SubtractiveBlending = 3;\nconst MultiplyBlending = 4;\nconst CustomBlending = 5;\nconst AddEquation = 100;\nconst SubtractEquation = 101;\nconst ReverseSubtractEquation = 102;\nconst MinEquation = 103;\nconst MaxEquation = 104;\nconst ZeroFactor = 200;\nconst OneFactor = 201;\nconst SrcColorFactor = 202;\nconst OneMinusSrcColorFactor = 203;\nconst SrcAlphaFactor = 204;\nconst OneMinusSrcAlphaFactor = 205;\nconst DstAlphaFactor = 206;\nconst OneMinusDstAlphaFactor = 207;\nconst DstColorFactor = 208;\nconst OneMinusDstColorFactor = 209;\nconst SrcAlphaSaturateFactor = 210;\nconst ConstantColorFactor = 211;\nconst OneMinusConstantColorFactor = 212;\nconst ConstantAlphaFactor = 213;\nconst OneMinusConstantAlphaFactor = 214;\nconst NeverDepth = 0;\nconst AlwaysDepth = 1;\nconst LessDepth = 2;\nconst LessEqualDepth = 3;\nconst EqualDepth = 4;\nconst GreaterEqualDepth = 5;\nconst GreaterDepth = 6;\nconst NotEqualDepth = 7;\nconst MultiplyOperation = 0;\nconst MixOperation = 1;\nconst AddOperation = 2;\nconst NoToneMapping = 0;\nconst LinearToneMapping = 1;\nconst ReinhardToneMapping = 2;\nconst CineonToneMapping = 3;\nconst ACESFilmicToneMapping = 4;\nconst CustomToneMapping = 5;\nconst AgXToneMapping = 6;\nconst NeutralToneMapping = 7;\nconst AttachedBindMode = 'attached';\nconst DetachedBindMode = 'detached';\n\nconst UVMapping = 300;\nconst CubeReflectionMapping = 301;\nconst CubeRefractionMapping = 302;\nconst EquirectangularReflectionMapping = 303;\nconst EquirectangularRefractionMapping = 304;\nconst CubeUVReflectionMapping = 306;\nconst RepeatWrapping = 1000;\nconst ClampToEdgeWrapping = 1001;\nconst MirroredRepeatWrapping = 1002;\nconst NearestFilter = 1003;\nconst NearestMipmapNearestFilter = 1004;\nconst NearestMipMapNearestFilter = 1004;\nconst NearestMipmapLinearFilter = 1005;\nconst NearestMipMapLinearFilter = 1005;\nconst LinearFilter = 1006;\nconst LinearMipmapNearestFilter = 1007;\nconst LinearMipMapNearestFilter = 1007;\nconst LinearMipmapLinearFilter = 1008;\nconst LinearMipMapLinearFilter = 1008;\nconst UnsignedByteType = 1009;\nconst ByteType = 1010;\nconst ShortType = 1011;\nconst UnsignedShortType = 1012;\nconst IntType = 1013;\nconst UnsignedIntType = 1014;\nconst FloatType = 1015;\nconst HalfFloatType = 1016;\nconst UnsignedShort4444Type = 1017;\nconst UnsignedShort5551Type = 1018;\nconst UnsignedInt248Type = 1020;\nconst UnsignedInt5999Type = 35902;\nconst AlphaFormat = 1021;\nconst RGBFormat = 1022;\nconst RGBAFormat = 1023;\nconst LuminanceFormat = 1024;\nconst LuminanceAlphaFormat = 1025;\nconst DepthFormat = 1026;\nconst DepthStencilFormat = 1027;\nconst RedFormat = 1028;\nconst RedIntegerFormat = 1029;\nconst RGFormat = 1030;\nconst RGIntegerFormat = 1031;\nconst RGBIntegerFormat = 1032;\nconst RGBAIntegerFormat = 1033;\n\nconst RGB_S3TC_DXT1_Format = 33776;\nconst RGBA_S3TC_DXT1_Format = 33777;\nconst RGBA_S3TC_DXT3_Format = 33778;\nconst RGBA_S3TC_DXT5_Format = 33779;\nconst RGB_PVRTC_4BPPV1_Format = 35840;\nconst RGB_PVRTC_2BPPV1_Format = 35841;\nconst RGBA_PVRTC_4BPPV1_Format = 35842;\nconst RGBA_PVRTC_2BPPV1_Format = 35843;\nconst RGB_ETC1_Format = 36196;\nconst RGB_ETC2_Format = 37492;\nconst RGBA_ETC2_EAC_Format = 37496;\nconst RGBA_ASTC_4x4_Format = 37808;\nconst RGBA_ASTC_5x4_Format = 37809;\nconst RGBA_ASTC_5x5_Format = 37810;\nconst RGBA_ASTC_6x5_Format = 37811;\nconst RGBA_ASTC_6x6_Format = 37812;\nconst RGBA_ASTC_8x5_Format = 37813;\nconst RGBA_ASTC_8x6_Format = 37814;\nconst RGBA_ASTC_8x8_Format = 37815;\nconst RGBA_ASTC_10x5_Format = 37816;\nconst RGBA_ASTC_10x6_Format = 37817;\nconst RGBA_ASTC_10x8_Format = 37818;\nconst RGBA_ASTC_10x10_Format = 37819;\nconst RGBA_ASTC_12x10_Format = 37820;\nconst RGBA_ASTC_12x12_Format = 37821;\nconst RGBA_BPTC_Format = 36492;\nconst RGB_BPTC_SIGNED_Format = 36494;\nconst RGB_BPTC_UNSIGNED_Format = 36495;\nconst RED_RGTC1_Format = 36283;\nconst SIGNED_RED_RGTC1_Format = 36284;\nconst RED_GREEN_RGTC2_Format = 36285;\nconst SIGNED_RED_GREEN_RGTC2_Format = 36286;\nconst LoopOnce = 2200;\nconst LoopRepeat = 2201;\nconst LoopPingPong = 2202;\nconst InterpolateDiscrete = 2300;\nconst InterpolateLinear = 2301;\nconst InterpolateSmooth = 2302;\nconst ZeroCurvatureEnding = 2400;\nconst ZeroSlopeEnding = 2401;\nconst WrapAroundEnding = 2402;\nconst NormalAnimationBlendMode = 2500;\nconst AdditiveAnimationBlendMode = 2501;\nconst TrianglesDrawMode = 0;\nconst TriangleStripDrawMode = 1;\nconst TriangleFanDrawMode = 2;\nconst BasicDepthPacking = 3200;\nconst RGBADepthPacking = 3201;\nconst RGBDepthPacking = 3202;\nconst RGDepthPacking = 3203;\nconst TangentSpaceNormalMap = 0;\nconst ObjectSpaceNormalMap = 1;\n\n// Color space string identifiers, matching CSS Color Module Level 4 and WebGPU names where available.\nconst NoColorSpace = '';\nconst SRGBColorSpace = 'srgb';\nconst LinearSRGBColorSpace = 'srgb-linear';\nconst DisplayP3ColorSpace = 'display-p3';\nconst LinearDisplayP3ColorSpace = 'display-p3-linear';\n\nconst LinearTransfer = 'linear';\nconst SRGBTransfer = 'srgb';\n\nconst Rec709Primaries = 'rec709';\nconst P3Primaries = 'p3';\n\nconst ZeroStencilOp = 0;\nconst KeepStencilOp = 7680;\nconst ReplaceStencilOp = 7681;\nconst IncrementStencilOp = 7682;\nconst DecrementStencilOp = 7683;\nconst IncrementWrapStencilOp = 34055;\nconst DecrementWrapStencilOp = 34056;\nconst InvertStencilOp = 5386;\n\nconst NeverStencilFunc = 512;\nconst LessStencilFunc = 513;\nconst EqualStencilFunc = 514;\nconst LessEqualStencilFunc = 515;\nconst GreaterStencilFunc = 516;\nconst NotEqualStencilFunc = 517;\nconst GreaterEqualStencilFunc = 518;\nconst AlwaysStencilFunc = 519;\n\nconst NeverCompare = 512;\nconst LessCompare = 513;\nconst EqualCompare = 514;\nconst LessEqualCompare = 515;\nconst GreaterCompare = 516;\nconst NotEqualCompare = 517;\nconst GreaterEqualCompare = 518;\nconst AlwaysCompare = 519;\n\nconst StaticDrawUsage = 35044;\nconst DynamicDrawUsage = 35048;\nconst StreamDrawUsage = 35040;\nconst StaticReadUsage = 35045;\nconst DynamicReadUsage = 35049;\nconst StreamReadUsage = 35041;\nconst StaticCopyUsage = 35046;\nconst DynamicCopyUsage = 35050;\nconst StreamCopyUsage = 35042;\n\nconst GLSL1 = '100';\nconst GLSL3 = '300 es';\n\nconst WebGLCoordinateSystem = 2000;\nconst WebGPUCoordinateSystem = 2001;\n\n/**\n * https://github.com/mrdoob/eventdispatcher.js/\n */\n\nclass EventDispatcher {\n\n\taddEventListener( type, listener ) {\n\n\t\tif ( this._listeners === undefined ) this._listeners = {};\n\n\t\tconst listeners = this._listeners;\n\n\t\tif ( listeners[ type ] === undefined ) {\n\n\t\t\tlisteners[ type ] = [];\n\n\t\t}\n\n\t\tif ( listeners[ type ].indexOf( listener ) === - 1 ) {\n\n\t\t\tlisteners[ type ].push( listener );\n\n\t\t}\n\n\t}\n\n\thasEventListener( type, listener ) {\n\n\t\tif ( this._listeners === undefined ) return false;\n\n\t\tconst listeners = this._listeners;\n\n\t\treturn listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;\n\n\t}\n\n\tremoveEventListener( type, listener ) {\n\n\t\tif ( this._listeners === undefined ) return;\n\n\t\tconst listeners = this._listeners;\n\t\tconst listenerArray = listeners[ type ];\n\n\t\tif ( listenerArray !== undefined ) {\n\n\t\t\tconst index = listenerArray.indexOf( listener );\n\n\t\t\tif ( index !== - 1 ) {\n\n\t\t\t\tlistenerArray.splice( index, 1 );\n\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\tdispatchEvent( event ) {\n\n\t\tif ( this._listeners === undefined ) return;\n\n\t\tconst listeners = this._listeners;\n\t\tconst listenerArray = listeners[ event.type ];\n\n\t\tif ( listenerArray !== undefined ) {\n\n\t\t\tevent.target = this;\n\n\t\t\t// Make a copy, in case listeners are removed while iterating.\n\t\t\tconst array = listenerArray.slice( 0 );\n\n\t\t\tfor ( let i = 0, l = array.length; i < l; i ++ ) {\n\n\t\t\t\tarray[ i ].call( this, event );\n\n\t\t\t}\n\n\t\t\tevent.target = null;\n\n\t\t}\n\n\t}\n\n}\n\nconst _lut = [ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0a', '0b', '0c', '0d', '0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', '2f', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3a', '3b', '3c', '3d', '3e', '3f', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', '5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '8a', '8b', '8c', '8d', '8e', '8f', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '9a', '9b', '9c', '9d', '9e', '9f', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'ba', 'bb', 'bc', 'bd', 'be', 'bf', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'ca', 'cb', 'cc', 'cd', 'ce', 'cf', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'da', 'db', 'dc', 'dd', 'de', 'df', 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'ea', 'eb', 'ec', 'ed', 'ee', 'ef', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'fa', 'fb', 'fc', 'fd', 'fe', 'ff' ];\n\nlet _seed = 1234567;\n\n\nconst DEG2RAD = Math.PI / 180;\nconst RAD2DEG = 180 / Math.PI;\n\n// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136\nfunction generateUUID() {\n\n\tconst d0 = Math.random() * 0xffffffff | 0;\n\tconst d1 = Math.random() * 0xffffffff | 0;\n\tconst d2 = Math.random() * 0xffffffff | 0;\n\tconst d3 = Math.random() * 0xffffffff | 0;\n\tconst uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +\n\t\t\t_lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +\n\t\t\t_lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +\n\t\t\t_lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];\n\n\t// .toLowerCase() here flattens concatenated strings to save heap memory space.\n\treturn uuid.toLowerCase();\n\n}\n\nfunction clamp( value, min, max ) {\n\n\treturn Math.max( min, Math.min( max, value ) );\n\n}\n\n// compute euclidean modulo of m % n\n// https://en.wikipedia.org/wiki/Modulo_operation\nfunction euclideanModulo( n, m ) {\n\n\treturn ( ( n % m ) + m ) % m;\n\n}\n\n// Linear mapping from range to range \nfunction mapLinear( x, a1, a2, b1, b2 ) {\n\n\treturn b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );\n\n}\n\n// https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/inverse-lerp-a-super-useful-yet-often-overlooked-function-r5230/\nfunction inverseLerp( x, y, value ) {\n\n\tif ( x !== y ) {\n\n\t\treturn ( value - x ) / ( y - x );\n\n\t} else {\n\n\t\treturn 0;\n\n\t}\n\n}\n\n// https://en.wikipedia.org/wiki/Linear_interpolation\nfunction lerp( x, y, t ) {\n\n\treturn ( 1 - t ) * x + t * y;\n\n}\n\n// http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/\nfunction damp( x, y, lambda, dt ) {\n\n\treturn lerp( x, y, 1 - Math.exp( - lambda * dt ) );\n\n}\n\n// https://www.desmos.com/calculator/vcsjnyz7x4\nfunction pingpong( x, length = 1 ) {\n\n\treturn length - Math.abs( euclideanModulo( x, length * 2 ) - length );\n\n}\n\n// http://en.wikipedia.org/wiki/Smoothstep\nfunction smoothstep( x, min, max ) {\n\n\tif ( x <= min ) return 0;\n\tif ( x >= max ) return 1;\n\n\tx = ( x - min ) / ( max - min );\n\n\treturn x * x * ( 3 - 2 * x );\n\n}\n\nfunction smootherstep( x, min, max ) {\n\n\tif ( x <= min ) return 0;\n\tif ( x >= max ) return 1;\n\n\tx = ( x - min ) / ( max - min );\n\n\treturn x * x * x * ( x * ( x * 6 - 15 ) + 10 );\n\n}\n\n// Random integer from interval\nfunction randInt( low, high ) {\n\n\treturn low + Math.floor( Math.random() * ( high - low + 1 ) );\n\n}\n\n// Random float from interval\nfunction randFloat( low, high ) {\n\n\treturn low + Math.random() * ( high - low );\n\n}\n\n// Random float from <-range/2, range/2> interval\nfunction randFloatSpread( range ) {\n\n\treturn range * ( 0.5 - Math.random() );\n\n}\n\n// Deterministic pseudo-random float in the interval [ 0, 1 ]\nfunction seededRandom( s ) {\n\n\tif ( s !== undefined ) _seed = s;\n\n\t// Mulberry32 generator\n\n\tlet t = _seed += 0x6D2B79F5;\n\n\tt = Math.imul( t ^ t >>> 15, t | 1 );\n\n\tt ^= t + Math.imul( t ^ t >>> 7, t | 61 );\n\n\treturn ( ( t ^ t >>> 14 ) >>> 0 ) / 4294967296;\n\n}\n\nfunction degToRad( degrees ) {\n\n\treturn degrees * DEG2RAD;\n\n}\n\nfunction radToDeg( radians ) {\n\n\treturn radians * RAD2DEG;\n\n}\n\nfunction isPowerOfTwo( value ) {\n\n\treturn ( value & ( value - 1 ) ) === 0 && value !== 0;\n\n}\n\nfunction ceilPowerOfTwo( value ) {\n\n\treturn Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );\n\n}\n\nfunction floorPowerOfTwo( value ) {\n\n\treturn Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );\n\n}\n\nfunction setQuaternionFromProperEuler( q, a, b, c, order ) {\n\n\t// Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles\n\n\t// rotations are applied to the axes in the order specified by 'order'\n\t// rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'\n\t// angles are in radians\n\n\tconst cos = Math.cos;\n\tconst sin = Math.sin;\n\n\tconst c2 = cos( b / 2 );\n\tconst s2 = sin( b / 2 );\n\n\tconst c13 = cos( ( a + c ) / 2 );\n\tconst s13 = sin( ( a + c ) / 2 );\n\n\tconst c1_3 = cos( ( a - c ) / 2 );\n\tconst s1_3 = sin( ( a - c ) / 2 );\n\n\tconst c3_1 = cos( ( c - a ) / 2 );\n\tconst s3_1 = sin( ( c - a ) / 2 );\n\n\tswitch ( order ) {\n\n\t\tcase 'XYX':\n\t\t\tq.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );\n\t\t\tbreak;\n\n\t\tcase 'YZY':\n\t\t\tq.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );\n\t\t\tbreak;\n\n\t\tcase 'ZXZ':\n\t\t\tq.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );\n\t\t\tbreak;\n\n\t\tcase 'XZX':\n\t\t\tq.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );\n\t\t\tbreak;\n\n\t\tcase 'YXY':\n\t\t\tq.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );\n\t\t\tbreak;\n\n\t\tcase 'ZYZ':\n\t\t\tq.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );\n\t\t\tbreak;\n\n\t\tdefault:\n\t\t\tconsole.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );\n\n\t}\n\n}\n\nfunction denormalize( value, array ) {\n\n\tswitch ( array.constructor ) {\n\n\t\tcase Float32Array:\n\n\t\t\treturn value;\n\n\t\tcase Uint32Array:\n\n\t\t\treturn value / 4294967295.0;\n\n\t\tcase Uint16Array:\n\n\t\t\treturn value / 65535.0;\n\n\t\tcase Uint8Array:\n\n\t\t\treturn value / 255.0;\n\n\t\tcase Int32Array:\n\n\t\t\treturn Math.max( value / 2147483647.0, - 1.0 );\n\n\t\tcase Int16Array:\n\n\t\t\treturn Math.max( value / 32767.0, - 1.0 );\n\n\t\tcase Int8Array:\n\n\t\t\treturn Math.max( value / 127.0, - 1.0 );\n\n\t\tdefault:\n\n\t\t\tthrow new Error( 'Invalid component type.' );\n\n\t}\n\n}\n\nfunction normalize( value, array ) {\n\n\tswitch ( array.constructor ) {\n\n\t\tcase Float32Array:\n\n\t\t\treturn value;\n\n\t\tcase Uint32Array:\n\n\t\t\treturn Math.round( value * 4294967295.0 );\n\n\t\tcase Uint16Array:\n\n\t\t\treturn Math.round( value * 65535.0 );\n\n\t\tcase Uint8Array:\n\n\t\t\treturn Math.round( value * 255.0 );\n\n\t\tcase Int32Array:\n\n\t\t\treturn Math.round( value * 2147483647.0 );\n\n\t\tcase Int16Array:\n\n\t\t\treturn Math.round( value * 32767.0 );\n\n\t\tcase Int8Array:\n\n\t\t\treturn Math.round( value * 127.0 );\n\n\t\tdefault:\n\n\t\t\tthrow new Error( 'Invalid component type.' );\n\n\t}\n\n}\n\nconst MathUtils = {\n\tDEG2RAD: DEG2RAD,\n\tRAD2DEG: RAD2DEG,\n\tgenerateUUID: generateUUID,\n\tclamp: clamp,\n\teuclideanModulo: euclideanModulo,\n\tmapLinear: mapLinear,\n\tinverseLerp: inverseLerp,\n\tlerp: lerp,\n\tdamp: damp,\n\tpingpong: pingpong,\n\tsmoothstep: smoothstep,\n\tsmootherstep: smootherstep,\n\trandInt: randInt,\n\trandFloat: randFloat,\n\trandFloatSpread: randFloatSpread,\n\tseededRandom: seededRandom,\n\tdegToRad: degToRad,\n\tradToDeg: radToDeg,\n\tisPowerOfTwo: isPowerOfTwo,\n\tceilPowerOfTwo: ceilPowerOfTwo,\n\tfloorPowerOfTwo: floorPowerOfTwo,\n\tsetQuaternionFromProperEuler: setQuaternionFromProperEuler,\n\tnormalize: normalize,\n\tdenormalize: denormalize\n};\n\nclass Vector2 {\n\n\tconstructor( x = 0, y = 0 ) {\n\n\t\tVector2.prototype.isVector2 = true;\n\n\t\tthis.x = x;\n\t\tthis.y = y;\n\n\t}\n\n\tget width() {\n\n\t\treturn this.x;\n\n\t}\n\n\tset width( value ) {\n\n\t\tthis.x = value;\n\n\t}\n\n\tget height() {\n\n\t\treturn this.y;\n\n\t}\n\n\tset height( value ) {\n\n\t\tthis.y = value;\n\n\t}\n\n\tset( x, y ) {\n\n\t\tthis.x = x;\n\t\tthis.y = y;\n\n\t\treturn this;\n\n\t}\n\n\tsetScalar( scalar ) {\n\n\t\tthis.x = scalar;\n\t\tthis.y = scalar;\n\n\t\treturn this;\n\n\t}\n\n\tsetX( x ) {\n\n\t\tthis.x = x;\n\n\t\treturn this;\n\n\t}\n\n\tsetY( y ) {\n\n\t\tthis.y = y;\n\n\t\treturn this;\n\n\t}\n\n\tsetComponent( index, value ) {\n\n\t\tswitch ( index ) {\n\n\t\t\tcase 0: this.x = value; break;\n\t\t\tcase 1: this.y = value; break;\n\t\t\tdefault: throw new Error( 'index is out of range: ' + index );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tgetComponent( index ) {\n\n\t\tswitch ( index ) {\n\n\t\t\tcase 0: return this.x;\n\t\t\tcase 1: return this.y;\n\t\t\tdefault: throw new Error( 'index is out of range: ' + index );\n\n\t\t}\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor( this.x, this.y );\n\n\t}\n\n\tcopy( v ) {\n\n\t\tthis.x = v.x;\n\t\tthis.y = v.y;\n\n\t\treturn this;\n\n\t}\n\n\tadd( v ) {\n\n\t\tthis.x += v.x;\n\t\tthis.y += v.y;\n\n\t\treturn this;\n\n\t}\n\n\taddScalar( s ) {\n\n\t\tthis.x += s;\n\t\tthis.y += s;\n\n\t\treturn this;\n\n\t}\n\n\taddVectors( a, b ) {\n\n\t\tthis.x = a.x + b.x;\n\t\tthis.y = a.y + b.y;\n\n\t\treturn this;\n\n\t}\n\n\taddScaledVector( v, s ) {\n\n\t\tthis.x += v.x * s;\n\t\tthis.y += v.y * s;\n\n\t\treturn this;\n\n\t}\n\n\tsub( v ) {\n\n\t\tthis.x -= v.x;\n\t\tthis.y -= v.y;\n\n\t\treturn this;\n\n\t}\n\n\tsubScalar( s ) {\n\n\t\tthis.x -= s;\n\t\tthis.y -= s;\n\n\t\treturn this;\n\n\t}\n\n\tsubVectors( a, b ) {\n\n\t\tthis.x = a.x - b.x;\n\t\tthis.y = a.y - b.y;\n\n\t\treturn this;\n\n\t}\n\n\tmultiply( v ) {\n\n\t\tthis.x *= v.x;\n\t\tthis.y *= v.y;\n\n\t\treturn this;\n\n\t}\n\n\tmultiplyScalar( scalar ) {\n\n\t\tthis.x *= scalar;\n\t\tthis.y *= scalar;\n\n\t\treturn this;\n\n\t}\n\n\tdivide( v ) {\n\n\t\tthis.x /= v.x;\n\t\tthis.y /= v.y;\n\n\t\treturn this;\n\n\t}\n\n\tdivideScalar( scalar ) {\n\n\t\treturn this.multiplyScalar( 1 / scalar );\n\n\t}\n\n\tapplyMatrix3( m ) {\n\n\t\tconst x = this.x, y = this.y;\n\t\tconst e = m.elements;\n\n\t\tthis.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];\n\t\tthis.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];\n\n\t\treturn this;\n\n\t}\n\n\tmin( v ) {\n\n\t\tthis.x = Math.min( this.x, v.x );\n\t\tthis.y = Math.min( this.y, v.y );\n\n\t\treturn this;\n\n\t}\n\n\tmax( v ) {\n\n\t\tthis.x = Math.max( this.x, v.x );\n\t\tthis.y = Math.max( this.y, v.y );\n\n\t\treturn this;\n\n\t}\n\n\tclamp( min, max ) {\n\n\t\t// assumes min < max, componentwise\n\n\t\tthis.x = Math.max( min.x, Math.min( max.x, this.x ) );\n\t\tthis.y = Math.max( min.y, Math.min( max.y, this.y ) );\n\n\t\treturn this;\n\n\t}\n\n\tclampScalar( minVal, maxVal ) {\n\n\t\tthis.x = Math.max( minVal, Math.min( maxVal, this.x ) );\n\t\tthis.y = Math.max( minVal, Math.min( maxVal, this.y ) );\n\n\t\treturn this;\n\n\t}\n\n\tclampLength( min, max ) {\n\n\t\tconst length = this.length();\n\n\t\treturn this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );\n\n\t}\n\n\tfloor() {\n\n\t\tthis.x = Math.floor( this.x );\n\t\tthis.y = Math.floor( this.y );\n\n\t\treturn this;\n\n\t}\n\n\tceil() {\n\n\t\tthis.x = Math.ceil( this.x );\n\t\tthis.y = Math.ceil( this.y );\n\n\t\treturn this;\n\n\t}\n\n\tround() {\n\n\t\tthis.x = Math.round( this.x );\n\t\tthis.y = Math.round( this.y );\n\n\t\treturn this;\n\n\t}\n\n\troundToZero() {\n\n\t\tthis.x = Math.trunc( this.x );\n\t\tthis.y = Math.trunc( this.y );\n\n\t\treturn this;\n\n\t}\n\n\tnegate() {\n\n\t\tthis.x = - this.x;\n\t\tthis.y = - this.y;\n\n\t\treturn this;\n\n\t}\n\n\tdot( v ) {\n\n\t\treturn this.x * v.x + this.y * v.y;\n\n\t}\n\n\tcross( v ) {\n\n\t\treturn this.x * v.y - this.y * v.x;\n\n\t}\n\n\tlengthSq() {\n\n\t\treturn this.x * this.x + this.y * this.y;\n\n\t}\n\n\tlength() {\n\n\t\treturn Math.sqrt( this.x * this.x + this.y * this.y );\n\n\t}\n\n\tmanhattanLength() {\n\n\t\treturn Math.abs( this.x ) + Math.abs( this.y );\n\n\t}\n\n\tnormalize() {\n\n\t\treturn this.divideScalar( this.length() || 1 );\n\n\t}\n\n\tangle() {\n\n\t\t// computes the angle in radians with respect to the positive x-axis\n\n\t\tconst angle = Math.atan2( - this.y, - this.x ) + Math.PI;\n\n\t\treturn angle;\n\n\t}\n\n\tangleTo( v ) {\n\n\t\tconst denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );\n\n\t\tif ( denominator === 0 ) return Math.PI / 2;\n\n\t\tconst theta = this.dot( v ) / denominator;\n\n\t\t// clamp, to handle numerical problems\n\n\t\treturn Math.acos( clamp( theta, - 1, 1 ) );\n\n\t}\n\n\tdistanceTo( v ) {\n\n\t\treturn Math.sqrt( this.distanceToSquared( v ) );\n\n\t}\n\n\tdistanceToSquared( v ) {\n\n\t\tconst dx = this.x - v.x, dy = this.y - v.y;\n\t\treturn dx * dx + dy * dy;\n\n\t}\n\n\tmanhattanDistanceTo( v ) {\n\n\t\treturn Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );\n\n\t}\n\n\tsetLength( length ) {\n\n\t\treturn this.normalize().multiplyScalar( length );\n\n\t}\n\n\tlerp( v, alpha ) {\n\n\t\tthis.x += ( v.x - this.x ) * alpha;\n\t\tthis.y += ( v.y - this.y ) * alpha;\n\n\t\treturn this;\n\n\t}\n\n\tlerpVectors( v1, v2, alpha ) {\n\n\t\tthis.x = v1.x + ( v2.x - v1.x ) * alpha;\n\t\tthis.y = v1.y + ( v2.y - v1.y ) * alpha;\n\n\t\treturn this;\n\n\t}\n\n\tequals( v ) {\n\n\t\treturn ( ( v.x === this.x ) && ( v.y === this.y ) );\n\n\t}\n\n\tfromArray( array, offset = 0 ) {\n\n\t\tthis.x = array[ offset ];\n\t\tthis.y = array[ offset + 1 ];\n\n\t\treturn this;\n\n\t}\n\n\ttoArray( array = [], offset = 0 ) {\n\n\t\tarray[ offset ] = this.x;\n\t\tarray[ offset + 1 ] = this.y;\n\n\t\treturn array;\n\n\t}\n\n\tfromBufferAttribute( attribute, index ) {\n\n\t\tthis.x = attribute.getX( index );\n\t\tthis.y = attribute.getY( index );\n\n\t\treturn this;\n\n\t}\n\n\trotateAround( center, angle ) {\n\n\t\tconst c = Math.cos( angle ), s = Math.sin( angle );\n\n\t\tconst x = this.x - center.x;\n\t\tconst y = this.y - center.y;\n\n\t\tthis.x = x * c - y * s + center.x;\n\t\tthis.y = x * s + y * c + center.y;\n\n\t\treturn this;\n\n\t}\n\n\trandom() {\n\n\t\tthis.x = Math.random();\n\t\tthis.y = Math.random();\n\n\t\treturn this;\n\n\t}\n\n\t*[ Symbol.iterator ]() {\n\n\t\tyield this.x;\n\t\tyield this.y;\n\n\t}\n\n}\n\nclass Matrix3 {\n\n\tconstructor( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {\n\n\t\tMatrix3.prototype.isMatrix3 = true;\n\n\t\tthis.elements = [\n\n\t\t\t1, 0, 0,\n\t\t\t0, 1, 0,\n\t\t\t0, 0, 1\n\n\t\t];\n\n\t\tif ( n11 !== undefined ) {\n\n\t\t\tthis.set( n11, n12, n13, n21, n22, n23, n31, n32, n33 );\n\n\t\t}\n\n\t}\n\n\tset( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {\n\n\t\tconst te = this.elements;\n\n\t\tte[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;\n\t\tte[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;\n\t\tte[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;\n\n\t\treturn this;\n\n\t}\n\n\tidentity() {\n\n\t\tthis.set(\n\n\t\t\t1, 0, 0,\n\t\t\t0, 1, 0,\n\t\t\t0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\tcopy( m ) {\n\n\t\tconst te = this.elements;\n\t\tconst me = m.elements;\n\n\t\tte[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];\n\t\tte[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];\n\t\tte[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];\n\n\t\treturn this;\n\n\t}\n\n\textractBasis( xAxis, yAxis, zAxis ) {\n\n\t\txAxis.setFromMatrix3Column( this, 0 );\n\t\tyAxis.setFromMatrix3Column( this, 1 );\n\t\tzAxis.setFromMatrix3Column( this, 2 );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromMatrix4( m ) {\n\n\t\tconst me = m.elements;\n\n\t\tthis.set(\n\n\t\t\tme[ 0 ], me[ 4 ], me[ 8 ],\n\t\t\tme[ 1 ], me[ 5 ], me[ 9 ],\n\t\t\tme[ 2 ], me[ 6 ], me[ 10 ]\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\tmultiply( m ) {\n\n\t\treturn this.multiplyMatrices( this, m );\n\n\t}\n\n\tpremultiply( m ) {\n\n\t\treturn this.multiplyMatrices( m, this );\n\n\t}\n\n\tmultiplyMatrices( a, b ) {\n\n\t\tconst ae = a.elements;\n\t\tconst be = b.elements;\n\t\tconst te = this.elements;\n\n\t\tconst a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];\n\t\tconst a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];\n\t\tconst a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];\n\n\t\tconst b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];\n\t\tconst b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];\n\t\tconst b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];\n\n\t\tte[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;\n\t\tte[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;\n\t\tte[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;\n\n\t\tte[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;\n\t\tte[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;\n\t\tte[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;\n\n\t\tte[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;\n\t\tte[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;\n\t\tte[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;\n\n\t\treturn this;\n\n\t}\n\n\tmultiplyScalar( s ) {\n\n\t\tconst te = this.elements;\n\n\t\tte[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;\n\t\tte[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;\n\t\tte[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;\n\n\t\treturn this;\n\n\t}\n\n\tdeterminant() {\n\n\t\tconst te = this.elements;\n\n\t\tconst a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],\n\t\t\td = te[ 3 ], e = te[ 4 ], f = te[ 5 ],\n\t\t\tg = te[ 6 ], h = te[ 7 ], i = te[ 8 ];\n\n\t\treturn a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;\n\n\t}\n\n\tinvert() {\n\n\t\tconst te = this.elements,\n\n\t\t\tn11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ],\n\t\t\tn12 = te[ 3 ], n22 = te[ 4 ], n32 = te[ 5 ],\n\t\t\tn13 = te[ 6 ], n23 = te[ 7 ], n33 = te[ 8 ],\n\n\t\t\tt11 = n33 * n22 - n32 * n23,\n\t\t\tt12 = n32 * n13 - n33 * n12,\n\t\t\tt13 = n23 * n12 - n22 * n13,\n\n\t\t\tdet = n11 * t11 + n21 * t12 + n31 * t13;\n\n\t\tif ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );\n\n\t\tconst detInv = 1 / det;\n\n\t\tte[ 0 ] = t11 * detInv;\n\t\tte[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;\n\t\tte[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;\n\n\t\tte[ 3 ] = t12 * detInv;\n\t\tte[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;\n\t\tte[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;\n\n\t\tte[ 6 ] = t13 * detInv;\n\t\tte[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;\n\t\tte[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;\n\n\t\treturn this;\n\n\t}\n\n\ttranspose() {\n\n\t\tlet tmp;\n\t\tconst m = this.elements;\n\n\t\ttmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;\n\t\ttmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;\n\t\ttmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;\n\n\t\treturn this;\n\n\t}\n\n\tgetNormalMatrix( matrix4 ) {\n\n\t\treturn this.setFromMatrix4( matrix4 ).invert().transpose();\n\n\t}\n\n\ttransposeIntoArray( r ) {\n\n\t\tconst m = this.elements;\n\n\t\tr[ 0 ] = m[ 0 ];\n\t\tr[ 1 ] = m[ 3 ];\n\t\tr[ 2 ] = m[ 6 ];\n\t\tr[ 3 ] = m[ 1 ];\n\t\tr[ 4 ] = m[ 4 ];\n\t\tr[ 5 ] = m[ 7 ];\n\t\tr[ 6 ] = m[ 2 ];\n\t\tr[ 7 ] = m[ 5 ];\n\t\tr[ 8 ] = m[ 8 ];\n\n\t\treturn this;\n\n\t}\n\n\tsetUvTransform( tx, ty, sx, sy, rotation, cx, cy ) {\n\n\t\tconst c = Math.cos( rotation );\n\t\tconst s = Math.sin( rotation );\n\n\t\tthis.set(\n\t\t\tsx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,\n\t\t\t- sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,\n\t\t\t0, 0, 1\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\t//\n\n\tscale( sx, sy ) {\n\n\t\tthis.premultiply( _m3.makeScale( sx, sy ) );\n\n\t\treturn this;\n\n\t}\n\n\trotate( theta ) {\n\n\t\tthis.premultiply( _m3.makeRotation( - theta ) );\n\n\t\treturn this;\n\n\t}\n\n\ttranslate( tx, ty ) {\n\n\t\tthis.premultiply( _m3.makeTranslation( tx, ty ) );\n\n\t\treturn this;\n\n\t}\n\n\t// for 2D Transforms\n\n\tmakeTranslation( x, y ) {\n\n\t\tif ( x.isVector2 ) {\n\n\t\t\tthis.set(\n\n\t\t\t\t1, 0, x.x,\n\t\t\t\t0, 1, x.y,\n\t\t\t\t0, 0, 1\n\n\t\t\t);\n\n\t\t} else {\n\n\t\t\tthis.set(\n\n\t\t\t\t1, 0, x,\n\t\t\t\t0, 1, y,\n\t\t\t\t0, 0, 1\n\n\t\t\t);\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tmakeRotation( theta ) {\n\n\t\t// counterclockwise\n\n\t\tconst c = Math.cos( theta );\n\t\tconst s = Math.sin( theta );\n\n\t\tthis.set(\n\n\t\t\tc, - s, 0,\n\t\t\ts, c, 0,\n\t\t\t0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\tmakeScale( x, y ) {\n\n\t\tthis.set(\n\n\t\t\tx, 0, 0,\n\t\t\t0, y, 0,\n\t\t\t0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\t//\n\n\tequals( matrix ) {\n\n\t\tconst te = this.elements;\n\t\tconst me = matrix.elements;\n\n\t\tfor ( let i = 0; i < 9; i ++ ) {\n\n\t\t\tif ( te[ i ] !== me[ i ] ) return false;\n\n\t\t}\n\n\t\treturn true;\n\n\t}\n\n\tfromArray( array, offset = 0 ) {\n\n\t\tfor ( let i = 0; i < 9; i ++ ) {\n\n\t\t\tthis.elements[ i ] = array[ i + offset ];\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\ttoArray( array = [], offset = 0 ) {\n\n\t\tconst te = this.elements;\n\n\t\tarray[ offset ] = te[ 0 ];\n\t\tarray[ offset + 1 ] = te[ 1 ];\n\t\tarray[ offset + 2 ] = te[ 2 ];\n\n\t\tarray[ offset + 3 ] = te[ 3 ];\n\t\tarray[ offset + 4 ] = te[ 4 ];\n\t\tarray[ offset + 5 ] = te[ 5 ];\n\n\t\tarray[ offset + 6 ] = te[ 6 ];\n\t\tarray[ offset + 7 ] = te[ 7 ];\n\t\tarray[ offset + 8 ] = te[ 8 ];\n\n\t\treturn array;\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().fromArray( this.elements );\n\n\t}\n\n}\n\nconst _m3 = /*@__PURE__*/ new Matrix3();\n\nfunction arrayNeedsUint32( array ) {\n\n\t// assumes larger values usually on last\n\n\tfor ( let i = array.length - 1; i >= 0; -- i ) {\n\n\t\tif ( array[ i ] >= 65535 ) return true; // account for PRIMITIVE_RESTART_FIXED_INDEX, #24565\n\n\t}\n\n\treturn false;\n\n}\n\nconst TYPED_ARRAYS = {\n\tInt8Array: Int8Array,\n\tUint8Array: Uint8Array,\n\tUint8ClampedArray: Uint8ClampedArray,\n\tInt16Array: Int16Array,\n\tUint16Array: Uint16Array,\n\tInt32Array: Int32Array,\n\tUint32Array: Uint32Array,\n\tFloat32Array: Float32Array,\n\tFloat64Array: Float64Array\n};\n\nfunction getTypedArray( type, buffer ) {\n\n\treturn new TYPED_ARRAYS[ type ]( buffer );\n\n}\n\nfunction createElementNS( name ) {\n\n\treturn document.createElementNS( 'http://www.w3.org/1999/xhtml', name );\n\n}\n\nfunction createCanvasElement() {\n\n\tconst canvas = createElementNS( 'canvas' );\n\tcanvas.style.display = 'block';\n\treturn canvas;\n\n}\n\nconst _cache = {};\n\nfunction warnOnce( message ) {\n\n\tif ( message in _cache ) return;\n\n\t_cache[ message ] = true;\n\n\tconsole.warn( message );\n\n}\n\nfunction probeAsync( gl, sync, interval ) {\n\n\treturn new Promise( function ( resolve, reject ) {\n\n\t\tfunction probe() {\n\n\t\t\tswitch ( gl.clientWaitSync( sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0 ) ) {\n\n\t\t\t\tcase gl.WAIT_FAILED:\n\t\t\t\t\treject();\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase gl.TIMEOUT_EXPIRED:\n\t\t\t\t\tsetTimeout( probe, interval );\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\t\t\t\t\tresolve();\n\n\t\t\t}\n\n\t\t}\n\n\t\tsetTimeout( probe, interval );\n\n\t} );\n\n}\n\n/**\n * Matrices converting P3 <-> Rec. 709 primaries, without gamut mapping\n * or clipping. Based on W3C specifications for sRGB and Display P3,\n * and ICC specifications for the D50 connection space. Values in/out\n * are _linear_ sRGB and _linear_ Display P3.\n *\n * Note that both sRGB and Display P3 use the sRGB transfer functions.\n *\n * Reference:\n * - http://www.russellcottrell.com/photo/matrixCalculator.htm\n */\n\nconst LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = /*@__PURE__*/ new Matrix3().set(\n\t0.8224621, 0.177538, 0.0,\n\t0.0331941, 0.9668058, 0.0,\n\t0.0170827, 0.0723974, 0.9105199,\n);\n\nconst LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = /*@__PURE__*/ new Matrix3().set(\n\t1.2249401, - 0.2249404, 0.0,\n\t- 0.0420569, 1.0420571, 0.0,\n\t- 0.0196376, - 0.0786361, 1.0982735\n);\n\n/**\n * Defines supported color spaces by transfer function and primaries,\n * and provides conversions to/from the Linear-sRGB reference space.\n */\nconst COLOR_SPACES = {\n\t[ LinearSRGBColorSpace ]: {\n\t\ttransfer: LinearTransfer,\n\t\tprimaries: Rec709Primaries,\n\t\tluminanceCoefficients: [ 0.2126, 0.7152, 0.0722 ],\n\t\ttoReference: ( color ) => color,\n\t\tfromReference: ( color ) => color,\n\t},\n\t[ SRGBColorSpace ]: {\n\t\ttransfer: SRGBTransfer,\n\t\tprimaries: Rec709Primaries,\n\t\tluminanceCoefficients: [ 0.2126, 0.7152, 0.0722 ],\n\t\ttoReference: ( color ) => color.convertSRGBToLinear(),\n\t\tfromReference: ( color ) => color.convertLinearToSRGB(),\n\t},\n\t[ LinearDisplayP3ColorSpace ]: {\n\t\ttransfer: LinearTransfer,\n\t\tprimaries: P3Primaries,\n\t\tluminanceCoefficients: [ 0.2289, 0.6917, 0.0793 ],\n\t\ttoReference: ( color ) => color.applyMatrix3( LINEAR_DISPLAY_P3_TO_LINEAR_SRGB ),\n\t\tfromReference: ( color ) => color.applyMatrix3( LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 ),\n\t},\n\t[ DisplayP3ColorSpace ]: {\n\t\ttransfer: SRGBTransfer,\n\t\tprimaries: P3Primaries,\n\t\tluminanceCoefficients: [ 0.2289, 0.6917, 0.0793 ],\n\t\ttoReference: ( color ) => color.convertSRGBToLinear().applyMatrix3( LINEAR_DISPLAY_P3_TO_LINEAR_SRGB ),\n\t\tfromReference: ( color ) => color.applyMatrix3( LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 ).convertLinearToSRGB(),\n\t},\n};\n\nconst SUPPORTED_WORKING_COLOR_SPACES = new Set( [ LinearSRGBColorSpace, LinearDisplayP3ColorSpace ] );\n\nconst ColorManagement = {\n\n\tenabled: true,\n\n\t_workingColorSpace: LinearSRGBColorSpace,\n\n\tget workingColorSpace() {\n\n\t\treturn this._workingColorSpace;\n\n\t},\n\n\tset workingColorSpace( colorSpace ) {\n\n\t\tif ( ! SUPPORTED_WORKING_COLOR_SPACES.has( colorSpace ) ) {\n\n\t\t\tthrow new Error( `Unsupported working color space, \"${ colorSpace }\".` );\n\n\t\t}\n\n\t\tthis._workingColorSpace = colorSpace;\n\n\t},\n\n\tconvert: function ( color, sourceColorSpace, targetColorSpace ) {\n\n\t\tif ( this.enabled === false || sourceColorSpace === targetColorSpace || ! sourceColorSpace || ! targetColorSpace ) {\n\n\t\t\treturn color;\n\n\t\t}\n\n\t\tconst sourceToReference = COLOR_SPACES[ sourceColorSpace ].toReference;\n\t\tconst targetFromReference = COLOR_SPACES[ targetColorSpace ].fromReference;\n\n\t\treturn targetFromReference( sourceToReference( color ) );\n\n\t},\n\n\tfromWorkingColorSpace: function ( color, targetColorSpace ) {\n\n\t\treturn this.convert( color, this._workingColorSpace, targetColorSpace );\n\n\t},\n\n\ttoWorkingColorSpace: function ( color, sourceColorSpace ) {\n\n\t\treturn this.convert( color, sourceColorSpace, this._workingColorSpace );\n\n\t},\n\n\tgetPrimaries: function ( colorSpace ) {\n\n\t\treturn COLOR_SPACES[ colorSpace ].primaries;\n\n\t},\n\n\tgetTransfer: function ( colorSpace ) {\n\n\t\tif ( colorSpace === NoColorSpace ) return LinearTransfer;\n\n\t\treturn COLOR_SPACES[ colorSpace ].transfer;\n\n\t},\n\n\tgetLuminanceCoefficients: function ( target, colorSpace = this._workingColorSpace ) {\n\n\t\treturn target.fromArray( COLOR_SPACES[ colorSpace ].luminanceCoefficients );\n\n\t},\n\n};\n\n\nfunction SRGBToLinear( c ) {\n\n\treturn ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );\n\n}\n\nfunction LinearToSRGB( c ) {\n\n\treturn ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;\n\n}\n\nlet _canvas;\n\nclass ImageUtils {\n\n\tstatic getDataURL( image ) {\n\n\t\tif ( /^data:/i.test( image.src ) ) {\n\n\t\t\treturn image.src;\n\n\t\t}\n\n\t\tif ( typeof HTMLCanvasElement === 'undefined' ) {\n\n\t\t\treturn image.src;\n\n\t\t}\n\n\t\tlet canvas;\n\n\t\tif ( image instanceof HTMLCanvasElement ) {\n\n\t\t\tcanvas = image;\n\n\t\t} else {\n\n\t\t\tif ( _canvas === undefined ) _canvas = createElementNS( 'canvas' );\n\n\t\t\t_canvas.width = image.width;\n\t\t\t_canvas.height = image.height;\n\n\t\t\tconst context = _canvas.getContext( '2d' );\n\n\t\t\tif ( image instanceof ImageData ) {\n\n\t\t\t\tcontext.putImageData( image, 0, 0 );\n\n\t\t\t} else {\n\n\t\t\t\tcontext.drawImage( image, 0, 0, image.width, image.height );\n\n\t\t\t}\n\n\t\t\tcanvas = _canvas;\n\n\t\t}\n\n\t\tif ( canvas.width > 2048 || canvas.height > 2048 ) {\n\n\t\t\tconsole.warn( 'THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons', image );\n\n\t\t\treturn canvas.toDataURL( 'image/jpeg', 0.6 );\n\n\t\t} else {\n\n\t\t\treturn canvas.toDataURL( 'image/png' );\n\n\t\t}\n\n\t}\n\n\tstatic sRGBToLinear( image ) {\n\n\t\tif ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||\n\t\t\t( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||\n\t\t\t( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {\n\n\t\t\tconst canvas = createElementNS( 'canvas' );\n\n\t\t\tcanvas.width = image.width;\n\t\t\tcanvas.height = image.height;\n\n\t\t\tconst context = canvas.getContext( '2d' );\n\t\t\tcontext.drawImage( image, 0, 0, image.width, image.height );\n\n\t\t\tconst imageData = context.getImageData( 0, 0, image.width, image.height );\n\t\t\tconst data = imageData.data;\n\n\t\t\tfor ( let i = 0; i < data.length; i ++ ) {\n\n\t\t\t\tdata[ i ] = SRGBToLinear( data[ i ] / 255 ) * 255;\n\n\t\t\t}\n\n\t\t\tcontext.putImageData( imageData, 0, 0 );\n\n\t\t\treturn canvas;\n\n\t\t} else if ( image.data ) {\n\n\t\t\tconst data = image.data.slice( 0 );\n\n\t\t\tfor ( let i = 0; i < data.length; i ++ ) {\n\n\t\t\t\tif ( data instanceof Uint8Array || data instanceof Uint8ClampedArray ) {\n\n\t\t\t\t\tdata[ i ] = Math.floor( SRGBToLinear( data[ i ] / 255 ) * 255 );\n\n\t\t\t\t} else {\n\n\t\t\t\t\t// assuming float\n\n\t\t\t\t\tdata[ i ] = SRGBToLinear( data[ i ] );\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tdata: data,\n\t\t\t\twidth: image.width,\n\t\t\t\theight: image.height\n\t\t\t};\n\n\t\t} else {\n\n\t\t\tconsole.warn( 'THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.' );\n\t\t\treturn image;\n\n\t\t}\n\n\t}\n\n}\n\nlet _sourceId = 0;\n\nclass Source {\n\n\tconstructor( data = null ) {\n\n\t\tthis.isSource = true;\n\n\t\tObject.defineProperty( this, 'id', { value: _sourceId ++ } );\n\n\t\tthis.uuid = generateUUID();\n\n\t\tthis.data = data;\n\t\tthis.dataReady = true;\n\n\t\tthis.version = 0;\n\n\t}\n\n\tset needsUpdate( value ) {\n\n\t\tif ( value === true ) this.version ++;\n\n\t}\n\n\ttoJSON( meta ) {\n\n\t\tconst isRootObject = ( meta === undefined || typeof meta === 'string' );\n\n\t\tif ( ! isRootObject && meta.images[ this.uuid ] !== undefined ) {\n\n\t\t\treturn meta.images[ this.uuid ];\n\n\t\t}\n\n\t\tconst output = {\n\t\t\tuuid: this.uuid,\n\t\t\turl: ''\n\t\t};\n\n\t\tconst data = this.data;\n\n\t\tif ( data !== null ) {\n\n\t\t\tlet url;\n\n\t\t\tif ( Array.isArray( data ) ) {\n\n\t\t\t\t// cube texture\n\n\t\t\t\turl = [];\n\n\t\t\t\tfor ( let i = 0, l = data.length; i < l; i ++ ) {\n\n\t\t\t\t\tif ( data[ i ].isDataTexture ) {\n\n\t\t\t\t\t\turl.push( serializeImage( data[ i ].image ) );\n\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\turl.push( serializeImage( data[ i ] ) );\n\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\t\t\t} else {\n\n\t\t\t\t// texture\n\n\t\t\t\turl = serializeImage( data );\n\n\t\t\t}\n\n\t\t\toutput.url = url;\n\n\t\t}\n\n\t\tif ( ! isRootObject ) {\n\n\t\t\tmeta.images[ this.uuid ] = output;\n\n\t\t}\n\n\t\treturn output;\n\n\t}\n\n}\n\nfunction serializeImage( image ) {\n\n\tif ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||\n\t\t( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||\n\t\t( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {\n\n\t\t// default images\n\n\t\treturn ImageUtils.getDataURL( image );\n\n\t} else {\n\n\t\tif ( image.data ) {\n\n\t\t\t// images of DataTexture\n\n\t\t\treturn {\n\t\t\t\tdata: Array.from( image.data ),\n\t\t\t\twidth: image.width,\n\t\t\t\theight: image.height,\n\t\t\t\ttype: image.data.constructor.name\n\t\t\t};\n\n\t\t} else {\n\n\t\t\tconsole.warn( 'THREE.Texture: Unable to serialize Texture.' );\n\t\t\treturn {};\n\n\t\t}\n\n\t}\n\n}\n\nlet _textureId = 0;\n\nclass Texture extends EventDispatcher {\n\n\tconstructor( image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = Texture.DEFAULT_ANISOTROPY, colorSpace = NoColorSpace ) {\n\n\t\tsuper();\n\n\t\tthis.isTexture = true;\n\n\t\tObject.defineProperty( this, 'id', { value: _textureId ++ } );\n\n\t\tthis.uuid = generateUUID();\n\n\t\tthis.name = '';\n\n\t\tthis.source = new Source( image );\n\t\tthis.mipmaps = [];\n\n\t\tthis.mapping = mapping;\n\t\tthis.channel = 0;\n\n\t\tthis.wrapS = wrapS;\n\t\tthis.wrapT = wrapT;\n\n\t\tthis.magFilter = magFilter;\n\t\tthis.minFilter = minFilter;\n\n\t\tthis.anisotropy = anisotropy;\n\n\t\tthis.format = format;\n\t\tthis.internalFormat = null;\n\t\tthis.type = type;\n\n\t\tthis.offset = new Vector2( 0, 0 );\n\t\tthis.repeat = new Vector2( 1, 1 );\n\t\tthis.center = new Vector2( 0, 0 );\n\t\tthis.rotation = 0;\n\n\t\tthis.matrixAutoUpdate = true;\n\t\tthis.matrix = new Matrix3();\n\n\t\tthis.generateMipmaps = true;\n\t\tthis.premultiplyAlpha = false;\n\t\tthis.flipY = true;\n\t\tthis.unpackAlignment = 4;\t// valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)\n\n\t\tthis.colorSpace = colorSpace;\n\n\t\tthis.userData = {};\n\n\t\tthis.version = 0;\n\t\tthis.onUpdate = null;\n\n\t\tthis.isRenderTargetTexture = false; // indicates whether a texture belongs to a render target or not\n\t\tthis.pmremVersion = 0; // indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures)\n\n\t}\n\n\tget image() {\n\n\t\treturn this.source.data;\n\n\t}\n\n\tset image( value = null ) {\n\n\t\tthis.source.data = value;\n\n\t}\n\n\tupdateMatrix() {\n\n\t\tthis.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n\tcopy( source ) {\n\n\t\tthis.name = source.name;\n\n\t\tthis.source = source.source;\n\t\tthis.mipmaps = source.mipmaps.slice( 0 );\n\n\t\tthis.mapping = source.mapping;\n\t\tthis.channel = source.channel;\n\n\t\tthis.wrapS = source.wrapS;\n\t\tthis.wrapT = source.wrapT;\n\n\t\tthis.magFilter = source.magFilter;\n\t\tthis.minFilter = source.minFilter;\n\n\t\tthis.anisotropy = source.anisotropy;\n\n\t\tthis.format = source.format;\n\t\tthis.internalFormat = source.internalFormat;\n\t\tthis.type = source.type;\n\n\t\tthis.offset.copy( source.offset );\n\t\tthis.repeat.copy( source.repeat );\n\t\tthis.center.copy( source.center );\n\t\tthis.rotation = source.rotation;\n\n\t\tthis.matrixAutoUpdate = source.matrixAutoUpdate;\n\t\tthis.matrix.copy( source.matrix );\n\n\t\tthis.generateMipmaps = source.generateMipmaps;\n\t\tthis.premultiplyAlpha = source.premultiplyAlpha;\n\t\tthis.flipY = source.flipY;\n\t\tthis.unpackAlignment = source.unpackAlignment;\n\t\tthis.colorSpace = source.colorSpace;\n\n\t\tthis.userData = JSON.parse( JSON.stringify( source.userData ) );\n\n\t\tthis.needsUpdate = true;\n\n\t\treturn this;\n\n\t}\n\n\ttoJSON( meta ) {\n\n\t\tconst isRootObject = ( meta === undefined || typeof meta === 'string' );\n\n\t\tif ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {\n\n\t\t\treturn meta.textures[ this.uuid ];\n\n\t\t}\n\n\t\tconst output = {\n\n\t\t\tmetadata: {\n\t\t\t\tversion: 4.6,\n\t\t\t\ttype: 'Texture',\n\t\t\t\tgenerator: 'Texture.toJSON'\n\t\t\t},\n\n\t\t\tuuid: this.uuid,\n\t\t\tname: this.name,\n\n\t\t\timage: this.source.toJSON( meta ).uuid,\n\n\t\t\tmapping: this.mapping,\n\t\t\tchannel: this.channel,\n\n\t\t\trepeat: [ this.repeat.x, this.repeat.y ],\n\t\t\toffset: [ this.offset.x, this.offset.y ],\n\t\t\tcenter: [ this.center.x, this.center.y ],\n\t\t\trotation: this.rotation,\n\n\t\t\twrap: [ this.wrapS, this.wrapT ],\n\n\t\t\tformat: this.format,\n\t\t\tinternalFormat: this.internalFormat,\n\t\t\ttype: this.type,\n\t\t\tcolorSpace: this.colorSpace,\n\n\t\t\tminFilter: this.minFilter,\n\t\t\tmagFilter: this.magFilter,\n\t\t\tanisotropy: this.anisotropy,\n\n\t\t\tflipY: this.flipY,\n\n\t\t\tgenerateMipmaps: this.generateMipmaps,\n\t\t\tpremultiplyAlpha: this.premultiplyAlpha,\n\t\t\tunpackAlignment: this.unpackAlignment\n\n\t\t};\n\n\t\tif ( Object.keys( this.userData ).length > 0 ) output.userData = this.userData;\n\n\t\tif ( ! isRootObject ) {\n\n\t\t\tmeta.textures[ this.uuid ] = output;\n\n\t\t}\n\n\t\treturn output;\n\n\t}\n\n\tdispose() {\n\n\t\tthis.dispatchEvent( { type: 'dispose' } );\n\n\t}\n\n\ttransformUv( uv ) {\n\n\t\tif ( this.mapping !== UVMapping ) return uv;\n\n\t\tuv.applyMatrix3( this.matrix );\n\n\t\tif ( uv.x < 0 || uv.x > 1 ) {\n\n\t\t\tswitch ( this.wrapS ) {\n\n\t\t\t\tcase RepeatWrapping:\n\n\t\t\t\t\tuv.x = uv.x - Math.floor( uv.x );\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase ClampToEdgeWrapping:\n\n\t\t\t\t\tuv.x = uv.x < 0 ? 0 : 1;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MirroredRepeatWrapping:\n\n\t\t\t\t\tif ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {\n\n\t\t\t\t\t\tuv.x = Math.ceil( uv.x ) - uv.x;\n\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\tuv.x = uv.x - Math.floor( uv.x );\n\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\n\t\t\t}\n\n\t\t}\n\n\t\tif ( uv.y < 0 || uv.y > 1 ) {\n\n\t\t\tswitch ( this.wrapT ) {\n\n\t\t\t\tcase RepeatWrapping:\n\n\t\t\t\t\tuv.y = uv.y - Math.floor( uv.y );\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase ClampToEdgeWrapping:\n\n\t\t\t\t\tuv.y = uv.y < 0 ? 0 : 1;\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase MirroredRepeatWrapping:\n\n\t\t\t\t\tif ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {\n\n\t\t\t\t\t\tuv.y = Math.ceil( uv.y ) - uv.y;\n\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\tuv.y = uv.y - Math.floor( uv.y );\n\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\n\t\t\t}\n\n\t\t}\n\n\t\tif ( this.flipY ) {\n\n\t\t\tuv.y = 1 - uv.y;\n\n\t\t}\n\n\t\treturn uv;\n\n\t}\n\n\tset needsUpdate( value ) {\n\n\t\tif ( value === true ) {\n\n\t\t\tthis.version ++;\n\t\t\tthis.source.needsUpdate = true;\n\n\t\t}\n\n\t}\n\n\tset needsPMREMUpdate( value ) {\n\n\t\tif ( value === true ) {\n\n\t\t\tthis.pmremVersion ++;\n\n\t\t}\n\n\t}\n\n}\n\nTexture.DEFAULT_IMAGE = null;\nTexture.DEFAULT_MAPPING = UVMapping;\nTexture.DEFAULT_ANISOTROPY = 1;\n\nclass Vector4 {\n\n\tconstructor( x = 0, y = 0, z = 0, w = 1 ) {\n\n\t\tVector4.prototype.isVector4 = true;\n\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.z = z;\n\t\tthis.w = w;\n\n\t}\n\n\tget width() {\n\n\t\treturn this.z;\n\n\t}\n\n\tset width( value ) {\n\n\t\tthis.z = value;\n\n\t}\n\n\tget height() {\n\n\t\treturn this.w;\n\n\t}\n\n\tset height( value ) {\n\n\t\tthis.w = value;\n\n\t}\n\n\tset( x, y, z, w ) {\n\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.z = z;\n\t\tthis.w = w;\n\n\t\treturn this;\n\n\t}\n\n\tsetScalar( scalar ) {\n\n\t\tthis.x = scalar;\n\t\tthis.y = scalar;\n\t\tthis.z = scalar;\n\t\tthis.w = scalar;\n\n\t\treturn this;\n\n\t}\n\n\tsetX( x ) {\n\n\t\tthis.x = x;\n\n\t\treturn this;\n\n\t}\n\n\tsetY( y ) {\n\n\t\tthis.y = y;\n\n\t\treturn this;\n\n\t}\n\n\tsetZ( z ) {\n\n\t\tthis.z = z;\n\n\t\treturn this;\n\n\t}\n\n\tsetW( w ) {\n\n\t\tthis.w = w;\n\n\t\treturn this;\n\n\t}\n\n\tsetComponent( index, value ) {\n\n\t\tswitch ( index ) {\n\n\t\t\tcase 0: this.x = value; break;\n\t\t\tcase 1: this.y = value; break;\n\t\t\tcase 2: this.z = value; break;\n\t\t\tcase 3: this.w = value; break;\n\t\t\tdefault: throw new Error( 'index is out of range: ' + index );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tgetComponent( index ) {\n\n\t\tswitch ( index ) {\n\n\t\t\tcase 0: return this.x;\n\t\t\tcase 1: return this.y;\n\t\t\tcase 2: return this.z;\n\t\t\tcase 3: return this.w;\n\t\t\tdefault: throw new Error( 'index is out of range: ' + index );\n\n\t\t}\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor( this.x, this.y, this.z, this.w );\n\n\t}\n\n\tcopy( v ) {\n\n\t\tthis.x = v.x;\n\t\tthis.y = v.y;\n\t\tthis.z = v.z;\n\t\tthis.w = ( v.w !== undefined ) ? v.w : 1;\n\n\t\treturn this;\n\n\t}\n\n\tadd( v ) {\n\n\t\tthis.x += v.x;\n\t\tthis.y += v.y;\n\t\tthis.z += v.z;\n\t\tthis.w += v.w;\n\n\t\treturn this;\n\n\t}\n\n\taddScalar( s ) {\n\n\t\tthis.x += s;\n\t\tthis.y += s;\n\t\tthis.z += s;\n\t\tthis.w += s;\n\n\t\treturn this;\n\n\t}\n\n\taddVectors( a, b ) {\n\n\t\tthis.x = a.x + b.x;\n\t\tthis.y = a.y + b.y;\n\t\tthis.z = a.z + b.z;\n\t\tthis.w = a.w + b.w;\n\n\t\treturn this;\n\n\t}\n\n\taddScaledVector( v, s ) {\n\n\t\tthis.x += v.x * s;\n\t\tthis.y += v.y * s;\n\t\tthis.z += v.z * s;\n\t\tthis.w += v.w * s;\n\n\t\treturn this;\n\n\t}\n\n\tsub( v ) {\n\n\t\tthis.x -= v.x;\n\t\tthis.y -= v.y;\n\t\tthis.z -= v.z;\n\t\tthis.w -= v.w;\n\n\t\treturn this;\n\n\t}\n\n\tsubScalar( s ) {\n\n\t\tthis.x -= s;\n\t\tthis.y -= s;\n\t\tthis.z -= s;\n\t\tthis.w -= s;\n\n\t\treturn this;\n\n\t}\n\n\tsubVectors( a, b ) {\n\n\t\tthis.x = a.x - b.x;\n\t\tthis.y = a.y - b.y;\n\t\tthis.z = a.z - b.z;\n\t\tthis.w = a.w - b.w;\n\n\t\treturn this;\n\n\t}\n\n\tmultiply( v ) {\n\n\t\tthis.x *= v.x;\n\t\tthis.y *= v.y;\n\t\tthis.z *= v.z;\n\t\tthis.w *= v.w;\n\n\t\treturn this;\n\n\t}\n\n\tmultiplyScalar( scalar ) {\n\n\t\tthis.x *= scalar;\n\t\tthis.y *= scalar;\n\t\tthis.z *= scalar;\n\t\tthis.w *= scalar;\n\n\t\treturn this;\n\n\t}\n\n\tapplyMatrix4( m ) {\n\n\t\tconst x = this.x, y = this.y, z = this.z, w = this.w;\n\t\tconst e = m.elements;\n\n\t\tthis.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;\n\t\tthis.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;\n\t\tthis.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;\n\t\tthis.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;\n\n\t\treturn this;\n\n\t}\n\n\tdivideScalar( scalar ) {\n\n\t\treturn this.multiplyScalar( 1 / scalar );\n\n\t}\n\n\tsetAxisAngleFromQuaternion( q ) {\n\n\t\t// http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm\n\n\t\t// q is assumed to be normalized\n\n\t\tthis.w = 2 * Math.acos( q.w );\n\n\t\tconst s = Math.sqrt( 1 - q.w * q.w );\n\n\t\tif ( s < 0.0001 ) {\n\n\t\t\tthis.x = 1;\n\t\t\tthis.y = 0;\n\t\t\tthis.z = 0;\n\n\t\t} else {\n\n\t\t\tthis.x = q.x / s;\n\t\t\tthis.y = q.y / s;\n\t\t\tthis.z = q.z / s;\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tsetAxisAngleFromRotationMatrix( m ) {\n\n\t\t// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm\n\n\t\t// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)\n\n\t\tlet angle, x, y, z; // variables for result\n\t\tconst epsilon = 0.01,\t\t// margin to allow for rounding errors\n\t\t\tepsilon2 = 0.1,\t\t// margin to distinguish between 0 and 180 degrees\n\n\t\t\tte = m.elements,\n\n\t\t\tm11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],\n\t\t\tm21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],\n\t\t\tm31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];\n\n\t\tif ( ( Math.abs( m12 - m21 ) < epsilon ) &&\n\t\t ( Math.abs( m13 - m31 ) < epsilon ) &&\n\t\t ( Math.abs( m23 - m32 ) < epsilon ) ) {\n\n\t\t\t// singularity found\n\t\t\t// first check for identity matrix which must have +1 for all terms\n\t\t\t// in leading diagonal and zero in other terms\n\n\t\t\tif ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&\n\t\t\t ( Math.abs( m13 + m31 ) < epsilon2 ) &&\n\t\t\t ( Math.abs( m23 + m32 ) < epsilon2 ) &&\n\t\t\t ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {\n\n\t\t\t\t// this singularity is identity matrix so angle = 0\n\n\t\t\t\tthis.set( 1, 0, 0, 0 );\n\n\t\t\t\treturn this; // zero angle, arbitrary axis\n\n\t\t\t}\n\n\t\t\t// otherwise this singularity is angle = 180\n\n\t\t\tangle = Math.PI;\n\n\t\t\tconst xx = ( m11 + 1 ) / 2;\n\t\t\tconst yy = ( m22 + 1 ) / 2;\n\t\t\tconst zz = ( m33 + 1 ) / 2;\n\t\t\tconst xy = ( m12 + m21 ) / 4;\n\t\t\tconst xz = ( m13 + m31 ) / 4;\n\t\t\tconst yz = ( m23 + m32 ) / 4;\n\n\t\t\tif ( ( xx > yy ) && ( xx > zz ) ) {\n\n\t\t\t\t// m11 is the largest diagonal term\n\n\t\t\t\tif ( xx < epsilon ) {\n\n\t\t\t\t\tx = 0;\n\t\t\t\t\ty = 0.707106781;\n\t\t\t\t\tz = 0.707106781;\n\n\t\t\t\t} else {\n\n\t\t\t\t\tx = Math.sqrt( xx );\n\t\t\t\t\ty = xy / x;\n\t\t\t\t\tz = xz / x;\n\n\t\t\t\t}\n\n\t\t\t} else if ( yy > zz ) {\n\n\t\t\t\t// m22 is the largest diagonal term\n\n\t\t\t\tif ( yy < epsilon ) {\n\n\t\t\t\t\tx = 0.707106781;\n\t\t\t\t\ty = 0;\n\t\t\t\t\tz = 0.707106781;\n\n\t\t\t\t} else {\n\n\t\t\t\t\ty = Math.sqrt( yy );\n\t\t\t\t\tx = xy / y;\n\t\t\t\t\tz = yz / y;\n\n\t\t\t\t}\n\n\t\t\t} else {\n\n\t\t\t\t// m33 is the largest diagonal term so base result on this\n\n\t\t\t\tif ( zz < epsilon ) {\n\n\t\t\t\t\tx = 0.707106781;\n\t\t\t\t\ty = 0.707106781;\n\t\t\t\t\tz = 0;\n\n\t\t\t\t} else {\n\n\t\t\t\t\tz = Math.sqrt( zz );\n\t\t\t\t\tx = xz / z;\n\t\t\t\t\ty = yz / z;\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tthis.set( x, y, z, angle );\n\n\t\t\treturn this; // return 180 deg rotation\n\n\t\t}\n\n\t\t// as we have reached here there are no singularities so we can handle normally\n\n\t\tlet s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +\n\t\t\t( m13 - m31 ) * ( m13 - m31 ) +\n\t\t\t( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize\n\n\t\tif ( Math.abs( s ) < 0.001 ) s = 1;\n\n\t\t// prevent divide by zero, should not happen if matrix is orthogonal and should be\n\t\t// caught by singularity test above, but I've left it in just in case\n\n\t\tthis.x = ( m32 - m23 ) / s;\n\t\tthis.y = ( m13 - m31 ) / s;\n\t\tthis.z = ( m21 - m12 ) / s;\n\t\tthis.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromMatrixPosition( m ) {\n\n\t\tconst e = m.elements;\n\n\t\tthis.x = e[ 12 ];\n\t\tthis.y = e[ 13 ];\n\t\tthis.z = e[ 14 ];\n\t\tthis.w = e[ 15 ];\n\n\t\treturn this;\n\n\t}\n\n\tmin( v ) {\n\n\t\tthis.x = Math.min( this.x, v.x );\n\t\tthis.y = Math.min( this.y, v.y );\n\t\tthis.z = Math.min( this.z, v.z );\n\t\tthis.w = Math.min( this.w, v.w );\n\n\t\treturn this;\n\n\t}\n\n\tmax( v ) {\n\n\t\tthis.x = Math.max( this.x, v.x );\n\t\tthis.y = Math.max( this.y, v.y );\n\t\tthis.z = Math.max( this.z, v.z );\n\t\tthis.w = Math.max( this.w, v.w );\n\n\t\treturn this;\n\n\t}\n\n\tclamp( min, max ) {\n\n\t\t// assumes min < max, componentwise\n\n\t\tthis.x = Math.max( min.x, Math.min( max.x, this.x ) );\n\t\tthis.y = Math.max( min.y, Math.min( max.y, this.y ) );\n\t\tthis.z = Math.max( min.z, Math.min( max.z, this.z ) );\n\t\tthis.w = Math.max( min.w, Math.min( max.w, this.w ) );\n\n\t\treturn this;\n\n\t}\n\n\tclampScalar( minVal, maxVal ) {\n\n\t\tthis.x = Math.max( minVal, Math.min( maxVal, this.x ) );\n\t\tthis.y = Math.max( minVal, Math.min( maxVal, this.y ) );\n\t\tthis.z = Math.max( minVal, Math.min( maxVal, this.z ) );\n\t\tthis.w = Math.max( minVal, Math.min( maxVal, this.w ) );\n\n\t\treturn this;\n\n\t}\n\n\tclampLength( min, max ) {\n\n\t\tconst length = this.length();\n\n\t\treturn this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );\n\n\t}\n\n\tfloor() {\n\n\t\tthis.x = Math.floor( this.x );\n\t\tthis.y = Math.floor( this.y );\n\t\tthis.z = Math.floor( this.z );\n\t\tthis.w = Math.floor( this.w );\n\n\t\treturn this;\n\n\t}\n\n\tceil() {\n\n\t\tthis.x = Math.ceil( this.x );\n\t\tthis.y = Math.ceil( this.y );\n\t\tthis.z = Math.ceil( this.z );\n\t\tthis.w = Math.ceil( this.w );\n\n\t\treturn this;\n\n\t}\n\n\tround() {\n\n\t\tthis.x = Math.round( this.x );\n\t\tthis.y = Math.round( this.y );\n\t\tthis.z = Math.round( this.z );\n\t\tthis.w = Math.round( this.w );\n\n\t\treturn this;\n\n\t}\n\n\troundToZero() {\n\n\t\tthis.x = Math.trunc( this.x );\n\t\tthis.y = Math.trunc( this.y );\n\t\tthis.z = Math.trunc( this.z );\n\t\tthis.w = Math.trunc( this.w );\n\n\t\treturn this;\n\n\t}\n\n\tnegate() {\n\n\t\tthis.x = - this.x;\n\t\tthis.y = - this.y;\n\t\tthis.z = - this.z;\n\t\tthis.w = - this.w;\n\n\t\treturn this;\n\n\t}\n\n\tdot( v ) {\n\n\t\treturn this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;\n\n\t}\n\n\tlengthSq() {\n\n\t\treturn this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;\n\n\t}\n\n\tlength() {\n\n\t\treturn Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );\n\n\t}\n\n\tmanhattanLength() {\n\n\t\treturn Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );\n\n\t}\n\n\tnormalize() {\n\n\t\treturn this.divideScalar( this.length() || 1 );\n\n\t}\n\n\tsetLength( length ) {\n\n\t\treturn this.normalize().multiplyScalar( length );\n\n\t}\n\n\tlerp( v, alpha ) {\n\n\t\tthis.x += ( v.x - this.x ) * alpha;\n\t\tthis.y += ( v.y - this.y ) * alpha;\n\t\tthis.z += ( v.z - this.z ) * alpha;\n\t\tthis.w += ( v.w - this.w ) * alpha;\n\n\t\treturn this;\n\n\t}\n\n\tlerpVectors( v1, v2, alpha ) {\n\n\t\tthis.x = v1.x + ( v2.x - v1.x ) * alpha;\n\t\tthis.y = v1.y + ( v2.y - v1.y ) * alpha;\n\t\tthis.z = v1.z + ( v2.z - v1.z ) * alpha;\n\t\tthis.w = v1.w + ( v2.w - v1.w ) * alpha;\n\n\t\treturn this;\n\n\t}\n\n\tequals( v ) {\n\n\t\treturn ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );\n\n\t}\n\n\tfromArray( array, offset = 0 ) {\n\n\t\tthis.x = array[ offset ];\n\t\tthis.y = array[ offset + 1 ];\n\t\tthis.z = array[ offset + 2 ];\n\t\tthis.w = array[ offset + 3 ];\n\n\t\treturn this;\n\n\t}\n\n\ttoArray( array = [], offset = 0 ) {\n\n\t\tarray[ offset ] = this.x;\n\t\tarray[ offset + 1 ] = this.y;\n\t\tarray[ offset + 2 ] = this.z;\n\t\tarray[ offset + 3 ] = this.w;\n\n\t\treturn array;\n\n\t}\n\n\tfromBufferAttribute( attribute, index ) {\n\n\t\tthis.x = attribute.getX( index );\n\t\tthis.y = attribute.getY( index );\n\t\tthis.z = attribute.getZ( index );\n\t\tthis.w = attribute.getW( index );\n\n\t\treturn this;\n\n\t}\n\n\trandom() {\n\n\t\tthis.x = Math.random();\n\t\tthis.y = Math.random();\n\t\tthis.z = Math.random();\n\t\tthis.w = Math.random();\n\n\t\treturn this;\n\n\t}\n\n\t*[ Symbol.iterator ]() {\n\n\t\tyield this.x;\n\t\tyield this.y;\n\t\tyield this.z;\n\t\tyield this.w;\n\n\t}\n\n}\n\n/*\n In options, we can specify:\n * Texture parameters for an auto-generated target texture\n * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers\n*/\nclass RenderTarget extends EventDispatcher {\n\n\tconstructor( width = 1, height = 1, options = {} ) {\n\n\t\tsuper();\n\n\t\tthis.isRenderTarget = true;\n\n\t\tthis.width = width;\n\t\tthis.height = height;\n\t\tthis.depth = 1;\n\n\t\tthis.scissor = new Vector4( 0, 0, width, height );\n\t\tthis.scissorTest = false;\n\n\t\tthis.viewport = new Vector4( 0, 0, width, height );\n\n\t\tconst image = { width: width, height: height, depth: 1 };\n\n\t\toptions = Object.assign( {\n\t\t\tgenerateMipmaps: false,\n\t\t\tinternalFormat: null,\n\t\t\tminFilter: LinearFilter,\n\t\t\tdepthBuffer: true,\n\t\t\tstencilBuffer: false,\n\t\t\tresolveDepthBuffer: true,\n\t\t\tresolveStencilBuffer: true,\n\t\t\tdepthTexture: null,\n\t\t\tsamples: 0,\n\t\t\tcount: 1\n\t\t}, options );\n\n\t\tconst texture = new Texture( image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );\n\n\t\ttexture.flipY = false;\n\t\ttexture.generateMipmaps = options.generateMipmaps;\n\t\ttexture.internalFormat = options.internalFormat;\n\n\t\tthis.textures = [];\n\n\t\tconst count = options.count;\n\t\tfor ( let i = 0; i < count; i ++ ) {\n\n\t\t\tthis.textures[ i ] = texture.clone();\n\t\t\tthis.textures[ i ].isRenderTargetTexture = true;\n\n\t\t}\n\n\t\tthis.depthBuffer = options.depthBuffer;\n\t\tthis.stencilBuffer = options.stencilBuffer;\n\n\t\tthis.resolveDepthBuffer = options.resolveDepthBuffer;\n\t\tthis.resolveStencilBuffer = options.resolveStencilBuffer;\n\n\t\tthis.depthTexture = options.depthTexture;\n\n\t\tthis.samples = options.samples;\n\n\t}\n\n\tget texture() {\n\n\t\treturn this.textures[ 0 ];\n\n\t}\n\n\tset texture( value ) {\n\n\t\tthis.textures[ 0 ] = value;\n\n\t}\n\n\tsetSize( width, height, depth = 1 ) {\n\n\t\tif ( this.width !== width || this.height !== height || this.depth !== depth ) {\n\n\t\t\tthis.width = width;\n\t\t\tthis.height = height;\n\t\t\tthis.depth = depth;\n\n\t\t\tfor ( let i = 0, il = this.textures.length; i < il; i ++ ) {\n\n\t\t\t\tthis.textures[ i ].image.width = width;\n\t\t\t\tthis.textures[ i ].image.height = height;\n\t\t\t\tthis.textures[ i ].image.depth = depth;\n\n\t\t\t}\n\n\t\t\tthis.dispose();\n\n\t\t}\n\n\t\tthis.viewport.set( 0, 0, width, height );\n\t\tthis.scissor.set( 0, 0, width, height );\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n\tcopy( source ) {\n\n\t\tthis.width = source.width;\n\t\tthis.height = source.height;\n\t\tthis.depth = source.depth;\n\n\t\tthis.scissor.copy( source.scissor );\n\t\tthis.scissorTest = source.scissorTest;\n\n\t\tthis.viewport.copy( source.viewport );\n\n\t\tthis.textures.length = 0;\n\n\t\tfor ( let i = 0, il = source.textures.length; i < il; i ++ ) {\n\n\t\t\tthis.textures[ i ] = source.textures[ i ].clone();\n\t\t\tthis.textures[ i ].isRenderTargetTexture = true;\n\n\t\t}\n\n\t\t// ensure image object is not shared, see #20328\n\n\t\tconst image = Object.assign( {}, source.texture.image );\n\t\tthis.texture.source = new Source( image );\n\n\t\tthis.depthBuffer = source.depthBuffer;\n\t\tthis.stencilBuffer = source.stencilBuffer;\n\n\t\tthis.resolveDepthBuffer = source.resolveDepthBuffer;\n\t\tthis.resolveStencilBuffer = source.resolveStencilBuffer;\n\n\t\tif ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone();\n\n\t\tthis.samples = source.samples;\n\n\t\treturn this;\n\n\t}\n\n\tdispose() {\n\n\t\tthis.dispatchEvent( { type: 'dispose' } );\n\n\t}\n\n}\n\nclass WebGLRenderTarget extends RenderTarget {\n\n\tconstructor( width = 1, height = 1, options = {} ) {\n\n\t\tsuper( width, height, options );\n\n\t\tthis.isWebGLRenderTarget = true;\n\n\t}\n\n}\n\nclass DataArrayTexture extends Texture {\n\n\tconstructor( data = null, width = 1, height = 1, depth = 1 ) {\n\n\t\tsuper( null );\n\n\t\tthis.isDataArrayTexture = true;\n\n\t\tthis.image = { data, width, height, depth };\n\n\t\tthis.magFilter = NearestFilter;\n\t\tthis.minFilter = NearestFilter;\n\n\t\tthis.wrapR = ClampToEdgeWrapping;\n\n\t\tthis.generateMipmaps = false;\n\t\tthis.flipY = false;\n\t\tthis.unpackAlignment = 1;\n\n\t\tthis.layerUpdates = new Set();\n\n\t}\n\n\taddLayerUpdate( layerIndex ) {\n\n\t\tthis.layerUpdates.add( layerIndex );\n\n\t}\n\n\tclearLayerUpdates() {\n\n\t\tthis.layerUpdates.clear();\n\n\t}\n\n}\n\nclass WebGLArrayRenderTarget extends WebGLRenderTarget {\n\n\tconstructor( width = 1, height = 1, depth = 1, options = {} ) {\n\n\t\tsuper( width, height, options );\n\n\t\tthis.isWebGLArrayRenderTarget = true;\n\n\t\tthis.depth = depth;\n\n\t\tthis.texture = new DataArrayTexture( null, width, height, depth );\n\n\t\tthis.texture.isRenderTargetTexture = true;\n\n\t}\n\n}\n\nclass Data3DTexture extends Texture {\n\n\tconstructor( data = null, width = 1, height = 1, depth = 1 ) {\n\n\t\t// We're going to add .setXXX() methods for setting properties later.\n\t\t// Users can still set in DataTexture3D directly.\n\t\t//\n\t\t//\tconst texture = new THREE.DataTexture3D( data, width, height, depth );\n\t\t// \ttexture.anisotropy = 16;\n\t\t//\n\t\t// See #14839\n\n\t\tsuper( null );\n\n\t\tthis.isData3DTexture = true;\n\n\t\tthis.image = { data, width, height, depth };\n\n\t\tthis.magFilter = NearestFilter;\n\t\tthis.minFilter = NearestFilter;\n\n\t\tthis.wrapR = ClampToEdgeWrapping;\n\n\t\tthis.generateMipmaps = false;\n\t\tthis.flipY = false;\n\t\tthis.unpackAlignment = 1;\n\n\t}\n\n}\n\nclass WebGL3DRenderTarget extends WebGLRenderTarget {\n\n\tconstructor( width = 1, height = 1, depth = 1, options = {} ) {\n\n\t\tsuper( width, height, options );\n\n\t\tthis.isWebGL3DRenderTarget = true;\n\n\t\tthis.depth = depth;\n\n\t\tthis.texture = new Data3DTexture( null, width, height, depth );\n\n\t\tthis.texture.isRenderTargetTexture = true;\n\n\t}\n\n}\n\nclass Quaternion {\n\n\tconstructor( x = 0, y = 0, z = 0, w = 1 ) {\n\n\t\tthis.isQuaternion = true;\n\n\t\tthis._x = x;\n\t\tthis._y = y;\n\t\tthis._z = z;\n\t\tthis._w = w;\n\n\t}\n\n\tstatic slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {\n\n\t\t// fuzz-free, array-based Quaternion SLERP operation\n\n\t\tlet x0 = src0[ srcOffset0 + 0 ],\n\t\t\ty0 = src0[ srcOffset0 + 1 ],\n\t\t\tz0 = src0[ srcOffset0 + 2 ],\n\t\t\tw0 = src0[ srcOffset0 + 3 ];\n\n\t\tconst x1 = src1[ srcOffset1 + 0 ],\n\t\t\ty1 = src1[ srcOffset1 + 1 ],\n\t\t\tz1 = src1[ srcOffset1 + 2 ],\n\t\t\tw1 = src1[ srcOffset1 + 3 ];\n\n\t\tif ( t === 0 ) {\n\n\t\t\tdst[ dstOffset + 0 ] = x0;\n\t\t\tdst[ dstOffset + 1 ] = y0;\n\t\t\tdst[ dstOffset + 2 ] = z0;\n\t\t\tdst[ dstOffset + 3 ] = w0;\n\t\t\treturn;\n\n\t\t}\n\n\t\tif ( t === 1 ) {\n\n\t\t\tdst[ dstOffset + 0 ] = x1;\n\t\t\tdst[ dstOffset + 1 ] = y1;\n\t\t\tdst[ dstOffset + 2 ] = z1;\n\t\t\tdst[ dstOffset + 3 ] = w1;\n\t\t\treturn;\n\n\t\t}\n\n\t\tif ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {\n\n\t\t\tlet s = 1 - t;\n\t\t\tconst cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,\n\t\t\t\tdir = ( cos >= 0 ? 1 : - 1 ),\n\t\t\t\tsqrSin = 1 - cos * cos;\n\n\t\t\t// Skip the Slerp for tiny steps to avoid numeric problems:\n\t\t\tif ( sqrSin > Number.EPSILON ) {\n\n\t\t\t\tconst sin = Math.sqrt( sqrSin ),\n\t\t\t\t\tlen = Math.atan2( sin, cos * dir );\n\n\t\t\t\ts = Math.sin( s * len ) / sin;\n\t\t\t\tt = Math.sin( t * len ) / sin;\n\n\t\t\t}\n\n\t\t\tconst tDir = t * dir;\n\n\t\t\tx0 = x0 * s + x1 * tDir;\n\t\t\ty0 = y0 * s + y1 * tDir;\n\t\t\tz0 = z0 * s + z1 * tDir;\n\t\t\tw0 = w0 * s + w1 * tDir;\n\n\t\t\t// Normalize in case we just did a lerp:\n\t\t\tif ( s === 1 - t ) {\n\n\t\t\t\tconst f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );\n\n\t\t\t\tx0 *= f;\n\t\t\t\ty0 *= f;\n\t\t\t\tz0 *= f;\n\t\t\t\tw0 *= f;\n\n\t\t\t}\n\n\t\t}\n\n\t\tdst[ dstOffset ] = x0;\n\t\tdst[ dstOffset + 1 ] = y0;\n\t\tdst[ dstOffset + 2 ] = z0;\n\t\tdst[ dstOffset + 3 ] = w0;\n\n\t}\n\n\tstatic multiplyQuaternionsFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {\n\n\t\tconst x0 = src0[ srcOffset0 ];\n\t\tconst y0 = src0[ srcOffset0 + 1 ];\n\t\tconst z0 = src0[ srcOffset0 + 2 ];\n\t\tconst w0 = src0[ srcOffset0 + 3 ];\n\n\t\tconst x1 = src1[ srcOffset1 ];\n\t\tconst y1 = src1[ srcOffset1 + 1 ];\n\t\tconst z1 = src1[ srcOffset1 + 2 ];\n\t\tconst w1 = src1[ srcOffset1 + 3 ];\n\n\t\tdst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;\n\t\tdst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;\n\t\tdst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;\n\t\tdst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;\n\n\t\treturn dst;\n\n\t}\n\n\tget x() {\n\n\t\treturn this._x;\n\n\t}\n\n\tset x( value ) {\n\n\t\tthis._x = value;\n\t\tthis._onChangeCallback();\n\n\t}\n\n\tget y() {\n\n\t\treturn this._y;\n\n\t}\n\n\tset y( value ) {\n\n\t\tthis._y = value;\n\t\tthis._onChangeCallback();\n\n\t}\n\n\tget z() {\n\n\t\treturn this._z;\n\n\t}\n\n\tset z( value ) {\n\n\t\tthis._z = value;\n\t\tthis._onChangeCallback();\n\n\t}\n\n\tget w() {\n\n\t\treturn this._w;\n\n\t}\n\n\tset w( value ) {\n\n\t\tthis._w = value;\n\t\tthis._onChangeCallback();\n\n\t}\n\n\tset( x, y, z, w ) {\n\n\t\tthis._x = x;\n\t\tthis._y = y;\n\t\tthis._z = z;\n\t\tthis._w = w;\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor( this._x, this._y, this._z, this._w );\n\n\t}\n\n\tcopy( quaternion ) {\n\n\t\tthis._x = quaternion.x;\n\t\tthis._y = quaternion.y;\n\t\tthis._z = quaternion.z;\n\t\tthis._w = quaternion.w;\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tsetFromEuler( euler, update = true ) {\n\n\t\tconst x = euler._x, y = euler._y, z = euler._z, order = euler._order;\n\n\t\t// http://www.mathworks.com/matlabcentral/fileexchange/\n\t\t// \t20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/\n\t\t//\tcontent/SpinCalc.m\n\n\t\tconst cos = Math.cos;\n\t\tconst sin = Math.sin;\n\n\t\tconst c1 = cos( x / 2 );\n\t\tconst c2 = cos( y / 2 );\n\t\tconst c3 = cos( z / 2 );\n\n\t\tconst s1 = sin( x / 2 );\n\t\tconst s2 = sin( y / 2 );\n\t\tconst s3 = sin( z / 2 );\n\n\t\tswitch ( order ) {\n\n\t\t\tcase 'XYZ':\n\t\t\t\tthis._x = s1 * c2 * c3 + c1 * s2 * s3;\n\t\t\t\tthis._y = c1 * s2 * c3 - s1 * c2 * s3;\n\t\t\t\tthis._z = c1 * c2 * s3 + s1 * s2 * c3;\n\t\t\t\tthis._w = c1 * c2 * c3 - s1 * s2 * s3;\n\t\t\t\tbreak;\n\n\t\t\tcase 'YXZ':\n\t\t\t\tthis._x = s1 * c2 * c3 + c1 * s2 * s3;\n\t\t\t\tthis._y = c1 * s2 * c3 - s1 * c2 * s3;\n\t\t\t\tthis._z = c1 * c2 * s3 - s1 * s2 * c3;\n\t\t\t\tthis._w = c1 * c2 * c3 + s1 * s2 * s3;\n\t\t\t\tbreak;\n\n\t\t\tcase 'ZXY':\n\t\t\t\tthis._x = s1 * c2 * c3 - c1 * s2 * s3;\n\t\t\t\tthis._y = c1 * s2 * c3 + s1 * c2 * s3;\n\t\t\t\tthis._z = c1 * c2 * s3 + s1 * s2 * c3;\n\t\t\t\tthis._w = c1 * c2 * c3 - s1 * s2 * s3;\n\t\t\t\tbreak;\n\n\t\t\tcase 'ZYX':\n\t\t\t\tthis._x = s1 * c2 * c3 - c1 * s2 * s3;\n\t\t\t\tthis._y = c1 * s2 * c3 + s1 * c2 * s3;\n\t\t\t\tthis._z = c1 * c2 * s3 - s1 * s2 * c3;\n\t\t\t\tthis._w = c1 * c2 * c3 + s1 * s2 * s3;\n\t\t\t\tbreak;\n\n\t\t\tcase 'YZX':\n\t\t\t\tthis._x = s1 * c2 * c3 + c1 * s2 * s3;\n\t\t\t\tthis._y = c1 * s2 * c3 + s1 * c2 * s3;\n\t\t\t\tthis._z = c1 * c2 * s3 - s1 * s2 * c3;\n\t\t\t\tthis._w = c1 * c2 * c3 - s1 * s2 * s3;\n\t\t\t\tbreak;\n\n\t\t\tcase 'XZY':\n\t\t\t\tthis._x = s1 * c2 * c3 - c1 * s2 * s3;\n\t\t\t\tthis._y = c1 * s2 * c3 - s1 * c2 * s3;\n\t\t\t\tthis._z = c1 * c2 * s3 + s1 * s2 * c3;\n\t\t\t\tthis._w = c1 * c2 * c3 + s1 * s2 * s3;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tconsole.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );\n\n\t\t}\n\n\t\tif ( update === true ) this._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tsetFromAxisAngle( axis, angle ) {\n\n\t\t// http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm\n\n\t\t// assumes axis is normalized\n\n\t\tconst halfAngle = angle / 2, s = Math.sin( halfAngle );\n\n\t\tthis._x = axis.x * s;\n\t\tthis._y = axis.y * s;\n\t\tthis._z = axis.z * s;\n\t\tthis._w = Math.cos( halfAngle );\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tsetFromRotationMatrix( m ) {\n\n\t\t// http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm\n\n\t\t// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)\n\n\t\tconst te = m.elements,\n\n\t\t\tm11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],\n\t\t\tm21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],\n\t\t\tm31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],\n\n\t\t\ttrace = m11 + m22 + m33;\n\n\t\tif ( trace > 0 ) {\n\n\t\t\tconst s = 0.5 / Math.sqrt( trace + 1.0 );\n\n\t\t\tthis._w = 0.25 / s;\n\t\t\tthis._x = ( m32 - m23 ) * s;\n\t\t\tthis._y = ( m13 - m31 ) * s;\n\t\t\tthis._z = ( m21 - m12 ) * s;\n\n\t\t} else if ( m11 > m22 && m11 > m33 ) {\n\n\t\t\tconst s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );\n\n\t\t\tthis._w = ( m32 - m23 ) / s;\n\t\t\tthis._x = 0.25 * s;\n\t\t\tthis._y = ( m12 + m21 ) / s;\n\t\t\tthis._z = ( m13 + m31 ) / s;\n\n\t\t} else if ( m22 > m33 ) {\n\n\t\t\tconst s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );\n\n\t\t\tthis._w = ( m13 - m31 ) / s;\n\t\t\tthis._x = ( m12 + m21 ) / s;\n\t\t\tthis._y = 0.25 * s;\n\t\t\tthis._z = ( m23 + m32 ) / s;\n\n\t\t} else {\n\n\t\t\tconst s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );\n\n\t\t\tthis._w = ( m21 - m12 ) / s;\n\t\t\tthis._x = ( m13 + m31 ) / s;\n\t\t\tthis._y = ( m23 + m32 ) / s;\n\t\t\tthis._z = 0.25 * s;\n\n\t\t}\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tsetFromUnitVectors( vFrom, vTo ) {\n\n\t\t// assumes direction vectors vFrom and vTo are normalized\n\n\t\tlet r = vFrom.dot( vTo ) + 1;\n\n\t\tif ( r < Number.EPSILON ) {\n\n\t\t\t// vFrom and vTo point in opposite directions\n\n\t\t\tr = 0;\n\n\t\t\tif ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {\n\n\t\t\t\tthis._x = - vFrom.y;\n\t\t\t\tthis._y = vFrom.x;\n\t\t\t\tthis._z = 0;\n\t\t\t\tthis._w = r;\n\n\t\t\t} else {\n\n\t\t\t\tthis._x = 0;\n\t\t\t\tthis._y = - vFrom.z;\n\t\t\t\tthis._z = vFrom.y;\n\t\t\t\tthis._w = r;\n\n\t\t\t}\n\n\t\t} else {\n\n\t\t\t// crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3\n\n\t\t\tthis._x = vFrom.y * vTo.z - vFrom.z * vTo.y;\n\t\t\tthis._y = vFrom.z * vTo.x - vFrom.x * vTo.z;\n\t\t\tthis._z = vFrom.x * vTo.y - vFrom.y * vTo.x;\n\t\t\tthis._w = r;\n\n\t\t}\n\n\t\treturn this.normalize();\n\n\t}\n\n\tangleTo( q ) {\n\n\t\treturn 2 * Math.acos( Math.abs( clamp( this.dot( q ), - 1, 1 ) ) );\n\n\t}\n\n\trotateTowards( q, step ) {\n\n\t\tconst angle = this.angleTo( q );\n\n\t\tif ( angle === 0 ) return this;\n\n\t\tconst t = Math.min( 1, step / angle );\n\n\t\tthis.slerp( q, t );\n\n\t\treturn this;\n\n\t}\n\n\tidentity() {\n\n\t\treturn this.set( 0, 0, 0, 1 );\n\n\t}\n\n\tinvert() {\n\n\t\t// quaternion is assumed to have unit length\n\n\t\treturn this.conjugate();\n\n\t}\n\n\tconjugate() {\n\n\t\tthis._x *= - 1;\n\t\tthis._y *= - 1;\n\t\tthis._z *= - 1;\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tdot( v ) {\n\n\t\treturn this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;\n\n\t}\n\n\tlengthSq() {\n\n\t\treturn this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;\n\n\t}\n\n\tlength() {\n\n\t\treturn Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );\n\n\t}\n\n\tnormalize() {\n\n\t\tlet l = this.length();\n\n\t\tif ( l === 0 ) {\n\n\t\t\tthis._x = 0;\n\t\t\tthis._y = 0;\n\t\t\tthis._z = 0;\n\t\t\tthis._w = 1;\n\n\t\t} else {\n\n\t\t\tl = 1 / l;\n\n\t\t\tthis._x = this._x * l;\n\t\t\tthis._y = this._y * l;\n\t\t\tthis._z = this._z * l;\n\t\t\tthis._w = this._w * l;\n\n\t\t}\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tmultiply( q ) {\n\n\t\treturn this.multiplyQuaternions( this, q );\n\n\t}\n\n\tpremultiply( q ) {\n\n\t\treturn this.multiplyQuaternions( q, this );\n\n\t}\n\n\tmultiplyQuaternions( a, b ) {\n\n\t\t// from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm\n\n\t\tconst qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;\n\t\tconst qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;\n\n\t\tthis._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;\n\t\tthis._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;\n\t\tthis._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;\n\t\tthis._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tslerp( qb, t ) {\n\n\t\tif ( t === 0 ) return this;\n\t\tif ( t === 1 ) return this.copy( qb );\n\n\t\tconst x = this._x, y = this._y, z = this._z, w = this._w;\n\n\t\t// http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/\n\n\t\tlet cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;\n\n\t\tif ( cosHalfTheta < 0 ) {\n\n\t\t\tthis._w = - qb._w;\n\t\t\tthis._x = - qb._x;\n\t\t\tthis._y = - qb._y;\n\t\t\tthis._z = - qb._z;\n\n\t\t\tcosHalfTheta = - cosHalfTheta;\n\n\t\t} else {\n\n\t\t\tthis.copy( qb );\n\n\t\t}\n\n\t\tif ( cosHalfTheta >= 1.0 ) {\n\n\t\t\tthis._w = w;\n\t\t\tthis._x = x;\n\t\t\tthis._y = y;\n\t\t\tthis._z = z;\n\n\t\t\treturn this;\n\n\t\t}\n\n\t\tconst sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;\n\n\t\tif ( sqrSinHalfTheta <= Number.EPSILON ) {\n\n\t\t\tconst s = 1 - t;\n\t\t\tthis._w = s * w + t * this._w;\n\t\t\tthis._x = s * x + t * this._x;\n\t\t\tthis._y = s * y + t * this._y;\n\t\t\tthis._z = s * z + t * this._z;\n\n\t\t\tthis.normalize(); // normalize calls _onChangeCallback()\n\n\t\t\treturn this;\n\n\t\t}\n\n\t\tconst sinHalfTheta = Math.sqrt( sqrSinHalfTheta );\n\t\tconst halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );\n\t\tconst ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,\n\t\t\tratioB = Math.sin( t * halfTheta ) / sinHalfTheta;\n\n\t\tthis._w = ( w * ratioA + this._w * ratioB );\n\t\tthis._x = ( x * ratioA + this._x * ratioB );\n\t\tthis._y = ( y * ratioA + this._y * ratioB );\n\t\tthis._z = ( z * ratioA + this._z * ratioB );\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tslerpQuaternions( qa, qb, t ) {\n\n\t\treturn this.copy( qa ).slerp( qb, t );\n\n\t}\n\n\trandom() {\n\n\t\t// sets this quaternion to a uniform random unit quaternnion\n\n\t\t// Ken Shoemake\n\t\t// Uniform random rotations\n\t\t// D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992.\n\n\t\tconst theta1 = 2 * Math.PI * Math.random();\n\t\tconst theta2 = 2 * Math.PI * Math.random();\n\n\t\tconst x0 = Math.random();\n\t\tconst r1 = Math.sqrt( 1 - x0 );\n\t\tconst r2 = Math.sqrt( x0 );\n\n\t\treturn this.set(\n\t\t\tr1 * Math.sin( theta1 ),\n\t\t\tr1 * Math.cos( theta1 ),\n\t\t\tr2 * Math.sin( theta2 ),\n\t\t\tr2 * Math.cos( theta2 ),\n\t\t);\n\n\t}\n\n\tequals( quaternion ) {\n\n\t\treturn ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );\n\n\t}\n\n\tfromArray( array, offset = 0 ) {\n\n\t\tthis._x = array[ offset ];\n\t\tthis._y = array[ offset + 1 ];\n\t\tthis._z = array[ offset + 2 ];\n\t\tthis._w = array[ offset + 3 ];\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\ttoArray( array = [], offset = 0 ) {\n\n\t\tarray[ offset ] = this._x;\n\t\tarray[ offset + 1 ] = this._y;\n\t\tarray[ offset + 2 ] = this._z;\n\t\tarray[ offset + 3 ] = this._w;\n\n\t\treturn array;\n\n\t}\n\n\tfromBufferAttribute( attribute, index ) {\n\n\t\tthis._x = attribute.getX( index );\n\t\tthis._y = attribute.getY( index );\n\t\tthis._z = attribute.getZ( index );\n\t\tthis._w = attribute.getW( index );\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\ttoJSON() {\n\n\t\treturn this.toArray();\n\n\t}\n\n\t_onChange( callback ) {\n\n\t\tthis._onChangeCallback = callback;\n\n\t\treturn this;\n\n\t}\n\n\t_onChangeCallback() {}\n\n\t*[ Symbol.iterator ]() {\n\n\t\tyield this._x;\n\t\tyield this._y;\n\t\tyield this._z;\n\t\tyield this._w;\n\n\t}\n\n}\n\nclass Vector3 {\n\n\tconstructor( x = 0, y = 0, z = 0 ) {\n\n\t\tVector3.prototype.isVector3 = true;\n\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.z = z;\n\n\t}\n\n\tset( x, y, z ) {\n\n\t\tif ( z === undefined ) z = this.z; // sprite.scale.set(x,y)\n\n\t\tthis.x = x;\n\t\tthis.y = y;\n\t\tthis.z = z;\n\n\t\treturn this;\n\n\t}\n\n\tsetScalar( scalar ) {\n\n\t\tthis.x = scalar;\n\t\tthis.y = scalar;\n\t\tthis.z = scalar;\n\n\t\treturn this;\n\n\t}\n\n\tsetX( x ) {\n\n\t\tthis.x = x;\n\n\t\treturn this;\n\n\t}\n\n\tsetY( y ) {\n\n\t\tthis.y = y;\n\n\t\treturn this;\n\n\t}\n\n\tsetZ( z ) {\n\n\t\tthis.z = z;\n\n\t\treturn this;\n\n\t}\n\n\tsetComponent( index, value ) {\n\n\t\tswitch ( index ) {\n\n\t\t\tcase 0: this.x = value; break;\n\t\t\tcase 1: this.y = value; break;\n\t\t\tcase 2: this.z = value; break;\n\t\t\tdefault: throw new Error( 'index is out of range: ' + index );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tgetComponent( index ) {\n\n\t\tswitch ( index ) {\n\n\t\t\tcase 0: return this.x;\n\t\t\tcase 1: return this.y;\n\t\t\tcase 2: return this.z;\n\t\t\tdefault: throw new Error( 'index is out of range: ' + index );\n\n\t\t}\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor( this.x, this.y, this.z );\n\n\t}\n\n\tcopy( v ) {\n\n\t\tthis.x = v.x;\n\t\tthis.y = v.y;\n\t\tthis.z = v.z;\n\n\t\treturn this;\n\n\t}\n\n\tadd( v ) {\n\n\t\tthis.x += v.x;\n\t\tthis.y += v.y;\n\t\tthis.z += v.z;\n\n\t\treturn this;\n\n\t}\n\n\taddScalar( s ) {\n\n\t\tthis.x += s;\n\t\tthis.y += s;\n\t\tthis.z += s;\n\n\t\treturn this;\n\n\t}\n\n\taddVectors( a, b ) {\n\n\t\tthis.x = a.x + b.x;\n\t\tthis.y = a.y + b.y;\n\t\tthis.z = a.z + b.z;\n\n\t\treturn this;\n\n\t}\n\n\taddScaledVector( v, s ) {\n\n\t\tthis.x += v.x * s;\n\t\tthis.y += v.y * s;\n\t\tthis.z += v.z * s;\n\n\t\treturn this;\n\n\t}\n\n\tsub( v ) {\n\n\t\tthis.x -= v.x;\n\t\tthis.y -= v.y;\n\t\tthis.z -= v.z;\n\n\t\treturn this;\n\n\t}\n\n\tsubScalar( s ) {\n\n\t\tthis.x -= s;\n\t\tthis.y -= s;\n\t\tthis.z -= s;\n\n\t\treturn this;\n\n\t}\n\n\tsubVectors( a, b ) {\n\n\t\tthis.x = a.x - b.x;\n\t\tthis.y = a.y - b.y;\n\t\tthis.z = a.z - b.z;\n\n\t\treturn this;\n\n\t}\n\n\tmultiply( v ) {\n\n\t\tthis.x *= v.x;\n\t\tthis.y *= v.y;\n\t\tthis.z *= v.z;\n\n\t\treturn this;\n\n\t}\n\n\tmultiplyScalar( scalar ) {\n\n\t\tthis.x *= scalar;\n\t\tthis.y *= scalar;\n\t\tthis.z *= scalar;\n\n\t\treturn this;\n\n\t}\n\n\tmultiplyVectors( a, b ) {\n\n\t\tthis.x = a.x * b.x;\n\t\tthis.y = a.y * b.y;\n\t\tthis.z = a.z * b.z;\n\n\t\treturn this;\n\n\t}\n\n\tapplyEuler( euler ) {\n\n\t\treturn this.applyQuaternion( _quaternion$4.setFromEuler( euler ) );\n\n\t}\n\n\tapplyAxisAngle( axis, angle ) {\n\n\t\treturn this.applyQuaternion( _quaternion$4.setFromAxisAngle( axis, angle ) );\n\n\t}\n\n\tapplyMatrix3( m ) {\n\n\t\tconst x = this.x, y = this.y, z = this.z;\n\t\tconst e = m.elements;\n\n\t\tthis.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;\n\t\tthis.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;\n\t\tthis.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;\n\n\t\treturn this;\n\n\t}\n\n\tapplyNormalMatrix( m ) {\n\n\t\treturn this.applyMatrix3( m ).normalize();\n\n\t}\n\n\tapplyMatrix4( m ) {\n\n\t\tconst x = this.x, y = this.y, z = this.z;\n\t\tconst e = m.elements;\n\n\t\tconst w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );\n\n\t\tthis.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;\n\t\tthis.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;\n\t\tthis.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;\n\n\t\treturn this;\n\n\t}\n\n\tapplyQuaternion( q ) {\n\n\t\t// quaternion q is assumed to have unit length\n\n\t\tconst vx = this.x, vy = this.y, vz = this.z;\n\t\tconst qx = q.x, qy = q.y, qz = q.z, qw = q.w;\n\n\t\t// t = 2 * cross( q.xyz, v );\n\t\tconst tx = 2 * ( qy * vz - qz * vy );\n\t\tconst ty = 2 * ( qz * vx - qx * vz );\n\t\tconst tz = 2 * ( qx * vy - qy * vx );\n\n\t\t// v + q.w * t + cross( q.xyz, t );\n\t\tthis.x = vx + qw * tx + qy * tz - qz * ty;\n\t\tthis.y = vy + qw * ty + qz * tx - qx * tz;\n\t\tthis.z = vz + qw * tz + qx * ty - qy * tx;\n\n\t\treturn this;\n\n\t}\n\n\tproject( camera ) {\n\n\t\treturn this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );\n\n\t}\n\n\tunproject( camera ) {\n\n\t\treturn this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );\n\n\t}\n\n\ttransformDirection( m ) {\n\n\t\t// input: THREE.Matrix4 affine matrix\n\t\t// vector interpreted as a direction\n\n\t\tconst x = this.x, y = this.y, z = this.z;\n\t\tconst e = m.elements;\n\n\t\tthis.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;\n\t\tthis.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;\n\t\tthis.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;\n\n\t\treturn this.normalize();\n\n\t}\n\n\tdivide( v ) {\n\n\t\tthis.x /= v.x;\n\t\tthis.y /= v.y;\n\t\tthis.z /= v.z;\n\n\t\treturn this;\n\n\t}\n\n\tdivideScalar( scalar ) {\n\n\t\treturn this.multiplyScalar( 1 / scalar );\n\n\t}\n\n\tmin( v ) {\n\n\t\tthis.x = Math.min( this.x, v.x );\n\t\tthis.y = Math.min( this.y, v.y );\n\t\tthis.z = Math.min( this.z, v.z );\n\n\t\treturn this;\n\n\t}\n\n\tmax( v ) {\n\n\t\tthis.x = Math.max( this.x, v.x );\n\t\tthis.y = Math.max( this.y, v.y );\n\t\tthis.z = Math.max( this.z, v.z );\n\n\t\treturn this;\n\n\t}\n\n\tclamp( min, max ) {\n\n\t\t// assumes min < max, componentwise\n\n\t\tthis.x = Math.max( min.x, Math.min( max.x, this.x ) );\n\t\tthis.y = Math.max( min.y, Math.min( max.y, this.y ) );\n\t\tthis.z = Math.max( min.z, Math.min( max.z, this.z ) );\n\n\t\treturn this;\n\n\t}\n\n\tclampScalar( minVal, maxVal ) {\n\n\t\tthis.x = Math.max( minVal, Math.min( maxVal, this.x ) );\n\t\tthis.y = Math.max( minVal, Math.min( maxVal, this.y ) );\n\t\tthis.z = Math.max( minVal, Math.min( maxVal, this.z ) );\n\n\t\treturn this;\n\n\t}\n\n\tclampLength( min, max ) {\n\n\t\tconst length = this.length();\n\n\t\treturn this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );\n\n\t}\n\n\tfloor() {\n\n\t\tthis.x = Math.floor( this.x );\n\t\tthis.y = Math.floor( this.y );\n\t\tthis.z = Math.floor( this.z );\n\n\t\treturn this;\n\n\t}\n\n\tceil() {\n\n\t\tthis.x = Math.ceil( this.x );\n\t\tthis.y = Math.ceil( this.y );\n\t\tthis.z = Math.ceil( this.z );\n\n\t\treturn this;\n\n\t}\n\n\tround() {\n\n\t\tthis.x = Math.round( this.x );\n\t\tthis.y = Math.round( this.y );\n\t\tthis.z = Math.round( this.z );\n\n\t\treturn this;\n\n\t}\n\n\troundToZero() {\n\n\t\tthis.x = Math.trunc( this.x );\n\t\tthis.y = Math.trunc( this.y );\n\t\tthis.z = Math.trunc( this.z );\n\n\t\treturn this;\n\n\t}\n\n\tnegate() {\n\n\t\tthis.x = - this.x;\n\t\tthis.y = - this.y;\n\t\tthis.z = - this.z;\n\n\t\treturn this;\n\n\t}\n\n\tdot( v ) {\n\n\t\treturn this.x * v.x + this.y * v.y + this.z * v.z;\n\n\t}\n\n\t// TODO lengthSquared?\n\n\tlengthSq() {\n\n\t\treturn this.x * this.x + this.y * this.y + this.z * this.z;\n\n\t}\n\n\tlength() {\n\n\t\treturn Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );\n\n\t}\n\n\tmanhattanLength() {\n\n\t\treturn Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );\n\n\t}\n\n\tnormalize() {\n\n\t\treturn this.divideScalar( this.length() || 1 );\n\n\t}\n\n\tsetLength( length ) {\n\n\t\treturn this.normalize().multiplyScalar( length );\n\n\t}\n\n\tlerp( v, alpha ) {\n\n\t\tthis.x += ( v.x - this.x ) * alpha;\n\t\tthis.y += ( v.y - this.y ) * alpha;\n\t\tthis.z += ( v.z - this.z ) * alpha;\n\n\t\treturn this;\n\n\t}\n\n\tlerpVectors( v1, v2, alpha ) {\n\n\t\tthis.x = v1.x + ( v2.x - v1.x ) * alpha;\n\t\tthis.y = v1.y + ( v2.y - v1.y ) * alpha;\n\t\tthis.z = v1.z + ( v2.z - v1.z ) * alpha;\n\n\t\treturn this;\n\n\t}\n\n\tcross( v ) {\n\n\t\treturn this.crossVectors( this, v );\n\n\t}\n\n\tcrossVectors( a, b ) {\n\n\t\tconst ax = a.x, ay = a.y, az = a.z;\n\t\tconst bx = b.x, by = b.y, bz = b.z;\n\n\t\tthis.x = ay * bz - az * by;\n\t\tthis.y = az * bx - ax * bz;\n\t\tthis.z = ax * by - ay * bx;\n\n\t\treturn this;\n\n\t}\n\n\tprojectOnVector( v ) {\n\n\t\tconst denominator = v.lengthSq();\n\n\t\tif ( denominator === 0 ) return this.set( 0, 0, 0 );\n\n\t\tconst scalar = v.dot( this ) / denominator;\n\n\t\treturn this.copy( v ).multiplyScalar( scalar );\n\n\t}\n\n\tprojectOnPlane( planeNormal ) {\n\n\t\t_vector$c.copy( this ).projectOnVector( planeNormal );\n\n\t\treturn this.sub( _vector$c );\n\n\t}\n\n\treflect( normal ) {\n\n\t\t// reflect incident vector off plane orthogonal to normal\n\t\t// normal is assumed to have unit length\n\n\t\treturn this.sub( _vector$c.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );\n\n\t}\n\n\tangleTo( v ) {\n\n\t\tconst denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );\n\n\t\tif ( denominator === 0 ) return Math.PI / 2;\n\n\t\tconst theta = this.dot( v ) / denominator;\n\n\t\t// clamp, to handle numerical problems\n\n\t\treturn Math.acos( clamp( theta, - 1, 1 ) );\n\n\t}\n\n\tdistanceTo( v ) {\n\n\t\treturn Math.sqrt( this.distanceToSquared( v ) );\n\n\t}\n\n\tdistanceToSquared( v ) {\n\n\t\tconst dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;\n\n\t\treturn dx * dx + dy * dy + dz * dz;\n\n\t}\n\n\tmanhattanDistanceTo( v ) {\n\n\t\treturn Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );\n\n\t}\n\n\tsetFromSpherical( s ) {\n\n\t\treturn this.setFromSphericalCoords( s.radius, s.phi, s.theta );\n\n\t}\n\n\tsetFromSphericalCoords( radius, phi, theta ) {\n\n\t\tconst sinPhiRadius = Math.sin( phi ) * radius;\n\n\t\tthis.x = sinPhiRadius * Math.sin( theta );\n\t\tthis.y = Math.cos( phi ) * radius;\n\t\tthis.z = sinPhiRadius * Math.cos( theta );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromCylindrical( c ) {\n\n\t\treturn this.setFromCylindricalCoords( c.radius, c.theta, c.y );\n\n\t}\n\n\tsetFromCylindricalCoords( radius, theta, y ) {\n\n\t\tthis.x = radius * Math.sin( theta );\n\t\tthis.y = y;\n\t\tthis.z = radius * Math.cos( theta );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromMatrixPosition( m ) {\n\n\t\tconst e = m.elements;\n\n\t\tthis.x = e[ 12 ];\n\t\tthis.y = e[ 13 ];\n\t\tthis.z = e[ 14 ];\n\n\t\treturn this;\n\n\t}\n\n\tsetFromMatrixScale( m ) {\n\n\t\tconst sx = this.setFromMatrixColumn( m, 0 ).length();\n\t\tconst sy = this.setFromMatrixColumn( m, 1 ).length();\n\t\tconst sz = this.setFromMatrixColumn( m, 2 ).length();\n\n\t\tthis.x = sx;\n\t\tthis.y = sy;\n\t\tthis.z = sz;\n\n\t\treturn this;\n\n\t}\n\n\tsetFromMatrixColumn( m, index ) {\n\n\t\treturn this.fromArray( m.elements, index * 4 );\n\n\t}\n\n\tsetFromMatrix3Column( m, index ) {\n\n\t\treturn this.fromArray( m.elements, index * 3 );\n\n\t}\n\n\tsetFromEuler( e ) {\n\n\t\tthis.x = e._x;\n\t\tthis.y = e._y;\n\t\tthis.z = e._z;\n\n\t\treturn this;\n\n\t}\n\n\tsetFromColor( c ) {\n\n\t\tthis.x = c.r;\n\t\tthis.y = c.g;\n\t\tthis.z = c.b;\n\n\t\treturn this;\n\n\t}\n\n\tequals( v ) {\n\n\t\treturn ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );\n\n\t}\n\n\tfromArray( array, offset = 0 ) {\n\n\t\tthis.x = array[ offset ];\n\t\tthis.y = array[ offset + 1 ];\n\t\tthis.z = array[ offset + 2 ];\n\n\t\treturn this;\n\n\t}\n\n\ttoArray( array = [], offset = 0 ) {\n\n\t\tarray[ offset ] = this.x;\n\t\tarray[ offset + 1 ] = this.y;\n\t\tarray[ offset + 2 ] = this.z;\n\n\t\treturn array;\n\n\t}\n\n\tfromBufferAttribute( attribute, index ) {\n\n\t\tthis.x = attribute.getX( index );\n\t\tthis.y = attribute.getY( index );\n\t\tthis.z = attribute.getZ( index );\n\n\t\treturn this;\n\n\t}\n\n\trandom() {\n\n\t\tthis.x = Math.random();\n\t\tthis.y = Math.random();\n\t\tthis.z = Math.random();\n\n\t\treturn this;\n\n\t}\n\n\trandomDirection() {\n\n\t\t// https://mathworld.wolfram.com/SpherePointPicking.html\n\n\t\tconst theta = Math.random() * Math.PI * 2;\n\t\tconst u = Math.random() * 2 - 1;\n\t\tconst c = Math.sqrt( 1 - u * u );\n\n\t\tthis.x = c * Math.cos( theta );\n\t\tthis.y = u;\n\t\tthis.z = c * Math.sin( theta );\n\n\t\treturn this;\n\n\t}\n\n\t*[ Symbol.iterator ]() {\n\n\t\tyield this.x;\n\t\tyield this.y;\n\t\tyield this.z;\n\n\t}\n\n}\n\nconst _vector$c = /*@__PURE__*/ new Vector3();\nconst _quaternion$4 = /*@__PURE__*/ new Quaternion();\n\nclass Box3 {\n\n\tconstructor( min = new Vector3( + Infinity, + Infinity, + Infinity ), max = new Vector3( - Infinity, - Infinity, - Infinity ) ) {\n\n\t\tthis.isBox3 = true;\n\n\t\tthis.min = min;\n\t\tthis.max = max;\n\n\t}\n\n\tset( min, max ) {\n\n\t\tthis.min.copy( min );\n\t\tthis.max.copy( max );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromArray( array ) {\n\n\t\tthis.makeEmpty();\n\n\t\tfor ( let i = 0, il = array.length; i < il; i += 3 ) {\n\n\t\t\tthis.expandByPoint( _vector$b.fromArray( array, i ) );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tsetFromBufferAttribute( attribute ) {\n\n\t\tthis.makeEmpty();\n\n\t\tfor ( let i = 0, il = attribute.count; i < il; i ++ ) {\n\n\t\t\tthis.expandByPoint( _vector$b.fromBufferAttribute( attribute, i ) );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tsetFromPoints( points ) {\n\n\t\tthis.makeEmpty();\n\n\t\tfor ( let i = 0, il = points.length; i < il; i ++ ) {\n\n\t\t\tthis.expandByPoint( points[ i ] );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tsetFromCenterAndSize( center, size ) {\n\n\t\tconst halfSize = _vector$b.copy( size ).multiplyScalar( 0.5 );\n\n\t\tthis.min.copy( center ).sub( halfSize );\n\t\tthis.max.copy( center ).add( halfSize );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromObject( object, precise = false ) {\n\n\t\tthis.makeEmpty();\n\n\t\treturn this.expandByObject( object, precise );\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n\tcopy( box ) {\n\n\t\tthis.min.copy( box.min );\n\t\tthis.max.copy( box.max );\n\n\t\treturn this;\n\n\t}\n\n\tmakeEmpty() {\n\n\t\tthis.min.x = this.min.y = this.min.z = + Infinity;\n\t\tthis.max.x = this.max.y = this.max.z = - Infinity;\n\n\t\treturn this;\n\n\t}\n\n\tisEmpty() {\n\n\t\t// this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes\n\n\t\treturn ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );\n\n\t}\n\n\tgetCenter( target ) {\n\n\t\treturn this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );\n\n\t}\n\n\tgetSize( target ) {\n\n\t\treturn this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );\n\n\t}\n\n\texpandByPoint( point ) {\n\n\t\tthis.min.min( point );\n\t\tthis.max.max( point );\n\n\t\treturn this;\n\n\t}\n\n\texpandByVector( vector ) {\n\n\t\tthis.min.sub( vector );\n\t\tthis.max.add( vector );\n\n\t\treturn this;\n\n\t}\n\n\texpandByScalar( scalar ) {\n\n\t\tthis.min.addScalar( - scalar );\n\t\tthis.max.addScalar( scalar );\n\n\t\treturn this;\n\n\t}\n\n\texpandByObject( object, precise = false ) {\n\n\t\t// Computes the world-axis-aligned bounding box of an object (including its children),\n\t\t// accounting for both the object's, and children's, world transforms\n\n\t\tobject.updateWorldMatrix( false, false );\n\n\t\tconst geometry = object.geometry;\n\n\t\tif ( geometry !== undefined ) {\n\n\t\t\tconst positionAttribute = geometry.getAttribute( 'position' );\n\n\t\t\t// precise AABB computation based on vertex data requires at least a position attribute.\n\t\t\t// instancing isn't supported so far and uses the normal (conservative) code path.\n\n\t\t\tif ( precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true ) {\n\n\t\t\t\tfor ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {\n\n\t\t\t\t\tif ( object.isMesh === true ) {\n\n\t\t\t\t\t\tobject.getVertexPosition( i, _vector$b );\n\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\t_vector$b.fromBufferAttribute( positionAttribute, i );\n\n\t\t\t\t\t}\n\n\t\t\t\t\t_vector$b.applyMatrix4( object.matrixWorld );\n\t\t\t\t\tthis.expandByPoint( _vector$b );\n\n\t\t\t\t}\n\n\t\t\t} else {\n\n\t\t\t\tif ( object.boundingBox !== undefined ) {\n\n\t\t\t\t\t// object-level bounding box\n\n\t\t\t\t\tif ( object.boundingBox === null ) {\n\n\t\t\t\t\t\tobject.computeBoundingBox();\n\n\t\t\t\t\t}\n\n\t\t\t\t\t_box$4.copy( object.boundingBox );\n\n\n\t\t\t\t} else {\n\n\t\t\t\t\t// geometry-level bounding box\n\n\t\t\t\t\tif ( geometry.boundingBox === null ) {\n\n\t\t\t\t\t\tgeometry.computeBoundingBox();\n\n\t\t\t\t\t}\n\n\t\t\t\t\t_box$4.copy( geometry.boundingBox );\n\n\t\t\t\t}\n\n\t\t\t\t_box$4.applyMatrix4( object.matrixWorld );\n\n\t\t\t\tthis.union( _box$4 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tconst children = object.children;\n\n\t\tfor ( let i = 0, l = children.length; i < l; i ++ ) {\n\n\t\t\tthis.expandByObject( children[ i ], precise );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tcontainsPoint( point ) {\n\n\t\treturn point.x >= this.min.x && point.x <= this.max.x &&\n\t\t\tpoint.y >= this.min.y && point.y <= this.max.y &&\n\t\t\tpoint.z >= this.min.z && point.z <= this.max.z;\n\n\t}\n\n\tcontainsBox( box ) {\n\n\t\treturn this.min.x <= box.min.x && box.max.x <= this.max.x &&\n\t\t\tthis.min.y <= box.min.y && box.max.y <= this.max.y &&\n\t\t\tthis.min.z <= box.min.z && box.max.z <= this.max.z;\n\n\t}\n\n\tgetParameter( point, target ) {\n\n\t\t// This can potentially have a divide by zero if the box\n\t\t// has a size dimension of 0.\n\n\t\treturn target.set(\n\t\t\t( point.x - this.min.x ) / ( this.max.x - this.min.x ),\n\t\t\t( point.y - this.min.y ) / ( this.max.y - this.min.y ),\n\t\t\t( point.z - this.min.z ) / ( this.max.z - this.min.z )\n\t\t);\n\n\t}\n\n\tintersectsBox( box ) {\n\n\t\t// using 6 splitting planes to rule out intersections.\n\t\treturn box.max.x >= this.min.x && box.min.x <= this.max.x &&\n\t\t\tbox.max.y >= this.min.y && box.min.y <= this.max.y &&\n\t\t\tbox.max.z >= this.min.z && box.min.z <= this.max.z;\n\n\t}\n\n\tintersectsSphere( sphere ) {\n\n\t\t// Find the point on the AABB closest to the sphere center.\n\t\tthis.clampPoint( sphere.center, _vector$b );\n\n\t\t// If that point is inside the sphere, the AABB and sphere intersect.\n\t\treturn _vector$b.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );\n\n\t}\n\n\tintersectsPlane( plane ) {\n\n\t\t// We compute the minimum and maximum dot product values. If those values\n\t\t// are on the same side (back or front) of the plane, then there is no intersection.\n\n\t\tlet min, max;\n\n\t\tif ( plane.normal.x > 0 ) {\n\n\t\t\tmin = plane.normal.x * this.min.x;\n\t\t\tmax = plane.normal.x * this.max.x;\n\n\t\t} else {\n\n\t\t\tmin = plane.normal.x * this.max.x;\n\t\t\tmax = plane.normal.x * this.min.x;\n\n\t\t}\n\n\t\tif ( plane.normal.y > 0 ) {\n\n\t\t\tmin += plane.normal.y * this.min.y;\n\t\t\tmax += plane.normal.y * this.max.y;\n\n\t\t} else {\n\n\t\t\tmin += plane.normal.y * this.max.y;\n\t\t\tmax += plane.normal.y * this.min.y;\n\n\t\t}\n\n\t\tif ( plane.normal.z > 0 ) {\n\n\t\t\tmin += plane.normal.z * this.min.z;\n\t\t\tmax += plane.normal.z * this.max.z;\n\n\t\t} else {\n\n\t\t\tmin += plane.normal.z * this.max.z;\n\t\t\tmax += plane.normal.z * this.min.z;\n\n\t\t}\n\n\t\treturn ( min <= - plane.constant && max >= - plane.constant );\n\n\t}\n\n\tintersectsTriangle( triangle ) {\n\n\t\tif ( this.isEmpty() ) {\n\n\t\t\treturn false;\n\n\t\t}\n\n\t\t// compute box center and extents\n\t\tthis.getCenter( _center );\n\t\t_extents.subVectors( this.max, _center );\n\n\t\t// translate triangle to aabb origin\n\t\t_v0$3.subVectors( triangle.a, _center );\n\t\t_v1$7.subVectors( triangle.b, _center );\n\t\t_v2$4.subVectors( triangle.c, _center );\n\n\t\t// compute edge vectors for triangle\n\t\t_f0.subVectors( _v1$7, _v0$3 );\n\t\t_f1.subVectors( _v2$4, _v1$7 );\n\t\t_f2.subVectors( _v0$3, _v2$4 );\n\n\t\t// test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb\n\t\t// make an axis testing of each of the 3 sides of the aabb against each of the 3 sides of the triangle = 9 axis of separation\n\t\t// axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)\n\t\tlet axes = [\n\t\t\t0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,\n\t\t\t_f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,\n\t\t\t- _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0\n\t\t];\n\t\tif ( ! satForAxes( axes, _v0$3, _v1$7, _v2$4, _extents ) ) {\n\n\t\t\treturn false;\n\n\t\t}\n\n\t\t// test 3 face normals from the aabb\n\t\taxes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];\n\t\tif ( ! satForAxes( axes, _v0$3, _v1$7, _v2$4, _extents ) ) {\n\n\t\t\treturn false;\n\n\t\t}\n\n\t\t// finally testing the face normal of the triangle\n\t\t// use already existing triangle edge vectors here\n\t\t_triangleNormal.crossVectors( _f0, _f1 );\n\t\taxes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];\n\n\t\treturn satForAxes( axes, _v0$3, _v1$7, _v2$4, _extents );\n\n\t}\n\n\tclampPoint( point, target ) {\n\n\t\treturn target.copy( point ).clamp( this.min, this.max );\n\n\t}\n\n\tdistanceToPoint( point ) {\n\n\t\treturn this.clampPoint( point, _vector$b ).distanceTo( point );\n\n\t}\n\n\tgetBoundingSphere( target ) {\n\n\t\tif ( this.isEmpty() ) {\n\n\t\t\ttarget.makeEmpty();\n\n\t\t} else {\n\n\t\t\tthis.getCenter( target.center );\n\n\t\t\ttarget.radius = this.getSize( _vector$b ).length() * 0.5;\n\n\t\t}\n\n\t\treturn target;\n\n\t}\n\n\tintersect( box ) {\n\n\t\tthis.min.max( box.min );\n\t\tthis.max.min( box.max );\n\n\t\t// ensure that if there is no overlap, the result is fully empty, not slightly empty with non-inf/+inf values that will cause subsequence intersects to erroneously return valid values.\n\t\tif ( this.isEmpty() ) this.makeEmpty();\n\n\t\treturn this;\n\n\t}\n\n\tunion( box ) {\n\n\t\tthis.min.min( box.min );\n\t\tthis.max.max( box.max );\n\n\t\treturn this;\n\n\t}\n\n\tapplyMatrix4( matrix ) {\n\n\t\t// transform of empty box is an empty box.\n\t\tif ( this.isEmpty() ) return this;\n\n\t\t// NOTE: I am using a binary pattern to specify all 2^3 combinations below\n\t\t_points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000\n\t\t_points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001\n\t\t_points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010\n\t\t_points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011\n\t\t_points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100\n\t\t_points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101\n\t\t_points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110\n\t\t_points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111\n\n\t\tthis.setFromPoints( _points );\n\n\t\treturn this;\n\n\t}\n\n\ttranslate( offset ) {\n\n\t\tthis.min.add( offset );\n\t\tthis.max.add( offset );\n\n\t\treturn this;\n\n\t}\n\n\tequals( box ) {\n\n\t\treturn box.min.equals( this.min ) && box.max.equals( this.max );\n\n\t}\n\n}\n\nconst _points = [\n\t/*@__PURE__*/ new Vector3(),\n\t/*@__PURE__*/ new Vector3(),\n\t/*@__PURE__*/ new Vector3(),\n\t/*@__PURE__*/ new Vector3(),\n\t/*@__PURE__*/ new Vector3(),\n\t/*@__PURE__*/ new Vector3(),\n\t/*@__PURE__*/ new Vector3(),\n\t/*@__PURE__*/ new Vector3()\n];\n\nconst _vector$b = /*@__PURE__*/ new Vector3();\n\nconst _box$4 = /*@__PURE__*/ new Box3();\n\n// triangle centered vertices\n\nconst _v0$3 = /*@__PURE__*/ new Vector3();\nconst _v1$7 = /*@__PURE__*/ new Vector3();\nconst _v2$4 = /*@__PURE__*/ new Vector3();\n\n// triangle edge vectors\n\nconst _f0 = /*@__PURE__*/ new Vector3();\nconst _f1 = /*@__PURE__*/ new Vector3();\nconst _f2 = /*@__PURE__*/ new Vector3();\n\nconst _center = /*@__PURE__*/ new Vector3();\nconst _extents = /*@__PURE__*/ new Vector3();\nconst _triangleNormal = /*@__PURE__*/ new Vector3();\nconst _testAxis = /*@__PURE__*/ new Vector3();\n\nfunction satForAxes( axes, v0, v1, v2, extents ) {\n\n\tfor ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {\n\n\t\t_testAxis.fromArray( axes, i );\n\t\t// project the aabb onto the separating axis\n\t\tconst r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );\n\t\t// project all 3 vertices of the triangle onto the separating axis\n\t\tconst p0 = v0.dot( _testAxis );\n\t\tconst p1 = v1.dot( _testAxis );\n\t\tconst p2 = v2.dot( _testAxis );\n\t\t// actual test, basically see if either of the most extreme of the triangle points intersects r\n\t\tif ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {\n\n\t\t\t// points of the projected triangle are outside the projected half-length of the aabb\n\t\t\t// the axis is separating and we can exit\n\t\t\treturn false;\n\n\t\t}\n\n\t}\n\n\treturn true;\n\n}\n\nconst _box$3 = /*@__PURE__*/ new Box3();\nconst _v1$6 = /*@__PURE__*/ new Vector3();\nconst _v2$3 = /*@__PURE__*/ new Vector3();\n\nclass Sphere {\n\n\tconstructor( center = new Vector3(), radius = - 1 ) {\n\n\t\tthis.isSphere = true;\n\n\t\tthis.center = center;\n\t\tthis.radius = radius;\n\n\t}\n\n\tset( center, radius ) {\n\n\t\tthis.center.copy( center );\n\t\tthis.radius = radius;\n\n\t\treturn this;\n\n\t}\n\n\tsetFromPoints( points, optionalCenter ) {\n\n\t\tconst center = this.center;\n\n\t\tif ( optionalCenter !== undefined ) {\n\n\t\t\tcenter.copy( optionalCenter );\n\n\t\t} else {\n\n\t\t\t_box$3.setFromPoints( points ).getCenter( center );\n\n\t\t}\n\n\t\tlet maxRadiusSq = 0;\n\n\t\tfor ( let i = 0, il = points.length; i < il; i ++ ) {\n\n\t\t\tmaxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );\n\n\t\t}\n\n\t\tthis.radius = Math.sqrt( maxRadiusSq );\n\n\t\treturn this;\n\n\t}\n\n\tcopy( sphere ) {\n\n\t\tthis.center.copy( sphere.center );\n\t\tthis.radius = sphere.radius;\n\n\t\treturn this;\n\n\t}\n\n\tisEmpty() {\n\n\t\treturn ( this.radius < 0 );\n\n\t}\n\n\tmakeEmpty() {\n\n\t\tthis.center.set( 0, 0, 0 );\n\t\tthis.radius = - 1;\n\n\t\treturn this;\n\n\t}\n\n\tcontainsPoint( point ) {\n\n\t\treturn ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );\n\n\t}\n\n\tdistanceToPoint( point ) {\n\n\t\treturn ( point.distanceTo( this.center ) - this.radius );\n\n\t}\n\n\tintersectsSphere( sphere ) {\n\n\t\tconst radiusSum = this.radius + sphere.radius;\n\n\t\treturn sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );\n\n\t}\n\n\tintersectsBox( box ) {\n\n\t\treturn box.intersectsSphere( this );\n\n\t}\n\n\tintersectsPlane( plane ) {\n\n\t\treturn Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;\n\n\t}\n\n\tclampPoint( point, target ) {\n\n\t\tconst deltaLengthSq = this.center.distanceToSquared( point );\n\n\t\ttarget.copy( point );\n\n\t\tif ( deltaLengthSq > ( this.radius * this.radius ) ) {\n\n\t\t\ttarget.sub( this.center ).normalize();\n\t\t\ttarget.multiplyScalar( this.radius ).add( this.center );\n\n\t\t}\n\n\t\treturn target;\n\n\t}\n\n\tgetBoundingBox( target ) {\n\n\t\tif ( this.isEmpty() ) {\n\n\t\t\t// Empty sphere produces empty bounding box\n\t\t\ttarget.makeEmpty();\n\t\t\treturn target;\n\n\t\t}\n\n\t\ttarget.set( this.center, this.center );\n\t\ttarget.expandByScalar( this.radius );\n\n\t\treturn target;\n\n\t}\n\n\tapplyMatrix4( matrix ) {\n\n\t\tthis.center.applyMatrix4( matrix );\n\t\tthis.radius = this.radius * matrix.getMaxScaleOnAxis();\n\n\t\treturn this;\n\n\t}\n\n\ttranslate( offset ) {\n\n\t\tthis.center.add( offset );\n\n\t\treturn this;\n\n\t}\n\n\texpandByPoint( point ) {\n\n\t\tif ( this.isEmpty() ) {\n\n\t\t\tthis.center.copy( point );\n\n\t\t\tthis.radius = 0;\n\n\t\t\treturn this;\n\n\t\t}\n\n\t\t_v1$6.subVectors( point, this.center );\n\n\t\tconst lengthSq = _v1$6.lengthSq();\n\n\t\tif ( lengthSq > ( this.radius * this.radius ) ) {\n\n\t\t\t// calculate the minimal sphere\n\n\t\t\tconst length = Math.sqrt( lengthSq );\n\n\t\t\tconst delta = ( length - this.radius ) * 0.5;\n\n\t\t\tthis.center.addScaledVector( _v1$6, delta / length );\n\n\t\t\tthis.radius += delta;\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tunion( sphere ) {\n\n\t\tif ( sphere.isEmpty() ) {\n\n\t\t\treturn this;\n\n\t\t}\n\n\t\tif ( this.isEmpty() ) {\n\n\t\t\tthis.copy( sphere );\n\n\t\t\treturn this;\n\n\t\t}\n\n\t\tif ( this.center.equals( sphere.center ) === true ) {\n\n\t\t\t this.radius = Math.max( this.radius, sphere.radius );\n\n\t\t} else {\n\n\t\t\t_v2$3.subVectors( sphere.center, this.center ).setLength( sphere.radius );\n\n\t\t\tthis.expandByPoint( _v1$6.copy( sphere.center ).add( _v2$3 ) );\n\n\t\t\tthis.expandByPoint( _v1$6.copy( sphere.center ).sub( _v2$3 ) );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tequals( sphere ) {\n\n\t\treturn sphere.center.equals( this.center ) && ( sphere.radius === this.radius );\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n}\n\nconst _vector$a = /*@__PURE__*/ new Vector3();\nconst _segCenter = /*@__PURE__*/ new Vector3();\nconst _segDir = /*@__PURE__*/ new Vector3();\nconst _diff = /*@__PURE__*/ new Vector3();\n\nconst _edge1 = /*@__PURE__*/ new Vector3();\nconst _edge2 = /*@__PURE__*/ new Vector3();\nconst _normal$1 = /*@__PURE__*/ new Vector3();\n\nclass Ray {\n\n\tconstructor( origin = new Vector3(), direction = new Vector3( 0, 0, - 1 ) ) {\n\n\t\tthis.origin = origin;\n\t\tthis.direction = direction;\n\n\t}\n\n\tset( origin, direction ) {\n\n\t\tthis.origin.copy( origin );\n\t\tthis.direction.copy( direction );\n\n\t\treturn this;\n\n\t}\n\n\tcopy( ray ) {\n\n\t\tthis.origin.copy( ray.origin );\n\t\tthis.direction.copy( ray.direction );\n\n\t\treturn this;\n\n\t}\n\n\tat( t, target ) {\n\n\t\treturn target.copy( this.origin ).addScaledVector( this.direction, t );\n\n\t}\n\n\tlookAt( v ) {\n\n\t\tthis.direction.copy( v ).sub( this.origin ).normalize();\n\n\t\treturn this;\n\n\t}\n\n\trecast( t ) {\n\n\t\tthis.origin.copy( this.at( t, _vector$a ) );\n\n\t\treturn this;\n\n\t}\n\n\tclosestPointToPoint( point, target ) {\n\n\t\ttarget.subVectors( point, this.origin );\n\n\t\tconst directionDistance = target.dot( this.direction );\n\n\t\tif ( directionDistance < 0 ) {\n\n\t\t\treturn target.copy( this.origin );\n\n\t\t}\n\n\t\treturn target.copy( this.origin ).addScaledVector( this.direction, directionDistance );\n\n\t}\n\n\tdistanceToPoint( point ) {\n\n\t\treturn Math.sqrt( this.distanceSqToPoint( point ) );\n\n\t}\n\n\tdistanceSqToPoint( point ) {\n\n\t\tconst directionDistance = _vector$a.subVectors( point, this.origin ).dot( this.direction );\n\n\t\t// point behind the ray\n\n\t\tif ( directionDistance < 0 ) {\n\n\t\t\treturn this.origin.distanceToSquared( point );\n\n\t\t}\n\n\t\t_vector$a.copy( this.origin ).addScaledVector( this.direction, directionDistance );\n\n\t\treturn _vector$a.distanceToSquared( point );\n\n\t}\n\n\tdistanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {\n\n\t\t// from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteDistRaySegment.h\n\t\t// It returns the min distance between the ray and the segment\n\t\t// defined by v0 and v1\n\t\t// It can also set two optional targets :\n\t\t// - The closest point on the ray\n\t\t// - The closest point on the segment\n\n\t\t_segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );\n\t\t_segDir.copy( v1 ).sub( v0 ).normalize();\n\t\t_diff.copy( this.origin ).sub( _segCenter );\n\n\t\tconst segExtent = v0.distanceTo( v1 ) * 0.5;\n\t\tconst a01 = - this.direction.dot( _segDir );\n\t\tconst b0 = _diff.dot( this.direction );\n\t\tconst b1 = - _diff.dot( _segDir );\n\t\tconst c = _diff.lengthSq();\n\t\tconst det = Math.abs( 1 - a01 * a01 );\n\t\tlet s0, s1, sqrDist, extDet;\n\n\t\tif ( det > 0 ) {\n\n\t\t\t// The ray and segment are not parallel.\n\n\t\t\ts0 = a01 * b1 - b0;\n\t\t\ts1 = a01 * b0 - b1;\n\t\t\textDet = segExtent * det;\n\n\t\t\tif ( s0 >= 0 ) {\n\n\t\t\t\tif ( s1 >= - extDet ) {\n\n\t\t\t\t\tif ( s1 <= extDet ) {\n\n\t\t\t\t\t\t// region 0\n\t\t\t\t\t\t// Minimum at interior points of ray and segment.\n\n\t\t\t\t\t\tconst invDet = 1 / det;\n\t\t\t\t\t\ts0 *= invDet;\n\t\t\t\t\t\ts1 *= invDet;\n\t\t\t\t\t\tsqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;\n\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\t// region 1\n\n\t\t\t\t\t\ts1 = segExtent;\n\t\t\t\t\t\ts0 = Math.max( 0, - ( a01 * s1 + b0 ) );\n\t\t\t\t\t\tsqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;\n\n\t\t\t\t\t}\n\n\t\t\t\t} else {\n\n\t\t\t\t\t// region 5\n\n\t\t\t\t\ts1 = - segExtent;\n\t\t\t\t\ts0 = Math.max( 0, - ( a01 * s1 + b0 ) );\n\t\t\t\t\tsqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;\n\n\t\t\t\t}\n\n\t\t\t} else {\n\n\t\t\t\tif ( s1 <= - extDet ) {\n\n\t\t\t\t\t// region 4\n\n\t\t\t\t\ts0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );\n\t\t\t\t\ts1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );\n\t\t\t\t\tsqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;\n\n\t\t\t\t} else if ( s1 <= extDet ) {\n\n\t\t\t\t\t// region 3\n\n\t\t\t\t\ts0 = 0;\n\t\t\t\t\ts1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );\n\t\t\t\t\tsqrDist = s1 * ( s1 + 2 * b1 ) + c;\n\n\t\t\t\t} else {\n\n\t\t\t\t\t// region 2\n\n\t\t\t\t\ts0 = Math.max( 0, - ( a01 * segExtent + b0 ) );\n\t\t\t\t\ts1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );\n\t\t\t\t\tsqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t} else {\n\n\t\t\t// Ray and segment are parallel.\n\n\t\t\ts1 = ( a01 > 0 ) ? - segExtent : segExtent;\n\t\t\ts0 = Math.max( 0, - ( a01 * s1 + b0 ) );\n\t\t\tsqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;\n\n\t\t}\n\n\t\tif ( optionalPointOnRay ) {\n\n\t\t\toptionalPointOnRay.copy( this.origin ).addScaledVector( this.direction, s0 );\n\n\t\t}\n\n\t\tif ( optionalPointOnSegment ) {\n\n\t\t\toptionalPointOnSegment.copy( _segCenter ).addScaledVector( _segDir, s1 );\n\n\t\t}\n\n\t\treturn sqrDist;\n\n\t}\n\n\tintersectSphere( sphere, target ) {\n\n\t\t_vector$a.subVectors( sphere.center, this.origin );\n\t\tconst tca = _vector$a.dot( this.direction );\n\t\tconst d2 = _vector$a.dot( _vector$a ) - tca * tca;\n\t\tconst radius2 = sphere.radius * sphere.radius;\n\n\t\tif ( d2 > radius2 ) return null;\n\n\t\tconst thc = Math.sqrt( radius2 - d2 );\n\n\t\t// t0 = first intersect point - entrance on front of sphere\n\t\tconst t0 = tca - thc;\n\n\t\t// t1 = second intersect point - exit point on back of sphere\n\t\tconst t1 = tca + thc;\n\n\t\t// test to see if t1 is behind the ray - if so, return null\n\t\tif ( t1 < 0 ) return null;\n\n\t\t// test to see if t0 is behind the ray:\n\t\t// if it is, the ray is inside the sphere, so return the second exit point scaled by t1,\n\t\t// in order to always return an intersect point that is in front of the ray.\n\t\tif ( t0 < 0 ) return this.at( t1, target );\n\n\t\t// else t0 is in front of the ray, so return the first collision point scaled by t0\n\t\treturn this.at( t0, target );\n\n\t}\n\n\tintersectsSphere( sphere ) {\n\n\t\treturn this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );\n\n\t}\n\n\tdistanceToPlane( plane ) {\n\n\t\tconst denominator = plane.normal.dot( this.direction );\n\n\t\tif ( denominator === 0 ) {\n\n\t\t\t// line is coplanar, return origin\n\t\t\tif ( plane.distanceToPoint( this.origin ) === 0 ) {\n\n\t\t\t\treturn 0;\n\n\t\t\t}\n\n\t\t\t// Null is preferable to undefined since undefined means.... it is undefined\n\n\t\t\treturn null;\n\n\t\t}\n\n\t\tconst t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;\n\n\t\t// Return if the ray never intersects the plane\n\n\t\treturn t >= 0 ? t : null;\n\n\t}\n\n\tintersectPlane( plane, target ) {\n\n\t\tconst t = this.distanceToPlane( plane );\n\n\t\tif ( t === null ) {\n\n\t\t\treturn null;\n\n\t\t}\n\n\t\treturn this.at( t, target );\n\n\t}\n\n\tintersectsPlane( plane ) {\n\n\t\t// check if the ray lies on the plane first\n\n\t\tconst distToPoint = plane.distanceToPoint( this.origin );\n\n\t\tif ( distToPoint === 0 ) {\n\n\t\t\treturn true;\n\n\t\t}\n\n\t\tconst denominator = plane.normal.dot( this.direction );\n\n\t\tif ( denominator * distToPoint < 0 ) {\n\n\t\t\treturn true;\n\n\t\t}\n\n\t\t// ray origin is behind the plane (and is pointing behind it)\n\n\t\treturn false;\n\n\t}\n\n\tintersectBox( box, target ) {\n\n\t\tlet tmin, tmax, tymin, tymax, tzmin, tzmax;\n\n\t\tconst invdirx = 1 / this.direction.x,\n\t\t\tinvdiry = 1 / this.direction.y,\n\t\t\tinvdirz = 1 / this.direction.z;\n\n\t\tconst origin = this.origin;\n\n\t\tif ( invdirx >= 0 ) {\n\n\t\t\ttmin = ( box.min.x - origin.x ) * invdirx;\n\t\t\ttmax = ( box.max.x - origin.x ) * invdirx;\n\n\t\t} else {\n\n\t\t\ttmin = ( box.max.x - origin.x ) * invdirx;\n\t\t\ttmax = ( box.min.x - origin.x ) * invdirx;\n\n\t\t}\n\n\t\tif ( invdiry >= 0 ) {\n\n\t\t\ttymin = ( box.min.y - origin.y ) * invdiry;\n\t\t\ttymax = ( box.max.y - origin.y ) * invdiry;\n\n\t\t} else {\n\n\t\t\ttymin = ( box.max.y - origin.y ) * invdiry;\n\t\t\ttymax = ( box.min.y - origin.y ) * invdiry;\n\n\t\t}\n\n\t\tif ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;\n\n\t\tif ( tymin > tmin || isNaN( tmin ) ) tmin = tymin;\n\n\t\tif ( tymax < tmax || isNaN( tmax ) ) tmax = tymax;\n\n\t\tif ( invdirz >= 0 ) {\n\n\t\t\ttzmin = ( box.min.z - origin.z ) * invdirz;\n\t\t\ttzmax = ( box.max.z - origin.z ) * invdirz;\n\n\t\t} else {\n\n\t\t\ttzmin = ( box.max.z - origin.z ) * invdirz;\n\t\t\ttzmax = ( box.min.z - origin.z ) * invdirz;\n\n\t\t}\n\n\t\tif ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;\n\n\t\tif ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;\n\n\t\tif ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;\n\n\t\t//return point closest to the ray (positive side)\n\n\t\tif ( tmax < 0 ) return null;\n\n\t\treturn this.at( tmin >= 0 ? tmin : tmax, target );\n\n\t}\n\n\tintersectsBox( box ) {\n\n\t\treturn this.intersectBox( box, _vector$a ) !== null;\n\n\t}\n\n\tintersectTriangle( a, b, c, backfaceCulling, target ) {\n\n\t\t// Compute the offset origin, edges, and normal.\n\n\t\t// from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h\n\n\t\t_edge1.subVectors( b, a );\n\t\t_edge2.subVectors( c, a );\n\t\t_normal$1.crossVectors( _edge1, _edge2 );\n\n\t\t// Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,\n\t\t// E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by\n\t\t// |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))\n\t\t// |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))\n\t\t// |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)\n\t\tlet DdN = this.direction.dot( _normal$1 );\n\t\tlet sign;\n\n\t\tif ( DdN > 0 ) {\n\n\t\t\tif ( backfaceCulling ) return null;\n\t\t\tsign = 1;\n\n\t\t} else if ( DdN < 0 ) {\n\n\t\t\tsign = - 1;\n\t\t\tDdN = - DdN;\n\n\t\t} else {\n\n\t\t\treturn null;\n\n\t\t}\n\n\t\t_diff.subVectors( this.origin, a );\n\t\tconst DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );\n\n\t\t// b1 < 0, no intersection\n\t\tif ( DdQxE2 < 0 ) {\n\n\t\t\treturn null;\n\n\t\t}\n\n\t\tconst DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );\n\n\t\t// b2 < 0, no intersection\n\t\tif ( DdE1xQ < 0 ) {\n\n\t\t\treturn null;\n\n\t\t}\n\n\t\t// b1+b2 > 1, no intersection\n\t\tif ( DdQxE2 + DdE1xQ > DdN ) {\n\n\t\t\treturn null;\n\n\t\t}\n\n\t\t// Line intersects triangle, check if ray does.\n\t\tconst QdN = - sign * _diff.dot( _normal$1 );\n\n\t\t// t < 0, no intersection\n\t\tif ( QdN < 0 ) {\n\n\t\t\treturn null;\n\n\t\t}\n\n\t\t// Ray intersects triangle.\n\t\treturn this.at( QdN / DdN, target );\n\n\t}\n\n\tapplyMatrix4( matrix4 ) {\n\n\t\tthis.origin.applyMatrix4( matrix4 );\n\t\tthis.direction.transformDirection( matrix4 );\n\n\t\treturn this;\n\n\t}\n\n\tequals( ray ) {\n\n\t\treturn ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n}\n\nclass Matrix4 {\n\n\tconstructor( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {\n\n\t\tMatrix4.prototype.isMatrix4 = true;\n\n\t\tthis.elements = [\n\n\t\t\t1, 0, 0, 0,\n\t\t\t0, 1, 0, 0,\n\t\t\t0, 0, 1, 0,\n\t\t\t0, 0, 0, 1\n\n\t\t];\n\n\t\tif ( n11 !== undefined ) {\n\n\t\t\tthis.set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 );\n\n\t\t}\n\n\t}\n\n\tset( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {\n\n\t\tconst te = this.elements;\n\n\t\tte[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;\n\t\tte[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;\n\t\tte[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;\n\t\tte[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;\n\n\t\treturn this;\n\n\t}\n\n\tidentity() {\n\n\t\tthis.set(\n\n\t\t\t1, 0, 0, 0,\n\t\t\t0, 1, 0, 0,\n\t\t\t0, 0, 1, 0,\n\t\t\t0, 0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\tclone() {\n\n\t\treturn new Matrix4().fromArray( this.elements );\n\n\t}\n\n\tcopy( m ) {\n\n\t\tconst te = this.elements;\n\t\tconst me = m.elements;\n\n\t\tte[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];\n\t\tte[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];\n\t\tte[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];\n\t\tte[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];\n\n\t\treturn this;\n\n\t}\n\n\tcopyPosition( m ) {\n\n\t\tconst te = this.elements, me = m.elements;\n\n\t\tte[ 12 ] = me[ 12 ];\n\t\tte[ 13 ] = me[ 13 ];\n\t\tte[ 14 ] = me[ 14 ];\n\n\t\treturn this;\n\n\t}\n\n\tsetFromMatrix3( m ) {\n\n\t\tconst me = m.elements;\n\n\t\tthis.set(\n\n\t\t\tme[ 0 ], me[ 3 ], me[ 6 ], 0,\n\t\t\tme[ 1 ], me[ 4 ], me[ 7 ], 0,\n\t\t\tme[ 2 ], me[ 5 ], me[ 8 ], 0,\n\t\t\t0, 0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\textractBasis( xAxis, yAxis, zAxis ) {\n\n\t\txAxis.setFromMatrixColumn( this, 0 );\n\t\tyAxis.setFromMatrixColumn( this, 1 );\n\t\tzAxis.setFromMatrixColumn( this, 2 );\n\n\t\treturn this;\n\n\t}\n\n\tmakeBasis( xAxis, yAxis, zAxis ) {\n\n\t\tthis.set(\n\t\t\txAxis.x, yAxis.x, zAxis.x, 0,\n\t\t\txAxis.y, yAxis.y, zAxis.y, 0,\n\t\t\txAxis.z, yAxis.z, zAxis.z, 0,\n\t\t\t0, 0, 0, 1\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\textractRotation( m ) {\n\n\t\t// this method does not support reflection matrices\n\n\t\tconst te = this.elements;\n\t\tconst me = m.elements;\n\n\t\tconst scaleX = 1 / _v1$5.setFromMatrixColumn( m, 0 ).length();\n\t\tconst scaleY = 1 / _v1$5.setFromMatrixColumn( m, 1 ).length();\n\t\tconst scaleZ = 1 / _v1$5.setFromMatrixColumn( m, 2 ).length();\n\n\t\tte[ 0 ] = me[ 0 ] * scaleX;\n\t\tte[ 1 ] = me[ 1 ] * scaleX;\n\t\tte[ 2 ] = me[ 2 ] * scaleX;\n\t\tte[ 3 ] = 0;\n\n\t\tte[ 4 ] = me[ 4 ] * scaleY;\n\t\tte[ 5 ] = me[ 5 ] * scaleY;\n\t\tte[ 6 ] = me[ 6 ] * scaleY;\n\t\tte[ 7 ] = 0;\n\n\t\tte[ 8 ] = me[ 8 ] * scaleZ;\n\t\tte[ 9 ] = me[ 9 ] * scaleZ;\n\t\tte[ 10 ] = me[ 10 ] * scaleZ;\n\t\tte[ 11 ] = 0;\n\n\t\tte[ 12 ] = 0;\n\t\tte[ 13 ] = 0;\n\t\tte[ 14 ] = 0;\n\t\tte[ 15 ] = 1;\n\n\t\treturn this;\n\n\t}\n\n\tmakeRotationFromEuler( euler ) {\n\n\t\tconst te = this.elements;\n\n\t\tconst x = euler.x, y = euler.y, z = euler.z;\n\t\tconst a = Math.cos( x ), b = Math.sin( x );\n\t\tconst c = Math.cos( y ), d = Math.sin( y );\n\t\tconst e = Math.cos( z ), f = Math.sin( z );\n\n\t\tif ( euler.order === 'XYZ' ) {\n\n\t\t\tconst ae = a * e, af = a * f, be = b * e, bf = b * f;\n\n\t\t\tte[ 0 ] = c * e;\n\t\t\tte[ 4 ] = - c * f;\n\t\t\tte[ 8 ] = d;\n\n\t\t\tte[ 1 ] = af + be * d;\n\t\t\tte[ 5 ] = ae - bf * d;\n\t\t\tte[ 9 ] = - b * c;\n\n\t\t\tte[ 2 ] = bf - ae * d;\n\t\t\tte[ 6 ] = be + af * d;\n\t\t\tte[ 10 ] = a * c;\n\n\t\t} else if ( euler.order === 'YXZ' ) {\n\n\t\t\tconst ce = c * e, cf = c * f, de = d * e, df = d * f;\n\n\t\t\tte[ 0 ] = ce + df * b;\n\t\t\tte[ 4 ] = de * b - cf;\n\t\t\tte[ 8 ] = a * d;\n\n\t\t\tte[ 1 ] = a * f;\n\t\t\tte[ 5 ] = a * e;\n\t\t\tte[ 9 ] = - b;\n\n\t\t\tte[ 2 ] = cf * b - de;\n\t\t\tte[ 6 ] = df + ce * b;\n\t\t\tte[ 10 ] = a * c;\n\n\t\t} else if ( euler.order === 'ZXY' ) {\n\n\t\t\tconst ce = c * e, cf = c * f, de = d * e, df = d * f;\n\n\t\t\tte[ 0 ] = ce - df * b;\n\t\t\tte[ 4 ] = - a * f;\n\t\t\tte[ 8 ] = de + cf * b;\n\n\t\t\tte[ 1 ] = cf + de * b;\n\t\t\tte[ 5 ] = a * e;\n\t\t\tte[ 9 ] = df - ce * b;\n\n\t\t\tte[ 2 ] = - a * d;\n\t\t\tte[ 6 ] = b;\n\t\t\tte[ 10 ] = a * c;\n\n\t\t} else if ( euler.order === 'ZYX' ) {\n\n\t\t\tconst ae = a * e, af = a * f, be = b * e, bf = b * f;\n\n\t\t\tte[ 0 ] = c * e;\n\t\t\tte[ 4 ] = be * d - af;\n\t\t\tte[ 8 ] = ae * d + bf;\n\n\t\t\tte[ 1 ] = c * f;\n\t\t\tte[ 5 ] = bf * d + ae;\n\t\t\tte[ 9 ] = af * d - be;\n\n\t\t\tte[ 2 ] = - d;\n\t\t\tte[ 6 ] = b * c;\n\t\t\tte[ 10 ] = a * c;\n\n\t\t} else if ( euler.order === 'YZX' ) {\n\n\t\t\tconst ac = a * c, ad = a * d, bc = b * c, bd = b * d;\n\n\t\t\tte[ 0 ] = c * e;\n\t\t\tte[ 4 ] = bd - ac * f;\n\t\t\tte[ 8 ] = bc * f + ad;\n\n\t\t\tte[ 1 ] = f;\n\t\t\tte[ 5 ] = a * e;\n\t\t\tte[ 9 ] = - b * e;\n\n\t\t\tte[ 2 ] = - d * e;\n\t\t\tte[ 6 ] = ad * f + bc;\n\t\t\tte[ 10 ] = ac - bd * f;\n\n\t\t} else if ( euler.order === 'XZY' ) {\n\n\t\t\tconst ac = a * c, ad = a * d, bc = b * c, bd = b * d;\n\n\t\t\tte[ 0 ] = c * e;\n\t\t\tte[ 4 ] = - f;\n\t\t\tte[ 8 ] = d * e;\n\n\t\t\tte[ 1 ] = ac * f + bd;\n\t\t\tte[ 5 ] = a * e;\n\t\t\tte[ 9 ] = ad * f - bc;\n\n\t\t\tte[ 2 ] = bc * f - ad;\n\t\t\tte[ 6 ] = b * e;\n\t\t\tte[ 10 ] = bd * f + ac;\n\n\t\t}\n\n\t\t// bottom row\n\t\tte[ 3 ] = 0;\n\t\tte[ 7 ] = 0;\n\t\tte[ 11 ] = 0;\n\n\t\t// last column\n\t\tte[ 12 ] = 0;\n\t\tte[ 13 ] = 0;\n\t\tte[ 14 ] = 0;\n\t\tte[ 15 ] = 1;\n\n\t\treturn this;\n\n\t}\n\n\tmakeRotationFromQuaternion( q ) {\n\n\t\treturn this.compose( _zero, q, _one );\n\n\t}\n\n\tlookAt( eye, target, up ) {\n\n\t\tconst te = this.elements;\n\n\t\t_z.subVectors( eye, target );\n\n\t\tif ( _z.lengthSq() === 0 ) {\n\n\t\t\t// eye and target are in the same position\n\n\t\t\t_z.z = 1;\n\n\t\t}\n\n\t\t_z.normalize();\n\t\t_x.crossVectors( up, _z );\n\n\t\tif ( _x.lengthSq() === 0 ) {\n\n\t\t\t// up and z are parallel\n\n\t\t\tif ( Math.abs( up.z ) === 1 ) {\n\n\t\t\t\t_z.x += 0.0001;\n\n\t\t\t} else {\n\n\t\t\t\t_z.z += 0.0001;\n\n\t\t\t}\n\n\t\t\t_z.normalize();\n\t\t\t_x.crossVectors( up, _z );\n\n\t\t}\n\n\t\t_x.normalize();\n\t\t_y.crossVectors( _z, _x );\n\n\t\tte[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;\n\t\tte[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;\n\t\tte[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;\n\n\t\treturn this;\n\n\t}\n\n\tmultiply( m ) {\n\n\t\treturn this.multiplyMatrices( this, m );\n\n\t}\n\n\tpremultiply( m ) {\n\n\t\treturn this.multiplyMatrices( m, this );\n\n\t}\n\n\tmultiplyMatrices( a, b ) {\n\n\t\tconst ae = a.elements;\n\t\tconst be = b.elements;\n\t\tconst te = this.elements;\n\n\t\tconst a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];\n\t\tconst a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];\n\t\tconst a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];\n\t\tconst a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];\n\n\t\tconst b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];\n\t\tconst b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];\n\t\tconst b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];\n\t\tconst b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];\n\n\t\tte[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;\n\t\tte[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;\n\t\tte[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;\n\t\tte[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;\n\n\t\tte[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;\n\t\tte[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;\n\t\tte[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;\n\t\tte[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;\n\n\t\tte[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;\n\t\tte[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;\n\t\tte[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;\n\t\tte[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;\n\n\t\tte[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;\n\t\tte[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;\n\t\tte[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;\n\t\tte[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;\n\n\t\treturn this;\n\n\t}\n\n\tmultiplyScalar( s ) {\n\n\t\tconst te = this.elements;\n\n\t\tte[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;\n\t\tte[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;\n\t\tte[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;\n\t\tte[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;\n\n\t\treturn this;\n\n\t}\n\n\tdeterminant() {\n\n\t\tconst te = this.elements;\n\n\t\tconst n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];\n\t\tconst n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];\n\t\tconst n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];\n\t\tconst n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];\n\n\t\t//TODO: make this more efficient\n\t\t//( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )\n\n\t\treturn (\n\t\t\tn41 * (\n\t\t\t\t+ n14 * n23 * n32\n\t\t\t\t - n13 * n24 * n32\n\t\t\t\t - n14 * n22 * n33\n\t\t\t\t + n12 * n24 * n33\n\t\t\t\t + n13 * n22 * n34\n\t\t\t\t - n12 * n23 * n34\n\t\t\t) +\n\t\t\tn42 * (\n\t\t\t\t+ n11 * n23 * n34\n\t\t\t\t - n11 * n24 * n33\n\t\t\t\t + n14 * n21 * n33\n\t\t\t\t - n13 * n21 * n34\n\t\t\t\t + n13 * n24 * n31\n\t\t\t\t - n14 * n23 * n31\n\t\t\t) +\n\t\t\tn43 * (\n\t\t\t\t+ n11 * n24 * n32\n\t\t\t\t - n11 * n22 * n34\n\t\t\t\t - n14 * n21 * n32\n\t\t\t\t + n12 * n21 * n34\n\t\t\t\t + n14 * n22 * n31\n\t\t\t\t - n12 * n24 * n31\n\t\t\t) +\n\t\t\tn44 * (\n\t\t\t\t- n13 * n22 * n31\n\t\t\t\t - n11 * n23 * n32\n\t\t\t\t + n11 * n22 * n33\n\t\t\t\t + n13 * n21 * n32\n\t\t\t\t - n12 * n21 * n33\n\t\t\t\t + n12 * n23 * n31\n\t\t\t)\n\n\t\t);\n\n\t}\n\n\ttranspose() {\n\n\t\tconst te = this.elements;\n\t\tlet tmp;\n\n\t\ttmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;\n\t\ttmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;\n\t\ttmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;\n\n\t\ttmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;\n\t\ttmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;\n\t\ttmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;\n\n\t\treturn this;\n\n\t}\n\n\tsetPosition( x, y, z ) {\n\n\t\tconst te = this.elements;\n\n\t\tif ( x.isVector3 ) {\n\n\t\t\tte[ 12 ] = x.x;\n\t\t\tte[ 13 ] = x.y;\n\t\t\tte[ 14 ] = x.z;\n\n\t\t} else {\n\n\t\t\tte[ 12 ] = x;\n\t\t\tte[ 13 ] = y;\n\t\t\tte[ 14 ] = z;\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tinvert() {\n\n\t\t// based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm\n\t\tconst te = this.elements,\n\n\t\t\tn11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], n41 = te[ 3 ],\n\t\t\tn12 = te[ 4 ], n22 = te[ 5 ], n32 = te[ 6 ], n42 = te[ 7 ],\n\t\t\tn13 = te[ 8 ], n23 = te[ 9 ], n33 = te[ 10 ], n43 = te[ 11 ],\n\t\t\tn14 = te[ 12 ], n24 = te[ 13 ], n34 = te[ 14 ], n44 = te[ 15 ],\n\n\t\t\tt11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,\n\t\t\tt12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,\n\t\t\tt13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,\n\t\t\tt14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;\n\n\t\tconst det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;\n\n\t\tif ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );\n\n\t\tconst detInv = 1 / det;\n\n\t\tte[ 0 ] = t11 * detInv;\n\t\tte[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;\n\t\tte[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;\n\t\tte[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;\n\n\t\tte[ 4 ] = t12 * detInv;\n\t\tte[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;\n\t\tte[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;\n\t\tte[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;\n\n\t\tte[ 8 ] = t13 * detInv;\n\t\tte[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;\n\t\tte[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;\n\t\tte[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;\n\n\t\tte[ 12 ] = t14 * detInv;\n\t\tte[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;\n\t\tte[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;\n\t\tte[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;\n\n\t\treturn this;\n\n\t}\n\n\tscale( v ) {\n\n\t\tconst te = this.elements;\n\t\tconst x = v.x, y = v.y, z = v.z;\n\n\t\tte[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;\n\t\tte[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;\n\t\tte[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;\n\t\tte[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;\n\n\t\treturn this;\n\n\t}\n\n\tgetMaxScaleOnAxis() {\n\n\t\tconst te = this.elements;\n\n\t\tconst scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];\n\t\tconst scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];\n\t\tconst scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];\n\n\t\treturn Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );\n\n\t}\n\n\tmakeTranslation( x, y, z ) {\n\n\t\tif ( x.isVector3 ) {\n\n\t\t\tthis.set(\n\n\t\t\t\t1, 0, 0, x.x,\n\t\t\t\t0, 1, 0, x.y,\n\t\t\t\t0, 0, 1, x.z,\n\t\t\t\t0, 0, 0, 1\n\n\t\t\t);\n\n\t\t} else {\n\n\t\t\tthis.set(\n\n\t\t\t\t1, 0, 0, x,\n\t\t\t\t0, 1, 0, y,\n\t\t\t\t0, 0, 1, z,\n\t\t\t\t0, 0, 0, 1\n\n\t\t\t);\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tmakeRotationX( theta ) {\n\n\t\tconst c = Math.cos( theta ), s = Math.sin( theta );\n\n\t\tthis.set(\n\n\t\t\t1, 0, 0, 0,\n\t\t\t0, c, - s, 0,\n\t\t\t0, s, c, 0,\n\t\t\t0, 0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\tmakeRotationY( theta ) {\n\n\t\tconst c = Math.cos( theta ), s = Math.sin( theta );\n\n\t\tthis.set(\n\n\t\t\t c, 0, s, 0,\n\t\t\t 0, 1, 0, 0,\n\t\t\t- s, 0, c, 0,\n\t\t\t 0, 0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\tmakeRotationZ( theta ) {\n\n\t\tconst c = Math.cos( theta ), s = Math.sin( theta );\n\n\t\tthis.set(\n\n\t\t\tc, - s, 0, 0,\n\t\t\ts, c, 0, 0,\n\t\t\t0, 0, 1, 0,\n\t\t\t0, 0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\tmakeRotationAxis( axis, angle ) {\n\n\t\t// Based on http://www.gamedev.net/reference/articles/article1199.asp\n\n\t\tconst c = Math.cos( angle );\n\t\tconst s = Math.sin( angle );\n\t\tconst t = 1 - c;\n\t\tconst x = axis.x, y = axis.y, z = axis.z;\n\t\tconst tx = t * x, ty = t * y;\n\n\t\tthis.set(\n\n\t\t\ttx * x + c, tx * y - s * z, tx * z + s * y, 0,\n\t\t\ttx * y + s * z, ty * y + c, ty * z - s * x, 0,\n\t\t\ttx * z - s * y, ty * z + s * x, t * z * z + c, 0,\n\t\t\t0, 0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\tmakeScale( x, y, z ) {\n\n\t\tthis.set(\n\n\t\t\tx, 0, 0, 0,\n\t\t\t0, y, 0, 0,\n\t\t\t0, 0, z, 0,\n\t\t\t0, 0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\tmakeShear( xy, xz, yx, yz, zx, zy ) {\n\n\t\tthis.set(\n\n\t\t\t1, yx, zx, 0,\n\t\t\txy, 1, zy, 0,\n\t\t\txz, yz, 1, 0,\n\t\t\t0, 0, 0, 1\n\n\t\t);\n\n\t\treturn this;\n\n\t}\n\n\tcompose( position, quaternion, scale ) {\n\n\t\tconst te = this.elements;\n\n\t\tconst x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;\n\t\tconst x2 = x + x,\ty2 = y + y, z2 = z + z;\n\t\tconst xx = x * x2, xy = x * y2, xz = x * z2;\n\t\tconst yy = y * y2, yz = y * z2, zz = z * z2;\n\t\tconst wx = w * x2, wy = w * y2, wz = w * z2;\n\n\t\tconst sx = scale.x, sy = scale.y, sz = scale.z;\n\n\t\tte[ 0 ] = ( 1 - ( yy + zz ) ) * sx;\n\t\tte[ 1 ] = ( xy + wz ) * sx;\n\t\tte[ 2 ] = ( xz - wy ) * sx;\n\t\tte[ 3 ] = 0;\n\n\t\tte[ 4 ] = ( xy - wz ) * sy;\n\t\tte[ 5 ] = ( 1 - ( xx + zz ) ) * sy;\n\t\tte[ 6 ] = ( yz + wx ) * sy;\n\t\tte[ 7 ] = 0;\n\n\t\tte[ 8 ] = ( xz + wy ) * sz;\n\t\tte[ 9 ] = ( yz - wx ) * sz;\n\t\tte[ 10 ] = ( 1 - ( xx + yy ) ) * sz;\n\t\tte[ 11 ] = 0;\n\n\t\tte[ 12 ] = position.x;\n\t\tte[ 13 ] = position.y;\n\t\tte[ 14 ] = position.z;\n\t\tte[ 15 ] = 1;\n\n\t\treturn this;\n\n\t}\n\n\tdecompose( position, quaternion, scale ) {\n\n\t\tconst te = this.elements;\n\n\t\tlet sx = _v1$5.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();\n\t\tconst sy = _v1$5.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();\n\t\tconst sz = _v1$5.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();\n\n\t\t// if determine is negative, we need to invert one scale\n\t\tconst det = this.determinant();\n\t\tif ( det < 0 ) sx = - sx;\n\n\t\tposition.x = te[ 12 ];\n\t\tposition.y = te[ 13 ];\n\t\tposition.z = te[ 14 ];\n\n\t\t// scale the rotation part\n\t\t_m1$4.copy( this );\n\n\t\tconst invSX = 1 / sx;\n\t\tconst invSY = 1 / sy;\n\t\tconst invSZ = 1 / sz;\n\n\t\t_m1$4.elements[ 0 ] *= invSX;\n\t\t_m1$4.elements[ 1 ] *= invSX;\n\t\t_m1$4.elements[ 2 ] *= invSX;\n\n\t\t_m1$4.elements[ 4 ] *= invSY;\n\t\t_m1$4.elements[ 5 ] *= invSY;\n\t\t_m1$4.elements[ 6 ] *= invSY;\n\n\t\t_m1$4.elements[ 8 ] *= invSZ;\n\t\t_m1$4.elements[ 9 ] *= invSZ;\n\t\t_m1$4.elements[ 10 ] *= invSZ;\n\n\t\tquaternion.setFromRotationMatrix( _m1$4 );\n\n\t\tscale.x = sx;\n\t\tscale.y = sy;\n\t\tscale.z = sz;\n\n\t\treturn this;\n\n\t}\n\n\tmakePerspective( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) {\n\n\t\tconst te = this.elements;\n\t\tconst x = 2 * near / ( right - left );\n\t\tconst y = 2 * near / ( top - bottom );\n\n\t\tconst a = ( right + left ) / ( right - left );\n\t\tconst b = ( top + bottom ) / ( top - bottom );\n\n\t\tlet c, d;\n\n\t\tif ( coordinateSystem === WebGLCoordinateSystem ) {\n\n\t\t\tc = - ( far + near ) / ( far - near );\n\t\t\td = ( - 2 * far * near ) / ( far - near );\n\n\t\t} else if ( coordinateSystem === WebGPUCoordinateSystem ) {\n\n\t\t\tc = - far / ( far - near );\n\t\t\td = ( - far * near ) / ( far - near );\n\n\t\t} else {\n\n\t\t\tthrow new Error( 'THREE.Matrix4.makePerspective(): Invalid coordinate system: ' + coordinateSystem );\n\n\t\t}\n\n\t\tte[ 0 ] = x;\tte[ 4 ] = 0;\tte[ 8 ] = a; \tte[ 12 ] = 0;\n\t\tte[ 1 ] = 0;\tte[ 5 ] = y;\tte[ 9 ] = b; \tte[ 13 ] = 0;\n\t\tte[ 2 ] = 0;\tte[ 6 ] = 0;\tte[ 10 ] = c; \tte[ 14 ] = d;\n\t\tte[ 3 ] = 0;\tte[ 7 ] = 0;\tte[ 11 ] = - 1;\tte[ 15 ] = 0;\n\n\t\treturn this;\n\n\t}\n\n\tmakeOrthographic( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) {\n\n\t\tconst te = this.elements;\n\t\tconst w = 1.0 / ( right - left );\n\t\tconst h = 1.0 / ( top - bottom );\n\t\tconst p = 1.0 / ( far - near );\n\n\t\tconst x = ( right + left ) * w;\n\t\tconst y = ( top + bottom ) * h;\n\n\t\tlet z, zInv;\n\n\t\tif ( coordinateSystem === WebGLCoordinateSystem ) {\n\n\t\t\tz = ( far + near ) * p;\n\t\t\tzInv = - 2 * p;\n\n\t\t} else if ( coordinateSystem === WebGPUCoordinateSystem ) {\n\n\t\t\tz = near * p;\n\t\t\tzInv = - 1 * p;\n\n\t\t} else {\n\n\t\t\tthrow new Error( 'THREE.Matrix4.makeOrthographic(): Invalid coordinate system: ' + coordinateSystem );\n\n\t\t}\n\n\t\tte[ 0 ] = 2 * w;\tte[ 4 ] = 0;\t\tte[ 8 ] = 0; \t\tte[ 12 ] = - x;\n\t\tte[ 1 ] = 0; \t\tte[ 5 ] = 2 * h;\tte[ 9 ] = 0; \t\tte[ 13 ] = - y;\n\t\tte[ 2 ] = 0; \t\tte[ 6 ] = 0;\t\tte[ 10 ] = zInv;\tte[ 14 ] = - z;\n\t\tte[ 3 ] = 0; \t\tte[ 7 ] = 0;\t\tte[ 11 ] = 0;\t\tte[ 15 ] = 1;\n\n\t\treturn this;\n\n\t}\n\n\tequals( matrix ) {\n\n\t\tconst te = this.elements;\n\t\tconst me = matrix.elements;\n\n\t\tfor ( let i = 0; i < 16; i ++ ) {\n\n\t\t\tif ( te[ i ] !== me[ i ] ) return false;\n\n\t\t}\n\n\t\treturn true;\n\n\t}\n\n\tfromArray( array, offset = 0 ) {\n\n\t\tfor ( let i = 0; i < 16; i ++ ) {\n\n\t\t\tthis.elements[ i ] = array[ i + offset ];\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\ttoArray( array = [], offset = 0 ) {\n\n\t\tconst te = this.elements;\n\n\t\tarray[ offset ] = te[ 0 ];\n\t\tarray[ offset + 1 ] = te[ 1 ];\n\t\tarray[ offset + 2 ] = te[ 2 ];\n\t\tarray[ offset + 3 ] = te[ 3 ];\n\n\t\tarray[ offset + 4 ] = te[ 4 ];\n\t\tarray[ offset + 5 ] = te[ 5 ];\n\t\tarray[ offset + 6 ] = te[ 6 ];\n\t\tarray[ offset + 7 ] = te[ 7 ];\n\n\t\tarray[ offset + 8 ] = te[ 8 ];\n\t\tarray[ offset + 9 ] = te[ 9 ];\n\t\tarray[ offset + 10 ] = te[ 10 ];\n\t\tarray[ offset + 11 ] = te[ 11 ];\n\n\t\tarray[ offset + 12 ] = te[ 12 ];\n\t\tarray[ offset + 13 ] = te[ 13 ];\n\t\tarray[ offset + 14 ] = te[ 14 ];\n\t\tarray[ offset + 15 ] = te[ 15 ];\n\n\t\treturn array;\n\n\t}\n\n}\n\nconst _v1$5 = /*@__PURE__*/ new Vector3();\nconst _m1$4 = /*@__PURE__*/ new Matrix4();\nconst _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );\nconst _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );\nconst _x = /*@__PURE__*/ new Vector3();\nconst _y = /*@__PURE__*/ new Vector3();\nconst _z = /*@__PURE__*/ new Vector3();\n\nconst _matrix$2 = /*@__PURE__*/ new Matrix4();\nconst _quaternion$3 = /*@__PURE__*/ new Quaternion();\n\nclass Euler {\n\n\tconstructor( x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER ) {\n\n\t\tthis.isEuler = true;\n\n\t\tthis._x = x;\n\t\tthis._y = y;\n\t\tthis._z = z;\n\t\tthis._order = order;\n\n\t}\n\n\tget x() {\n\n\t\treturn this._x;\n\n\t}\n\n\tset x( value ) {\n\n\t\tthis._x = value;\n\t\tthis._onChangeCallback();\n\n\t}\n\n\tget y() {\n\n\t\treturn this._y;\n\n\t}\n\n\tset y( value ) {\n\n\t\tthis._y = value;\n\t\tthis._onChangeCallback();\n\n\t}\n\n\tget z() {\n\n\t\treturn this._z;\n\n\t}\n\n\tset z( value ) {\n\n\t\tthis._z = value;\n\t\tthis._onChangeCallback();\n\n\t}\n\n\tget order() {\n\n\t\treturn this._order;\n\n\t}\n\n\tset order( value ) {\n\n\t\tthis._order = value;\n\t\tthis._onChangeCallback();\n\n\t}\n\n\tset( x, y, z, order = this._order ) {\n\n\t\tthis._x = x;\n\t\tthis._y = y;\n\t\tthis._z = z;\n\t\tthis._order = order;\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor( this._x, this._y, this._z, this._order );\n\n\t}\n\n\tcopy( euler ) {\n\n\t\tthis._x = euler._x;\n\t\tthis._y = euler._y;\n\t\tthis._z = euler._z;\n\t\tthis._order = euler._order;\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tsetFromRotationMatrix( m, order = this._order, update = true ) {\n\n\t\t// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)\n\n\t\tconst te = m.elements;\n\t\tconst m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];\n\t\tconst m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];\n\t\tconst m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];\n\n\t\tswitch ( order ) {\n\n\t\t\tcase 'XYZ':\n\n\t\t\t\tthis._y = Math.asin( clamp( m13, - 1, 1 ) );\n\n\t\t\t\tif ( Math.abs( m13 ) < 0.9999999 ) {\n\n\t\t\t\t\tthis._x = Math.atan2( - m23, m33 );\n\t\t\t\t\tthis._z = Math.atan2( - m12, m11 );\n\n\t\t\t\t} else {\n\n\t\t\t\t\tthis._x = Math.atan2( m32, m22 );\n\t\t\t\t\tthis._z = 0;\n\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tcase 'YXZ':\n\n\t\t\t\tthis._x = Math.asin( - clamp( m23, - 1, 1 ) );\n\n\t\t\t\tif ( Math.abs( m23 ) < 0.9999999 ) {\n\n\t\t\t\t\tthis._y = Math.atan2( m13, m33 );\n\t\t\t\t\tthis._z = Math.atan2( m21, m22 );\n\n\t\t\t\t} else {\n\n\t\t\t\t\tthis._y = Math.atan2( - m31, m11 );\n\t\t\t\t\tthis._z = 0;\n\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tcase 'ZXY':\n\n\t\t\t\tthis._x = Math.asin( clamp( m32, - 1, 1 ) );\n\n\t\t\t\tif ( Math.abs( m32 ) < 0.9999999 ) {\n\n\t\t\t\t\tthis._y = Math.atan2( - m31, m33 );\n\t\t\t\t\tthis._z = Math.atan2( - m12, m22 );\n\n\t\t\t\t} else {\n\n\t\t\t\t\tthis._y = 0;\n\t\t\t\t\tthis._z = Math.atan2( m21, m11 );\n\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tcase 'ZYX':\n\n\t\t\t\tthis._y = Math.asin( - clamp( m31, - 1, 1 ) );\n\n\t\t\t\tif ( Math.abs( m31 ) < 0.9999999 ) {\n\n\t\t\t\t\tthis._x = Math.atan2( m32, m33 );\n\t\t\t\t\tthis._z = Math.atan2( m21, m11 );\n\n\t\t\t\t} else {\n\n\t\t\t\t\tthis._x = 0;\n\t\t\t\t\tthis._z = Math.atan2( - m12, m22 );\n\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tcase 'YZX':\n\n\t\t\t\tthis._z = Math.asin( clamp( m21, - 1, 1 ) );\n\n\t\t\t\tif ( Math.abs( m21 ) < 0.9999999 ) {\n\n\t\t\t\t\tthis._x = Math.atan2( - m23, m22 );\n\t\t\t\t\tthis._y = Math.atan2( - m31, m11 );\n\n\t\t\t\t} else {\n\n\t\t\t\t\tthis._x = 0;\n\t\t\t\t\tthis._y = Math.atan2( m13, m33 );\n\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tcase 'XZY':\n\n\t\t\t\tthis._z = Math.asin( - clamp( m12, - 1, 1 ) );\n\n\t\t\t\tif ( Math.abs( m12 ) < 0.9999999 ) {\n\n\t\t\t\t\tthis._x = Math.atan2( m32, m22 );\n\t\t\t\t\tthis._y = Math.atan2( m13, m11 );\n\n\t\t\t\t} else {\n\n\t\t\t\t\tthis._x = Math.atan2( - m23, m33 );\n\t\t\t\t\tthis._y = 0;\n\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\n\t\t\t\tconsole.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );\n\n\t\t}\n\n\t\tthis._order = order;\n\n\t\tif ( update === true ) this._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\tsetFromQuaternion( q, order, update ) {\n\n\t\t_matrix$2.makeRotationFromQuaternion( q );\n\n\t\treturn this.setFromRotationMatrix( _matrix$2, order, update );\n\n\t}\n\n\tsetFromVector3( v, order = this._order ) {\n\n\t\treturn this.set( v.x, v.y, v.z, order );\n\n\t}\n\n\treorder( newOrder ) {\n\n\t\t// WARNING: this discards revolution information -bhouston\n\n\t\t_quaternion$3.setFromEuler( this );\n\n\t\treturn this.setFromQuaternion( _quaternion$3, newOrder );\n\n\t}\n\n\tequals( euler ) {\n\n\t\treturn ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );\n\n\t}\n\n\tfromArray( array ) {\n\n\t\tthis._x = array[ 0 ];\n\t\tthis._y = array[ 1 ];\n\t\tthis._z = array[ 2 ];\n\t\tif ( array[ 3 ] !== undefined ) this._order = array[ 3 ];\n\n\t\tthis._onChangeCallback();\n\n\t\treturn this;\n\n\t}\n\n\ttoArray( array = [], offset = 0 ) {\n\n\t\tarray[ offset ] = this._x;\n\t\tarray[ offset + 1 ] = this._y;\n\t\tarray[ offset + 2 ] = this._z;\n\t\tarray[ offset + 3 ] = this._order;\n\n\t\treturn array;\n\n\t}\n\n\t_onChange( callback ) {\n\n\t\tthis._onChangeCallback = callback;\n\n\t\treturn this;\n\n\t}\n\n\t_onChangeCallback() {}\n\n\t*[ Symbol.iterator ]() {\n\n\t\tyield this._x;\n\t\tyield this._y;\n\t\tyield this._z;\n\t\tyield this._order;\n\n\t}\n\n}\n\nEuler.DEFAULT_ORDER = 'XYZ';\n\nclass Layers {\n\n\tconstructor() {\n\n\t\tthis.mask = 1 | 0;\n\n\t}\n\n\tset( channel ) {\n\n\t\tthis.mask = ( 1 << channel | 0 ) >>> 0;\n\n\t}\n\n\tenable( channel ) {\n\n\t\tthis.mask |= 1 << channel | 0;\n\n\t}\n\n\tenableAll() {\n\n\t\tthis.mask = 0xffffffff | 0;\n\n\t}\n\n\ttoggle( channel ) {\n\n\t\tthis.mask ^= 1 << channel | 0;\n\n\t}\n\n\tdisable( channel ) {\n\n\t\tthis.mask &= ~ ( 1 << channel | 0 );\n\n\t}\n\n\tdisableAll() {\n\n\t\tthis.mask = 0;\n\n\t}\n\n\ttest( layers ) {\n\n\t\treturn ( this.mask & layers.mask ) !== 0;\n\n\t}\n\n\tisEnabled( channel ) {\n\n\t\treturn ( this.mask & ( 1 << channel | 0 ) ) !== 0;\n\n\t}\n\n}\n\nlet _object3DId = 0;\n\nconst _v1$4 = /*@__PURE__*/ new Vector3();\nconst _q1 = /*@__PURE__*/ new Quaternion();\nconst _m1$3 = /*@__PURE__*/ new Matrix4();\nconst _target = /*@__PURE__*/ new Vector3();\n\nconst _position$3 = /*@__PURE__*/ new Vector3();\nconst _scale$2 = /*@__PURE__*/ new Vector3();\nconst _quaternion$2 = /*@__PURE__*/ new Quaternion();\n\nconst _xAxis = /*@__PURE__*/ new Vector3( 1, 0, 0 );\nconst _yAxis = /*@__PURE__*/ new Vector3( 0, 1, 0 );\nconst _zAxis = /*@__PURE__*/ new Vector3( 0, 0, 1 );\n\nconst _addedEvent = { type: 'added' };\nconst _removedEvent = { type: 'removed' };\n\nconst _childaddedEvent = { type: 'childadded', child: null };\nconst _childremovedEvent = { type: 'childremoved', child: null };\n\nclass Object3D extends EventDispatcher {\n\n\tconstructor() {\n\n\t\tsuper();\n\n\t\tthis.isObject3D = true;\n\n\t\tObject.defineProperty( this, 'id', { value: _object3DId ++ } );\n\n\t\tthis.uuid = generateUUID();\n\n\t\tthis.name = '';\n\t\tthis.type = 'Object3D';\n\n\t\tthis.parent = null;\n\t\tthis.children = [];\n\n\t\tthis.up = Object3D.DEFAULT_UP.clone();\n\n\t\tconst position = new Vector3();\n\t\tconst rotation = new Euler();\n\t\tconst quaternion = new Quaternion();\n\t\tconst scale = new Vector3( 1, 1, 1 );\n\n\t\tfunction onRotationChange() {\n\n\t\t\tquaternion.setFromEuler( rotation, false );\n\n\t\t}\n\n\t\tfunction onQuaternionChange() {\n\n\t\t\trotation.setFromQuaternion( quaternion, undefined, false );\n\n\t\t}\n\n\t\trotation._onChange( onRotationChange );\n\t\tquaternion._onChange( onQuaternionChange );\n\n\t\tObject.defineProperties( this, {\n\t\t\tposition: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tvalue: position\n\t\t\t},\n\t\t\trotation: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tvalue: rotation\n\t\t\t},\n\t\t\tquaternion: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tvalue: quaternion\n\t\t\t},\n\t\t\tscale: {\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t\tvalue: scale\n\t\t\t},\n\t\t\tmodelViewMatrix: {\n\t\t\t\tvalue: new Matrix4()\n\t\t\t},\n\t\t\tnormalMatrix: {\n\t\t\t\tvalue: new Matrix3()\n\t\t\t}\n\t\t} );\n\n\t\tthis.matrix = new Matrix4();\n\t\tthis.matrixWorld = new Matrix4();\n\n\t\tthis.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE;\n\n\t\tthis.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; // checked by the renderer\n\t\tthis.matrixWorldNeedsUpdate = false;\n\n\t\tthis.layers = new Layers();\n\t\tthis.visible = true;\n\n\t\tthis.castShadow = false;\n\t\tthis.receiveShadow = false;\n\n\t\tthis.frustumCulled = true;\n\t\tthis.renderOrder = 0;\n\n\t\tthis.animations = [];\n\n\t\tthis.userData = {};\n\n\t}\n\n\tonBeforeShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}\n\n\tonAfterShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}\n\n\tonBeforeRender( /* renderer, scene, camera, geometry, material, group */ ) {}\n\n\tonAfterRender( /* renderer, scene, camera, geometry, material, group */ ) {}\n\n\tapplyMatrix4( matrix ) {\n\n\t\tif ( this.matrixAutoUpdate ) this.updateMatrix();\n\n\t\tthis.matrix.premultiply( matrix );\n\n\t\tthis.matrix.decompose( this.position, this.quaternion, this.scale );\n\n\t}\n\n\tapplyQuaternion( q ) {\n\n\t\tthis.quaternion.premultiply( q );\n\n\t\treturn this;\n\n\t}\n\n\tsetRotationFromAxisAngle( axis, angle ) {\n\n\t\t// assumes axis is normalized\n\n\t\tthis.quaternion.setFromAxisAngle( axis, angle );\n\n\t}\n\n\tsetRotationFromEuler( euler ) {\n\n\t\tthis.quaternion.setFromEuler( euler, true );\n\n\t}\n\n\tsetRotationFromMatrix( m ) {\n\n\t\t// assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)\n\n\t\tthis.quaternion.setFromRotationMatrix( m );\n\n\t}\n\n\tsetRotationFromQuaternion( q ) {\n\n\t\t// assumes q is normalized\n\n\t\tthis.quaternion.copy( q );\n\n\t}\n\n\trotateOnAxis( axis, angle ) {\n\n\t\t// rotate object on axis in object space\n\t\t// axis is assumed to be normalized\n\n\t\t_q1.setFromAxisAngle( axis, angle );\n\n\t\tthis.quaternion.multiply( _q1 );\n\n\t\treturn this;\n\n\t}\n\n\trotateOnWorldAxis( axis, angle ) {\n\n\t\t// rotate object on axis in world space\n\t\t// axis is assumed to be normalized\n\t\t// method assumes no rotated parent\n\n\t\t_q1.setFromAxisAngle( axis, angle );\n\n\t\tthis.quaternion.premultiply( _q1 );\n\n\t\treturn this;\n\n\t}\n\n\trotateX( angle ) {\n\n\t\treturn this.rotateOnAxis( _xAxis, angle );\n\n\t}\n\n\trotateY( angle ) {\n\n\t\treturn this.rotateOnAxis( _yAxis, angle );\n\n\t}\n\n\trotateZ( angle ) {\n\n\t\treturn this.rotateOnAxis( _zAxis, angle );\n\n\t}\n\n\ttranslateOnAxis( axis, distance ) {\n\n\t\t// translate object by distance along axis in object space\n\t\t// axis is assumed to be normalized\n\n\t\t_v1$4.copy( axis ).applyQuaternion( this.quaternion );\n\n\t\tthis.position.add( _v1$4.multiplyScalar( distance ) );\n\n\t\treturn this;\n\n\t}\n\n\ttranslateX( distance ) {\n\n\t\treturn this.translateOnAxis( _xAxis, distance );\n\n\t}\n\n\ttranslateY( distance ) {\n\n\t\treturn this.translateOnAxis( _yAxis, distance );\n\n\t}\n\n\ttranslateZ( distance ) {\n\n\t\treturn this.translateOnAxis( _zAxis, distance );\n\n\t}\n\n\tlocalToWorld( vector ) {\n\n\t\tthis.updateWorldMatrix( true, false );\n\n\t\treturn vector.applyMatrix4( this.matrixWorld );\n\n\t}\n\n\tworldToLocal( vector ) {\n\n\t\tthis.updateWorldMatrix( true, false );\n\n\t\treturn vector.applyMatrix4( _m1$3.copy( this.matrixWorld ).invert() );\n\n\t}\n\n\tlookAt( x, y, z ) {\n\n\t\t// This method does not support objects having non-uniformly-scaled parent(s)\n\n\t\tif ( x.isVector3 ) {\n\n\t\t\t_target.copy( x );\n\n\t\t} else {\n\n\t\t\t_target.set( x, y, z );\n\n\t\t}\n\n\t\tconst parent = this.parent;\n\n\t\tthis.updateWorldMatrix( true, false );\n\n\t\t_position$3.setFromMatrixPosition( this.matrixWorld );\n\n\t\tif ( this.isCamera || this.isLight ) {\n\n\t\t\t_m1$3.lookAt( _position$3, _target, this.up );\n\n\t\t} else {\n\n\t\t\t_m1$3.lookAt( _target, _position$3, this.up );\n\n\t\t}\n\n\t\tthis.quaternion.setFromRotationMatrix( _m1$3 );\n\n\t\tif ( parent ) {\n\n\t\t\t_m1$3.extractRotation( parent.matrixWorld );\n\t\t\t_q1.setFromRotationMatrix( _m1$3 );\n\t\t\tthis.quaternion.premultiply( _q1.invert() );\n\n\t\t}\n\n\t}\n\n\tadd( object ) {\n\n\t\tif ( arguments.length > 1 ) {\n\n\t\t\tfor ( let i = 0; i < arguments.length; i ++ ) {\n\n\t\t\t\tthis.add( arguments[ i ] );\n\n\t\t\t}\n\n\t\t\treturn this;\n\n\t\t}\n\n\t\tif ( object === this ) {\n\n\t\t\tconsole.error( 'THREE.Object3D.add: object can\\'t be added as a child of itself.', object );\n\t\t\treturn this;\n\n\t\t}\n\n\t\tif ( object && object.isObject3D ) {\n\n\t\t\tobject.removeFromParent();\n\t\t\tobject.parent = this;\n\t\t\tthis.children.push( object );\n\n\t\t\tobject.dispatchEvent( _addedEvent );\n\n\t\t\t_childaddedEvent.child = object;\n\t\t\tthis.dispatchEvent( _childaddedEvent );\n\t\t\t_childaddedEvent.child = null;\n\n\t\t} else {\n\n\t\t\tconsole.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tremove( object ) {\n\n\t\tif ( arguments.length > 1 ) {\n\n\t\t\tfor ( let i = 0; i < arguments.length; i ++ ) {\n\n\t\t\t\tthis.remove( arguments[ i ] );\n\n\t\t\t}\n\n\t\t\treturn this;\n\n\t\t}\n\n\t\tconst index = this.children.indexOf( object );\n\n\t\tif ( index !== - 1 ) {\n\n\t\t\tobject.parent = null;\n\t\t\tthis.children.splice( index, 1 );\n\n\t\t\tobject.dispatchEvent( _removedEvent );\n\n\t\t\t_childremovedEvent.child = object;\n\t\t\tthis.dispatchEvent( _childremovedEvent );\n\t\t\t_childremovedEvent.child = null;\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tremoveFromParent() {\n\n\t\tconst parent = this.parent;\n\n\t\tif ( parent !== null ) {\n\n\t\t\tparent.remove( this );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tclear() {\n\n\t\treturn this.remove( ... this.children );\n\n\t}\n\n\tattach( object ) {\n\n\t\t// adds object as a child of this, while maintaining the object's world transform\n\n\t\t// Note: This method does not support scene graphs having non-uniformly-scaled nodes(s)\n\n\t\tthis.updateWorldMatrix( true, false );\n\n\t\t_m1$3.copy( this.matrixWorld ).invert();\n\n\t\tif ( object.parent !== null ) {\n\n\t\t\tobject.parent.updateWorldMatrix( true, false );\n\n\t\t\t_m1$3.multiply( object.parent.matrixWorld );\n\n\t\t}\n\n\t\tobject.applyMatrix4( _m1$3 );\n\n\t\tobject.removeFromParent();\n\t\tobject.parent = this;\n\t\tthis.children.push( object );\n\n\t\tobject.updateWorldMatrix( false, true );\n\n\t\tobject.dispatchEvent( _addedEvent );\n\n\t\t_childaddedEvent.child = object;\n\t\tthis.dispatchEvent( _childaddedEvent );\n\t\t_childaddedEvent.child = null;\n\n\t\treturn this;\n\n\t}\n\n\tgetObjectById( id ) {\n\n\t\treturn this.getObjectByProperty( 'id', id );\n\n\t}\n\n\tgetObjectByName( name ) {\n\n\t\treturn this.getObjectByProperty( 'name', name );\n\n\t}\n\n\tgetObjectByProperty( name, value ) {\n\n\t\tif ( this[ name ] === value ) return this;\n\n\t\tfor ( let i = 0, l = this.children.length; i < l; i ++ ) {\n\n\t\t\tconst child = this.children[ i ];\n\t\t\tconst object = child.getObjectByProperty( name, value );\n\n\t\t\tif ( object !== undefined ) {\n\n\t\t\t\treturn object;\n\n\t\t\t}\n\n\t\t}\n\n\t\treturn undefined;\n\n\t}\n\n\tgetObjectsByProperty( name, value, result = [] ) {\n\n\t\tif ( this[ name ] === value ) result.push( this );\n\n\t\tconst children = this.children;\n\n\t\tfor ( let i = 0, l = children.length; i < l; i ++ ) {\n\n\t\t\tchildren[ i ].getObjectsByProperty( name, value, result );\n\n\t\t}\n\n\t\treturn result;\n\n\t}\n\n\tgetWorldPosition( target ) {\n\n\t\tthis.updateWorldMatrix( true, false );\n\n\t\treturn target.setFromMatrixPosition( this.matrixWorld );\n\n\t}\n\n\tgetWorldQuaternion( target ) {\n\n\t\tthis.updateWorldMatrix( true, false );\n\n\t\tthis.matrixWorld.decompose( _position$3, target, _scale$2 );\n\n\t\treturn target;\n\n\t}\n\n\tgetWorldScale( target ) {\n\n\t\tthis.updateWorldMatrix( true, false );\n\n\t\tthis.matrixWorld.decompose( _position$3, _quaternion$2, target );\n\n\t\treturn target;\n\n\t}\n\n\tgetWorldDirection( target ) {\n\n\t\tthis.updateWorldMatrix( true, false );\n\n\t\tconst e = this.matrixWorld.elements;\n\n\t\treturn target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();\n\n\t}\n\n\traycast( /* raycaster, intersects */ ) {}\n\n\ttraverse( callback ) {\n\n\t\tcallback( this );\n\n\t\tconst children = this.children;\n\n\t\tfor ( let i = 0, l = children.length; i < l; i ++ ) {\n\n\t\t\tchildren[ i ].traverse( callback );\n\n\t\t}\n\n\t}\n\n\ttraverseVisible( callback ) {\n\n\t\tif ( this.visible === false ) return;\n\n\t\tcallback( this );\n\n\t\tconst children = this.children;\n\n\t\tfor ( let i = 0, l = children.length; i < l; i ++ ) {\n\n\t\t\tchildren[ i ].traverseVisible( callback );\n\n\t\t}\n\n\t}\n\n\ttraverseAncestors( callback ) {\n\n\t\tconst parent = this.parent;\n\n\t\tif ( parent !== null ) {\n\n\t\t\tcallback( parent );\n\n\t\t\tparent.traverseAncestors( callback );\n\n\t\t}\n\n\t}\n\n\tupdateMatrix() {\n\n\t\tthis.matrix.compose( this.position, this.quaternion, this.scale );\n\n\t\tthis.matrixWorldNeedsUpdate = true;\n\n\t}\n\n\tupdateMatrixWorld( force ) {\n\n\t\tif ( this.matrixAutoUpdate ) this.updateMatrix();\n\n\t\tif ( this.matrixWorldNeedsUpdate || force ) {\n\n\t\t\tif ( this.matrixWorldAutoUpdate === true ) {\n\n\t\t\t\tif ( this.parent === null ) {\n\n\t\t\t\t\tthis.matrixWorld.copy( this.matrix );\n\n\t\t\t\t} else {\n\n\t\t\t\t\tthis.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tthis.matrixWorldNeedsUpdate = false;\n\n\t\t\tforce = true;\n\n\t\t}\n\n\t\t// make sure descendants are updated if required\n\n\t\tconst children = this.children;\n\n\t\tfor ( let i = 0, l = children.length; i < l; i ++ ) {\n\n\t\t\tconst child = children[ i ];\n\n\t\t\tchild.updateMatrixWorld( force );\n\n\t\t}\n\n\t}\n\n\tupdateWorldMatrix( updateParents, updateChildren ) {\n\n\t\tconst parent = this.parent;\n\n\t\tif ( updateParents === true && parent !== null ) {\n\n\t\t\tparent.updateWorldMatrix( true, false );\n\n\t\t}\n\n\t\tif ( this.matrixAutoUpdate ) this.updateMatrix();\n\n\t\tif ( this.matrixWorldAutoUpdate === true ) {\n\n\t\t\tif ( this.parent === null ) {\n\n\t\t\t\tthis.matrixWorld.copy( this.matrix );\n\n\t\t\t} else {\n\n\t\t\t\tthis.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );\n\n\t\t\t}\n\n\t\t}\n\n\t\t// make sure descendants are updated\n\n\t\tif ( updateChildren === true ) {\n\n\t\t\tconst children = this.children;\n\n\t\t\tfor ( let i = 0, l = children.length; i < l; i ++ ) {\n\n\t\t\t\tconst child = children[ i ];\n\n\t\t\t\tchild.updateWorldMatrix( false, true );\n\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\ttoJSON( meta ) {\n\n\t\t// meta is a string when called from JSON.stringify\n\t\tconst isRootObject = ( meta === undefined || typeof meta === 'string' );\n\n\t\tconst output = {};\n\n\t\t// meta is a hash used to collect geometries, materials.\n\t\t// not providing it implies that this is the root object\n\t\t// being serialized.\n\t\tif ( isRootObject ) {\n\n\t\t\t// initialize meta obj\n\t\t\tmeta = {\n\t\t\t\tgeometries: {},\n\t\t\t\tmaterials: {},\n\t\t\t\ttextures: {},\n\t\t\t\timages: {},\n\t\t\t\tshapes: {},\n\t\t\t\tskeletons: {},\n\t\t\t\tanimations: {},\n\t\t\t\tnodes: {}\n\t\t\t};\n\n\t\t\toutput.metadata = {\n\t\t\t\tversion: 4.6,\n\t\t\t\ttype: 'Object',\n\t\t\t\tgenerator: 'Object3D.toJSON'\n\t\t\t};\n\n\t\t}\n\n\t\t// standard Object3D serialization\n\n\t\tconst object = {};\n\n\t\tobject.uuid = this.uuid;\n\t\tobject.type = this.type;\n\n\t\tif ( this.name !== '' ) object.name = this.name;\n\t\tif ( this.castShadow === true ) object.castShadow = true;\n\t\tif ( this.receiveShadow === true ) object.receiveShadow = true;\n\t\tif ( this.visible === false ) object.visible = false;\n\t\tif ( this.frustumCulled === false ) object.frustumCulled = false;\n\t\tif ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;\n\t\tif ( Object.keys( this.userData ).length > 0 ) object.userData = this.userData;\n\n\t\tobject.layers = this.layers.mask;\n\t\tobject.matrix = this.matrix.toArray();\n\t\tobject.up = this.up.toArray();\n\n\t\tif ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;\n\n\t\t// object specific properties\n\n\t\tif ( this.isInstancedMesh ) {\n\n\t\t\tobject.type = 'InstancedMesh';\n\t\t\tobject.count = this.count;\n\t\t\tobject.instanceMatrix = this.instanceMatrix.toJSON();\n\t\t\tif ( this.instanceColor !== null ) object.instanceColor = this.instanceColor.toJSON();\n\n\t\t}\n\n\t\tif ( this.isBatchedMesh ) {\n\n\t\t\tobject.type = 'BatchedMesh';\n\t\t\tobject.perObjectFrustumCulled = this.perObjectFrustumCulled;\n\t\t\tobject.sortObjects = this.sortObjects;\n\n\t\t\tobject.drawRanges = this._drawRanges;\n\t\t\tobject.reservedRanges = this._reservedRanges;\n\n\t\t\tobject.visibility = this._visibility;\n\t\t\tobject.active = this._active;\n\t\t\tobject.bounds = this._bounds.map( bound => ( {\n\t\t\t\tboxInitialized: bound.boxInitialized,\n\t\t\t\tboxMin: bound.box.min.toArray(),\n\t\t\t\tboxMax: bound.box.max.toArray(),\n\n\t\t\t\tsphereInitialized: bound.sphereInitialized,\n\t\t\t\tsphereRadius: bound.sphere.radius,\n\t\t\t\tsphereCenter: bound.sphere.center.toArray()\n\t\t\t} ) );\n\n\t\t\tobject.maxInstanceCount = this._maxInstanceCount;\n\t\t\tobject.maxVertexCount = this._maxVertexCount;\n\t\t\tobject.maxIndexCount = this._maxIndexCount;\n\n\t\t\tobject.geometryInitialized = this._geometryInitialized;\n\t\t\tobject.geometryCount = this._geometryCount;\n\n\t\t\tobject.matricesTexture = this._matricesTexture.toJSON( meta );\n\n\t\t\tif ( this._colorsTexture !== null ) object.colorsTexture = this._colorsTexture.toJSON( meta );\n\n\t\t\tif ( this.boundingSphere !== null ) {\n\n\t\t\t\tobject.boundingSphere = {\n\t\t\t\t\tcenter: object.boundingSphere.center.toArray(),\n\t\t\t\t\tradius: object.boundingSphere.radius\n\t\t\t\t};\n\n\t\t\t}\n\n\t\t\tif ( this.boundingBox !== null ) {\n\n\t\t\t\tobject.boundingBox = {\n\t\t\t\t\tmin: object.boundingBox.min.toArray(),\n\t\t\t\t\tmax: object.boundingBox.max.toArray()\n\t\t\t\t};\n\n\t\t\t}\n\n\t\t}\n\n\t\t//\n\n\t\tfunction serialize( library, element ) {\n\n\t\t\tif ( library[ element.uuid ] === undefined ) {\n\n\t\t\t\tlibrary[ element.uuid ] = element.toJSON( meta );\n\n\t\t\t}\n\n\t\t\treturn element.uuid;\n\n\t\t}\n\n\t\tif ( this.isScene ) {\n\n\t\t\tif ( this.background ) {\n\n\t\t\t\tif ( this.background.isColor ) {\n\n\t\t\t\t\tobject.background = this.background.toJSON();\n\n\t\t\t\t} else if ( this.background.isTexture ) {\n\n\t\t\t\t\tobject.background = this.background.toJSON( meta ).uuid;\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tif ( this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true ) {\n\n\t\t\t\tobject.environment = this.environment.toJSON( meta ).uuid;\n\n\t\t\t}\n\n\t\t} else if ( this.isMesh || this.isLine || this.isPoints ) {\n\n\t\t\tobject.geometry = serialize( meta.geometries, this.geometry );\n\n\t\t\tconst parameters = this.geometry.parameters;\n\n\t\t\tif ( parameters !== undefined && parameters.shapes !== undefined ) {\n\n\t\t\t\tconst shapes = parameters.shapes;\n\n\t\t\t\tif ( Array.isArray( shapes ) ) {\n\n\t\t\t\t\tfor ( let i = 0, l = shapes.length; i < l; i ++ ) {\n\n\t\t\t\t\t\tconst shape = shapes[ i ];\n\n\t\t\t\t\t\tserialize( meta.shapes, shape );\n\n\t\t\t\t\t}\n\n\t\t\t\t} else {\n\n\t\t\t\t\tserialize( meta.shapes, shapes );\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\t\tif ( this.isSkinnedMesh ) {\n\n\t\t\tobject.bindMode = this.bindMode;\n\t\t\tobject.bindMatrix = this.bindMatrix.toArray();\n\n\t\t\tif ( this.skeleton !== undefined ) {\n\n\t\t\t\tserialize( meta.skeletons, this.skeleton );\n\n\t\t\t\tobject.skeleton = this.skeleton.uuid;\n\n\t\t\t}\n\n\t\t}\n\n\t\tif ( this.material !== undefined ) {\n\n\t\t\tif ( Array.isArray( this.material ) ) {\n\n\t\t\t\tconst uuids = [];\n\n\t\t\t\tfor ( let i = 0, l = this.material.length; i < l; i ++ ) {\n\n\t\t\t\t\tuuids.push( serialize( meta.materials, this.material[ i ] ) );\n\n\t\t\t\t}\n\n\t\t\t\tobject.material = uuids;\n\n\t\t\t} else {\n\n\t\t\t\tobject.material = serialize( meta.materials, this.material );\n\n\t\t\t}\n\n\t\t}\n\n\t\t//\n\n\t\tif ( this.children.length > 0 ) {\n\n\t\t\tobject.children = [];\n\n\t\t\tfor ( let i = 0; i < this.children.length; i ++ ) {\n\n\t\t\t\tobject.children.push( this.children[ i ].toJSON( meta ).object );\n\n\t\t\t}\n\n\t\t}\n\n\t\t//\n\n\t\tif ( this.animations.length > 0 ) {\n\n\t\t\tobject.animations = [];\n\n\t\t\tfor ( let i = 0; i < this.animations.length; i ++ ) {\n\n\t\t\t\tconst animation = this.animations[ i ];\n\n\t\t\t\tobject.animations.push( serialize( meta.animations, animation ) );\n\n\t\t\t}\n\n\t\t}\n\n\t\tif ( isRootObject ) {\n\n\t\t\tconst geometries = extractFromCache( meta.geometries );\n\t\t\tconst materials = extractFromCache( meta.materials );\n\t\t\tconst textures = extractFromCache( meta.textures );\n\t\t\tconst images = extractFromCache( meta.images );\n\t\t\tconst shapes = extractFromCache( meta.shapes );\n\t\t\tconst skeletons = extractFromCache( meta.skeletons );\n\t\t\tconst animations = extractFromCache( meta.animations );\n\t\t\tconst nodes = extractFromCache( meta.nodes );\n\n\t\t\tif ( geometries.length > 0 ) output.geometries = geometries;\n\t\t\tif ( materials.length > 0 ) output.materials = materials;\n\t\t\tif ( textures.length > 0 ) output.textures = textures;\n\t\t\tif ( images.length > 0 ) output.images = images;\n\t\t\tif ( shapes.length > 0 ) output.shapes = shapes;\n\t\t\tif ( skeletons.length > 0 ) output.skeletons = skeletons;\n\t\t\tif ( animations.length > 0 ) output.animations = animations;\n\t\t\tif ( nodes.length > 0 ) output.nodes = nodes;\n\n\t\t}\n\n\t\toutput.object = object;\n\n\t\treturn output;\n\n\t\t// extract data from the cache hash\n\t\t// remove metadata on each item\n\t\t// and return as array\n\t\tfunction extractFromCache( cache ) {\n\n\t\t\tconst values = [];\n\t\t\tfor ( const key in cache ) {\n\n\t\t\t\tconst data = cache[ key ];\n\t\t\t\tdelete data.metadata;\n\t\t\t\tvalues.push( data );\n\n\t\t\t}\n\n\t\t\treturn values;\n\n\t\t}\n\n\t}\n\n\tclone( recursive ) {\n\n\t\treturn new this.constructor().copy( this, recursive );\n\n\t}\n\n\tcopy( source, recursive = true ) {\n\n\t\tthis.name = source.name;\n\n\t\tthis.up.copy( source.up );\n\n\t\tthis.position.copy( source.position );\n\t\tthis.rotation.order = source.rotation.order;\n\t\tthis.quaternion.copy( source.quaternion );\n\t\tthis.scale.copy( source.scale );\n\n\t\tthis.matrix.copy( source.matrix );\n\t\tthis.matrixWorld.copy( source.matrixWorld );\n\n\t\tthis.matrixAutoUpdate = source.matrixAutoUpdate;\n\n\t\tthis.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate;\n\t\tthis.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;\n\n\t\tthis.layers.mask = source.layers.mask;\n\t\tthis.visible = source.visible;\n\n\t\tthis.castShadow = source.castShadow;\n\t\tthis.receiveShadow = source.receiveShadow;\n\n\t\tthis.frustumCulled = source.frustumCulled;\n\t\tthis.renderOrder = source.renderOrder;\n\n\t\tthis.animations = source.animations.slice();\n\n\t\tthis.userData = JSON.parse( JSON.stringify( source.userData ) );\n\n\t\tif ( recursive === true ) {\n\n\t\t\tfor ( let i = 0; i < source.children.length; i ++ ) {\n\n\t\t\t\tconst child = source.children[ i ];\n\t\t\t\tthis.add( child.clone() );\n\n\t\t\t}\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n}\n\nObject3D.DEFAULT_UP = /*@__PURE__*/ new Vector3( 0, 1, 0 );\nObject3D.DEFAULT_MATRIX_AUTO_UPDATE = true;\nObject3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true;\n\nconst _v0$2 = /*@__PURE__*/ new Vector3();\nconst _v1$3 = /*@__PURE__*/ new Vector3();\nconst _v2$2 = /*@__PURE__*/ new Vector3();\nconst _v3$2 = /*@__PURE__*/ new Vector3();\n\nconst _vab = /*@__PURE__*/ new Vector3();\nconst _vac = /*@__PURE__*/ new Vector3();\nconst _vbc = /*@__PURE__*/ new Vector3();\nconst _vap = /*@__PURE__*/ new Vector3();\nconst _vbp = /*@__PURE__*/ new Vector3();\nconst _vcp = /*@__PURE__*/ new Vector3();\n\nclass Triangle {\n\n\tconstructor( a = new Vector3(), b = new Vector3(), c = new Vector3() ) {\n\n\t\tthis.a = a;\n\t\tthis.b = b;\n\t\tthis.c = c;\n\n\t}\n\n\tstatic getNormal( a, b, c, target ) {\n\n\t\ttarget.subVectors( c, b );\n\t\t_v0$2.subVectors( a, b );\n\t\ttarget.cross( _v0$2 );\n\n\t\tconst targetLengthSq = target.lengthSq();\n\t\tif ( targetLengthSq > 0 ) {\n\n\t\t\treturn target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );\n\n\t\t}\n\n\t\treturn target.set( 0, 0, 0 );\n\n\t}\n\n\t// static/instance method to calculate barycentric coordinates\n\t// based on: http://www.blackpawn.com/texts/pointinpoly/default.html\n\tstatic getBarycoord( point, a, b, c, target ) {\n\n\t\t_v0$2.subVectors( c, a );\n\t\t_v1$3.subVectors( b, a );\n\t\t_v2$2.subVectors( point, a );\n\n\t\tconst dot00 = _v0$2.dot( _v0$2 );\n\t\tconst dot01 = _v0$2.dot( _v1$3 );\n\t\tconst dot02 = _v0$2.dot( _v2$2 );\n\t\tconst dot11 = _v1$3.dot( _v1$3 );\n\t\tconst dot12 = _v1$3.dot( _v2$2 );\n\n\t\tconst denom = ( dot00 * dot11 - dot01 * dot01 );\n\n\t\t// collinear or singular triangle\n\t\tif ( denom === 0 ) {\n\n\t\t\ttarget.set( 0, 0, 0 );\n\t\t\treturn null;\n\n\t\t}\n\n\t\tconst invDenom = 1 / denom;\n\t\tconst u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;\n\t\tconst v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;\n\n\t\t// barycentric coordinates must always sum to 1\n\t\treturn target.set( 1 - u - v, v, u );\n\n\t}\n\n\tstatic containsPoint( point, a, b, c ) {\n\n\t\t// if the triangle is degenerate then we can't contain a point\n\t\tif ( this.getBarycoord( point, a, b, c, _v3$2 ) === null ) {\n\n\t\t\treturn false;\n\n\t\t}\n\n\t\treturn ( _v3$2.x >= 0 ) && ( _v3$2.y >= 0 ) && ( ( _v3$2.x + _v3$2.y ) <= 1 );\n\n\t}\n\n\tstatic getInterpolation( point, p1, p2, p3, v1, v2, v3, target ) {\n\n\t\tif ( this.getBarycoord( point, p1, p2, p3, _v3$2 ) === null ) {\n\n\t\t\ttarget.x = 0;\n\t\t\ttarget.y = 0;\n\t\t\tif ( 'z' in target ) target.z = 0;\n\t\t\tif ( 'w' in target ) target.w = 0;\n\t\t\treturn null;\n\n\t\t}\n\n\t\ttarget.setScalar( 0 );\n\t\ttarget.addScaledVector( v1, _v3$2.x );\n\t\ttarget.addScaledVector( v2, _v3$2.y );\n\t\ttarget.addScaledVector( v3, _v3$2.z );\n\n\t\treturn target;\n\n\t}\n\n\tstatic isFrontFacing( a, b, c, direction ) {\n\n\t\t_v0$2.subVectors( c, b );\n\t\t_v1$3.subVectors( a, b );\n\n\t\t// strictly front facing\n\t\treturn ( _v0$2.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;\n\n\t}\n\n\tset( a, b, c ) {\n\n\t\tthis.a.copy( a );\n\t\tthis.b.copy( b );\n\t\tthis.c.copy( c );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromPointsAndIndices( points, i0, i1, i2 ) {\n\n\t\tthis.a.copy( points[ i0 ] );\n\t\tthis.b.copy( points[ i1 ] );\n\t\tthis.c.copy( points[ i2 ] );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromAttributeAndIndices( attribute, i0, i1, i2 ) {\n\n\t\tthis.a.fromBufferAttribute( attribute, i0 );\n\t\tthis.b.fromBufferAttribute( attribute, i1 );\n\t\tthis.c.fromBufferAttribute( attribute, i2 );\n\n\t\treturn this;\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n\tcopy( triangle ) {\n\n\t\tthis.a.copy( triangle.a );\n\t\tthis.b.copy( triangle.b );\n\t\tthis.c.copy( triangle.c );\n\n\t\treturn this;\n\n\t}\n\n\tgetArea() {\n\n\t\t_v0$2.subVectors( this.c, this.b );\n\t\t_v1$3.subVectors( this.a, this.b );\n\n\t\treturn _v0$2.cross( _v1$3 ).length() * 0.5;\n\n\t}\n\n\tgetMidpoint( target ) {\n\n\t\treturn target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );\n\n\t}\n\n\tgetNormal( target ) {\n\n\t\treturn Triangle.getNormal( this.a, this.b, this.c, target );\n\n\t}\n\n\tgetPlane( target ) {\n\n\t\treturn target.setFromCoplanarPoints( this.a, this.b, this.c );\n\n\t}\n\n\tgetBarycoord( point, target ) {\n\n\t\treturn Triangle.getBarycoord( point, this.a, this.b, this.c, target );\n\n\t}\n\n\tgetInterpolation( point, v1, v2, v3, target ) {\n\n\t\treturn Triangle.getInterpolation( point, this.a, this.b, this.c, v1, v2, v3, target );\n\n\t}\n\n\tcontainsPoint( point ) {\n\n\t\treturn Triangle.containsPoint( point, this.a, this.b, this.c );\n\n\t}\n\n\tisFrontFacing( direction ) {\n\n\t\treturn Triangle.isFrontFacing( this.a, this.b, this.c, direction );\n\n\t}\n\n\tintersectsBox( box ) {\n\n\t\treturn box.intersectsTriangle( this );\n\n\t}\n\n\tclosestPointToPoint( p, target ) {\n\n\t\tconst a = this.a, b = this.b, c = this.c;\n\t\tlet v, w;\n\n\t\t// algorithm thanks to Real-Time Collision Detection by Christer Ericson,\n\t\t// published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,\n\t\t// under the accompanying license; see chapter 5.1.5 for detailed explanation.\n\t\t// basically, we're distinguishing which of the voronoi regions of the triangle\n\t\t// the point lies in with the minimum amount of redundant computation.\n\n\t\t_vab.subVectors( b, a );\n\t\t_vac.subVectors( c, a );\n\t\t_vap.subVectors( p, a );\n\t\tconst d1 = _vab.dot( _vap );\n\t\tconst d2 = _vac.dot( _vap );\n\t\tif ( d1 <= 0 && d2 <= 0 ) {\n\n\t\t\t// vertex region of A; barycentric coords (1, 0, 0)\n\t\t\treturn target.copy( a );\n\n\t\t}\n\n\t\t_vbp.subVectors( p, b );\n\t\tconst d3 = _vab.dot( _vbp );\n\t\tconst d4 = _vac.dot( _vbp );\n\t\tif ( d3 >= 0 && d4 <= d3 ) {\n\n\t\t\t// vertex region of B; barycentric coords (0, 1, 0)\n\t\t\treturn target.copy( b );\n\n\t\t}\n\n\t\tconst vc = d1 * d4 - d3 * d2;\n\t\tif ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {\n\n\t\t\tv = d1 / ( d1 - d3 );\n\t\t\t// edge region of AB; barycentric coords (1-v, v, 0)\n\t\t\treturn target.copy( a ).addScaledVector( _vab, v );\n\n\t\t}\n\n\t\t_vcp.subVectors( p, c );\n\t\tconst d5 = _vab.dot( _vcp );\n\t\tconst d6 = _vac.dot( _vcp );\n\t\tif ( d6 >= 0 && d5 <= d6 ) {\n\n\t\t\t// vertex region of C; barycentric coords (0, 0, 1)\n\t\t\treturn target.copy( c );\n\n\t\t}\n\n\t\tconst vb = d5 * d2 - d1 * d6;\n\t\tif ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {\n\n\t\t\tw = d2 / ( d2 - d6 );\n\t\t\t// edge region of AC; barycentric coords (1-w, 0, w)\n\t\t\treturn target.copy( a ).addScaledVector( _vac, w );\n\n\t\t}\n\n\t\tconst va = d3 * d6 - d5 * d4;\n\t\tif ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {\n\n\t\t\t_vbc.subVectors( c, b );\n\t\t\tw = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );\n\t\t\t// edge region of BC; barycentric coords (0, 1-w, w)\n\t\t\treturn target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC\n\n\t\t}\n\n\t\t// face region\n\t\tconst denom = 1 / ( va + vb + vc );\n\t\t// u = va * denom\n\t\tv = vb * denom;\n\t\tw = vc * denom;\n\n\t\treturn target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );\n\n\t}\n\n\tequals( triangle ) {\n\n\t\treturn triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );\n\n\t}\n\n}\n\nconst _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,\n\t'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,\n\t'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,\n\t'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,\n\t'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,\n\t'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,\n\t'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,\n\t'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,\n\t'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,\n\t'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,\n\t'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,\n\t'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,\n\t'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,\n\t'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,\n\t'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,\n\t'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,\n\t'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,\n\t'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,\n\t'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,\n\t'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,\n\t'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,\n\t'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,\n\t'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,\n\t'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };\n\nconst _hslA = { h: 0, s: 0, l: 0 };\nconst _hslB = { h: 0, s: 0, l: 0 };\n\nfunction hue2rgb( p, q, t ) {\n\n\tif ( t < 0 ) t += 1;\n\tif ( t > 1 ) t -= 1;\n\tif ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;\n\tif ( t < 1 / 2 ) return q;\n\tif ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );\n\treturn p;\n\n}\n\nclass Color {\n\n\tconstructor( r, g, b ) {\n\n\t\tthis.isColor = true;\n\n\t\tthis.r = 1;\n\t\tthis.g = 1;\n\t\tthis.b = 1;\n\n\t\treturn this.set( r, g, b );\n\n\t}\n\n\tset( r, g, b ) {\n\n\t\tif ( g === undefined && b === undefined ) {\n\n\t\t\t// r is THREE.Color, hex or string\n\n\t\t\tconst value = r;\n\n\t\t\tif ( value && value.isColor ) {\n\n\t\t\t\tthis.copy( value );\n\n\t\t\t} else if ( typeof value === 'number' ) {\n\n\t\t\t\tthis.setHex( value );\n\n\t\t\t} else if ( typeof value === 'string' ) {\n\n\t\t\t\tthis.setStyle( value );\n\n\t\t\t}\n\n\t\t} else {\n\n\t\t\tthis.setRGB( r, g, b );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tsetScalar( scalar ) {\n\n\t\tthis.r = scalar;\n\t\tthis.g = scalar;\n\t\tthis.b = scalar;\n\n\t\treturn this;\n\n\t}\n\n\tsetHex( hex, colorSpace = SRGBColorSpace ) {\n\n\t\thex = Math.floor( hex );\n\n\t\tthis.r = ( hex >> 16 & 255 ) / 255;\n\t\tthis.g = ( hex >> 8 & 255 ) / 255;\n\t\tthis.b = ( hex & 255 ) / 255;\n\n\t\tColorManagement.toWorkingColorSpace( this, colorSpace );\n\n\t\treturn this;\n\n\t}\n\n\tsetRGB( r, g, b, colorSpace = ColorManagement.workingColorSpace ) {\n\n\t\tthis.r = r;\n\t\tthis.g = g;\n\t\tthis.b = b;\n\n\t\tColorManagement.toWorkingColorSpace( this, colorSpace );\n\n\t\treturn this;\n\n\t}\n\n\tsetHSL( h, s, l, colorSpace = ColorManagement.workingColorSpace ) {\n\n\t\t// h,s,l ranges are in 0.0 - 1.0\n\t\th = euclideanModulo( h, 1 );\n\t\ts = clamp( s, 0, 1 );\n\t\tl = clamp( l, 0, 1 );\n\n\t\tif ( s === 0 ) {\n\n\t\t\tthis.r = this.g = this.b = l;\n\n\t\t} else {\n\n\t\t\tconst p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );\n\t\t\tconst q = ( 2 * l ) - p;\n\n\t\t\tthis.r = hue2rgb( q, p, h + 1 / 3 );\n\t\t\tthis.g = hue2rgb( q, p, h );\n\t\t\tthis.b = hue2rgb( q, p, h - 1 / 3 );\n\n\t\t}\n\n\t\tColorManagement.toWorkingColorSpace( this, colorSpace );\n\n\t\treturn this;\n\n\t}\n\n\tsetStyle( style, colorSpace = SRGBColorSpace ) {\n\n\t\tfunction handleAlpha( string ) {\n\n\t\t\tif ( string === undefined ) return;\n\n\t\t\tif ( parseFloat( string ) < 1 ) {\n\n\t\t\t\tconsole.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );\n\n\t\t\t}\n\n\t\t}\n\n\n\t\tlet m;\n\n\t\tif ( m = /^(\\w+)\\(([^\\)]*)\\)/.exec( style ) ) {\n\n\t\t\t// rgb / hsl\n\n\t\t\tlet color;\n\t\t\tconst name = m[ 1 ];\n\t\t\tconst components = m[ 2 ];\n\n\t\t\tswitch ( name ) {\n\n\t\t\t\tcase 'rgb':\n\t\t\t\tcase 'rgba':\n\n\t\t\t\t\tif ( color = /^\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec( components ) ) {\n\n\t\t\t\t\t\t// rgb(255,0,0) rgba(255,0,0,0.5)\n\n\t\t\t\t\t\thandleAlpha( color[ 4 ] );\n\n\t\t\t\t\t\treturn this.setRGB(\n\t\t\t\t\t\t\tMath.min( 255, parseInt( color[ 1 ], 10 ) ) / 255,\n\t\t\t\t\t\t\tMath.min( 255, parseInt( color[ 2 ], 10 ) ) / 255,\n\t\t\t\t\t\t\tMath.min( 255, parseInt( color[ 3 ], 10 ) ) / 255,\n\t\t\t\t\t\t\tcolorSpace\n\t\t\t\t\t\t);\n\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( color = /^\\s*(\\d+)\\%\\s*,\\s*(\\d+)\\%\\s*,\\s*(\\d+)\\%\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec( components ) ) {\n\n\t\t\t\t\t\t// rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)\n\n\t\t\t\t\t\thandleAlpha( color[ 4 ] );\n\n\t\t\t\t\t\treturn this.setRGB(\n\t\t\t\t\t\t\tMath.min( 100, parseInt( color[ 1 ], 10 ) ) / 100,\n\t\t\t\t\t\t\tMath.min( 100, parseInt( color[ 2 ], 10 ) ) / 100,\n\t\t\t\t\t\t\tMath.min( 100, parseInt( color[ 3 ], 10 ) ) / 100,\n\t\t\t\t\t\t\tcolorSpace\n\t\t\t\t\t\t);\n\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase 'hsl':\n\t\t\t\tcase 'hsla':\n\n\t\t\t\t\tif ( color = /^\\s*(\\d*\\.?\\d+)\\s*,\\s*(\\d*\\.?\\d+)\\%\\s*,\\s*(\\d*\\.?\\d+)\\%\\s*(?:,\\s*(\\d*\\.?\\d+)\\s*)?$/.exec( components ) ) {\n\n\t\t\t\t\t\t// hsl(120,50%,50%) hsla(120,50%,50%,0.5)\n\n\t\t\t\t\t\thandleAlpha( color[ 4 ] );\n\n\t\t\t\t\t\treturn this.setHSL(\n\t\t\t\t\t\t\tparseFloat( color[ 1 ] ) / 360,\n\t\t\t\t\t\t\tparseFloat( color[ 2 ] ) / 100,\n\t\t\t\t\t\t\tparseFloat( color[ 3 ] ) / 100,\n\t\t\t\t\t\t\tcolorSpace\n\t\t\t\t\t\t);\n\n\t\t\t\t\t}\n\n\t\t\t\t\tbreak;\n\n\t\t\t\tdefault:\n\n\t\t\t\t\tconsole.warn( 'THREE.Color: Unknown color model ' + style );\n\n\t\t\t}\n\n\t\t} else if ( m = /^\\#([A-Fa-f\\d]+)$/.exec( style ) ) {\n\n\t\t\t// hex color\n\n\t\t\tconst hex = m[ 1 ];\n\t\t\tconst size = hex.length;\n\n\t\t\tif ( size === 3 ) {\n\n\t\t\t\t// #ff0\n\t\t\t\treturn this.setRGB(\n\t\t\t\t\tparseInt( hex.charAt( 0 ), 16 ) / 15,\n\t\t\t\t\tparseInt( hex.charAt( 1 ), 16 ) / 15,\n\t\t\t\t\tparseInt( hex.charAt( 2 ), 16 ) / 15,\n\t\t\t\t\tcolorSpace\n\t\t\t\t);\n\n\t\t\t} else if ( size === 6 ) {\n\n\t\t\t\t// #ff0000\n\t\t\t\treturn this.setHex( parseInt( hex, 16 ), colorSpace );\n\n\t\t\t} else {\n\n\t\t\t\tconsole.warn( 'THREE.Color: Invalid hex color ' + style );\n\n\t\t\t}\n\n\t\t} else if ( style && style.length > 0 ) {\n\n\t\t\treturn this.setColorName( style, colorSpace );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tsetColorName( style, colorSpace = SRGBColorSpace ) {\n\n\t\t// color keywords\n\t\tconst hex = _colorKeywords[ style.toLowerCase() ];\n\n\t\tif ( hex !== undefined ) {\n\n\t\t\t// red\n\t\t\tthis.setHex( hex, colorSpace );\n\n\t\t} else {\n\n\t\t\t// unknown color\n\t\t\tconsole.warn( 'THREE.Color: Unknown color ' + style );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor( this.r, this.g, this.b );\n\n\t}\n\n\tcopy( color ) {\n\n\t\tthis.r = color.r;\n\t\tthis.g = color.g;\n\t\tthis.b = color.b;\n\n\t\treturn this;\n\n\t}\n\n\tcopySRGBToLinear( color ) {\n\n\t\tthis.r = SRGBToLinear( color.r );\n\t\tthis.g = SRGBToLinear( color.g );\n\t\tthis.b = SRGBToLinear( color.b );\n\n\t\treturn this;\n\n\t}\n\n\tcopyLinearToSRGB( color ) {\n\n\t\tthis.r = LinearToSRGB( color.r );\n\t\tthis.g = LinearToSRGB( color.g );\n\t\tthis.b = LinearToSRGB( color.b );\n\n\t\treturn this;\n\n\t}\n\n\tconvertSRGBToLinear() {\n\n\t\tthis.copySRGBToLinear( this );\n\n\t\treturn this;\n\n\t}\n\n\tconvertLinearToSRGB() {\n\n\t\tthis.copyLinearToSRGB( this );\n\n\t\treturn this;\n\n\t}\n\n\tgetHex( colorSpace = SRGBColorSpace ) {\n\n\t\tColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );\n\n\t\treturn Math.round( clamp( _color.r * 255, 0, 255 ) ) * 65536 + Math.round( clamp( _color.g * 255, 0, 255 ) ) * 256 + Math.round( clamp( _color.b * 255, 0, 255 ) );\n\n\t}\n\n\tgetHexString( colorSpace = SRGBColorSpace ) {\n\n\t\treturn ( '000000' + this.getHex( colorSpace ).toString( 16 ) ).slice( - 6 );\n\n\t}\n\n\tgetHSL( target, colorSpace = ColorManagement.workingColorSpace ) {\n\n\t\t// h,s,l ranges are in 0.0 - 1.0\n\n\t\tColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );\n\n\t\tconst r = _color.r, g = _color.g, b = _color.b;\n\n\t\tconst max = Math.max( r, g, b );\n\t\tconst min = Math.min( r, g, b );\n\n\t\tlet hue, saturation;\n\t\tconst lightness = ( min + max ) / 2.0;\n\n\t\tif ( min === max ) {\n\n\t\t\thue = 0;\n\t\t\tsaturation = 0;\n\n\t\t} else {\n\n\t\t\tconst delta = max - min;\n\n\t\t\tsaturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );\n\n\t\t\tswitch ( max ) {\n\n\t\t\t\tcase r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;\n\t\t\t\tcase g: hue = ( b - r ) / delta + 2; break;\n\t\t\t\tcase b: hue = ( r - g ) / delta + 4; break;\n\n\t\t\t}\n\n\t\t\thue /= 6;\n\n\t\t}\n\n\t\ttarget.h = hue;\n\t\ttarget.s = saturation;\n\t\ttarget.l = lightness;\n\n\t\treturn target;\n\n\t}\n\n\tgetRGB( target, colorSpace = ColorManagement.workingColorSpace ) {\n\n\t\tColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );\n\n\t\ttarget.r = _color.r;\n\t\ttarget.g = _color.g;\n\t\ttarget.b = _color.b;\n\n\t\treturn target;\n\n\t}\n\n\tgetStyle( colorSpace = SRGBColorSpace ) {\n\n\t\tColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );\n\n\t\tconst r = _color.r, g = _color.g, b = _color.b;\n\n\t\tif ( colorSpace !== SRGBColorSpace ) {\n\n\t\t\t// Requires CSS Color Module Level 4 (https://www.w3.org/TR/css-color-4/).\n\t\t\treturn `color(${ colorSpace } ${ r.toFixed( 3 ) } ${ g.toFixed( 3 ) } ${ b.toFixed( 3 ) })`;\n\n\t\t}\n\n\t\treturn `rgb(${ Math.round( r * 255 ) },${ Math.round( g * 255 ) },${ Math.round( b * 255 ) })`;\n\n\t}\n\n\toffsetHSL( h, s, l ) {\n\n\t\tthis.getHSL( _hslA );\n\n\t\treturn this.setHSL( _hslA.h + h, _hslA.s + s, _hslA.l + l );\n\n\t}\n\n\tadd( color ) {\n\n\t\tthis.r += color.r;\n\t\tthis.g += color.g;\n\t\tthis.b += color.b;\n\n\t\treturn this;\n\n\t}\n\n\taddColors( color1, color2 ) {\n\n\t\tthis.r = color1.r + color2.r;\n\t\tthis.g = color1.g + color2.g;\n\t\tthis.b = color1.b + color2.b;\n\n\t\treturn this;\n\n\t}\n\n\taddScalar( s ) {\n\n\t\tthis.r += s;\n\t\tthis.g += s;\n\t\tthis.b += s;\n\n\t\treturn this;\n\n\t}\n\n\tsub( color ) {\n\n\t\tthis.r = Math.max( 0, this.r - color.r );\n\t\tthis.g = Math.max( 0, this.g - color.g );\n\t\tthis.b = Math.max( 0, this.b - color.b );\n\n\t\treturn this;\n\n\t}\n\n\tmultiply( color ) {\n\n\t\tthis.r *= color.r;\n\t\tthis.g *= color.g;\n\t\tthis.b *= color.b;\n\n\t\treturn this;\n\n\t}\n\n\tmultiplyScalar( s ) {\n\n\t\tthis.r *= s;\n\t\tthis.g *= s;\n\t\tthis.b *= s;\n\n\t\treturn this;\n\n\t}\n\n\tlerp( color, alpha ) {\n\n\t\tthis.r += ( color.r - this.r ) * alpha;\n\t\tthis.g += ( color.g - this.g ) * alpha;\n\t\tthis.b += ( color.b - this.b ) * alpha;\n\n\t\treturn this;\n\n\t}\n\n\tlerpColors( color1, color2, alpha ) {\n\n\t\tthis.r = color1.r + ( color2.r - color1.r ) * alpha;\n\t\tthis.g = color1.g + ( color2.g - color1.g ) * alpha;\n\t\tthis.b = color1.b + ( color2.b - color1.b ) * alpha;\n\n\t\treturn this;\n\n\t}\n\n\tlerpHSL( color, alpha ) {\n\n\t\tthis.getHSL( _hslA );\n\t\tcolor.getHSL( _hslB );\n\n\t\tconst h = lerp( _hslA.h, _hslB.h, alpha );\n\t\tconst s = lerp( _hslA.s, _hslB.s, alpha );\n\t\tconst l = lerp( _hslA.l, _hslB.l, alpha );\n\n\t\tthis.setHSL( h, s, l );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromVector3( v ) {\n\n\t\tthis.r = v.x;\n\t\tthis.g = v.y;\n\t\tthis.b = v.z;\n\n\t\treturn this;\n\n\t}\n\n\tapplyMatrix3( m ) {\n\n\t\tconst r = this.r, g = this.g, b = this.b;\n\t\tconst e = m.elements;\n\n\t\tthis.r = e[ 0 ] * r + e[ 3 ] * g + e[ 6 ] * b;\n\t\tthis.g = e[ 1 ] * r + e[ 4 ] * g + e[ 7 ] * b;\n\t\tthis.b = e[ 2 ] * r + e[ 5 ] * g + e[ 8 ] * b;\n\n\t\treturn this;\n\n\t}\n\n\tequals( c ) {\n\n\t\treturn ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );\n\n\t}\n\n\tfromArray( array, offset = 0 ) {\n\n\t\tthis.r = array[ offset ];\n\t\tthis.g = array[ offset + 1 ];\n\t\tthis.b = array[ offset + 2 ];\n\n\t\treturn this;\n\n\t}\n\n\ttoArray( array = [], offset = 0 ) {\n\n\t\tarray[ offset ] = this.r;\n\t\tarray[ offset + 1 ] = this.g;\n\t\tarray[ offset + 2 ] = this.b;\n\n\t\treturn array;\n\n\t}\n\n\tfromBufferAttribute( attribute, index ) {\n\n\t\tthis.r = attribute.getX( index );\n\t\tthis.g = attribute.getY( index );\n\t\tthis.b = attribute.getZ( index );\n\n\t\treturn this;\n\n\t}\n\n\ttoJSON() {\n\n\t\treturn this.getHex();\n\n\t}\n\n\t*[ Symbol.iterator ]() {\n\n\t\tyield this.r;\n\t\tyield this.g;\n\t\tyield this.b;\n\n\t}\n\n}\n\nconst _color = /*@__PURE__*/ new Color();\n\nColor.NAMES = _colorKeywords;\n\nlet _materialId = 0;\n\nclass Material extends EventDispatcher {\n\n\tconstructor() {\n\n\t\tsuper();\n\n\t\tthis.isMaterial = true;\n\n\t\tObject.defineProperty( this, 'id', { value: _materialId ++ } );\n\n\t\tthis.uuid = generateUUID();\n\n\t\tthis.name = '';\n\t\tthis.type = 'Material';\n\n\t\tthis.blending = NormalBlending;\n\t\tthis.side = FrontSide;\n\t\tthis.vertexColors = false;\n\n\t\tthis.opacity = 1;\n\t\tthis.transparent = false;\n\t\tthis.alphaHash = false;\n\n\t\tthis.blendSrc = SrcAlphaFactor;\n\t\tthis.blendDst = OneMinusSrcAlphaFactor;\n\t\tthis.blendEquation = AddEquation;\n\t\tthis.blendSrcAlpha = null;\n\t\tthis.blendDstAlpha = null;\n\t\tthis.blendEquationAlpha = null;\n\t\tthis.blendColor = new Color( 0, 0, 0 );\n\t\tthis.blendAlpha = 0;\n\n\t\tthis.depthFunc = LessEqualDepth;\n\t\tthis.depthTest = true;\n\t\tthis.depthWrite = true;\n\n\t\tthis.stencilWriteMask = 0xff;\n\t\tthis.stencilFunc = AlwaysStencilFunc;\n\t\tthis.stencilRef = 0;\n\t\tthis.stencilFuncMask = 0xff;\n\t\tthis.stencilFail = KeepStencilOp;\n\t\tthis.stencilZFail = KeepStencilOp;\n\t\tthis.stencilZPass = KeepStencilOp;\n\t\tthis.stencilWrite = false;\n\n\t\tthis.clippingPlanes = null;\n\t\tthis.clipIntersection = false;\n\t\tthis.clipShadows = false;\n\n\t\tthis.shadowSide = null;\n\n\t\tthis.colorWrite = true;\n\n\t\tthis.precision = null; // override the renderer's default precision for this material\n\n\t\tthis.polygonOffset = false;\n\t\tthis.polygonOffsetFactor = 0;\n\t\tthis.polygonOffsetUnits = 0;\n\n\t\tthis.dithering = false;\n\n\t\tthis.alphaToCoverage = false;\n\t\tthis.premultipliedAlpha = false;\n\t\tthis.forceSinglePass = false;\n\n\t\tthis.visible = true;\n\n\t\tthis.toneMapped = true;\n\n\t\tthis.userData = {};\n\n\t\tthis.version = 0;\n\n\t\tthis._alphaTest = 0;\n\n\t}\n\n\tget alphaTest() {\n\n\t\treturn this._alphaTest;\n\n\t}\n\n\tset alphaTest( value ) {\n\n\t\tif ( this._alphaTest > 0 !== value > 0 ) {\n\n\t\t\tthis.version ++;\n\n\t\t}\n\n\t\tthis._alphaTest = value;\n\n\t}\n\n\t// onBeforeRender and onBeforeCompile only supported in WebGLRenderer\n\n\tonBeforeRender( /* renderer, scene, camera, geometry, object, group */ ) {}\n\n\tonBeforeCompile( /* shaderobject, renderer */ ) {}\n\n\tcustomProgramCacheKey() {\n\n\t\treturn this.onBeforeCompile.toString();\n\n\t}\n\n\tsetValues( values ) {\n\n\t\tif ( values === undefined ) return;\n\n\t\tfor ( const key in values ) {\n\n\t\t\tconst newValue = values[ key ];\n\n\t\t\tif ( newValue === undefined ) {\n\n\t\t\t\tconsole.warn( `THREE.Material: parameter '${ key }' has value of undefined.` );\n\t\t\t\tcontinue;\n\n\t\t\t}\n\n\t\t\tconst currentValue = this[ key ];\n\n\t\t\tif ( currentValue === undefined ) {\n\n\t\t\t\tconsole.warn( `THREE.Material: '${ key }' is not a property of THREE.${ this.type }.` );\n\t\t\t\tcontinue;\n\n\t\t\t}\n\n\t\t\tif ( currentValue && currentValue.isColor ) {\n\n\t\t\t\tcurrentValue.set( newValue );\n\n\t\t\t} else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {\n\n\t\t\t\tcurrentValue.copy( newValue );\n\n\t\t\t} else {\n\n\t\t\t\tthis[ key ] = newValue;\n\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\ttoJSON( meta ) {\n\n\t\tconst isRootObject = ( meta === undefined || typeof meta === 'string' );\n\n\t\tif ( isRootObject ) {\n\n\t\t\tmeta = {\n\t\t\t\ttextures: {},\n\t\t\t\timages: {}\n\t\t\t};\n\n\t\t}\n\n\t\tconst data = {\n\t\t\tmetadata: {\n\t\t\t\tversion: 4.6,\n\t\t\t\ttype: 'Material',\n\t\t\t\tgenerator: 'Material.toJSON'\n\t\t\t}\n\t\t};\n\n\t\t// standard Material serialization\n\t\tdata.uuid = this.uuid;\n\t\tdata.type = this.type;\n\n\t\tif ( this.name !== '' ) data.name = this.name;\n\n\t\tif ( this.color && this.color.isColor ) data.color = this.color.getHex();\n\n\t\tif ( this.roughness !== undefined ) data.roughness = this.roughness;\n\t\tif ( this.metalness !== undefined ) data.metalness = this.metalness;\n\n\t\tif ( this.sheen !== undefined ) data.sheen = this.sheen;\n\t\tif ( this.sheenColor && this.sheenColor.isColor ) data.sheenColor = this.sheenColor.getHex();\n\t\tif ( this.sheenRoughness !== undefined ) data.sheenRoughness = this.sheenRoughness;\n\t\tif ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();\n\t\tif ( this.emissiveIntensity !== undefined && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;\n\n\t\tif ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();\n\t\tif ( this.specularIntensity !== undefined ) data.specularIntensity = this.specularIntensity;\n\t\tif ( this.specularColor && this.specularColor.isColor ) data.specularColor = this.specularColor.getHex();\n\t\tif ( this.shininess !== undefined ) data.shininess = this.shininess;\n\t\tif ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;\n\t\tif ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;\n\n\t\tif ( this.clearcoatMap && this.clearcoatMap.isTexture ) {\n\n\t\t\tdata.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;\n\n\t\t}\n\n\t\tif ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {\n\n\t\t\tdata.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;\n\n\t\t}\n\n\t\tif ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {\n\n\t\t\tdata.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;\n\t\t\tdata.clearcoatNormalScale = this.clearcoatNormalScale.toArray();\n\n\t\t}\n\n\t\tif ( this.dispersion !== undefined ) data.dispersion = this.dispersion;\n\n\t\tif ( this.iridescence !== undefined ) data.iridescence = this.iridescence;\n\t\tif ( this.iridescenceIOR !== undefined ) data.iridescenceIOR = this.iridescenceIOR;\n\t\tif ( this.iridescenceThicknessRange !== undefined ) data.iridescenceThicknessRange = this.iridescenceThicknessRange;\n\n\t\tif ( this.iridescenceMap && this.iridescenceMap.isTexture ) {\n\n\t\t\tdata.iridescenceMap = this.iridescenceMap.toJSON( meta ).uuid;\n\n\t\t}\n\n\t\tif ( this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture ) {\n\n\t\t\tdata.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON( meta ).uuid;\n\n\t\t}\n\n\t\tif ( this.anisotropy !== undefined ) data.anisotropy = this.anisotropy;\n\t\tif ( this.anisotropyRotation !== undefined ) data.anisotropyRotation = this.anisotropyRotation;\n\n\t\tif ( this.anisotropyMap && this.anisotropyMap.isTexture ) {\n\n\t\t\tdata.anisotropyMap = this.anisotropyMap.toJSON( meta ).uuid;\n\n\t\t}\n\n\t\tif ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;\n\t\tif ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;\n\t\tif ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;\n\n\t\tif ( this.lightMap && this.lightMap.isTexture ) {\n\n\t\t\tdata.lightMap = this.lightMap.toJSON( meta ).uuid;\n\t\t\tdata.lightMapIntensity = this.lightMapIntensity;\n\n\t\t}\n\n\t\tif ( this.aoMap && this.aoMap.isTexture ) {\n\n\t\t\tdata.aoMap = this.aoMap.toJSON( meta ).uuid;\n\t\t\tdata.aoMapIntensity = this.aoMapIntensity;\n\n\t\t}\n\n\t\tif ( this.bumpMap && this.bumpMap.isTexture ) {\n\n\t\t\tdata.bumpMap = this.bumpMap.toJSON( meta ).uuid;\n\t\t\tdata.bumpScale = this.bumpScale;\n\n\t\t}\n\n\t\tif ( this.normalMap && this.normalMap.isTexture ) {\n\n\t\t\tdata.normalMap = this.normalMap.toJSON( meta ).uuid;\n\t\t\tdata.normalMapType = this.normalMapType;\n\t\t\tdata.normalScale = this.normalScale.toArray();\n\n\t\t}\n\n\t\tif ( this.displacementMap && this.displacementMap.isTexture ) {\n\n\t\t\tdata.displacementMap = this.displacementMap.toJSON( meta ).uuid;\n\t\t\tdata.displacementScale = this.displacementScale;\n\t\t\tdata.displacementBias = this.displacementBias;\n\n\t\t}\n\n\t\tif ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;\n\t\tif ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;\n\n\t\tif ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;\n\t\tif ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;\n\t\tif ( this.specularIntensityMap && this.specularIntensityMap.isTexture ) data.specularIntensityMap = this.specularIntensityMap.toJSON( meta ).uuid;\n\t\tif ( this.specularColorMap && this.specularColorMap.isTexture ) data.specularColorMap = this.specularColorMap.toJSON( meta ).uuid;\n\n\t\tif ( this.envMap && this.envMap.isTexture ) {\n\n\t\t\tdata.envMap = this.envMap.toJSON( meta ).uuid;\n\n\t\t\tif ( this.combine !== undefined ) data.combine = this.combine;\n\n\t\t}\n\n\t\tif ( this.envMapRotation !== undefined ) data.envMapRotation = this.envMapRotation.toArray();\n\t\tif ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;\n\t\tif ( this.reflectivity !== undefined ) data.reflectivity = this.reflectivity;\n\t\tif ( this.refractionRatio !== undefined ) data.refractionRatio = this.refractionRatio;\n\n\t\tif ( this.gradientMap && this.gradientMap.isTexture ) {\n\n\t\t\tdata.gradientMap = this.gradientMap.toJSON( meta ).uuid;\n\n\t\t}\n\n\t\tif ( this.transmission !== undefined ) data.transmission = this.transmission;\n\t\tif ( this.transmissionMap && this.transmissionMap.isTexture ) data.transmissionMap = this.transmissionMap.toJSON( meta ).uuid;\n\t\tif ( this.thickness !== undefined ) data.thickness = this.thickness;\n\t\tif ( this.thicknessMap && this.thicknessMap.isTexture ) data.thicknessMap = this.thicknessMap.toJSON( meta ).uuid;\n\t\tif ( this.attenuationDistance !== undefined && this.attenuationDistance !== Infinity ) data.attenuationDistance = this.attenuationDistance;\n\t\tif ( this.attenuationColor !== undefined ) data.attenuationColor = this.attenuationColor.getHex();\n\n\t\tif ( this.size !== undefined ) data.size = this.size;\n\t\tif ( this.shadowSide !== null ) data.shadowSide = this.shadowSide;\n\t\tif ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;\n\n\t\tif ( this.blending !== NormalBlending ) data.blending = this.blending;\n\t\tif ( this.side !== FrontSide ) data.side = this.side;\n\t\tif ( this.vertexColors === true ) data.vertexColors = true;\n\n\t\tif ( this.opacity < 1 ) data.opacity = this.opacity;\n\t\tif ( this.transparent === true ) data.transparent = true;\n\n\t\tif ( this.blendSrc !== SrcAlphaFactor ) data.blendSrc = this.blendSrc;\n\t\tif ( this.blendDst !== OneMinusSrcAlphaFactor ) data.blendDst = this.blendDst;\n\t\tif ( this.blendEquation !== AddEquation ) data.blendEquation = this.blendEquation;\n\t\tif ( this.blendSrcAlpha !== null ) data.blendSrcAlpha = this.blendSrcAlpha;\n\t\tif ( this.blendDstAlpha !== null ) data.blendDstAlpha = this.blendDstAlpha;\n\t\tif ( this.blendEquationAlpha !== null ) data.blendEquationAlpha = this.blendEquationAlpha;\n\t\tif ( this.blendColor && this.blendColor.isColor ) data.blendColor = this.blendColor.getHex();\n\t\tif ( this.blendAlpha !== 0 ) data.blendAlpha = this.blendAlpha;\n\n\t\tif ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc;\n\t\tif ( this.depthTest === false ) data.depthTest = this.depthTest;\n\t\tif ( this.depthWrite === false ) data.depthWrite = this.depthWrite;\n\t\tif ( this.colorWrite === false ) data.colorWrite = this.colorWrite;\n\n\t\tif ( this.stencilWriteMask !== 0xff ) data.stencilWriteMask = this.stencilWriteMask;\n\t\tif ( this.stencilFunc !== AlwaysStencilFunc ) data.stencilFunc = this.stencilFunc;\n\t\tif ( this.stencilRef !== 0 ) data.stencilRef = this.stencilRef;\n\t\tif ( this.stencilFuncMask !== 0xff ) data.stencilFuncMask = this.stencilFuncMask;\n\t\tif ( this.stencilFail !== KeepStencilOp ) data.stencilFail = this.stencilFail;\n\t\tif ( this.stencilZFail !== KeepStencilOp ) data.stencilZFail = this.stencilZFail;\n\t\tif ( this.stencilZPass !== KeepStencilOp ) data.stencilZPass = this.stencilZPass;\n\t\tif ( this.stencilWrite === true ) data.stencilWrite = this.stencilWrite;\n\n\t\t// rotation (SpriteMaterial)\n\t\tif ( this.rotation !== undefined && this.rotation !== 0 ) data.rotation = this.rotation;\n\n\t\tif ( this.polygonOffset === true ) data.polygonOffset = true;\n\t\tif ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;\n\t\tif ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;\n\n\t\tif ( this.linewidth !== undefined && this.linewidth !== 1 ) data.linewidth = this.linewidth;\n\t\tif ( this.dashSize !== undefined ) data.dashSize = this.dashSize;\n\t\tif ( this.gapSize !== undefined ) data.gapSize = this.gapSize;\n\t\tif ( this.scale !== undefined ) data.scale = this.scale;\n\n\t\tif ( this.dithering === true ) data.dithering = true;\n\n\t\tif ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;\n\t\tif ( this.alphaHash === true ) data.alphaHash = true;\n\t\tif ( this.alphaToCoverage === true ) data.alphaToCoverage = true;\n\t\tif ( this.premultipliedAlpha === true ) data.premultipliedAlpha = true;\n\t\tif ( this.forceSinglePass === true ) data.forceSinglePass = true;\n\n\t\tif ( this.wireframe === true ) data.wireframe = true;\n\t\tif ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;\n\t\tif ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;\n\t\tif ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;\n\n\t\tif ( this.flatShading === true ) data.flatShading = true;\n\n\t\tif ( this.visible === false ) data.visible = false;\n\n\t\tif ( this.toneMapped === false ) data.toneMapped = false;\n\n\t\tif ( this.fog === false ) data.fog = false;\n\n\t\tif ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;\n\n\t\t// TODO: Copied from Object3D.toJSON\n\n\t\tfunction extractFromCache( cache ) {\n\n\t\t\tconst values = [];\n\n\t\t\tfor ( const key in cache ) {\n\n\t\t\t\tconst data = cache[ key ];\n\t\t\t\tdelete data.metadata;\n\t\t\t\tvalues.push( data );\n\n\t\t\t}\n\n\t\t\treturn values;\n\n\t\t}\n\n\t\tif ( isRootObject ) {\n\n\t\t\tconst textures = extractFromCache( meta.textures );\n\t\t\tconst images = extractFromCache( meta.images );\n\n\t\t\tif ( textures.length > 0 ) data.textures = textures;\n\t\t\tif ( images.length > 0 ) data.images = images;\n\n\t\t}\n\n\t\treturn data;\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n\tcopy( source ) {\n\n\t\tthis.name = source.name;\n\n\t\tthis.blending = source.blending;\n\t\tthis.side = source.side;\n\t\tthis.vertexColors = source.vertexColors;\n\n\t\tthis.opacity = source.opacity;\n\t\tthis.transparent = source.transparent;\n\n\t\tthis.blendSrc = source.blendSrc;\n\t\tthis.blendDst = source.blendDst;\n\t\tthis.blendEquation = source.blendEquation;\n\t\tthis.blendSrcAlpha = source.blendSrcAlpha;\n\t\tthis.blendDstAlpha = source.blendDstAlpha;\n\t\tthis.blendEquationAlpha = source.blendEquationAlpha;\n\t\tthis.blendColor.copy( source.blendColor );\n\t\tthis.blendAlpha = source.blendAlpha;\n\n\t\tthis.depthFunc = source.depthFunc;\n\t\tthis.depthTest = source.depthTest;\n\t\tthis.depthWrite = source.depthWrite;\n\n\t\tthis.stencilWriteMask = source.stencilWriteMask;\n\t\tthis.stencilFunc = source.stencilFunc;\n\t\tthis.stencilRef = source.stencilRef;\n\t\tthis.stencilFuncMask = source.stencilFuncMask;\n\t\tthis.stencilFail = source.stencilFail;\n\t\tthis.stencilZFail = source.stencilZFail;\n\t\tthis.stencilZPass = source.stencilZPass;\n\t\tthis.stencilWrite = source.stencilWrite;\n\n\t\tconst srcPlanes = source.clippingPlanes;\n\t\tlet dstPlanes = null;\n\n\t\tif ( srcPlanes !== null ) {\n\n\t\t\tconst n = srcPlanes.length;\n\t\t\tdstPlanes = new Array( n );\n\n\t\t\tfor ( let i = 0; i !== n; ++ i ) {\n\n\t\t\t\tdstPlanes[ i ] = srcPlanes[ i ].clone();\n\n\t\t\t}\n\n\t\t}\n\n\t\tthis.clippingPlanes = dstPlanes;\n\t\tthis.clipIntersection = source.clipIntersection;\n\t\tthis.clipShadows = source.clipShadows;\n\n\t\tthis.shadowSide = source.shadowSide;\n\n\t\tthis.colorWrite = source.colorWrite;\n\n\t\tthis.precision = source.precision;\n\n\t\tthis.polygonOffset = source.polygonOffset;\n\t\tthis.polygonOffsetFactor = source.polygonOffsetFactor;\n\t\tthis.polygonOffsetUnits = source.polygonOffsetUnits;\n\n\t\tthis.dithering = source.dithering;\n\n\t\tthis.alphaTest = source.alphaTest;\n\t\tthis.alphaHash = source.alphaHash;\n\t\tthis.alphaToCoverage = source.alphaToCoverage;\n\t\tthis.premultipliedAlpha = source.premultipliedAlpha;\n\t\tthis.forceSinglePass = source.forceSinglePass;\n\n\t\tthis.visible = source.visible;\n\n\t\tthis.toneMapped = source.toneMapped;\n\n\t\tthis.userData = JSON.parse( JSON.stringify( source.userData ) );\n\n\t\treturn this;\n\n\t}\n\n\tdispose() {\n\n\t\tthis.dispatchEvent( { type: 'dispose' } );\n\n\t}\n\n\tset needsUpdate( value ) {\n\n\t\tif ( value === true ) this.version ++;\n\n\t}\n\n\tonBuild( /* shaderobject, renderer */ ) {\n\n\t\tconsole.warn( 'Material: onBuild() has been removed.' ); // @deprecated, r166\n\n\t}\n\n}\n\nclass MeshBasicMaterial extends Material {\n\n\tconstructor( parameters ) {\n\n\t\tsuper();\n\n\t\tthis.isMeshBasicMaterial = true;\n\n\t\tthis.type = 'MeshBasicMaterial';\n\n\t\tthis.color = new Color( 0xffffff ); // emissive\n\n\t\tthis.map = null;\n\n\t\tthis.lightMap = null;\n\t\tthis.lightMapIntensity = 1.0;\n\n\t\tthis.aoMap = null;\n\t\tthis.aoMapIntensity = 1.0;\n\n\t\tthis.specularMap = null;\n\n\t\tthis.alphaMap = null;\n\n\t\tthis.envMap = null;\n\t\tthis.envMapRotation = new Euler();\n\t\tthis.combine = MultiplyOperation;\n\t\tthis.reflectivity = 1;\n\t\tthis.refractionRatio = 0.98;\n\n\t\tthis.wireframe = false;\n\t\tthis.wireframeLinewidth = 1;\n\t\tthis.wireframeLinecap = 'round';\n\t\tthis.wireframeLinejoin = 'round';\n\n\t\tthis.fog = true;\n\n\t\tthis.setValues( parameters );\n\n\t}\n\n\tcopy( source ) {\n\n\t\tsuper.copy( source );\n\n\t\tthis.color.copy( source.color );\n\n\t\tthis.map = source.map;\n\n\t\tthis.lightMap = source.lightMap;\n\t\tthis.lightMapIntensity = source.lightMapIntensity;\n\n\t\tthis.aoMap = source.aoMap;\n\t\tthis.aoMapIntensity = source.aoMapIntensity;\n\n\t\tthis.specularMap = source.specularMap;\n\n\t\tthis.alphaMap = source.alphaMap;\n\n\t\tthis.envMap = source.envMap;\n\t\tthis.envMapRotation.copy( source.envMapRotation );\n\t\tthis.combine = source.combine;\n\t\tthis.reflectivity = source.reflectivity;\n\t\tthis.refractionRatio = source.refractionRatio;\n\n\t\tthis.wireframe = source.wireframe;\n\t\tthis.wireframeLinewidth = source.wireframeLinewidth;\n\t\tthis.wireframeLinecap = source.wireframeLinecap;\n\t\tthis.wireframeLinejoin = source.wireframeLinejoin;\n\n\t\tthis.fog = source.fog;\n\n\t\treturn this;\n\n\t}\n\n}\n\n// Fast Half Float Conversions, http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf\n\nconst _tables = /*@__PURE__*/ _generateTables();\n\nfunction _generateTables() {\n\n\t// float32 to float16 helpers\n\n\tconst buffer = new ArrayBuffer( 4 );\n\tconst floatView = new Float32Array( buffer );\n\tconst uint32View = new Uint32Array( buffer );\n\n\tconst baseTable = new Uint32Array( 512 );\n\tconst shiftTable = new Uint32Array( 512 );\n\n\tfor ( let i = 0; i < 256; ++ i ) {\n\n\t\tconst e = i - 127;\n\n\t\t// very small number (0, -0)\n\n\t\tif ( e < - 27 ) {\n\n\t\t\tbaseTable[ i ] = 0x0000;\n\t\t\tbaseTable[ i | 0x100 ] = 0x8000;\n\t\t\tshiftTable[ i ] = 24;\n\t\t\tshiftTable[ i | 0x100 ] = 24;\n\n\t\t\t// small number (denorm)\n\n\t\t} else if ( e < - 14 ) {\n\n\t\t\tbaseTable[ i ] = 0x0400 >> ( - e - 14 );\n\t\t\tbaseTable[ i | 0x100 ] = ( 0x0400 >> ( - e - 14 ) ) | 0x8000;\n\t\t\tshiftTable[ i ] = - e - 1;\n\t\t\tshiftTable[ i | 0x100 ] = - e - 1;\n\n\t\t\t// normal number\n\n\t\t} else if ( e <= 15 ) {\n\n\t\t\tbaseTable[ i ] = ( e + 15 ) << 10;\n\t\t\tbaseTable[ i | 0x100 ] = ( ( e + 15 ) << 10 ) | 0x8000;\n\t\t\tshiftTable[ i ] = 13;\n\t\t\tshiftTable[ i | 0x100 ] = 13;\n\n\t\t\t// large number (Infinity, -Infinity)\n\n\t\t} else if ( e < 128 ) {\n\n\t\t\tbaseTable[ i ] = 0x7c00;\n\t\t\tbaseTable[ i | 0x100 ] = 0xfc00;\n\t\t\tshiftTable[ i ] = 24;\n\t\t\tshiftTable[ i | 0x100 ] = 24;\n\n\t\t\t// stay (NaN, Infinity, -Infinity)\n\n\t\t} else {\n\n\t\t\tbaseTable[ i ] = 0x7c00;\n\t\t\tbaseTable[ i | 0x100 ] = 0xfc00;\n\t\t\tshiftTable[ i ] = 13;\n\t\t\tshiftTable[ i | 0x100 ] = 13;\n\n\t\t}\n\n\t}\n\n\t// float16 to float32 helpers\n\n\tconst mantissaTable = new Uint32Array( 2048 );\n\tconst exponentTable = new Uint32Array( 64 );\n\tconst offsetTable = new Uint32Array( 64 );\n\n\tfor ( let i = 1; i < 1024; ++ i ) {\n\n\t\tlet m = i << 13; // zero pad mantissa bits\n\t\tlet e = 0; // zero exponent\n\n\t\t// normalized\n\t\twhile ( ( m & 0x00800000 ) === 0 ) {\n\n\t\t\tm <<= 1;\n\t\t\te -= 0x00800000; // decrement exponent\n\n\t\t}\n\n\t\tm &= ~ 0x00800000; // clear leading 1 bit\n\t\te += 0x38800000; // adjust bias\n\n\t\tmantissaTable[ i ] = m | e;\n\n\t}\n\n\tfor ( let i = 1024; i < 2048; ++ i ) {\n\n\t\tmantissaTable[ i ] = 0x38000000 + ( ( i - 1024 ) << 13 );\n\n\t}\n\n\tfor ( let i = 1; i < 31; ++ i ) {\n\n\t\texponentTable[ i ] = i << 23;\n\n\t}\n\n\texponentTable[ 31 ] = 0x47800000;\n\texponentTable[ 32 ] = 0x80000000;\n\n\tfor ( let i = 33; i < 63; ++ i ) {\n\n\t\texponentTable[ i ] = 0x80000000 + ( ( i - 32 ) << 23 );\n\n\t}\n\n\texponentTable[ 63 ] = 0xc7800000;\n\n\tfor ( let i = 1; i < 64; ++ i ) {\n\n\t\tif ( i !== 32 ) {\n\n\t\t\toffsetTable[ i ] = 1024;\n\n\t\t}\n\n\t}\n\n\treturn {\n\t\tfloatView: floatView,\n\t\tuint32View: uint32View,\n\t\tbaseTable: baseTable,\n\t\tshiftTable: shiftTable,\n\t\tmantissaTable: mantissaTable,\n\t\texponentTable: exponentTable,\n\t\toffsetTable: offsetTable\n\t};\n\n}\n\n// float32 to float16\n\nfunction toHalfFloat( val ) {\n\n\tif ( Math.abs( val ) > 65504 ) console.warn( 'THREE.DataUtils.toHalfFloat(): Value out of range.' );\n\n\tval = clamp( val, - 65504, 65504 );\n\n\t_tables.floatView[ 0 ] = val;\n\tconst f = _tables.uint32View[ 0 ];\n\tconst e = ( f >> 23 ) & 0x1ff;\n\treturn _tables.baseTable[ e ] + ( ( f & 0x007fffff ) >> _tables.shiftTable[ e ] );\n\n}\n\n// float16 to float32\n\nfunction fromHalfFloat( val ) {\n\n\tconst m = val >> 10;\n\t_tables.uint32View[ 0 ] = _tables.mantissaTable[ _tables.offsetTable[ m ] + ( val & 0x3ff ) ] + _tables.exponentTable[ m ];\n\treturn _tables.floatView[ 0 ];\n\n}\n\nconst DataUtils = {\n\ttoHalfFloat: toHalfFloat,\n\tfromHalfFloat: fromHalfFloat,\n};\n\nconst _vector$9 = /*@__PURE__*/ new Vector3();\nconst _vector2$1 = /*@__PURE__*/ new Vector2();\n\nclass BufferAttribute {\n\n\tconstructor( array, itemSize, normalized = false ) {\n\n\t\tif ( Array.isArray( array ) ) {\n\n\t\t\tthrow new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );\n\n\t\t}\n\n\t\tthis.isBufferAttribute = true;\n\n\t\tthis.name = '';\n\n\t\tthis.array = array;\n\t\tthis.itemSize = itemSize;\n\t\tthis.count = array !== undefined ? array.length / itemSize : 0;\n\t\tthis.normalized = normalized;\n\n\t\tthis.usage = StaticDrawUsage;\n\t\tthis._updateRange = { offset: 0, count: - 1 };\n\t\tthis.updateRanges = [];\n\t\tthis.gpuType = FloatType;\n\n\t\tthis.version = 0;\n\n\t}\n\n\tonUploadCallback() {}\n\n\tset needsUpdate( value ) {\n\n\t\tif ( value === true ) this.version ++;\n\n\t}\n\n\tget updateRange() {\n\n\t\twarnOnce( 'THREE.BufferAttribute: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead.' ); // @deprecated, r159\n\t\treturn this._updateRange;\n\n\t}\n\n\tsetUsage( value ) {\n\n\t\tthis.usage = value;\n\n\t\treturn this;\n\n\t}\n\n\taddUpdateRange( start, count ) {\n\n\t\tthis.updateRanges.push( { start, count } );\n\n\t}\n\n\tclearUpdateRanges() {\n\n\t\tthis.updateRanges.length = 0;\n\n\t}\n\n\tcopy( source ) {\n\n\t\tthis.name = source.name;\n\t\tthis.array = new source.array.constructor( source.array );\n\t\tthis.itemSize = source.itemSize;\n\t\tthis.count = source.count;\n\t\tthis.normalized = source.normalized;\n\n\t\tthis.usage = source.usage;\n\t\tthis.gpuType = source.gpuType;\n\n\t\treturn this;\n\n\t}\n\n\tcopyAt( index1, attribute, index2 ) {\n\n\t\tindex1 *= this.itemSize;\n\t\tindex2 *= attribute.itemSize;\n\n\t\tfor ( let i = 0, l = this.itemSize; i < l; i ++ ) {\n\n\t\t\tthis.array[ index1 + i ] = attribute.array[ index2 + i ];\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tcopyArray( array ) {\n\n\t\tthis.array.set( array );\n\n\t\treturn this;\n\n\t}\n\n\tapplyMatrix3( m ) {\n\n\t\tif ( this.itemSize === 2 ) {\n\n\t\t\tfor ( let i = 0, l = this.count; i < l; i ++ ) {\n\n\t\t\t\t_vector2$1.fromBufferAttribute( this, i );\n\t\t\t\t_vector2$1.applyMatrix3( m );\n\n\t\t\t\tthis.setXY( i, _vector2$1.x, _vector2$1.y );\n\n\t\t\t}\n\n\t\t} else if ( this.itemSize === 3 ) {\n\n\t\t\tfor ( let i = 0, l = this.count; i < l; i ++ ) {\n\n\t\t\t\t_vector$9.fromBufferAttribute( this, i );\n\t\t\t\t_vector$9.applyMatrix3( m );\n\n\t\t\t\tthis.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );\n\n\t\t\t}\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tapplyMatrix4( m ) {\n\n\t\tfor ( let i = 0, l = this.count; i < l; i ++ ) {\n\n\t\t\t_vector$9.fromBufferAttribute( this, i );\n\n\t\t\t_vector$9.applyMatrix4( m );\n\n\t\t\tthis.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tapplyNormalMatrix( m ) {\n\n\t\tfor ( let i = 0, l = this.count; i < l; i ++ ) {\n\n\t\t\t_vector$9.fromBufferAttribute( this, i );\n\n\t\t\t_vector$9.applyNormalMatrix( m );\n\n\t\t\tthis.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\ttransformDirection( m ) {\n\n\t\tfor ( let i = 0, l = this.count; i < l; i ++ ) {\n\n\t\t\t_vector$9.fromBufferAttribute( this, i );\n\n\t\t\t_vector$9.transformDirection( m );\n\n\t\t\tthis.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tset( value, offset = 0 ) {\n\n\t\t// Matching BufferAttribute constructor, do not normalize the array.\n\t\tthis.array.set( value, offset );\n\n\t\treturn this;\n\n\t}\n\n\tgetComponent( index, component ) {\n\n\t\tlet value = this.array[ index * this.itemSize + component ];\n\n\t\tif ( this.normalized ) value = denormalize( value, this.array );\n\n\t\treturn value;\n\n\t}\n\n\tsetComponent( index, component, value ) {\n\n\t\tif ( this.normalized ) value = normalize( value, this.array );\n\n\t\tthis.array[ index * this.itemSize + component ] = value;\n\n\t\treturn this;\n\n\t}\n\n\tgetX( index ) {\n\n\t\tlet x = this.array[ index * this.itemSize ];\n\n\t\tif ( this.normalized ) x = denormalize( x, this.array );\n\n\t\treturn x;\n\n\t}\n\n\tsetX( index, x ) {\n\n\t\tif ( this.normalized ) x = normalize( x, this.array );\n\n\t\tthis.array[ index * this.itemSize ] = x;\n\n\t\treturn this;\n\n\t}\n\n\tgetY( index ) {\n\n\t\tlet y = this.array[ index * this.itemSize + 1 ];\n\n\t\tif ( this.normalized ) y = denormalize( y, this.array );\n\n\t\treturn y;\n\n\t}\n\n\tsetY( index, y ) {\n\n\t\tif ( this.normalized ) y = normalize( y, this.array );\n\n\t\tthis.array[ index * this.itemSize + 1 ] = y;\n\n\t\treturn this;\n\n\t}\n\n\tgetZ( index ) {\n\n\t\tlet z = this.array[ index * this.itemSize + 2 ];\n\n\t\tif ( this.normalized ) z = denormalize( z, this.array );\n\n\t\treturn z;\n\n\t}\n\n\tsetZ( index, z ) {\n\n\t\tif ( this.normalized ) z = normalize( z, this.array );\n\n\t\tthis.array[ index * this.itemSize + 2 ] = z;\n\n\t\treturn this;\n\n\t}\n\n\tgetW( index ) {\n\n\t\tlet w = this.array[ index * this.itemSize + 3 ];\n\n\t\tif ( this.normalized ) w = denormalize( w, this.array );\n\n\t\treturn w;\n\n\t}\n\n\tsetW( index, w ) {\n\n\t\tif ( this.normalized ) w = normalize( w, this.array );\n\n\t\tthis.array[ index * this.itemSize + 3 ] = w;\n\n\t\treturn this;\n\n\t}\n\n\tsetXY( index, x, y ) {\n\n\t\tindex *= this.itemSize;\n\n\t\tif ( this.normalized ) {\n\n\t\t\tx = normalize( x, this.array );\n\t\t\ty = normalize( y, this.array );\n\n\t\t}\n\n\t\tthis.array[ index + 0 ] = x;\n\t\tthis.array[ index + 1 ] = y;\n\n\t\treturn this;\n\n\t}\n\n\tsetXYZ( index, x, y, z ) {\n\n\t\tindex *= this.itemSize;\n\n\t\tif ( this.normalized ) {\n\n\t\t\tx = normalize( x, this.array );\n\t\t\ty = normalize( y, this.array );\n\t\t\tz = normalize( z, this.array );\n\n\t\t}\n\n\t\tthis.array[ index + 0 ] = x;\n\t\tthis.array[ index + 1 ] = y;\n\t\tthis.array[ index + 2 ] = z;\n\n\t\treturn this;\n\n\t}\n\n\tsetXYZW( index, x, y, z, w ) {\n\n\t\tindex *= this.itemSize;\n\n\t\tif ( this.normalized ) {\n\n\t\t\tx = normalize( x, this.array );\n\t\t\ty = normalize( y, this.array );\n\t\t\tz = normalize( z, this.array );\n\t\t\tw = normalize( w, this.array );\n\n\t\t}\n\n\t\tthis.array[ index + 0 ] = x;\n\t\tthis.array[ index + 1 ] = y;\n\t\tthis.array[ index + 2 ] = z;\n\t\tthis.array[ index + 3 ] = w;\n\n\t\treturn this;\n\n\t}\n\n\tonUpload( callback ) {\n\n\t\tthis.onUploadCallback = callback;\n\n\t\treturn this;\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor( this.array, this.itemSize ).copy( this );\n\n\t}\n\n\ttoJSON() {\n\n\t\tconst data = {\n\t\t\titemSize: this.itemSize,\n\t\t\ttype: this.array.constructor.name,\n\t\t\tarray: Array.from( this.array ),\n\t\t\tnormalized: this.normalized\n\t\t};\n\n\t\tif ( this.name !== '' ) data.name = this.name;\n\t\tif ( this.usage !== StaticDrawUsage ) data.usage = this.usage;\n\n\t\treturn data;\n\n\t}\n\n}\n\n//\n\nclass Int8BufferAttribute extends BufferAttribute {\n\n\tconstructor( array, itemSize, normalized ) {\n\n\t\tsuper( new Int8Array( array ), itemSize, normalized );\n\n\t}\n\n}\n\nclass Uint8BufferAttribute extends BufferAttribute {\n\n\tconstructor( array, itemSize, normalized ) {\n\n\t\tsuper( new Uint8Array( array ), itemSize, normalized );\n\n\t}\n\n}\n\nclass Uint8ClampedBufferAttribute extends BufferAttribute {\n\n\tconstructor( array, itemSize, normalized ) {\n\n\t\tsuper( new Uint8ClampedArray( array ), itemSize, normalized );\n\n\t}\n\n}\n\nclass Int16BufferAttribute extends BufferAttribute {\n\n\tconstructor( array, itemSize, normalized ) {\n\n\t\tsuper( new Int16Array( array ), itemSize, normalized );\n\n\t}\n\n}\n\nclass Uint16BufferAttribute extends BufferAttribute {\n\n\tconstructor( array, itemSize, normalized ) {\n\n\t\tsuper( new Uint16Array( array ), itemSize, normalized );\n\n\t}\n\n}\n\nclass Int32BufferAttribute extends BufferAttribute {\n\n\tconstructor( array, itemSize, normalized ) {\n\n\t\tsuper( new Int32Array( array ), itemSize, normalized );\n\n\t}\n\n}\n\nclass Uint32BufferAttribute extends BufferAttribute {\n\n\tconstructor( array, itemSize, normalized ) {\n\n\t\tsuper( new Uint32Array( array ), itemSize, normalized );\n\n\t}\n\n}\n\nclass Float16BufferAttribute extends BufferAttribute {\n\n\tconstructor( array, itemSize, normalized ) {\n\n\t\tsuper( new Uint16Array( array ), itemSize, normalized );\n\n\t\tthis.isFloat16BufferAttribute = true;\n\n\t}\n\n\tgetX( index ) {\n\n\t\tlet x = fromHalfFloat( this.array[ index * this.itemSize ] );\n\n\t\tif ( this.normalized ) x = denormalize( x, this.array );\n\n\t\treturn x;\n\n\t}\n\n\tsetX( index, x ) {\n\n\t\tif ( this.normalized ) x = normalize( x, this.array );\n\n\t\tthis.array[ index * this.itemSize ] = toHalfFloat( x );\n\n\t\treturn this;\n\n\t}\n\n\tgetY( index ) {\n\n\t\tlet y = fromHalfFloat( this.array[ index * this.itemSize + 1 ] );\n\n\t\tif ( this.normalized ) y = denormalize( y, this.array );\n\n\t\treturn y;\n\n\t}\n\n\tsetY( index, y ) {\n\n\t\tif ( this.normalized ) y = normalize( y, this.array );\n\n\t\tthis.array[ index * this.itemSize + 1 ] = toHalfFloat( y );\n\n\t\treturn this;\n\n\t}\n\n\tgetZ( index ) {\n\n\t\tlet z = fromHalfFloat( this.array[ index * this.itemSize + 2 ] );\n\n\t\tif ( this.normalized ) z = denormalize( z, this.array );\n\n\t\treturn z;\n\n\t}\n\n\tsetZ( index, z ) {\n\n\t\tif ( this.normalized ) z = normalize( z, this.array );\n\n\t\tthis.array[ index * this.itemSize + 2 ] = toHalfFloat( z );\n\n\t\treturn this;\n\n\t}\n\n\tgetW( index ) {\n\n\t\tlet w = fromHalfFloat( this.array[ index * this.itemSize + 3 ] );\n\n\t\tif ( this.normalized ) w = denormalize( w, this.array );\n\n\t\treturn w;\n\n\t}\n\n\tsetW( index, w ) {\n\n\t\tif ( this.normalized ) w = normalize( w, this.array );\n\n\t\tthis.array[ index * this.itemSize + 3 ] = toHalfFloat( w );\n\n\t\treturn this;\n\n\t}\n\n\tsetXY( index, x, y ) {\n\n\t\tindex *= this.itemSize;\n\n\t\tif ( this.normalized ) {\n\n\t\t\tx = normalize( x, this.array );\n\t\t\ty = normalize( y, this.array );\n\n\t\t}\n\n\t\tthis.array[ index + 0 ] = toHalfFloat( x );\n\t\tthis.array[ index + 1 ] = toHalfFloat( y );\n\n\t\treturn this;\n\n\t}\n\n\tsetXYZ( index, x, y, z ) {\n\n\t\tindex *= this.itemSize;\n\n\t\tif ( this.normalized ) {\n\n\t\t\tx = normalize( x, this.array );\n\t\t\ty = normalize( y, this.array );\n\t\t\tz = normalize( z, this.array );\n\n\t\t}\n\n\t\tthis.array[ index + 0 ] = toHalfFloat( x );\n\t\tthis.array[ index + 1 ] = toHalfFloat( y );\n\t\tthis.array[ index + 2 ] = toHalfFloat( z );\n\n\t\treturn this;\n\n\t}\n\n\tsetXYZW( index, x, y, z, w ) {\n\n\t\tindex *= this.itemSize;\n\n\t\tif ( this.normalized ) {\n\n\t\t\tx = normalize( x, this.array );\n\t\t\ty = normalize( y, this.array );\n\t\t\tz = normalize( z, this.array );\n\t\t\tw = normalize( w, this.array );\n\n\t\t}\n\n\t\tthis.array[ index + 0 ] = toHalfFloat( x );\n\t\tthis.array[ index + 1 ] = toHalfFloat( y );\n\t\tthis.array[ index + 2 ] = toHalfFloat( z );\n\t\tthis.array[ index + 3 ] = toHalfFloat( w );\n\n\t\treturn this;\n\n\t}\n\n}\n\n\nclass Float32BufferAttribute extends BufferAttribute {\n\n\tconstructor( array, itemSize, normalized ) {\n\n\t\tsuper( new Float32Array( array ), itemSize, normalized );\n\n\t}\n\n}\n\nlet _id$2 = 0;\n\nconst _m1$2 = /*@__PURE__*/ new Matrix4();\nconst _obj = /*@__PURE__*/ new Object3D();\nconst _offset = /*@__PURE__*/ new Vector3();\nconst _box$2 = /*@__PURE__*/ new Box3();\nconst _boxMorphTargets = /*@__PURE__*/ new Box3();\nconst _vector$8 = /*@__PURE__*/ new Vector3();\n\nclass BufferGeometry extends EventDispatcher {\n\n\tconstructor() {\n\n\t\tsuper();\n\n\t\tthis.isBufferGeometry = true;\n\n\t\tObject.defineProperty( this, 'id', { value: _id$2 ++ } );\n\n\t\tthis.uuid = generateUUID();\n\n\t\tthis.name = '';\n\t\tthis.type = 'BufferGeometry';\n\n\t\tthis.index = null;\n\t\tthis.attributes = {};\n\n\t\tthis.morphAttributes = {};\n\t\tthis.morphTargetsRelative = false;\n\n\t\tthis.groups = [];\n\n\t\tthis.boundingBox = null;\n\t\tthis.boundingSphere = null;\n\n\t\tthis.drawRange = { start: 0, count: Infinity };\n\n\t\tthis.userData = {};\n\n\t}\n\n\tgetIndex() {\n\n\t\treturn this.index;\n\n\t}\n\n\tsetIndex( index ) {\n\n\t\tif ( Array.isArray( index ) ) {\n\n\t\t\tthis.index = new ( arrayNeedsUint32( index ) ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );\n\n\t\t} else {\n\n\t\t\tthis.index = index;\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tgetAttribute( name ) {\n\n\t\treturn this.attributes[ name ];\n\n\t}\n\n\tsetAttribute( name, attribute ) {\n\n\t\tthis.attributes[ name ] = attribute;\n\n\t\treturn this;\n\n\t}\n\n\tdeleteAttribute( name ) {\n\n\t\tdelete this.attributes[ name ];\n\n\t\treturn this;\n\n\t}\n\n\thasAttribute( name ) {\n\n\t\treturn this.attributes[ name ] !== undefined;\n\n\t}\n\n\taddGroup( start, count, materialIndex = 0 ) {\n\n\t\tthis.groups.push( {\n\n\t\t\tstart: start,\n\t\t\tcount: count,\n\t\t\tmaterialIndex: materialIndex\n\n\t\t} );\n\n\t}\n\n\tclearGroups() {\n\n\t\tthis.groups = [];\n\n\t}\n\n\tsetDrawRange( start, count ) {\n\n\t\tthis.drawRange.start = start;\n\t\tthis.drawRange.count = count;\n\n\t}\n\n\tapplyMatrix4( matrix ) {\n\n\t\tconst position = this.attributes.position;\n\n\t\tif ( position !== undefined ) {\n\n\t\t\tposition.applyMatrix4( matrix );\n\n\t\t\tposition.needsUpdate = true;\n\n\t\t}\n\n\t\tconst normal = this.attributes.normal;\n\n\t\tif ( normal !== undefined ) {\n\n\t\t\tconst normalMatrix = new Matrix3().getNormalMatrix( matrix );\n\n\t\t\tnormal.applyNormalMatrix( normalMatrix );\n\n\t\t\tnormal.needsUpdate = true;\n\n\t\t}\n\n\t\tconst tangent = this.attributes.tangent;\n\n\t\tif ( tangent !== undefined ) {\n\n\t\t\ttangent.transformDirection( matrix );\n\n\t\t\ttangent.needsUpdate = true;\n\n\t\t}\n\n\t\tif ( this.boundingBox !== null ) {\n\n\t\t\tthis.computeBoundingBox();\n\n\t\t}\n\n\t\tif ( this.boundingSphere !== null ) {\n\n\t\t\tthis.computeBoundingSphere();\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tapplyQuaternion( q ) {\n\n\t\t_m1$2.makeRotationFromQuaternion( q );\n\n\t\tthis.applyMatrix4( _m1$2 );\n\n\t\treturn this;\n\n\t}\n\n\trotateX( angle ) {\n\n\t\t// rotate geometry around world x-axis\n\n\t\t_m1$2.makeRotationX( angle );\n\n\t\tthis.applyMatrix4( _m1$2 );\n\n\t\treturn this;\n\n\t}\n\n\trotateY( angle ) {\n\n\t\t// rotate geometry around world y-axis\n\n\t\t_m1$2.makeRotationY( angle );\n\n\t\tthis.applyMatrix4( _m1$2 );\n\n\t\treturn this;\n\n\t}\n\n\trotateZ( angle ) {\n\n\t\t// rotate geometry around world z-axis\n\n\t\t_m1$2.makeRotationZ( angle );\n\n\t\tthis.applyMatrix4( _m1$2 );\n\n\t\treturn this;\n\n\t}\n\n\ttranslate( x, y, z ) {\n\n\t\t// translate geometry\n\n\t\t_m1$2.makeTranslation( x, y, z );\n\n\t\tthis.applyMatrix4( _m1$2 );\n\n\t\treturn this;\n\n\t}\n\n\tscale( x, y, z ) {\n\n\t\t// scale geometry\n\n\t\t_m1$2.makeScale( x, y, z );\n\n\t\tthis.applyMatrix4( _m1$2 );\n\n\t\treturn this;\n\n\t}\n\n\tlookAt( vector ) {\n\n\t\t_obj.lookAt( vector );\n\n\t\t_obj.updateMatrix();\n\n\t\tthis.applyMatrix4( _obj.matrix );\n\n\t\treturn this;\n\n\t}\n\n\tcenter() {\n\n\t\tthis.computeBoundingBox();\n\n\t\tthis.boundingBox.getCenter( _offset ).negate();\n\n\t\tthis.translate( _offset.x, _offset.y, _offset.z );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromPoints( points ) {\n\n\t\tconst position = [];\n\n\t\tfor ( let i = 0, l = points.length; i < l; i ++ ) {\n\n\t\t\tconst point = points[ i ];\n\t\t\tposition.push( point.x, point.y, point.z || 0 );\n\n\t\t}\n\n\t\tthis.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );\n\n\t\treturn this;\n\n\t}\n\n\tcomputeBoundingBox() {\n\n\t\tif ( this.boundingBox === null ) {\n\n\t\t\tthis.boundingBox = new Box3();\n\n\t\t}\n\n\t\tconst position = this.attributes.position;\n\t\tconst morphAttributesPosition = this.morphAttributes.position;\n\n\t\tif ( position && position.isGLBufferAttribute ) {\n\n\t\t\tconsole.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.', this );\n\n\t\t\tthis.boundingBox.set(\n\t\t\t\tnew Vector3( - Infinity, - Infinity, - Infinity ),\n\t\t\t\tnew Vector3( + Infinity, + Infinity, + Infinity )\n\t\t\t);\n\n\t\t\treturn;\n\n\t\t}\n\n\t\tif ( position !== undefined ) {\n\n\t\t\tthis.boundingBox.setFromBufferAttribute( position );\n\n\t\t\t// process morph attributes if present\n\n\t\t\tif ( morphAttributesPosition ) {\n\n\t\t\t\tfor ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {\n\n\t\t\t\t\tconst morphAttribute = morphAttributesPosition[ i ];\n\t\t\t\t\t_box$2.setFromBufferAttribute( morphAttribute );\n\n\t\t\t\t\tif ( this.morphTargetsRelative ) {\n\n\t\t\t\t\t\t_vector$8.addVectors( this.boundingBox.min, _box$2.min );\n\t\t\t\t\t\tthis.boundingBox.expandByPoint( _vector$8 );\n\n\t\t\t\t\t\t_vector$8.addVectors( this.boundingBox.max, _box$2.max );\n\t\t\t\t\t\tthis.boundingBox.expandByPoint( _vector$8 );\n\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\tthis.boundingBox.expandByPoint( _box$2.min );\n\t\t\t\t\t\tthis.boundingBox.expandByPoint( _box$2.max );\n\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t} else {\n\n\t\t\tthis.boundingBox.makeEmpty();\n\n\t\t}\n\n\t\tif ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {\n\n\t\t\tconsole.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The \"position\" attribute is likely to have NaN values.', this );\n\n\t\t}\n\n\t}\n\n\tcomputeBoundingSphere() {\n\n\t\tif ( this.boundingSphere === null ) {\n\n\t\t\tthis.boundingSphere = new Sphere();\n\n\t\t}\n\n\t\tconst position = this.attributes.position;\n\t\tconst morphAttributesPosition = this.morphAttributes.position;\n\n\t\tif ( position && position.isGLBufferAttribute ) {\n\n\t\t\tconsole.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.', this );\n\n\t\t\tthis.boundingSphere.set( new Vector3(), Infinity );\n\n\t\t\treturn;\n\n\t\t}\n\n\t\tif ( position ) {\n\n\t\t\t// first, find the center of the bounding sphere\n\n\t\t\tconst center = this.boundingSphere.center;\n\n\t\t\t_box$2.setFromBufferAttribute( position );\n\n\t\t\t// process morph attributes if present\n\n\t\t\tif ( morphAttributesPosition ) {\n\n\t\t\t\tfor ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {\n\n\t\t\t\t\tconst morphAttribute = morphAttributesPosition[ i ];\n\t\t\t\t\t_boxMorphTargets.setFromBufferAttribute( morphAttribute );\n\n\t\t\t\t\tif ( this.morphTargetsRelative ) {\n\n\t\t\t\t\t\t_vector$8.addVectors( _box$2.min, _boxMorphTargets.min );\n\t\t\t\t\t\t_box$2.expandByPoint( _vector$8 );\n\n\t\t\t\t\t\t_vector$8.addVectors( _box$2.max, _boxMorphTargets.max );\n\t\t\t\t\t\t_box$2.expandByPoint( _vector$8 );\n\n\t\t\t\t\t} else {\n\n\t\t\t\t\t\t_box$2.expandByPoint( _boxMorphTargets.min );\n\t\t\t\t\t\t_box$2.expandByPoint( _boxMorphTargets.max );\n\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\t_box$2.getCenter( center );\n\n\t\t\t// second, try to find a boundingSphere with a radius smaller than the\n\t\t\t// boundingSphere of the boundingBox: sqrt(3) smaller in the best case\n\n\t\t\tlet maxRadiusSq = 0;\n\n\t\t\tfor ( let i = 0, il = position.count; i < il; i ++ ) {\n\n\t\t\t\t_vector$8.fromBufferAttribute( position, i );\n\n\t\t\t\tmaxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );\n\n\t\t\t}\n\n\t\t\t// process morph attributes if present\n\n\t\t\tif ( morphAttributesPosition ) {\n\n\t\t\t\tfor ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {\n\n\t\t\t\t\tconst morphAttribute = morphAttributesPosition[ i ];\n\t\t\t\t\tconst morphTargetsRelative = this.morphTargetsRelative;\n\n\t\t\t\t\tfor ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {\n\n\t\t\t\t\t\t_vector$8.fromBufferAttribute( morphAttribute, j );\n\n\t\t\t\t\t\tif ( morphTargetsRelative ) {\n\n\t\t\t\t\t\t\t_offset.fromBufferAttribute( position, j );\n\t\t\t\t\t\t\t_vector$8.add( _offset );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tmaxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );\n\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tthis.boundingSphere.radius = Math.sqrt( maxRadiusSq );\n\n\t\t\tif ( isNaN( this.boundingSphere.radius ) ) {\n\n\t\t\t\tconsole.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The \"position\" attribute is likely to have NaN values.', this );\n\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\tcomputeTangents() {\n\n\t\tconst index = this.index;\n\t\tconst attributes = this.attributes;\n\n\t\t// based on http://www.terathon.com/code/tangent.html\n\t\t// (per vertex tangents)\n\n\t\tif ( index === null ||\n\t\t\t attributes.position === undefined ||\n\t\t\t attributes.normal === undefined ||\n\t\t\t attributes.uv === undefined ) {\n\n\t\t\tconsole.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );\n\t\t\treturn;\n\n\t\t}\n\n\t\tconst positionAttribute = attributes.position;\n\t\tconst normalAttribute = attributes.normal;\n\t\tconst uvAttribute = attributes.uv;\n\n\t\tif ( this.hasAttribute( 'tangent' ) === false ) {\n\n\t\t\tthis.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * positionAttribute.count ), 4 ) );\n\n\t\t}\n\n\t\tconst tangentAttribute = this.getAttribute( 'tangent' );\n\n\t\tconst tan1 = [], tan2 = [];\n\n\t\tfor ( let i = 0; i < positionAttribute.count; i ++ ) {\n\n\t\t\ttan1[ i ] = new Vector3();\n\t\t\ttan2[ i ] = new Vector3();\n\n\t\t}\n\n\t\tconst vA = new Vector3(),\n\t\t\tvB = new Vector3(),\n\t\t\tvC = new Vector3(),\n\n\t\t\tuvA = new Vector2(),\n\t\t\tuvB = new Vector2(),\n\t\t\tuvC = new Vector2(),\n\n\t\t\tsdir = new Vector3(),\n\t\t\ttdir = new Vector3();\n\n\t\tfunction handleTriangle( a, b, c ) {\n\n\t\t\tvA.fromBufferAttribute( positionAttribute, a );\n\t\t\tvB.fromBufferAttribute( positionAttribute, b );\n\t\t\tvC.fromBufferAttribute( positionAttribute, c );\n\n\t\t\tuvA.fromBufferAttribute( uvAttribute, a );\n\t\t\tuvB.fromBufferAttribute( uvAttribute, b );\n\t\t\tuvC.fromBufferAttribute( uvAttribute, c );\n\n\t\t\tvB.sub( vA );\n\t\t\tvC.sub( vA );\n\n\t\t\tuvB.sub( uvA );\n\t\t\tuvC.sub( uvA );\n\n\t\t\tconst r = 1.0 / ( uvB.x * uvC.y - uvC.x * uvB.y );\n\n\t\t\t// silently ignore degenerate uv triangles having coincident or colinear vertices\n\n\t\t\tif ( ! isFinite( r ) ) return;\n\n\t\t\tsdir.copy( vB ).multiplyScalar( uvC.y ).addScaledVector( vC, - uvB.y ).multiplyScalar( r );\n\t\t\ttdir.copy( vC ).multiplyScalar( uvB.x ).addScaledVector( vB, - uvC.x ).multiplyScalar( r );\n\n\t\t\ttan1[ a ].add( sdir );\n\t\t\ttan1[ b ].add( sdir );\n\t\t\ttan1[ c ].add( sdir );\n\n\t\t\ttan2[ a ].add( tdir );\n\t\t\ttan2[ b ].add( tdir );\n\t\t\ttan2[ c ].add( tdir );\n\n\t\t}\n\n\t\tlet groups = this.groups;\n\n\t\tif ( groups.length === 0 ) {\n\n\t\t\tgroups = [ {\n\t\t\t\tstart: 0,\n\t\t\t\tcount: index.count\n\t\t\t} ];\n\n\t\t}\n\n\t\tfor ( let i = 0, il = groups.length; i < il; ++ i ) {\n\n\t\t\tconst group = groups[ i ];\n\n\t\t\tconst start = group.start;\n\t\t\tconst count = group.count;\n\n\t\t\tfor ( let j = start, jl = start + count; j < jl; j += 3 ) {\n\n\t\t\t\thandleTriangle(\n\t\t\t\t\tindex.getX( j + 0 ),\n\t\t\t\t\tindex.getX( j + 1 ),\n\t\t\t\t\tindex.getX( j + 2 )\n\t\t\t\t);\n\n\t\t\t}\n\n\t\t}\n\n\t\tconst tmp = new Vector3(), tmp2 = new Vector3();\n\t\tconst n = new Vector3(), n2 = new Vector3();\n\n\t\tfunction handleVertex( v ) {\n\n\t\t\tn.fromBufferAttribute( normalAttribute, v );\n\t\t\tn2.copy( n );\n\n\t\t\tconst t = tan1[ v ];\n\n\t\t\t// Gram-Schmidt orthogonalize\n\n\t\t\ttmp.copy( t );\n\t\t\ttmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();\n\n\t\t\t// Calculate handedness\n\n\t\t\ttmp2.crossVectors( n2, t );\n\t\t\tconst test = tmp2.dot( tan2[ v ] );\n\t\t\tconst w = ( test < 0.0 ) ? - 1.0 : 1.0;\n\n\t\t\ttangentAttribute.setXYZW( v, tmp.x, tmp.y, tmp.z, w );\n\n\t\t}\n\n\t\tfor ( let i = 0, il = groups.length; i < il; ++ i ) {\n\n\t\t\tconst group = groups[ i ];\n\n\t\t\tconst start = group.start;\n\t\t\tconst count = group.count;\n\n\t\t\tfor ( let j = start, jl = start + count; j < jl; j += 3 ) {\n\n\t\t\t\thandleVertex( index.getX( j + 0 ) );\n\t\t\t\thandleVertex( index.getX( j + 1 ) );\n\t\t\t\thandleVertex( index.getX( j + 2 ) );\n\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\tcomputeVertexNormals() {\n\n\t\tconst index = this.index;\n\t\tconst positionAttribute = this.getAttribute( 'position' );\n\n\t\tif ( positionAttribute !== undefined ) {\n\n\t\t\tlet normalAttribute = this.getAttribute( 'normal' );\n\n\t\t\tif ( normalAttribute === undefined ) {\n\n\t\t\t\tnormalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );\n\t\t\t\tthis.setAttribute( 'normal', normalAttribute );\n\n\t\t\t} else {\n\n\t\t\t\t// reset existing normals to zero\n\n\t\t\t\tfor ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {\n\n\t\t\t\t\tnormalAttribute.setXYZ( i, 0, 0, 0 );\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tconst pA = new Vector3(), pB = new Vector3(), pC = new Vector3();\n\t\t\tconst nA = new Vector3(), nB = new Vector3(), nC = new Vector3();\n\t\t\tconst cb = new Vector3(), ab = new Vector3();\n\n\t\t\t// indexed elements\n\n\t\t\tif ( index ) {\n\n\t\t\t\tfor ( let i = 0, il = index.count; i < il; i += 3 ) {\n\n\t\t\t\t\tconst vA = index.getX( i + 0 );\n\t\t\t\t\tconst vB = index.getX( i + 1 );\n\t\t\t\t\tconst vC = index.getX( i + 2 );\n\n\t\t\t\t\tpA.fromBufferAttribute( positionAttribute, vA );\n\t\t\t\t\tpB.fromBufferAttribute( positionAttribute, vB );\n\t\t\t\t\tpC.fromBufferAttribute( positionAttribute, vC );\n\n\t\t\t\t\tcb.subVectors( pC, pB );\n\t\t\t\t\tab.subVectors( pA, pB );\n\t\t\t\t\tcb.cross( ab );\n\n\t\t\t\t\tnA.fromBufferAttribute( normalAttribute, vA );\n\t\t\t\t\tnB.fromBufferAttribute( normalAttribute, vB );\n\t\t\t\t\tnC.fromBufferAttribute( normalAttribute, vC );\n\n\t\t\t\t\tnA.add( cb );\n\t\t\t\t\tnB.add( cb );\n\t\t\t\t\tnC.add( cb );\n\n\t\t\t\t\tnormalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );\n\t\t\t\t\tnormalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );\n\t\t\t\t\tnormalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );\n\n\t\t\t\t}\n\n\t\t\t} else {\n\n\t\t\t\t// non-indexed elements (unconnected triangle soup)\n\n\t\t\t\tfor ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {\n\n\t\t\t\t\tpA.fromBufferAttribute( positionAttribute, i + 0 );\n\t\t\t\t\tpB.fromBufferAttribute( positionAttribute, i + 1 );\n\t\t\t\t\tpC.fromBufferAttribute( positionAttribute, i + 2 );\n\n\t\t\t\t\tcb.subVectors( pC, pB );\n\t\t\t\t\tab.subVectors( pA, pB );\n\t\t\t\t\tcb.cross( ab );\n\n\t\t\t\t\tnormalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );\n\t\t\t\t\tnormalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );\n\t\t\t\t\tnormalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tthis.normalizeNormals();\n\n\t\t\tnormalAttribute.needsUpdate = true;\n\n\t\t}\n\n\t}\n\n\tnormalizeNormals() {\n\n\t\tconst normals = this.attributes.normal;\n\n\t\tfor ( let i = 0, il = normals.count; i < il; i ++ ) {\n\n\t\t\t_vector$8.fromBufferAttribute( normals, i );\n\n\t\t\t_vector$8.normalize();\n\n\t\t\tnormals.setXYZ( i, _vector$8.x, _vector$8.y, _vector$8.z );\n\n\t\t}\n\n\t}\n\n\ttoNonIndexed() {\n\n\t\tfunction convertBufferAttribute( attribute, indices ) {\n\n\t\t\tconst array = attribute.array;\n\t\t\tconst itemSize = attribute.itemSize;\n\t\t\tconst normalized = attribute.normalized;\n\n\t\t\tconst array2 = new array.constructor( indices.length * itemSize );\n\n\t\t\tlet index = 0, index2 = 0;\n\n\t\t\tfor ( let i = 0, l = indices.length; i < l; i ++ ) {\n\n\t\t\t\tif ( attribute.isInterleavedBufferAttribute ) {\n\n\t\t\t\t\tindex = indices[ i ] * attribute.data.stride + attribute.offset;\n\n\t\t\t\t} else {\n\n\t\t\t\t\tindex = indices[ i ] * itemSize;\n\n\t\t\t\t}\n\n\t\t\t\tfor ( let j = 0; j < itemSize; j ++ ) {\n\n\t\t\t\t\tarray2[ index2 ++ ] = array[ index ++ ];\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\treturn new BufferAttribute( array2, itemSize, normalized );\n\n\t\t}\n\n\t\t//\n\n\t\tif ( this.index === null ) {\n\n\t\t\tconsole.warn( 'THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.' );\n\t\t\treturn this;\n\n\t\t}\n\n\t\tconst geometry2 = new BufferGeometry();\n\n\t\tconst indices = this.index.array;\n\t\tconst attributes = this.attributes;\n\n\t\t// attributes\n\n\t\tfor ( const name in attributes ) {\n\n\t\t\tconst attribute = attributes[ name ];\n\n\t\t\tconst newAttribute = convertBufferAttribute( attribute, indices );\n\n\t\t\tgeometry2.setAttribute( name, newAttribute );\n\n\t\t}\n\n\t\t// morph attributes\n\n\t\tconst morphAttributes = this.morphAttributes;\n\n\t\tfor ( const name in morphAttributes ) {\n\n\t\t\tconst morphArray = [];\n\t\t\tconst morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes\n\n\t\t\tfor ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {\n\n\t\t\t\tconst attribute = morphAttribute[ i ];\n\n\t\t\t\tconst newAttribute = convertBufferAttribute( attribute, indices );\n\n\t\t\t\tmorphArray.push( newAttribute );\n\n\t\t\t}\n\n\t\t\tgeometry2.morphAttributes[ name ] = morphArray;\n\n\t\t}\n\n\t\tgeometry2.morphTargetsRelative = this.morphTargetsRelative;\n\n\t\t// groups\n\n\t\tconst groups = this.groups;\n\n\t\tfor ( let i = 0, l = groups.length; i < l; i ++ ) {\n\n\t\t\tconst group = groups[ i ];\n\t\t\tgeometry2.addGroup( group.start, group.count, group.materialIndex );\n\n\t\t}\n\n\t\treturn geometry2;\n\n\t}\n\n\ttoJSON() {\n\n\t\tconst data = {\n\t\t\tmetadata: {\n\t\t\t\tversion: 4.6,\n\t\t\t\ttype: 'BufferGeometry',\n\t\t\t\tgenerator: 'BufferGeometry.toJSON'\n\t\t\t}\n\t\t};\n\n\t\t// standard BufferGeometry serialization\n\n\t\tdata.uuid = this.uuid;\n\t\tdata.type = this.type;\n\t\tif ( this.name !== '' ) data.name = this.name;\n\t\tif ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;\n\n\t\tif ( this.parameters !== undefined ) {\n\n\t\t\tconst parameters = this.parameters;\n\n\t\t\tfor ( const key in parameters ) {\n\n\t\t\t\tif ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];\n\n\t\t\t}\n\n\t\t\treturn data;\n\n\t\t}\n\n\t\t// for simplicity the code assumes attributes are not shared across geometries, see #15811\n\n\t\tdata.data = { attributes: {} };\n\n\t\tconst index = this.index;\n\n\t\tif ( index !== null ) {\n\n\t\t\tdata.data.index = {\n\t\t\t\ttype: index.array.constructor.name,\n\t\t\t\tarray: Array.prototype.slice.call( index.array )\n\t\t\t};\n\n\t\t}\n\n\t\tconst attributes = this.attributes;\n\n\t\tfor ( const key in attributes ) {\n\n\t\t\tconst attribute = attributes[ key ];\n\n\t\t\tdata.data.attributes[ key ] = attribute.toJSON( data.data );\n\n\t\t}\n\n\t\tconst morphAttributes = {};\n\t\tlet hasMorphAttributes = false;\n\n\t\tfor ( const key in this.morphAttributes ) {\n\n\t\t\tconst attributeArray = this.morphAttributes[ key ];\n\n\t\t\tconst array = [];\n\n\t\t\tfor ( let i = 0, il = attributeArray.length; i < il; i ++ ) {\n\n\t\t\t\tconst attribute = attributeArray[ i ];\n\n\t\t\t\tarray.push( attribute.toJSON( data.data ) );\n\n\t\t\t}\n\n\t\t\tif ( array.length > 0 ) {\n\n\t\t\t\tmorphAttributes[ key ] = array;\n\n\t\t\t\thasMorphAttributes = true;\n\n\t\t\t}\n\n\t\t}\n\n\t\tif ( hasMorphAttributes ) {\n\n\t\t\tdata.data.morphAttributes = morphAttributes;\n\t\t\tdata.data.morphTargetsRelative = this.morphTargetsRelative;\n\n\t\t}\n\n\t\tconst groups = this.groups;\n\n\t\tif ( groups.length > 0 ) {\n\n\t\t\tdata.data.groups = JSON.parse( JSON.stringify( groups ) );\n\n\t\t}\n\n\t\tconst boundingSphere = this.boundingSphere;\n\n\t\tif ( boundingSphere !== null ) {\n\n\t\t\tdata.data.boundingSphere = {\n\t\t\t\tcenter: boundingSphere.center.toArray(),\n\t\t\t\tradius: boundingSphere.radius\n\t\t\t};\n\n\t\t}\n\n\t\treturn data;\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n\tcopy( source ) {\n\n\t\t// reset\n\n\t\tthis.index = null;\n\t\tthis.attributes = {};\n\t\tthis.morphAttributes = {};\n\t\tthis.groups = [];\n\t\tthis.boundingBox = null;\n\t\tthis.boundingSphere = null;\n\n\t\t// used for storing cloned, shared data\n\n\t\tconst data = {};\n\n\t\t// name\n\n\t\tthis.name = source.name;\n\n\t\t// index\n\n\t\tconst index = source.index;\n\n\t\tif ( index !== null ) {\n\n\t\t\tthis.setIndex( index.clone( data ) );\n\n\t\t}\n\n\t\t// attributes\n\n\t\tconst attributes = source.attributes;\n\n\t\tfor ( const name in attributes ) {\n\n\t\t\tconst attribute = attributes[ name ];\n\t\t\tthis.setAttribute( name, attribute.clone( data ) );\n\n\t\t}\n\n\t\t// morph attributes\n\n\t\tconst morphAttributes = source.morphAttributes;\n\n\t\tfor ( const name in morphAttributes ) {\n\n\t\t\tconst array = [];\n\t\t\tconst morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes\n\n\t\t\tfor ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {\n\n\t\t\t\tarray.push( morphAttribute[ i ].clone( data ) );\n\n\t\t\t}\n\n\t\t\tthis.morphAttributes[ name ] = array;\n\n\t\t}\n\n\t\tthis.morphTargetsRelative = source.morphTargetsRelative;\n\n\t\t// groups\n\n\t\tconst groups = source.groups;\n\n\t\tfor ( let i = 0, l = groups.length; i < l; i ++ ) {\n\n\t\t\tconst group = groups[ i ];\n\t\t\tthis.addGroup( group.start, group.count, group.materialIndex );\n\n\t\t}\n\n\t\t// bounding box\n\n\t\tconst boundingBox = source.boundingBox;\n\n\t\tif ( boundingBox !== null ) {\n\n\t\t\tthis.boundingBox = boundingBox.clone();\n\n\t\t}\n\n\t\t// bounding sphere\n\n\t\tconst boundingSphere = source.boundingSphere;\n\n\t\tif ( boundingSphere !== null ) {\n\n\t\t\tthis.boundingSphere = boundingSphere.clone();\n\n\t\t}\n\n\t\t// draw range\n\n\t\tthis.drawRange.start = source.drawRange.start;\n\t\tthis.drawRange.count = source.drawRange.count;\n\n\t\t// user data\n\n\t\tthis.userData = source.userData;\n\n\t\treturn this;\n\n\t}\n\n\tdispose() {\n\n\t\tthis.dispatchEvent( { type: 'dispose' } );\n\n\t}\n\n}\n\nconst _inverseMatrix$3 = /*@__PURE__*/ new Matrix4();\nconst _ray$3 = /*@__PURE__*/ new Ray();\nconst _sphere$6 = /*@__PURE__*/ new Sphere();\nconst _sphereHitAt = /*@__PURE__*/ new Vector3();\n\nconst _vA$1 = /*@__PURE__*/ new Vector3();\nconst _vB$1 = /*@__PURE__*/ new Vector3();\nconst _vC$1 = /*@__PURE__*/ new Vector3();\n\nconst _tempA = /*@__PURE__*/ new Vector3();\nconst _morphA = /*@__PURE__*/ new Vector3();\n\nconst _uvA$1 = /*@__PURE__*/ new Vector2();\nconst _uvB$1 = /*@__PURE__*/ new Vector2();\nconst _uvC$1 = /*@__PURE__*/ new Vector2();\n\nconst _normalA = /*@__PURE__*/ new Vector3();\nconst _normalB = /*@__PURE__*/ new Vector3();\nconst _normalC = /*@__PURE__*/ new Vector3();\n\nconst _intersectionPoint = /*@__PURE__*/ new Vector3();\nconst _intersectionPointWorld = /*@__PURE__*/ new Vector3();\n\nclass Mesh extends Object3D {\n\n\tconstructor( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {\n\n\t\tsuper();\n\n\t\tthis.isMesh = true;\n\n\t\tthis.type = 'Mesh';\n\n\t\tthis.geometry = geometry;\n\t\tthis.material = material;\n\n\t\tthis.updateMorphTargets();\n\n\t}\n\n\tcopy( source, recursive ) {\n\n\t\tsuper.copy( source, recursive );\n\n\t\tif ( source.morphTargetInfluences !== undefined ) {\n\n\t\t\tthis.morphTargetInfluences = source.morphTargetInfluences.slice();\n\n\t\t}\n\n\t\tif ( source.morphTargetDictionary !== undefined ) {\n\n\t\t\tthis.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );\n\n\t\t}\n\n\t\tthis.material = Array.isArray( source.material ) ? source.material.slice() : source.material;\n\t\tthis.geometry = source.geometry;\n\n\t\treturn this;\n\n\t}\n\n\tupdateMorphTargets() {\n\n\t\tconst geometry = this.geometry;\n\n\t\tconst morphAttributes = geometry.morphAttributes;\n\t\tconst keys = Object.keys( morphAttributes );\n\n\t\tif ( keys.length > 0 ) {\n\n\t\t\tconst morphAttribute = morphAttributes[ keys[ 0 ] ];\n\n\t\t\tif ( morphAttribute !== undefined ) {\n\n\t\t\t\tthis.morphTargetInfluences = [];\n\t\t\t\tthis.morphTargetDictionary = {};\n\n\t\t\t\tfor ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {\n\n\t\t\t\t\tconst name = morphAttribute[ m ].name || String( m );\n\n\t\t\t\t\tthis.morphTargetInfluences.push( 0 );\n\t\t\t\t\tthis.morphTargetDictionary[ name ] = m;\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\tgetVertexPosition( index, target ) {\n\n\t\tconst geometry = this.geometry;\n\t\tconst position = geometry.attributes.position;\n\t\tconst morphPosition = geometry.morphAttributes.position;\n\t\tconst morphTargetsRelative = geometry.morphTargetsRelative;\n\n\t\ttarget.fromBufferAttribute( position, index );\n\n\t\tconst morphInfluences = this.morphTargetInfluences;\n\n\t\tif ( morphPosition && morphInfluences ) {\n\n\t\t\t_morphA.set( 0, 0, 0 );\n\n\t\t\tfor ( let i = 0, il = morphPosition.length; i < il; i ++ ) {\n\n\t\t\t\tconst influence = morphInfluences[ i ];\n\t\t\t\tconst morphAttribute = morphPosition[ i ];\n\n\t\t\t\tif ( influence === 0 ) continue;\n\n\t\t\t\t_tempA.fromBufferAttribute( morphAttribute, index );\n\n\t\t\t\tif ( morphTargetsRelative ) {\n\n\t\t\t\t\t_morphA.addScaledVector( _tempA, influence );\n\n\t\t\t\t} else {\n\n\t\t\t\t\t_morphA.addScaledVector( _tempA.sub( target ), influence );\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\ttarget.add( _morphA );\n\n\t\t}\n\n\t\treturn target;\n\n\t}\n\n\traycast( raycaster, intersects ) {\n\n\t\tconst geometry = this.geometry;\n\t\tconst material = this.material;\n\t\tconst matrixWorld = this.matrixWorld;\n\n\t\tif ( material === undefined ) return;\n\n\t\t// test with bounding sphere in world space\n\n\t\tif ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();\n\n\t\t_sphere$6.copy( geometry.boundingSphere );\n\t\t_sphere$6.applyMatrix4( matrixWorld );\n\n\t\t// check distance from ray origin to bounding sphere\n\n\t\t_ray$3.copy( raycaster.ray ).recast( raycaster.near );\n\n\t\tif ( _sphere$6.containsPoint( _ray$3.origin ) === false ) {\n\n\t\t\tif ( _ray$3.intersectSphere( _sphere$6, _sphereHitAt ) === null ) return;\n\n\t\t\tif ( _ray$3.origin.distanceToSquared( _sphereHitAt ) > ( raycaster.far - raycaster.near ) ** 2 ) return;\n\n\t\t}\n\n\t\t// convert ray to local space of mesh\n\n\t\t_inverseMatrix$3.copy( matrixWorld ).invert();\n\t\t_ray$3.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$3 );\n\n\t\t// test with bounding box in local space\n\n\t\tif ( geometry.boundingBox !== null ) {\n\n\t\t\tif ( _ray$3.intersectsBox( geometry.boundingBox ) === false ) return;\n\n\t\t}\n\n\t\t// test for intersections with geometry\n\n\t\tthis._computeIntersections( raycaster, intersects, _ray$3 );\n\n\t}\n\n\t_computeIntersections( raycaster, intersects, rayLocalSpace ) {\n\n\t\tlet intersection;\n\n\t\tconst geometry = this.geometry;\n\t\tconst material = this.material;\n\n\t\tconst index = geometry.index;\n\t\tconst position = geometry.attributes.position;\n\t\tconst uv = geometry.attributes.uv;\n\t\tconst uv1 = geometry.attributes.uv1;\n\t\tconst normal = geometry.attributes.normal;\n\t\tconst groups = geometry.groups;\n\t\tconst drawRange = geometry.drawRange;\n\n\t\tif ( index !== null ) {\n\n\t\t\t// indexed buffer geometry\n\n\t\t\tif ( Array.isArray( material ) ) {\n\n\t\t\t\tfor ( let i = 0, il = groups.length; i < il; i ++ ) {\n\n\t\t\t\t\tconst group = groups[ i ];\n\t\t\t\t\tconst groupMaterial = material[ group.materialIndex ];\n\n\t\t\t\t\tconst start = Math.max( group.start, drawRange.start );\n\t\t\t\t\tconst end = Math.min( index.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );\n\n\t\t\t\t\tfor ( let j = start, jl = end; j < jl; j += 3 ) {\n\n\t\t\t\t\t\tconst a = index.getX( j );\n\t\t\t\t\t\tconst b = index.getX( j + 1 );\n\t\t\t\t\t\tconst c = index.getX( j + 2 );\n\n\t\t\t\t\t\tintersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );\n\n\t\t\t\t\t\tif ( intersection ) {\n\n\t\t\t\t\t\t\tintersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics\n\t\t\t\t\t\t\tintersection.face.materialIndex = group.materialIndex;\n\t\t\t\t\t\t\tintersects.push( intersection );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\t\t\t} else {\n\n\t\t\t\tconst start = Math.max( 0, drawRange.start );\n\t\t\t\tconst end = Math.min( index.count, ( drawRange.start + drawRange.count ) );\n\n\t\t\t\tfor ( let i = start, il = end; i < il; i += 3 ) {\n\n\t\t\t\t\tconst a = index.getX( i );\n\t\t\t\t\tconst b = index.getX( i + 1 );\n\t\t\t\t\tconst c = index.getX( i + 2 );\n\n\t\t\t\t\tintersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );\n\n\t\t\t\t\tif ( intersection ) {\n\n\t\t\t\t\t\tintersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics\n\t\t\t\t\t\tintersects.push( intersection );\n\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t} else if ( position !== undefined ) {\n\n\t\t\t// non-indexed buffer geometry\n\n\t\t\tif ( Array.isArray( material ) ) {\n\n\t\t\t\tfor ( let i = 0, il = groups.length; i < il; i ++ ) {\n\n\t\t\t\t\tconst group = groups[ i ];\n\t\t\t\t\tconst groupMaterial = material[ group.materialIndex ];\n\n\t\t\t\t\tconst start = Math.max( group.start, drawRange.start );\n\t\t\t\t\tconst end = Math.min( position.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );\n\n\t\t\t\t\tfor ( let j = start, jl = end; j < jl; j += 3 ) {\n\n\t\t\t\t\t\tconst a = j;\n\t\t\t\t\t\tconst b = j + 1;\n\t\t\t\t\t\tconst c = j + 2;\n\n\t\t\t\t\t\tintersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );\n\n\t\t\t\t\t\tif ( intersection ) {\n\n\t\t\t\t\t\t\tintersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics\n\t\t\t\t\t\t\tintersection.face.materialIndex = group.materialIndex;\n\t\t\t\t\t\t\tintersects.push( intersection );\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\t\t\t} else {\n\n\t\t\t\tconst start = Math.max( 0, drawRange.start );\n\t\t\t\tconst end = Math.min( position.count, ( drawRange.start + drawRange.count ) );\n\n\t\t\t\tfor ( let i = start, il = end; i < il; i += 3 ) {\n\n\t\t\t\t\tconst a = i;\n\t\t\t\t\tconst b = i + 1;\n\t\t\t\t\tconst c = i + 2;\n\n\t\t\t\t\tintersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );\n\n\t\t\t\t\tif ( intersection ) {\n\n\t\t\t\t\t\tintersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics\n\t\t\t\t\t\tintersects.push( intersection );\n\n\t\t\t\t\t}\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t}\n\n\t}\n\n}\n\nfunction checkIntersection$1( object, material, raycaster, ray, pA, pB, pC, point ) {\n\n\tlet intersect;\n\n\tif ( material.side === BackSide ) {\n\n\t\tintersect = ray.intersectTriangle( pC, pB, pA, true, point );\n\n\t} else {\n\n\t\tintersect = ray.intersectTriangle( pA, pB, pC, ( material.side === FrontSide ), point );\n\n\t}\n\n\tif ( intersect === null ) return null;\n\n\t_intersectionPointWorld.copy( point );\n\t_intersectionPointWorld.applyMatrix4( object.matrixWorld );\n\n\tconst distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );\n\n\tif ( distance < raycaster.near || distance > raycaster.far ) return null;\n\n\treturn {\n\t\tdistance: distance,\n\t\tpoint: _intersectionPointWorld.clone(),\n\t\tobject: object\n\t};\n\n}\n\nfunction checkGeometryIntersection( object, material, raycaster, ray, uv, uv1, normal, a, b, c ) {\n\n\tobject.getVertexPosition( a, _vA$1 );\n\tobject.getVertexPosition( b, _vB$1 );\n\tobject.getVertexPosition( c, _vC$1 );\n\n\tconst intersection = checkIntersection$1( object, material, raycaster, ray, _vA$1, _vB$1, _vC$1, _intersectionPoint );\n\n\tif ( intersection ) {\n\n\t\tif ( uv ) {\n\n\t\t\t_uvA$1.fromBufferAttribute( uv, a );\n\t\t\t_uvB$1.fromBufferAttribute( uv, b );\n\t\t\t_uvC$1.fromBufferAttribute( uv, c );\n\n\t\t\tintersection.uv = Triangle.getInterpolation( _intersectionPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() );\n\n\t\t}\n\n\t\tif ( uv1 ) {\n\n\t\t\t_uvA$1.fromBufferAttribute( uv1, a );\n\t\t\t_uvB$1.fromBufferAttribute( uv1, b );\n\t\t\t_uvC$1.fromBufferAttribute( uv1, c );\n\n\t\t\tintersection.uv1 = Triangle.getInterpolation( _intersectionPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() );\n\n\t\t}\n\n\t\tif ( normal ) {\n\n\t\t\t_normalA.fromBufferAttribute( normal, a );\n\t\t\t_normalB.fromBufferAttribute( normal, b );\n\t\t\t_normalC.fromBufferAttribute( normal, c );\n\n\t\t\tintersection.normal = Triangle.getInterpolation( _intersectionPoint, _vA$1, _vB$1, _vC$1, _normalA, _normalB, _normalC, new Vector3() );\n\n\t\t\tif ( intersection.normal.dot( ray.direction ) > 0 ) {\n\n\t\t\t\tintersection.normal.multiplyScalar( - 1 );\n\n\t\t\t}\n\n\t\t}\n\n\t\tconst face = {\n\t\t\ta: a,\n\t\t\tb: b,\n\t\t\tc: c,\n\t\t\tnormal: new Vector3(),\n\t\t\tmaterialIndex: 0\n\t\t};\n\n\t\tTriangle.getNormal( _vA$1, _vB$1, _vC$1, face.normal );\n\n\t\tintersection.face = face;\n\n\t}\n\n\treturn intersection;\n\n}\n\nclass BoxGeometry extends BufferGeometry {\n\n\tconstructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {\n\n\t\tsuper();\n\n\t\tthis.type = 'BoxGeometry';\n\n\t\tthis.parameters = {\n\t\t\twidth: width,\n\t\t\theight: height,\n\t\t\tdepth: depth,\n\t\t\twidthSegments: widthSegments,\n\t\t\theightSegments: heightSegments,\n\t\t\tdepthSegments: depthSegments\n\t\t};\n\n\t\tconst scope = this;\n\n\t\t// segments\n\n\t\twidthSegments = Math.floor( widthSegments );\n\t\theightSegments = Math.floor( heightSegments );\n\t\tdepthSegments = Math.floor( depthSegments );\n\n\t\t// buffers\n\n\t\tconst indices = [];\n\t\tconst vertices = [];\n\t\tconst normals = [];\n\t\tconst uvs = [];\n\n\t\t// helper variables\n\n\t\tlet numberOfVertices = 0;\n\t\tlet groupStart = 0;\n\n\t\t// build each side of the box geometry\n\n\t\tbuildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px\n\t\tbuildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx\n\t\tbuildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py\n\t\tbuildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny\n\t\tbuildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz\n\t\tbuildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz\n\n\t\t// build geometry\n\n\t\tthis.setIndex( indices );\n\t\tthis.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );\n\t\tthis.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );\n\t\tthis.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );\n\n\t\tfunction buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {\n\n\t\t\tconst segmentWidth = width / gridX;\n\t\t\tconst segmentHeight = height / gridY;\n\n\t\t\tconst widthHalf = width / 2;\n\t\t\tconst heightHalf = height / 2;\n\t\t\tconst depthHalf = depth / 2;\n\n\t\t\tconst gridX1 = gridX + 1;\n\t\t\tconst gridY1 = gridY + 1;\n\n\t\t\tlet vertexCounter = 0;\n\t\t\tlet groupCount = 0;\n\n\t\t\tconst vector = new Vector3();\n\n\t\t\t// generate vertices, normals and uvs\n\n\t\t\tfor ( let iy = 0; iy < gridY1; iy ++ ) {\n\n\t\t\t\tconst y = iy * segmentHeight - heightHalf;\n\n\t\t\t\tfor ( let ix = 0; ix < gridX1; ix ++ ) {\n\n\t\t\t\t\tconst x = ix * segmentWidth - widthHalf;\n\n\t\t\t\t\t// set values to correct vector component\n\n\t\t\t\t\tvector[ u ] = x * udir;\n\t\t\t\t\tvector[ v ] = y * vdir;\n\t\t\t\t\tvector[ w ] = depthHalf;\n\n\t\t\t\t\t// now apply vector to vertex buffer\n\n\t\t\t\t\tvertices.push( vector.x, vector.y, vector.z );\n\n\t\t\t\t\t// set values to correct vector component\n\n\t\t\t\t\tvector[ u ] = 0;\n\t\t\t\t\tvector[ v ] = 0;\n\t\t\t\t\tvector[ w ] = depth > 0 ? 1 : - 1;\n\n\t\t\t\t\t// now apply vector to normal buffer\n\n\t\t\t\t\tnormals.push( vector.x, vector.y, vector.z );\n\n\t\t\t\t\t// uvs\n\n\t\t\t\t\tuvs.push( ix / gridX );\n\t\t\t\t\tuvs.push( 1 - ( iy / gridY ) );\n\n\t\t\t\t\t// counters\n\n\t\t\t\t\tvertexCounter += 1;\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\t// indices\n\n\t\t\t// 1. you need three indices to draw a single face\n\t\t\t// 2. a single segment consists of two faces\n\t\t\t// 3. so we need to generate six (2*3) indices per segment\n\n\t\t\tfor ( let iy = 0; iy < gridY; iy ++ ) {\n\n\t\t\t\tfor ( let ix = 0; ix < gridX; ix ++ ) {\n\n\t\t\t\t\tconst a = numberOfVertices + ix + gridX1 * iy;\n\t\t\t\t\tconst b = numberOfVertices + ix + gridX1 * ( iy + 1 );\n\t\t\t\t\tconst c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );\n\t\t\t\t\tconst d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;\n\n\t\t\t\t\t// faces\n\n\t\t\t\t\tindices.push( a, b, d );\n\t\t\t\t\tindices.push( b, c, d );\n\n\t\t\t\t\t// increase counter\n\n\t\t\t\t\tgroupCount += 6;\n\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\t// add a group to the geometry. this will ensure multi material support\n\n\t\t\tscope.addGroup( groupStart, groupCount, materialIndex );\n\n\t\t\t// calculate new start value for groups\n\n\t\t\tgroupStart += groupCount;\n\n\t\t\t// update total number of vertices\n\n\t\t\tnumberOfVertices += vertexCounter;\n\n\t\t}\n\n\t}\n\n\tcopy( source ) {\n\n\t\tsuper.copy( source );\n\n\t\tthis.parameters = Object.assign( {}, source.parameters );\n\n\t\treturn this;\n\n\t}\n\n\tstatic fromJSON( data ) {\n\n\t\treturn new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments );\n\n\t}\n\n}\n\n/**\n * Uniform Utilities\n */\n\nfunction cloneUniforms( src ) {\n\n\tconst dst = {};\n\n\tfor ( const u in src ) {\n\n\t\tdst[ u ] = {};\n\n\t\tfor ( const p in src[ u ] ) {\n\n\t\t\tconst property = src[ u ][ p ];\n\n\t\t\tif ( property && ( property.isColor ||\n\t\t\t\tproperty.isMatrix3 || property.isMatrix4 ||\n\t\t\t\tproperty.isVector2 || property.isVector3 || property.isVector4 ||\n\t\t\t\tproperty.isTexture || property.isQuaternion ) ) {\n\n\t\t\t\tif ( property.isRenderTargetTexture ) {\n\n\t\t\t\t\tconsole.warn( 'UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().' );\n\t\t\t\t\tdst[ u ][ p ] = null;\n\n\t\t\t\t} else {\n\n\t\t\t\t\tdst[ u ][ p ] = property.clone();\n\n\t\t\t\t}\n\n\t\t\t} else if ( Array.isArray( property ) ) {\n\n\t\t\t\tdst[ u ][ p ] = property.slice();\n\n\t\t\t} else {\n\n\t\t\t\tdst[ u ][ p ] = property;\n\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\treturn dst;\n\n}\n\nfunction mergeUniforms( uniforms ) {\n\n\tconst merged = {};\n\n\tfor ( let u = 0; u < uniforms.length; u ++ ) {\n\n\t\tconst tmp = cloneUniforms( uniforms[ u ] );\n\n\t\tfor ( const p in tmp ) {\n\n\t\t\tmerged[ p ] = tmp[ p ];\n\n\t\t}\n\n\t}\n\n\treturn merged;\n\n}\n\nfunction cloneUniformsGroups( src ) {\n\n\tconst dst = [];\n\n\tfor ( let u = 0; u < src.length; u ++ ) {\n\n\t\tdst.push( src[ u ].clone() );\n\n\t}\n\n\treturn dst;\n\n}\n\nfunction getUnlitUniformColorSpace( renderer ) {\n\n\tconst currentRenderTarget = renderer.getRenderTarget();\n\n\tif ( currentRenderTarget === null ) {\n\n\t\t// https://github.com/mrdoob/three.js/pull/23937#issuecomment-1111067398\n\t\treturn renderer.outputColorSpace;\n\n\t}\n\n\t// https://github.com/mrdoob/three.js/issues/27868\n\tif ( currentRenderTarget.isXRRenderTarget === true ) {\n\n\t\treturn currentRenderTarget.texture.colorSpace;\n\n\t}\n\n\treturn ColorManagement.workingColorSpace;\n\n}\n\n// Legacy\n\nconst UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };\n\nvar default_vertex = \"void main() {\\n\\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\\n}\";\n\nvar default_fragment = \"void main() {\\n\\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\\n}\";\n\nclass ShaderMaterial extends Material {\n\n\tconstructor( parameters ) {\n\n\t\tsuper();\n\n\t\tthis.isShaderMaterial = true;\n\n\t\tthis.type = 'ShaderMaterial';\n\n\t\tthis.defines = {};\n\t\tthis.uniforms = {};\n\t\tthis.uniformsGroups = [];\n\n\t\tthis.vertexShader = default_vertex;\n\t\tthis.fragmentShader = default_fragment;\n\n\t\tthis.linewidth = 1;\n\n\t\tthis.wireframe = false;\n\t\tthis.wireframeLinewidth = 1;\n\n\t\tthis.fog = false; // set to use scene fog\n\t\tthis.lights = false; // set to use scene lights\n\t\tthis.clipping = false; // set to use user-defined clipping planes\n\n\t\tthis.forceSinglePass = true;\n\n\t\tthis.extensions = {\n\t\t\tclipCullDistance: false, // set to use vertex shader clipping\n\t\t\tmultiDraw: false // set to use vertex shader multi_draw / enable gl_DrawID\n\t\t};\n\n\t\t// When rendered geometry doesn't include these attributes but the material does,\n\t\t// use these default values in WebGL. This avoids errors when buffer data is missing.\n\t\tthis.defaultAttributeValues = {\n\t\t\t'color': [ 1, 1, 1 ],\n\t\t\t'uv': [ 0, 0 ],\n\t\t\t'uv1': [ 0, 0 ]\n\t\t};\n\n\t\tthis.index0AttributeName = undefined;\n\t\tthis.uniformsNeedUpdate = false;\n\n\t\tthis.glslVersion = null;\n\n\t\tif ( parameters !== undefined ) {\n\n\t\t\tthis.setValues( parameters );\n\n\t\t}\n\n\t}\n\n\tcopy( source ) {\n\n\t\tsuper.copy( source );\n\n\t\tthis.fragmentShader = source.fragmentShader;\n\t\tthis.vertexShader = source.vertexShader;\n\n\t\tthis.uniforms = cloneUniforms( source.uniforms );\n\t\tthis.uniformsGroups = cloneUniformsGroups( source.uniformsGroups );\n\n\t\tthis.defines = Object.assign( {}, source.defines );\n\n\t\tthis.wireframe = source.wireframe;\n\t\tthis.wireframeLinewidth = source.wireframeLinewidth;\n\n\t\tthis.fog = source.fog;\n\t\tthis.lights = source.lights;\n\t\tthis.clipping = source.clipping;\n\n\t\tthis.extensions = Object.assign( {}, source.extensions );\n\n\t\tthis.glslVersion = source.glslVersion;\n\n\t\treturn this;\n\n\t}\n\n\ttoJSON( meta ) {\n\n\t\tconst data = super.toJSON( meta );\n\n\t\tdata.glslVersion = this.glslVersion;\n\t\tdata.uniforms = {};\n\n\t\tfor ( const name in this.uniforms ) {\n\n\t\t\tconst uniform = this.uniforms[ name ];\n\t\t\tconst value = uniform.value;\n\n\t\t\tif ( value && value.isTexture ) {\n\n\t\t\t\tdata.uniforms[ name ] = {\n\t\t\t\t\ttype: 't',\n\t\t\t\t\tvalue: value.toJSON( meta ).uuid\n\t\t\t\t};\n\n\t\t\t} else if ( value && value.isColor ) {\n\n\t\t\t\tdata.uniforms[ name ] = {\n\t\t\t\t\ttype: 'c',\n\t\t\t\t\tvalue: value.getHex()\n\t\t\t\t};\n\n\t\t\t} else if ( value && value.isVector2 ) {\n\n\t\t\t\tdata.uniforms[ name ] = {\n\t\t\t\t\ttype: 'v2',\n\t\t\t\t\tvalue: value.toArray()\n\t\t\t\t};\n\n\t\t\t} else if ( value && value.isVector3 ) {\n\n\t\t\t\tdata.uniforms[ name ] = {\n\t\t\t\t\ttype: 'v3',\n\t\t\t\t\tvalue: value.toArray()\n\t\t\t\t};\n\n\t\t\t} else if ( value && value.isVector4 ) {\n\n\t\t\t\tdata.uniforms[ name ] = {\n\t\t\t\t\ttype: 'v4',\n\t\t\t\t\tvalue: value.toArray()\n\t\t\t\t};\n\n\t\t\t} else if ( value && value.isMatrix3 ) {\n\n\t\t\t\tdata.uniforms[ name ] = {\n\t\t\t\t\ttype: 'm3',\n\t\t\t\t\tvalue: value.toArray()\n\t\t\t\t};\n\n\t\t\t} else if ( value && value.isMatrix4 ) {\n\n\t\t\t\tdata.uniforms[ name ] = {\n\t\t\t\t\ttype: 'm4',\n\t\t\t\t\tvalue: value.toArray()\n\t\t\t\t};\n\n\t\t\t} else {\n\n\t\t\t\tdata.uniforms[ name ] = {\n\t\t\t\t\tvalue: value\n\t\t\t\t};\n\n\t\t\t\t// note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far\n\n\t\t\t}\n\n\t\t}\n\n\t\tif ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;\n\n\t\tdata.vertexShader = this.vertexShader;\n\t\tdata.fragmentShader = this.fragmentShader;\n\n\t\tdata.lights = this.lights;\n\t\tdata.clipping = this.clipping;\n\n\t\tconst extensions = {};\n\n\t\tfor ( const key in this.extensions ) {\n\n\t\t\tif ( this.extensions[ key ] === true ) extensions[ key ] = true;\n\n\t\t}\n\n\t\tif ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;\n\n\t\treturn data;\n\n\t}\n\n}\n\nclass Camera extends Object3D {\n\n\tconstructor() {\n\n\t\tsuper();\n\n\t\tthis.isCamera = true;\n\n\t\tthis.type = 'Camera';\n\n\t\tthis.matrixWorldInverse = new Matrix4();\n\n\t\tthis.projectionMatrix = new Matrix4();\n\t\tthis.projectionMatrixInverse = new Matrix4();\n\n\t\tthis.coordinateSystem = WebGLCoordinateSystem;\n\n\t}\n\n\tcopy( source, recursive ) {\n\n\t\tsuper.copy( source, recursive );\n\n\t\tthis.matrixWorldInverse.copy( source.matrixWorldInverse );\n\n\t\tthis.projectionMatrix.copy( source.projectionMatrix );\n\t\tthis.projectionMatrixInverse.copy( source.projectionMatrixInverse );\n\n\t\tthis.coordinateSystem = source.coordinateSystem;\n\n\t\treturn this;\n\n\t}\n\n\tgetWorldDirection( target ) {\n\n\t\treturn super.getWorldDirection( target ).negate();\n\n\t}\n\n\tupdateMatrixWorld( force ) {\n\n\t\tsuper.updateMatrixWorld( force );\n\n\t\tthis.matrixWorldInverse.copy( this.matrixWorld ).invert();\n\n\t}\n\n\tupdateWorldMatrix( updateParents, updateChildren ) {\n\n\t\tsuper.updateWorldMatrix( updateParents, updateChildren );\n\n\t\tthis.matrixWorldInverse.copy( this.matrixWorld ).invert();\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n}\n\nconst _v3$1 = /*@__PURE__*/ new Vector3();\nconst _minTarget = /*@__PURE__*/ new Vector2();\nconst _maxTarget = /*@__PURE__*/ new Vector2();\n\n\nclass PerspectiveCamera extends Camera {\n\n\tconstructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {\n\n\t\tsuper();\n\n\t\tthis.isPerspectiveCamera = true;\n\n\t\tthis.type = 'PerspectiveCamera';\n\n\t\tthis.fov = fov;\n\t\tthis.zoom = 1;\n\n\t\tthis.near = near;\n\t\tthis.far = far;\n\t\tthis.focus = 10;\n\n\t\tthis.aspect = aspect;\n\t\tthis.view = null;\n\n\t\tthis.filmGauge = 35;\t// width of the film (default in millimeters)\n\t\tthis.filmOffset = 0;\t// horizontal film offset (same unit as gauge)\n\n\t\tthis.updateProjectionMatrix();\n\n\t}\n\n\tcopy( source, recursive ) {\n\n\t\tsuper.copy( source, recursive );\n\n\t\tthis.fov = source.fov;\n\t\tthis.zoom = source.zoom;\n\n\t\tthis.near = source.near;\n\t\tthis.far = source.far;\n\t\tthis.focus = source.focus;\n\n\t\tthis.aspect = source.aspect;\n\t\tthis.view = source.view === null ? null : Object.assign( {}, source.view );\n\n\t\tthis.filmGauge = source.filmGauge;\n\t\tthis.filmOffset = source.filmOffset;\n\n\t\treturn this;\n\n\t}\n\n\t/**\n\t * Sets the FOV by focal length in respect to the current .filmGauge.\n\t *\n\t * The default film gauge is 35, so that the focal length can be specified for\n\t * a 35mm (full frame) camera.\n\t *\n\t * Values for focal length and film gauge must have the same unit.\n\t */\n\tsetFocalLength( focalLength ) {\n\n\t\t/** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */\n\t\tconst vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;\n\n\t\tthis.fov = RAD2DEG * 2 * Math.atan( vExtentSlope );\n\t\tthis.updateProjectionMatrix();\n\n\t}\n\n\t/**\n\t * Calculates the focal length from the current .fov and .filmGauge.\n\t */\n\tgetFocalLength() {\n\n\t\tconst vExtentSlope = Math.tan( DEG2RAD * 0.5 * this.fov );\n\n\t\treturn 0.5 * this.getFilmHeight() / vExtentSlope;\n\n\t}\n\n\tgetEffectiveFOV() {\n\n\t\treturn RAD2DEG * 2 * Math.atan(\n\t\t\tMath.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom );\n\n\t}\n\n\tgetFilmWidth() {\n\n\t\t// film not completely covered in portrait format (aspect < 1)\n\t\treturn this.filmGauge * Math.min( this.aspect, 1 );\n\n\t}\n\n\tgetFilmHeight() {\n\n\t\t// film not completely covered in landscape format (aspect > 1)\n\t\treturn this.filmGauge / Math.max( this.aspect, 1 );\n\n\t}\n\n\t/**\n\t * Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.\n\t * Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corners of the view rectangle.\n\t */\n\tgetViewBounds( distance, minTarget, maxTarget ) {\n\n\t\t_v3$1.set( - 1, - 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );\n\n\t\tminTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );\n\n\t\t_v3$1.set( 1, 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );\n\n\t\tmaxTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );\n\n\t}\n\n\t/**\n\t * Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.\n\t * Copies the result into the target Vector2, where x is width and y is height.\n\t */\n\tgetViewSize( distance, target ) {\n\n\t\tthis.getViewBounds( distance, _minTarget, _maxTarget );\n\n\t\treturn target.subVectors( _maxTarget, _minTarget );\n\n\t}\n\n\t/**\n\t * Sets an offset in a larger frustum. This is useful for multi-window or\n\t * multi-monitor/multi-machine setups.\n\t *\n\t * For example, if you have 3x2 monitors and each monitor is 1920x1080 and\n\t * the monitors are in grid like this\n\t *\n\t * +---+---+---+\n\t * | A | B | C |\n\t * +---+---+---+\n\t * | D | E | F |\n\t * +---+---+---+\n\t *\n\t * then for each monitor you would call it like this\n\t *\n\t * const w = 1920;\n\t * const h = 1080;\n\t * const fullWidth = w * 3;\n\t * const fullHeight = h * 2;\n\t *\n\t * --A--\n\t * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );\n\t * --B--\n\t * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );\n\t * --C--\n\t * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );\n\t * --D--\n\t * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );\n\t * --E--\n\t * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );\n\t * --F--\n\t * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );\n\t *\n\t * Note there is no reason monitors have to be the same size or in a grid.\n\t */\n\tsetViewOffset( fullWidth, fullHeight, x, y, width, height ) {\n\n\t\tthis.aspect = fullWidth / fullHeight;\n\n\t\tif ( this.view === null ) {\n\n\t\t\tthis.view = {\n\t\t\t\tenabled: true,\n\t\t\t\tfullWidth: 1,\n\t\t\t\tfullHeight: 1,\n\t\t\t\toffsetX: 0,\n\t\t\t\toffsetY: 0,\n\t\t\t\twidth: 1,\n\t\t\t\theight: 1\n\t\t\t};\n\n\t\t}\n\n\t\tthis.view.enabled = true;\n\t\tthis.view.fullWidth = fullWidth;\n\t\tthis.view.fullHeight = fullHeight;\n\t\tthis.view.offsetX = x;\n\t\tthis.view.offsetY = y;\n\t\tthis.view.width = width;\n\t\tthis.view.height = height;\n\n\t\tthis.updateProjectionMatrix();\n\n\t}\n\n\tclearViewOffset() {\n\n\t\tif ( this.view !== null ) {\n\n\t\t\tthis.view.enabled = false;\n\n\t\t}\n\n\t\tthis.updateProjectionMatrix();\n\n\t}\n\n\tupdateProjectionMatrix() {\n\n\t\tconst near = this.near;\n\t\tlet top = near * Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom;\n\t\tlet height = 2 * top;\n\t\tlet width = this.aspect * height;\n\t\tlet left = - 0.5 * width;\n\t\tconst view = this.view;\n\n\t\tif ( this.view !== null && this.view.enabled ) {\n\n\t\t\tconst fullWidth = view.fullWidth,\n\t\t\t\tfullHeight = view.fullHeight;\n\n\t\t\tleft += view.offsetX * width / fullWidth;\n\t\t\ttop -= view.offsetY * height / fullHeight;\n\t\t\twidth *= view.width / fullWidth;\n\t\t\theight *= view.height / fullHeight;\n\n\t\t}\n\n\t\tconst skew = this.filmOffset;\n\t\tif ( skew !== 0 ) left += near * skew / this.getFilmWidth();\n\n\t\tthis.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far, this.coordinateSystem );\n\n\t\tthis.projectionMatrixInverse.copy( this.projectionMatrix ).invert();\n\n\t}\n\n\ttoJSON( meta ) {\n\n\t\tconst data = super.toJSON( meta );\n\n\t\tdata.object.fov = this.fov;\n\t\tdata.object.zoom = this.zoom;\n\n\t\tdata.object.near = this.near;\n\t\tdata.object.far = this.far;\n\t\tdata.object.focus = this.focus;\n\n\t\tdata.object.aspect = this.aspect;\n\n\t\tif ( this.view !== null ) data.object.view = Object.assign( {}, this.view );\n\n\t\tdata.object.filmGauge = this.filmGauge;\n\t\tdata.object.filmOffset = this.filmOffset;\n\n\t\treturn data;\n\n\t}\n\n}\n\nconst fov = - 90; // negative fov is not an error\nconst aspect = 1;\n\nclass CubeCamera extends Object3D {\n\n\tconstructor( near, far, renderTarget ) {\n\n\t\tsuper();\n\n\t\tthis.type = 'CubeCamera';\n\n\t\tthis.renderTarget = renderTarget;\n\t\tthis.coordinateSystem = null;\n\t\tthis.activeMipmapLevel = 0;\n\n\t\tconst cameraPX = new PerspectiveCamera( fov, aspect, near, far );\n\t\tcameraPX.layers = this.layers;\n\t\tthis.add( cameraPX );\n\n\t\tconst cameraNX = new PerspectiveCamera( fov, aspect, near, far );\n\t\tcameraNX.layers = this.layers;\n\t\tthis.add( cameraNX );\n\n\t\tconst cameraPY = new PerspectiveCamera( fov, aspect, near, far );\n\t\tcameraPY.layers = this.layers;\n\t\tthis.add( cameraPY );\n\n\t\tconst cameraNY = new PerspectiveCamera( fov, aspect, near, far );\n\t\tcameraNY.layers = this.layers;\n\t\tthis.add( cameraNY );\n\n\t\tconst cameraPZ = new PerspectiveCamera( fov, aspect, near, far );\n\t\tcameraPZ.layers = this.layers;\n\t\tthis.add( cameraPZ );\n\n\t\tconst cameraNZ = new PerspectiveCamera( fov, aspect, near, far );\n\t\tcameraNZ.layers = this.layers;\n\t\tthis.add( cameraNZ );\n\n\t}\n\n\tupdateCoordinateSystem() {\n\n\t\tconst coordinateSystem = this.coordinateSystem;\n\n\t\tconst cameras = this.children.concat();\n\n\t\tconst [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = cameras;\n\n\t\tfor ( const camera of cameras ) this.remove( camera );\n\n\t\tif ( coordinateSystem === WebGLCoordinateSystem ) {\n\n\t\t\tcameraPX.up.set( 0, 1, 0 );\n\t\t\tcameraPX.lookAt( 1, 0, 0 );\n\n\t\t\tcameraNX.up.set( 0, 1, 0 );\n\t\t\tcameraNX.lookAt( - 1, 0, 0 );\n\n\t\t\tcameraPY.up.set( 0, 0, - 1 );\n\t\t\tcameraPY.lookAt( 0, 1, 0 );\n\n\t\t\tcameraNY.up.set( 0, 0, 1 );\n\t\t\tcameraNY.lookAt( 0, - 1, 0 );\n\n\t\t\tcameraPZ.up.set( 0, 1, 0 );\n\t\t\tcameraPZ.lookAt( 0, 0, 1 );\n\n\t\t\tcameraNZ.up.set( 0, 1, 0 );\n\t\t\tcameraNZ.lookAt( 0, 0, - 1 );\n\n\t\t} else if ( coordinateSystem === WebGPUCoordinateSystem ) {\n\n\t\t\tcameraPX.up.set( 0, - 1, 0 );\n\t\t\tcameraPX.lookAt( - 1, 0, 0 );\n\n\t\t\tcameraNX.up.set( 0, - 1, 0 );\n\t\t\tcameraNX.lookAt( 1, 0, 0 );\n\n\t\t\tcameraPY.up.set( 0, 0, 1 );\n\t\t\tcameraPY.lookAt( 0, 1, 0 );\n\n\t\t\tcameraNY.up.set( 0, 0, - 1 );\n\t\t\tcameraNY.lookAt( 0, - 1, 0 );\n\n\t\t\tcameraPZ.up.set( 0, - 1, 0 );\n\t\t\tcameraPZ.lookAt( 0, 0, 1 );\n\n\t\t\tcameraNZ.up.set( 0, - 1, 0 );\n\t\t\tcameraNZ.lookAt( 0, 0, - 1 );\n\n\t\t} else {\n\n\t\t\tthrow new Error( 'THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: ' + coordinateSystem );\n\n\t\t}\n\n\t\tfor ( const camera of cameras ) {\n\n\t\t\tthis.add( camera );\n\n\t\t\tcamera.updateMatrixWorld();\n\n\t\t}\n\n\t}\n\n\tupdate( renderer, scene ) {\n\n\t\tif ( this.parent === null ) this.updateMatrixWorld();\n\n\t\tconst { renderTarget, activeMipmapLevel } = this;\n\n\t\tif ( this.coordinateSystem !== renderer.coordinateSystem ) {\n\n\t\t\tthis.coordinateSystem = renderer.coordinateSystem;\n\n\t\t\tthis.updateCoordinateSystem();\n\n\t\t}\n\n\t\tconst [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children;\n\n\t\tconst currentRenderTarget = renderer.getRenderTarget();\n\t\tconst currentActiveCubeFace = renderer.getActiveCubeFace();\n\t\tconst currentActiveMipmapLevel = renderer.getActiveMipmapLevel();\n\n\t\tconst currentXrEnabled = renderer.xr.enabled;\n\n\t\trenderer.xr.enabled = false;\n\n\t\tconst generateMipmaps = renderTarget.texture.generateMipmaps;\n\n\t\trenderTarget.texture.generateMipmaps = false;\n\n\t\trenderer.setRenderTarget( renderTarget, 0, activeMipmapLevel );\n\t\trenderer.render( scene, cameraPX );\n\n\t\trenderer.setRenderTarget( renderTarget, 1, activeMipmapLevel );\n\t\trenderer.render( scene, cameraNX );\n\n\t\trenderer.setRenderTarget( renderTarget, 2, activeMipmapLevel );\n\t\trenderer.render( scene, cameraPY );\n\n\t\trenderer.setRenderTarget( renderTarget, 3, activeMipmapLevel );\n\t\trenderer.render( scene, cameraNY );\n\n\t\trenderer.setRenderTarget( renderTarget, 4, activeMipmapLevel );\n\t\trenderer.render( scene, cameraPZ );\n\n\t\t// mipmaps are generated during the last call of render()\n\t\t// at this point, all sides of the cube render target are defined\n\n\t\trenderTarget.texture.generateMipmaps = generateMipmaps;\n\n\t\trenderer.setRenderTarget( renderTarget, 5, activeMipmapLevel );\n\t\trenderer.render( scene, cameraNZ );\n\n\t\trenderer.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );\n\n\t\trenderer.xr.enabled = currentXrEnabled;\n\n\t\trenderTarget.texture.needsPMREMUpdate = true;\n\n\t}\n\n}\n\nclass CubeTexture extends Texture {\n\n\tconstructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ) {\n\n\t\timages = images !== undefined ? images : [];\n\t\tmapping = mapping !== undefined ? mapping : CubeReflectionMapping;\n\n\t\tsuper( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );\n\n\t\tthis.isCubeTexture = true;\n\n\t\tthis.flipY = false;\n\n\t}\n\n\tget images() {\n\n\t\treturn this.image;\n\n\t}\n\n\tset images( value ) {\n\n\t\tthis.image = value;\n\n\t}\n\n}\n\nclass WebGLCubeRenderTarget extends WebGLRenderTarget {\n\n\tconstructor( size = 1, options = {} ) {\n\n\t\tsuper( size, size, options );\n\n\t\tthis.isWebGLCubeRenderTarget = true;\n\n\t\tconst image = { width: size, height: size, depth: 1 };\n\t\tconst images = [ image, image, image, image, image, image ];\n\n\t\tthis.texture = new CubeTexture( images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );\n\n\t\t// By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)\n\t\t// in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,\n\t\t// in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.\n\n\t\t// three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped\n\t\t// and the flag isRenderTargetTexture controls this conversion. The flip is not required when using WebGLCubeRenderTarget.texture\n\t\t// as a cube texture (this is detected when isRenderTargetTexture is set to true for cube textures).\n\n\t\tthis.texture.isRenderTargetTexture = true;\n\n\t\tthis.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;\n\t\tthis.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;\n\n\t}\n\n\tfromEquirectangularTexture( renderer, texture ) {\n\n\t\tthis.texture.type = texture.type;\n\t\tthis.texture.colorSpace = texture.colorSpace;\n\n\t\tthis.texture.generateMipmaps = texture.generateMipmaps;\n\t\tthis.texture.minFilter = texture.minFilter;\n\t\tthis.texture.magFilter = texture.magFilter;\n\n\t\tconst shader = {\n\n\t\t\tuniforms: {\n\t\t\t\ttEquirect: { value: null },\n\t\t\t},\n\n\t\t\tvertexShader: /* glsl */`\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\tvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\n\t\t\t\t\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n\n\t\t\t\t}\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvWorldDirection = transformDirection( position, modelMatrix );\n\n\t\t\t\t\t#include \n\t\t\t\t\t#include \n\n\t\t\t\t}\n\t\t\t`,\n\n\t\t\tfragmentShader: /* glsl */`\n\n\t\t\t\tuniform sampler2D tEquirect;\n\n\t\t\t\tvarying vec3 vWorldDirection;\n\n\t\t\t\t#include \n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\tvec3 direction = normalize( vWorldDirection );\n\n\t\t\t\t\tvec2 sampleUV = equirectUv( direction );\n\n\t\t\t\t\tgl_FragColor = texture2D( tEquirect, sampleUV );\n\n\t\t\t\t}\n\t\t\t`\n\t\t};\n\n\t\tconst geometry = new BoxGeometry( 5, 5, 5 );\n\n\t\tconst material = new ShaderMaterial( {\n\n\t\t\tname: 'CubemapFromEquirect',\n\n\t\t\tuniforms: cloneUniforms( shader.uniforms ),\n\t\t\tvertexShader: shader.vertexShader,\n\t\t\tfragmentShader: shader.fragmentShader,\n\t\t\tside: BackSide,\n\t\t\tblending: NoBlending\n\n\t\t} );\n\n\t\tmaterial.uniforms.tEquirect.value = texture;\n\n\t\tconst mesh = new Mesh( geometry, material );\n\n\t\tconst currentMinFilter = texture.minFilter;\n\n\t\t// Avoid blurred poles\n\t\tif ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;\n\n\t\tconst camera = new CubeCamera( 1, 10, this );\n\t\tcamera.update( renderer, mesh );\n\n\t\ttexture.minFilter = currentMinFilter;\n\n\t\tmesh.geometry.dispose();\n\t\tmesh.material.dispose();\n\n\t\treturn this;\n\n\t}\n\n\tclear( renderer, color, depth, stencil ) {\n\n\t\tconst currentRenderTarget = renderer.getRenderTarget();\n\n\t\tfor ( let i = 0; i < 6; i ++ ) {\n\n\t\t\trenderer.setRenderTarget( this, i );\n\n\t\t\trenderer.clear( color, depth, stencil );\n\n\t\t}\n\n\t\trenderer.setRenderTarget( currentRenderTarget );\n\n\t}\n\n}\n\nconst _vector1 = /*@__PURE__*/ new Vector3();\nconst _vector2 = /*@__PURE__*/ new Vector3();\nconst _normalMatrix = /*@__PURE__*/ new Matrix3();\n\nclass Plane {\n\n\tconstructor( normal = new Vector3( 1, 0, 0 ), constant = 0 ) {\n\n\t\tthis.isPlane = true;\n\n\t\t// normal is assumed to be normalized\n\n\t\tthis.normal = normal;\n\t\tthis.constant = constant;\n\n\t}\n\n\tset( normal, constant ) {\n\n\t\tthis.normal.copy( normal );\n\t\tthis.constant = constant;\n\n\t\treturn this;\n\n\t}\n\n\tsetComponents( x, y, z, w ) {\n\n\t\tthis.normal.set( x, y, z );\n\t\tthis.constant = w;\n\n\t\treturn this;\n\n\t}\n\n\tsetFromNormalAndCoplanarPoint( normal, point ) {\n\n\t\tthis.normal.copy( normal );\n\t\tthis.constant = - point.dot( this.normal );\n\n\t\treturn this;\n\n\t}\n\n\tsetFromCoplanarPoints( a, b, c ) {\n\n\t\tconst normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();\n\n\t\t// Q: should an error be thrown if normal is zero (e.g. degenerate plane)?\n\n\t\tthis.setFromNormalAndCoplanarPoint( normal, a );\n\n\t\treturn this;\n\n\t}\n\n\tcopy( plane ) {\n\n\t\tthis.normal.copy( plane.normal );\n\t\tthis.constant = plane.constant;\n\n\t\treturn this;\n\n\t}\n\n\tnormalize() {\n\n\t\t// Note: will lead to a divide by zero if the plane is invalid.\n\n\t\tconst inverseNormalLength = 1.0 / this.normal.length();\n\t\tthis.normal.multiplyScalar( inverseNormalLength );\n\t\tthis.constant *= inverseNormalLength;\n\n\t\treturn this;\n\n\t}\n\n\tnegate() {\n\n\t\tthis.constant *= - 1;\n\t\tthis.normal.negate();\n\n\t\treturn this;\n\n\t}\n\n\tdistanceToPoint( point ) {\n\n\t\treturn this.normal.dot( point ) + this.constant;\n\n\t}\n\n\tdistanceToSphere( sphere ) {\n\n\t\treturn this.distanceToPoint( sphere.center ) - sphere.radius;\n\n\t}\n\n\tprojectPoint( point, target ) {\n\n\t\treturn target.copy( point ).addScaledVector( this.normal, - this.distanceToPoint( point ) );\n\n\t}\n\n\tintersectLine( line, target ) {\n\n\t\tconst direction = line.delta( _vector1 );\n\n\t\tconst denominator = this.normal.dot( direction );\n\n\t\tif ( denominator === 0 ) {\n\n\t\t\t// line is coplanar, return origin\n\t\t\tif ( this.distanceToPoint( line.start ) === 0 ) {\n\n\t\t\t\treturn target.copy( line.start );\n\n\t\t\t}\n\n\t\t\t// Unsure if this is the correct method to handle this case.\n\t\t\treturn null;\n\n\t\t}\n\n\t\tconst t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;\n\n\t\tif ( t < 0 || t > 1 ) {\n\n\t\t\treturn null;\n\n\t\t}\n\n\t\treturn target.copy( line.start ).addScaledVector( direction, t );\n\n\t}\n\n\tintersectsLine( line ) {\n\n\t\t// Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.\n\n\t\tconst startSign = this.distanceToPoint( line.start );\n\t\tconst endSign = this.distanceToPoint( line.end );\n\n\t\treturn ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );\n\n\t}\n\n\tintersectsBox( box ) {\n\n\t\treturn box.intersectsPlane( this );\n\n\t}\n\n\tintersectsSphere( sphere ) {\n\n\t\treturn sphere.intersectsPlane( this );\n\n\t}\n\n\tcoplanarPoint( target ) {\n\n\t\treturn target.copy( this.normal ).multiplyScalar( - this.constant );\n\n\t}\n\n\tapplyMatrix4( matrix, optionalNormalMatrix ) {\n\n\t\tconst normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );\n\n\t\tconst referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );\n\n\t\tconst normal = this.normal.applyMatrix3( normalMatrix ).normalize();\n\n\t\tthis.constant = - referencePoint.dot( normal );\n\n\t\treturn this;\n\n\t}\n\n\ttranslate( offset ) {\n\n\t\tthis.constant -= offset.dot( this.normal );\n\n\t\treturn this;\n\n\t}\n\n\tequals( plane ) {\n\n\t\treturn plane.normal.equals( this.normal ) && ( plane.constant === this.constant );\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n}\n\nconst _sphere$5 = /*@__PURE__*/ new Sphere();\nconst _vector$7 = /*@__PURE__*/ new Vector3();\n\nclass Frustum {\n\n\tconstructor( p0 = new Plane(), p1 = new Plane(), p2 = new Plane(), p3 = new Plane(), p4 = new Plane(), p5 = new Plane() ) {\n\n\t\tthis.planes = [ p0, p1, p2, p3, p4, p5 ];\n\n\t}\n\n\tset( p0, p1, p2, p3, p4, p5 ) {\n\n\t\tconst planes = this.planes;\n\n\t\tplanes[ 0 ].copy( p0 );\n\t\tplanes[ 1 ].copy( p1 );\n\t\tplanes[ 2 ].copy( p2 );\n\t\tplanes[ 3 ].copy( p3 );\n\t\tplanes[ 4 ].copy( p4 );\n\t\tplanes[ 5 ].copy( p5 );\n\n\t\treturn this;\n\n\t}\n\n\tcopy( frustum ) {\n\n\t\tconst planes = this.planes;\n\n\t\tfor ( let i = 0; i < 6; i ++ ) {\n\n\t\t\tplanes[ i ].copy( frustum.planes[ i ] );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tsetFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem ) {\n\n\t\tconst planes = this.planes;\n\t\tconst me = m.elements;\n\t\tconst me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];\n\t\tconst me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];\n\t\tconst me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];\n\t\tconst me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];\n\n\t\tplanes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();\n\t\tplanes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();\n\t\tplanes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();\n\t\tplanes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();\n\t\tplanes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();\n\n\t\tif ( coordinateSystem === WebGLCoordinateSystem ) {\n\n\t\t\tplanes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();\n\n\t\t} else if ( coordinateSystem === WebGPUCoordinateSystem ) {\n\n\t\t\tplanes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize();\n\n\t\t} else {\n\n\t\t\tthrow new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );\n\n\t\t}\n\n\t\treturn this;\n\n\t}\n\n\tintersectsObject( object ) {\n\n\t\tif ( object.boundingSphere !== undefined ) {\n\n\t\t\tif ( object.boundingSphere === null ) object.computeBoundingSphere();\n\n\t\t\t_sphere$5.copy( object.boundingSphere ).applyMatrix4( object.matrixWorld );\n\n\t\t} else {\n\n\t\t\tconst geometry = object.geometry;\n\n\t\t\tif ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();\n\n\t\t\t_sphere$5.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );\n\n\t\t}\n\n\t\treturn this.intersectsSphere( _sphere$5 );\n\n\t}\n\n\tintersectsSprite( sprite ) {\n\n\t\t_sphere$5.center.set( 0, 0, 0 );\n\t\t_sphere$5.radius = 0.7071067811865476;\n\t\t_sphere$5.applyMatrix4( sprite.matrixWorld );\n\n\t\treturn this.intersectsSphere( _sphere$5 );\n\n\t}\n\n\tintersectsSphere( sphere ) {\n\n\t\tconst planes = this.planes;\n\t\tconst center = sphere.center;\n\t\tconst negRadius = - sphere.radius;\n\n\t\tfor ( let i = 0; i < 6; i ++ ) {\n\n\t\t\tconst distance = planes[ i ].distanceToPoint( center );\n\n\t\t\tif ( distance < negRadius ) {\n\n\t\t\t\treturn false;\n\n\t\t\t}\n\n\t\t}\n\n\t\treturn true;\n\n\t}\n\n\tintersectsBox( box ) {\n\n\t\tconst planes = this.planes;\n\n\t\tfor ( let i = 0; i < 6; i ++ ) {\n\n\t\t\tconst plane = planes[ i ];\n\n\t\t\t// corner at max distance\n\n\t\t\t_vector$7.x = plane.normal.x > 0 ? box.max.x : box.min.x;\n\t\t\t_vector$7.y = plane.normal.y > 0 ? box.max.y : box.min.y;\n\t\t\t_vector$7.z = plane.normal.z > 0 ? box.max.z : box.min.z;\n\n\t\t\tif ( plane.distanceToPoint( _vector$7 ) < 0 ) {\n\n\t\t\t\treturn false;\n\n\t\t\t}\n\n\t\t}\n\n\t\treturn true;\n\n\t}\n\n\tcontainsPoint( point ) {\n\n\t\tconst planes = this.planes;\n\n\t\tfor ( let i = 0; i < 6; i ++ ) {\n\n\t\t\tif ( planes[ i ].distanceToPoint( point ) < 0 ) {\n\n\t\t\t\treturn false;\n\n\t\t\t}\n\n\t\t}\n\n\t\treturn true;\n\n\t}\n\n\tclone() {\n\n\t\treturn new this.constructor().copy( this );\n\n\t}\n\n}\n\nfunction WebGLAnimation() {\n\n\tlet context = null;\n\tlet isAnimating = false;\n\tlet animationLoop = null;\n\tlet requestId = null;\n\n\tfunction onAnimationFrame( time, frame ) {\n\n\t\tanimationLoop( time, frame );\n\n\t\trequestId = context.requestAnimationFrame( onAnimationFrame );\n\n\t}\n\n\treturn {\n\n\t\tstart: function () {\n\n\t\t\tif ( isAnimating === true ) return;\n\t\t\tif ( animationLoop === null ) return;\n\n\t\t\trequestId = context.requestAnimationFrame( onAnimationFrame );\n\n\t\t\tisAnimating = true;\n\n\t\t},\n\n\t\tstop: function () {\n\n\t\t\tcontext.cancelAnimationFrame( requestId );\n\n\t\t\tisAnimating = false;\n\n\t\t},\n\n\t\tsetAnimationLoop: function ( callback ) {\n\n\t\t\tanimationLoop = callback;\n\n\t\t},\n\n\t\tsetContext: function ( value ) {\n\n\t\t\tcontext = value;\n\n\t\t}\n\n\t};\n\n}\n\nfunction WebGLAttributes( gl ) {\n\n\tconst buffers = new WeakMap();\n\n\tfunction createBuffer( attribute, bufferType ) {\n\n\t\tconst array = attribute.array;\n\t\tconst usage = attribute.usage;\n\t\tconst size = array.byteLength;\n\n\t\tconst buffer = gl.createBuffer();\n\n\t\tgl.bindBuffer( bufferType, buffer );\n\t\tgl.bufferData( bufferType, array, usage );\n\n\t\tattribute.onUploadCallback();\n\n\t\tlet type;\n\n\t\tif ( array instanceof Float32Array ) {\n\n\t\t\ttype = gl.FLOAT;\n\n\t\t} else if ( array instanceof Uint16Array ) {\n\n\t\t\tif ( attribute.isFloat16BufferAttribute ) {\n\n\t\t\t\ttype = gl.HALF_FLOAT;\n\n\t\t\t} else {\n\n\t\t\t\ttype = gl.UNSIGNED_SHORT;\n\n\t\t\t}\n\n\t\t} else if ( array instanceof Int16Array ) {\n\n\t\t\ttype = gl.SHORT;\n\n\t\t} else if ( array instanceof Uint32Array ) {\n\n\t\t\ttype = gl.UNSIGNED_INT;\n\n\t\t} else if ( array instanceof Int32Array ) {\n\n\t\t\ttype = gl.INT;\n\n\t\t} else if ( array instanceof Int8Array ) {\n\n\t\t\ttype = gl.BYTE;\n\n\t\t} else if ( array instanceof Uint8Array ) {\n\n\t\t\ttype = gl.UNSIGNED_BYTE;\n\n\t\t} else if ( array instanceof Uint8ClampedArray ) {\n\n\t\t\ttype = gl.UNSIGNED_BYTE;\n\n\t\t} else {\n\n\t\t\tthrow new Error( 'THREE.WebGLAttributes: Unsupported buffer data format: ' + array );\n\n\t\t}\n\n\t\treturn {\n\t\t\tbuffer: buffer,\n\t\t\ttype: type,\n\t\t\tbytesPerElement: array.BYTES_PER_ELEMENT,\n\t\t\tversion: attribute.version,\n\t\t\tsize: size\n\t\t};\n\n\t}\n\n\tfunction updateBuffer( buffer, attribute, bufferType ) {\n\n\t\tconst array = attribute.array;\n\t\tconst updateRange = attribute._updateRange; // @deprecated, r159\n\t\tconst updateRanges = attribute.updateRanges;\n\n\t\tgl.bindBuffer( bufferType, buffer );\n\n\t\tif ( updateRange.count === - 1 && updateRanges.length === 0 ) {\n\n\t\t\t// Not using update ranges\n\t\t\tgl.bufferSubData( bufferType, 0, array );\n\n\t\t}\n\n\t\tif ( updateRanges.length !== 0 ) {\n\n\t\t\tfor ( let i = 0, l = updateRanges.length; i < l; i ++ ) {\n\n\t\t\t\tconst range = updateRanges[ i ];\n\n\t\t\t\tgl.bufferSubData( bufferType, range.start * array.BYTES_PER_ELEMENT,\n\t\t\t\t\tarray, range.start, range.count );\n\n\t\t\t}\n\n\t\t\tattribute.clearUpdateRanges();\n\n\t\t}\n\n\t\t// @deprecated, r159\n\t\tif ( updateRange.count !== - 1 ) {\n\n\t\t\tgl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,\n\t\t\t\tarray, updateRange.offset, updateRange.count );\n\n\t\t\tupdateRange.count = - 1; // reset range\n\n\t\t}\n\n\t\tattribute.onUploadCallback();\n\n\t}\n\n\t//\n\n\tfunction get( attribute ) {\n\n\t\tif ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;\n\n\t\treturn buffers.get( attribute );\n\n\t}\n\n\tfunction remove( attribute ) {\n\n\t\tif ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;\n\n\t\tconst data = buffers.get( attribute );\n\n\t\tif ( data ) {\n\n\t\t\tgl.deleteBuffer( data.buffer );\n\n\t\t\tbuffers.delete( attribute );\n\n\t\t}\n\n\t}\n\n\tfunction update( attribute, bufferType ) {\n\n\t\tif ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;\n\n\t\tif ( attribute.isGLBufferAttribute ) {\n\n\t\t\tconst cached = buffers.get( attribute );\n\n\t\t\tif ( ! cached || cached.version < attribute.version ) {\n\n\t\t\t\tbuffers.set( attribute, {\n\t\t\t\t\tbuffer: attribute.buffer,\n\t\t\t\t\ttype: attribute.type,\n\t\t\t\t\tbytesPerElement: attribute.elementSize,\n\t\t\t\t\tversion: attribute.version\n\t\t\t\t} );\n\n\t\t\t}\n\n\t\t\treturn;\n\n\t\t}\n\n\t\tconst data = buffers.get( attribute );\n\n\t\tif ( data === undefined ) {\n\n\t\t\tbuffers.set( attribute, createBuffer( attribute, bufferType ) );\n\n\t\t} else if ( data.version < attribute.version ) {\n\n\t\t\tif ( data.size !== attribute.array.byteLength ) {\n\n\t\t\t\tthrow new Error( 'THREE.WebGLAttributes: The size of the buffer attribute\\'s array buffer does not match the original size. Resizing buffer attributes is not supported.' );\n\n\t\t\t}\n\n\t\t\tupdateBuffer( data.buffer, attribute, bufferType );\n\n\t\t\tdata.version = attribute.version;\n\n\t\t}\n\n\t}\n\n\treturn {\n\n\t\tget: get,\n\t\tremove: remove,\n\t\tupdate: update\n\n\t};\n\n}\n\nclass PlaneGeometry extends BufferGeometry {\n\n\tconstructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {\n\n\t\tsuper();\n\n\t\tthis.type = 'PlaneGeometry';\n\n\t\tthis.parameters = {\n\t\t\twidth: width,\n\t\t\theight: height,\n\t\t\twidthSegments: widthSegments,\n\t\t\theightSegments: heightSegments\n\t\t};\n\n\t\tconst width_half = width / 2;\n\t\tconst height_half = height / 2;\n\n\t\tconst gridX = Math.floor( widthSegments );\n\t\tconst gridY = Math.floor( heightSegments );\n\n\t\tconst gridX1 = gridX + 1;\n\t\tconst gridY1 = gridY + 1;\n\n\t\tconst segment_width = width / gridX;\n\t\tconst segment_height = height / gridY;\n\n\t\t//\n\n\t\tconst indices = [];\n\t\tconst vertices = [];\n\t\tconst normals = [];\n\t\tconst uvs = [];\n\n\t\tfor ( let iy = 0; iy < gridY1; iy ++ ) {\n\n\t\t\tconst y = iy * segment_height - height_half;\n\n\t\t\tfor ( let ix = 0; ix < gridX1; ix ++ ) {\n\n\t\t\t\tconst x = ix * segment_width - width_half;\n\n\t\t\t\tvertices.push( x, - y, 0 );\n\n\t\t\t\tnormals.push( 0, 0, 1 );\n\n\t\t\t\tuvs.push( ix / gridX );\n\t\t\t\tuvs.push( 1 - ( iy / gridY ) );\n\n\t\t\t}\n\n\t\t}\n\n\t\tfor ( let iy = 0; iy < gridY; iy ++ ) {\n\n\t\t\tfor ( let ix = 0; ix < gridX; ix ++ ) {\n\n\t\t\t\tconst a = ix + gridX1 * iy;\n\t\t\t\tconst b = ix + gridX1 * ( iy + 1 );\n\t\t\t\tconst c = ( ix + 1 ) + gridX1 * ( iy + 1 );\n\t\t\t\tconst d = ( ix + 1 ) + gridX1 * iy;\n\n\t\t\t\tindices.push( a, b, d );\n\t\t\t\tindices.push( b, c, d );\n\n\t\t\t}\n\n\t\t}\n\n\t\tthis.setIndex( indices );\n\t\tthis.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );\n\t\tthis.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );\n\t\tthis.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );\n\n\t}\n\n\tcopy( source ) {\n\n\t\tsuper.copy( source );\n\n\t\tthis.parameters = Object.assign( {}, source.parameters );\n\n\t\treturn this;\n\n\t}\n\n\tstatic fromJSON( data ) {\n\n\t\treturn new PlaneGeometry( data.width, data.height, data.widthSegments, data.heightSegments );\n\n\t}\n\n}\n\nvar alphahash_fragment = \"#ifdef USE_ALPHAHASH\\n\\tif ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;\\n#endif\";\n\nvar alphahash_pars_fragment = \"#ifdef USE_ALPHAHASH\\n\\tconst float ALPHA_HASH_SCALE = 0.05;\\n\\tfloat hash2D( vec2 value ) {\\n\\t\\treturn fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );\\n\\t}\\n\\tfloat hash3D( vec3 value ) {\\n\\t\\treturn hash2D( vec2( hash2D( value.xy ), value.z ) );\\n\\t}\\n\\tfloat getAlphaHashThreshold( vec3 position ) {\\n\\t\\tfloat maxDeriv = max(\\n\\t\\t\\tlength( dFdx( position.xyz ) ),\\n\\t\\t\\tlength( dFdy( position.xyz ) )\\n\\t\\t);\\n\\t\\tfloat pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );\\n\\t\\tvec2 pixScales = vec2(\\n\\t\\t\\texp2( floor( log2( pixScale ) ) ),\\n\\t\\t\\texp2( ceil( log2( pixScale ) ) )\\n\\t\\t);\\n\\t\\tvec2 alpha = vec2(\\n\\t\\t\\thash3D( floor( pixScales.x * position.xyz ) ),\\n\\t\\t\\thash3D( floor( pixScales.y * position.xyz ) )\\n\\t\\t);\\n\\t\\tfloat lerpFactor = fract( log2( pixScale ) );\\n\\t\\tfloat x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;\\n\\t\\tfloat a = min( lerpFactor, 1.0 - lerpFactor );\\n\\t\\tvec3 cases = vec3(\\n\\t\\t\\tx * x / ( 2.0 * a * ( 1.0 - a ) ),\\n\\t\\t\\t( x - 0.5 * a ) / ( 1.0 - a ),\\n\\t\\t\\t1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )\\n\\t\\t);\\n\\t\\tfloat threshold = ( x < ( 1.0 - a ) )\\n\\t\\t\\t? ( ( x < a ) ? cases.x : cases.y )\\n\\t\\t\\t: cases.z;\\n\\t\\treturn clamp( threshold , 1.0e-6, 1.0 );\\n\\t}\\n#endif\";\n\nvar alphamap_fragment = \"#ifdef USE_ALPHAMAP\\n\\tdiffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;\\n#endif\";\n\nvar alphamap_pars_fragment = \"#ifdef USE_ALPHAMAP\\n\\tuniform sampler2D alphaMap;\\n#endif\";\n\nvar alphatest_fragment = \"#ifdef USE_ALPHATEST\\n\\t#ifdef ALPHA_TO_COVERAGE\\n\\tdiffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );\\n\\tif ( diffuseColor.a == 0.0 ) discard;\\n\\t#else\\n\\tif ( diffuseColor.a < alphaTest ) discard;\\n\\t#endif\\n#endif\";\n\nvar alphatest_pars_fragment = \"#ifdef USE_ALPHATEST\\n\\tuniform float alphaTest;\\n#endif\";\n\nvar aomap_fragment = \"#ifdef USE_AOMAP\\n\\tfloat ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;\\n\\treflectedLight.indirectDiffuse *= ambientOcclusion;\\n\\t#if defined( USE_CLEARCOAT ) \\n\\t\\tclearcoatSpecularIndirect *= ambientOcclusion;\\n\\t#endif\\n\\t#if defined( USE_SHEEN ) \\n\\t\\tsheenSpecularIndirect *= ambientOcclusion;\\n\\t#endif\\n\\t#if defined( USE_ENVMAP ) && defined( STANDARD )\\n\\t\\tfloat dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\\n\\t\\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\\n\\t#endif\\n#endif\";\n\nvar aomap_pars_fragment = \"#ifdef USE_AOMAP\\n\\tuniform sampler2D aoMap;\\n\\tuniform float aoMapIntensity;\\n#endif\";\n\nvar batching_pars_vertex = \"#ifdef USE_BATCHING\\n\\t#if ! defined( GL_ANGLE_multi_draw )\\n\\t#define gl_DrawID _gl_DrawID\\n\\tuniform int _gl_DrawID;\\n\\t#endif\\n\\tuniform highp sampler2D batchingTexture;\\n\\tuniform highp usampler2D batchingIdTexture;\\n\\tmat4 getBatchingMatrix( const in float i ) {\\n\\t\\tint size = textureSize( batchingTexture, 0 ).x;\\n\\t\\tint j = int( i ) * 4;\\n\\t\\tint x = j % size;\\n\\t\\tint y = j / size;\\n\\t\\tvec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );\\n\\t\\tvec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );\\n\\t\\tvec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );\\n\\t\\tvec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );\\n\\t\\treturn mat4( v1, v2, v3, v4 );\\n\\t}\\n\\tfloat getIndirectIndex( const in int i ) {\\n\\t\\tint size = textureSize( batchingIdTexture, 0 ).x;\\n\\t\\tint x = i % size;\\n\\t\\tint y = i / size;\\n\\t\\treturn float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );\\n\\t}\\n#endif\\n#ifdef USE_BATCHING_COLOR\\n\\tuniform sampler2D batchingColorTexture;\\n\\tvec3 getBatchingColor( const in float i ) {\\n\\t\\tint size = textureSize( batchingColorTexture, 0 ).x;\\n\\t\\tint j = int( i );\\n\\t\\tint x = j % size;\\n\\t\\tint y = j / size;\\n\\t\\treturn texelFetch( batchingColorTexture, ivec2( x, y ), 0 ).rgb;\\n\\t}\\n#endif\";\n\nvar batching_vertex = \"#ifdef USE_BATCHING\\n\\tmat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );\\n#endif\";\n\nvar begin_vertex = \"vec3 transformed = vec3( position );\\n#ifdef USE_ALPHAHASH\\n\\tvPosition = vec3( position );\\n#endif\";\n\nvar beginnormal_vertex = \"vec3 objectNormal = vec3( normal );\\n#ifdef USE_TANGENT\\n\\tvec3 objectTangent = vec3( tangent.xyz );\\n#endif\";\n\nvar bsdfs = \"float G_BlinnPhong_Implicit( ) {\\n\\treturn 0.25;\\n}\\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\\n\\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\\n}\\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\\n\\tvec3 halfDir = normalize( lightDir + viewDir );\\n\\tfloat dotNH = saturate( dot( normal, halfDir ) );\\n\\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\\n\\tvec3 F = F_Schlick( specularColor, 1.0, dotVH );\\n\\tfloat G = G_BlinnPhong_Implicit( );\\n\\tfloat D = D_BlinnPhong( shininess, dotNH );\\n\\treturn F * ( G * D );\\n} // validated\";\n\nvar iridescence_fragment = \"#ifdef USE_IRIDESCENCE\\n\\tconst mat3 XYZ_TO_REC709 = mat3(\\n\\t\\t 3.2404542, -0.9692660, 0.0556434,\\n\\t\\t-1.5371385, 1.8760108, -0.2040259,\\n\\t\\t-0.4985314, 0.0415560, 1.0572252\\n\\t);\\n\\tvec3 Fresnel0ToIor( vec3 fresnel0 ) {\\n\\t\\tvec3 sqrtF0 = sqrt( fresnel0 );\\n\\t\\treturn ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );\\n\\t}\\n\\tvec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {\\n\\t\\treturn pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );\\n\\t}\\n\\tfloat IorToFresnel0( float transmittedIor, float incidentIor ) {\\n\\t\\treturn pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));\\n\\t}\\n\\tvec3 evalSensitivity( float OPD, vec3 shift ) {\\n\\t\\tfloat phase = 2.0 * PI * OPD * 1.0e-9;\\n\\t\\tvec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );\\n\\t\\tvec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );\\n\\t\\tvec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );\\n\\t\\tvec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );\\n\\t\\txyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );\\n\\t\\txyz /= 1.0685e-7;\\n\\t\\tvec3 rgb = XYZ_TO_REC709 * xyz;\\n\\t\\treturn rgb;\\n\\t}\\n\\tvec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {\\n\\t\\tvec3 I;\\n\\t\\tfloat iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );\\n\\t\\tfloat sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );\\n\\t\\tfloat cosTheta2Sq = 1.0 - sinTheta2Sq;\\n\\t\\tif ( cosTheta2Sq < 0.0 ) {\\n\\t\\t\\treturn vec3( 1.0 );\\n\\t\\t}\\n\\t\\tfloat cosTheta2 = sqrt( cosTheta2Sq );\\n\\t\\tfloat R0 = IorToFresnel0( iridescenceIOR, outsideIOR );\\n\\t\\tfloat R12 = F_Schlick( R0, 1.0, cosTheta1 );\\n\\t\\tfloat T121 = 1.0 - R12;\\n\\t\\tfloat phi12 = 0.0;\\n\\t\\tif ( iridescenceIOR < outsideIOR ) phi12 = PI;\\n\\t\\tfloat phi21 = PI - phi12;\\n\\t\\tvec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) );\\t\\tvec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );\\n\\t\\tvec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );\\n\\t\\tvec3 phi23 = vec3( 0.0 );\\n\\t\\tif ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;\\n\\t\\tif ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;\\n\\t\\tif ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;\\n\\t\\tfloat OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;\\n\\t\\tvec3 phi = vec3( phi21 ) + phi23;\\n\\t\\tvec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );\\n\\t\\tvec3 r123 = sqrt( R123 );\\n\\t\\tvec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );\\n\\t\\tvec3 C0 = R12 + Rs;\\n\\t\\tI = C0;\\n\\t\\tvec3 Cm = Rs - T121;\\n\\t\\tfor ( int m = 1; m <= 2; ++ m ) {\\n\\t\\t\\tCm *= r123;\\n\\t\\t\\tvec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );\\n\\t\\t\\tI += Cm * Sm;\\n\\t\\t}\\n\\t\\treturn max( I, vec3( 0.0 ) );\\n\\t}\\n#endif\";\n\nvar bumpmap_pars_fragment = \"#ifdef USE_BUMPMAP\\n\\tuniform sampler2D bumpMap;\\n\\tuniform float bumpScale;\\n\\tvec2 dHdxy_fwd() {\\n\\t\\tvec2 dSTdx = dFdx( vBumpMapUv );\\n\\t\\tvec2 dSTdy = dFdy( vBumpMapUv );\\n\\t\\tfloat Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;\\n\\t\\tfloat dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;\\n\\t\\tfloat dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;\\n\\t\\treturn vec2( dBx, dBy );\\n\\t}\\n\\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\\n\\t\\tvec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );\\n\\t\\tvec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );\\n\\t\\tvec3 vN = surf_norm;\\n\\t\\tvec3 R1 = cross( vSigmaY, vN );\\n\\t\\tvec3 R2 = cross( vN, vSigmaX );\\n\\t\\tfloat fDet = dot( vSigmaX, R1 ) * faceDirection;\\n\\t\\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\\n\\t\\treturn normalize( abs( fDet ) * surf_norm - vGrad );\\n\\t}\\n#endif\";\n\nvar clipping_planes_fragment = \"#if NUM_CLIPPING_PLANES > 0\\n\\tvec4 plane;\\n\\t#ifdef ALPHA_TO_COVERAGE\\n\\t\\tfloat distanceToPlane, distanceGradient;\\n\\t\\tfloat clipOpacity = 1.0;\\n\\t\\t#pragma unroll_loop_start\\n\\t\\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\\n\\t\\t\\tplane = clippingPlanes[ i ];\\n\\t\\t\\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\\n\\t\\t\\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\\n\\t\\t\\tclipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\\n\\t\\t\\tif ( clipOpacity == 0.0 ) discard;\\n\\t\\t}\\n\\t\\t#pragma unroll_loop_end\\n\\t\\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\\n\\t\\t\\tfloat unionClipOpacity = 1.0;\\n\\t\\t\\t#pragma unroll_loop_start\\n\\t\\t\\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\\n\\t\\t\\t\\tplane = clippingPlanes[ i ];\\n\\t\\t\\t\\tdistanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;\\n\\t\\t\\t\\tdistanceGradient = fwidth( distanceToPlane ) / 2.0;\\n\\t\\t\\t\\tunionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );\\n\\t\\t\\t}\\n\\t\\t\\t#pragma unroll_loop_end\\n\\t\\t\\tclipOpacity *= 1.0 - unionClipOpacity;\\n\\t\\t#endif\\n\\t\\tdiffuseColor.a *= clipOpacity;\\n\\t\\tif ( diffuseColor.a == 0.0 ) discard;\\n\\t#else\\n\\t\\t#pragma unroll_loop_start\\n\\t\\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\\n\\t\\t\\tplane = clippingPlanes[ i ];\\n\\t\\t\\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\\n\\t\\t}\\n\\t\\t#pragma unroll_loop_end\\n\\t\\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\\n\\t\\t\\tbool clipped = true;\\n\\t\\t\\t#pragma unroll_loop_start\\n\\t\\t\\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\\n\\t\\t\\t\\tplane = clippingPlanes[ i ];\\n\\t\\t\\t\\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\\n\\t\\t\\t}\\n\\t\\t\\t#pragma unroll_loop_end\\n\\t\\t\\tif ( clipped ) discard;\\n\\t\\t#endif\\n\\t#endif\\n#endif\";\n\nvar clipping_planes_pars_fragment = \"#if NUM_CLIPPING_PLANES > 0\\n\\tvarying vec3 vClipPosition;\\n\\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\\n#endif\";\n\nvar clipping_planes_pars_vertex = \"#if NUM_CLIPPING_PLANES > 0\\n\\tvarying vec3 vClipPosition;\\n#endif\";\n\nvar clipping_planes_vertex = \"#if NUM_CLIPPING_PLANES > 0\\n\\tvClipPosition = - mvPosition.xyz;\\n#endif\";\n\nvar color_fragment = \"#if defined( USE_COLOR_ALPHA )\\n\\tdiffuseColor *= vColor;\\n#elif defined( USE_COLOR )\\n\\tdiffuseColor.rgb *= vColor;\\n#endif\";\n\nvar color_pars_fragment = \"#if defined( USE_COLOR_ALPHA )\\n\\tvarying vec4 vColor;\\n#elif defined( USE_COLOR )\\n\\tvarying vec3 vColor;\\n#endif\";\n\nvar color_pars_vertex = \"#if defined( USE_COLOR_ALPHA )\\n\\tvarying vec4 vColor;\\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\\n\\tvarying vec3 vColor;\\n#endif\";\n\nvar color_vertex = \"#if defined( USE_COLOR_ALPHA )\\n\\tvColor = vec4( 1.0 );\\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )\\n\\tvColor = vec3( 1.0 );\\n#endif\\n#ifdef USE_COLOR\\n\\tvColor *= color;\\n#endif\\n#ifdef USE_INSTANCING_COLOR\\n\\tvColor.xyz *= instanceColor.xyz;\\n#endif\\n#ifdef USE_BATCHING_COLOR\\n\\tvec3 batchingColor = getBatchingColor( getIndirectIndex( gl_DrawID ) );\\n\\tvColor.xyz *= batchingColor.xyz;\\n#endif\";\n\nvar common = \"#define PI 3.141592653589793\\n#define PI2 6.283185307179586\\n#define PI_HALF 1.5707963267948966\\n#define RECIPROCAL_PI 0.3183098861837907\\n#define RECIPROCAL_PI2 0.15915494309189535\\n#define EPSILON 1e-6\\n#ifndef saturate\\n#define saturate( a ) clamp( a, 0.0, 1.0 )\\n#endif\\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\\nfloat pow2( const in float x ) { return x*x; }\\nvec3 pow2( const in vec3 x ) { return x*x; }\\nfloat pow3( const in float x ) { return x*x*x; }\\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\\nhighp float rand( const in vec2 uv ) {\\n\\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\\n\\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\\n\\treturn fract( sin( sn ) * c );\\n}\\n#ifdef HIGH_PRECISION\\n\\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\\n#else\\n\\tfloat precisionSafeLength( vec3 v ) {\\n\\t\\tfloat maxComponent = max3( abs( v ) );\\n\\t\\treturn length( v / maxComponent ) * maxComponent;\\n\\t}\\n#endif\\nstruct IncidentLight {\\n\\tvec3 color;\\n\\tvec3 direction;\\n\\tbool visible;\\n};\\nstruct ReflectedLight {\\n\\tvec3 directDiffuse;\\n\\tvec3 directSpecular;\\n\\tvec3 indirectDiffuse;\\n\\tvec3 indirectSpecular;\\n};\\n#ifdef USE_ALPHAHASH\\n\\tvarying vec3 vPosition;\\n#endif\\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\\n\\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\\n}\\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\\n\\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\\n}\\nmat3 transposeMat3( const in mat3 m ) {\\n\\tmat3 tmp;\\n\\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\\n\\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\\n\\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\\n\\treturn tmp;\\n}\\nbool isPerspectiveMatrix( mat4 m ) {\\n\\treturn m[ 2 ][ 3 ] == - 1.0;\\n}\\nvec2 equirectUv( in vec3 dir ) {\\n\\tfloat u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\\n\\tfloat v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\\n\\treturn vec2( u, v );\\n}\\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\\n\\treturn RECIPROCAL_PI * diffuseColor;\\n}\\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\\n\\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\\n\\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\\n}\\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\\n\\tfloat fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\\n\\treturn f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\\n} // validated\";\n\nvar cube_uv_reflection_fragment = \"#ifdef ENVMAP_TYPE_CUBE_UV\\n\\t#define cubeUV_minMipLevel 4.0\\n\\t#define cubeUV_minTileSize 16.0\\n\\tfloat getFace( vec3 direction ) {\\n\\t\\tvec3 absDirection = abs( direction );\\n\\t\\tfloat face = - 1.0;\\n\\t\\tif ( absDirection.x > absDirection.z ) {\\n\\t\\t\\tif ( absDirection.x > absDirection.y )\\n\\t\\t\\t\\tface = direction.x > 0.0 ? 0.0 : 3.0;\\n\\t\\t\\telse\\n\\t\\t\\t\\tface = direction.y > 0.0 ? 1.0 : 4.0;\\n\\t\\t} else {\\n\\t\\t\\tif ( absDirection.z > absDirection.y )\\n\\t\\t\\t\\tface = direction.z > 0.0 ? 2.0 : 5.0;\\n\\t\\t\\telse\\n\\t\\t\\t\\tface = direction.y > 0.0 ? 1.0 : 4.0;\\n\\t\\t}\\n\\t\\treturn face;\\n\\t}\\n\\tvec2 getUV( vec3 direction, float face ) {\\n\\t\\tvec2 uv;\\n\\t\\tif ( face == 0.0 ) {\\n\\t\\t\\tuv = vec2( direction.z, direction.y ) / abs( direction.x );\\n\\t\\t} else if ( face == 1.0 ) {\\n\\t\\t\\tuv = vec2( - direction.x, - direction.z ) / abs( direction.y );\\n\\t\\t} else if ( face == 2.0 ) {\\n\\t\\t\\tuv = vec2( - direction.x, direction.y ) / abs( direction.z );\\n\\t\\t} else if ( face == 3.0 ) {\\n\\t\\t\\tuv = vec2( - direction.z, direction.y ) / abs( direction.x );\\n\\t\\t} else if ( face == 4.0 ) {\\n\\t\\t\\tuv = vec2( - direction.x, direction.z ) / abs( direction.y );\\n\\t\\t} else {\\n\\t\\t\\tuv = vec2( direction.x, direction.y ) / abs( direction.z );\\n\\t\\t}\\n\\t\\treturn 0.5 * ( uv + 1.0 );\\n\\t}\\n\\tvec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\\n\\t\\tfloat face = getFace( direction );\\n\\t\\tfloat filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\\n\\t\\tmipInt = max( mipInt, cubeUV_minMipLevel );\\n\\t\\tfloat faceSize = exp2( mipInt );\\n\\t\\thighp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;\\n\\t\\tif ( face > 2.0 ) {\\n\\t\\t\\tuv.y += faceSize;\\n\\t\\t\\tface -= 3.0;\\n\\t\\t}\\n\\t\\tuv.x += face * faceSize;\\n\\t\\tuv.x += filterInt * 3.0 * cubeUV_minTileSize;\\n\\t\\tuv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\\n\\t\\tuv.x *= CUBEUV_TEXEL_WIDTH;\\n\\t\\tuv.y *= CUBEUV_TEXEL_HEIGHT;\\n\\t\\t#ifdef texture2DGradEXT\\n\\t\\t\\treturn texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;\\n\\t\\t#else\\n\\t\\t\\treturn texture2D( envMap, uv ).rgb;\\n\\t\\t#endif\\n\\t}\\n\\t#define cubeUV_r0 1.0\\n\\t#define cubeUV_m0 - 2.0\\n\\t#define cubeUV_r1 0.8\\n\\t#define cubeUV_m1 - 1.0\\n\\t#define cubeUV_r4 0.4\\n\\t#define cubeUV_m4 2.0\\n\\t#define cubeUV_r5 0.305\\n\\t#define cubeUV_m5 3.0\\n\\t#define cubeUV_r6 0.21\\n\\t#define cubeUV_m6 4.0\\n\\tfloat roughnessToMip( float roughness ) {\\n\\t\\tfloat mip = 0.0;\\n\\t\\tif ( roughness >= cubeUV_r1 ) {\\n\\t\\t\\tmip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\\n\\t\\t} else if ( roughness >= cubeUV_r4 ) {\\n\\t\\t\\tmip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\\n\\t\\t} else if ( roughness >= cubeUV_r5 ) {\\n\\t\\t\\tmip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\\n\\t\\t} else if ( roughness >= cubeUV_r6 ) {\\n\\t\\t\\tmip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\\n\\t\\t} else {\\n\\t\\t\\tmip = - 2.0 * log2( 1.16 * roughness );\\t\\t}\\n\\t\\treturn mip;\\n\\t}\\n\\tvec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\\n\\t\\tfloat mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\\n\\t\\tfloat mipF = fract( mip );\\n\\t\\tfloat mipInt = floor( mip );\\n\\t\\tvec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\\n\\t\\tif ( mipF == 0.0 ) {\\n\\t\\t\\treturn vec4( color0, 1.0 );\\n\\t\\t} else {\\n\\t\\t\\tvec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\\n\\t\\t\\treturn vec4( mix( color0, color1, mipF ), 1.0 );\\n\\t\\t}\\n\\t}\\n#endif\";\n\nvar defaultnormal_vertex = \"vec3 transformedNormal = objectNormal;\\n#ifdef USE_TANGENT\\n\\tvec3 transformedTangent = objectTangent;\\n#endif\\n#ifdef USE_BATCHING\\n\\tmat3 bm = mat3( batchingMatrix );\\n\\ttransformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );\\n\\ttransformedNormal = bm * transformedNormal;\\n\\t#ifdef USE_TANGENT\\n\\t\\ttransformedTangent = bm * transformedTangent;\\n\\t#endif\\n#endif\\n#ifdef USE_INSTANCING\\n\\tmat3 im = mat3( instanceMatrix );\\n\\ttransformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );\\n\\ttransformedNormal = im * transformedNormal;\\n\\t#ifdef USE_TANGENT\\n\\t\\ttransformedTangent = im * transformedTangent;\\n\\t#endif\\n#endif\\ntransformedNormal = normalMatrix * transformedNormal;\\n#ifdef FLIP_SIDED\\n\\ttransformedNormal = - transformedNormal;\\n#endif\\n#ifdef USE_TANGENT\\n\\ttransformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;\\n\\t#ifdef FLIP_SIDED\\n\\t\\ttransformedTangent = - transformedTangent;\\n\\t#endif\\n#endif\";\n\nvar displacementmap_pars_vertex = \"#ifdef USE_DISPLACEMENTMAP\\n\\tuniform sampler2D displacementMap;\\n\\tuniform float displacementScale;\\n\\tuniform float displacementBias;\\n#endif\";\n\nvar displacementmap_vertex = \"#ifdef USE_DISPLACEMENTMAP\\n\\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\\n#endif\";\n\nvar emissivemap_fragment = \"#ifdef USE_EMISSIVEMAP\\n\\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\\n\\ttotalEmissiveRadiance *= emissiveColor.rgb;\\n#endif\";\n\nvar emissivemap_pars_fragment = \"#ifdef USE_EMISSIVEMAP\\n\\tuniform sampler2D emissiveMap;\\n#endif\";\n\nvar colorspace_fragment = \"gl_FragColor = linearToOutputTexel( gl_FragColor );\";\n\nvar colorspace_pars_fragment = \"\\nconst mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(\\n\\tvec3( 0.8224621, 0.177538, 0.0 ),\\n\\tvec3( 0.0331941, 0.9668058, 0.0 ),\\n\\tvec3( 0.0170827, 0.0723974, 0.9105199 )\\n);\\nconst mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3(\\n\\tvec3( 1.2249401, - 0.2249404, 0.0 ),\\n\\tvec3( - 0.0420569, 1.0420571, 0.0 ),\\n\\tvec3( - 0.0196376, - 0.0786361, 1.0982735 )\\n);\\nvec4 LinearSRGBToLinearDisplayP3( in vec4 value ) {\\n\\treturn vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a );\\n}\\nvec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) {\\n\\treturn vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a );\\n}\\nvec4 LinearTransferOETF( in vec4 value ) {\\n\\treturn value;\\n}\\nvec4 sRGBTransferOETF( in vec4 value ) {\\n\\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\\n}\";\n\nvar envmap_fragment = \"#ifdef USE_ENVMAP\\n\\t#ifdef ENV_WORLDPOS\\n\\t\\tvec3 cameraToFrag;\\n\\t\\tif ( isOrthographic ) {\\n\\t\\t\\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\\n\\t\\t} else {\\n\\t\\t\\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\\n\\t\\t}\\n\\t\\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\\n\\t\\t#ifdef ENVMAP_MODE_REFLECTION\\n\\t\\t\\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\\n\\t\\t#else\\n\\t\\t\\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\\n\\t\\t#endif\\n\\t#else\\n\\t\\tvec3 reflectVec = vReflect;\\n\\t#endif\\n\\t#ifdef ENVMAP_TYPE_CUBE\\n\\t\\tvec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\\n\\t#else\\n\\t\\tvec4 envColor = vec4( 0.0 );\\n\\t#endif\\n\\t#ifdef ENVMAP_BLENDING_MULTIPLY\\n\\t\\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\\n\\t#elif defined( ENVMAP_BLENDING_MIX )\\n\\t\\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\\n\\t#elif defined( ENVMAP_BLENDING_ADD )\\n\\t\\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\\n\\t#endif\\n#endif\";\n\nvar envmap_common_pars_fragment = \"#ifdef USE_ENVMAP\\n\\tuniform float envMapIntensity;\\n\\tuniform float flipEnvMap;\\n\\tuniform mat3 envMapRotation;\\n\\t#ifdef ENVMAP_TYPE_CUBE\\n\\t\\tuniform samplerCube envMap;\\n\\t#else\\n\\t\\tuniform sampler2D envMap;\\n\\t#endif\\n\\t\\n#endif\";\n\nvar envmap_pars_fragment = \"#ifdef USE_ENVMAP\\n\\tuniform float reflectivity;\\n\\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\\n\\t\\t#define ENV_WORLDPOS\\n\\t#endif\\n\\t#ifdef ENV_WORLDPOS\\n\\t\\tvarying vec3 vWorldPosition;\\n\\t\\tuniform float refractionRatio;\\n\\t#else\\n\\t\\tvarying vec3 vReflect;\\n\\t#endif\\n#endif\";\n\nvar envmap_pars_vertex = \"#ifdef USE_ENVMAP\\n\\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\\n\\t\\t#define ENV_WORLDPOS\\n\\t#endif\\n\\t#ifdef ENV_WORLDPOS\\n\\t\\t\\n\\t\\tvarying vec3 vWorldPosition;\\n\\t#else\\n\\t\\tvarying vec3 vReflect;\\n\\t\\tuniform float refractionRatio;\\n\\t#endif\\n#endif\";\n\nvar envmap_vertex = \"#ifdef USE_ENVMAP\\n\\t#ifdef ENV_WORLDPOS\\n\\t\\tvWorldPosition = worldPosition.xyz;\\n\\t#else\\n\\t\\tvec3 cameraToVertex;\\n\\t\\tif ( isOrthographic ) {\\n\\t\\t\\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\\n\\t\\t} else {\\n\\t\\t\\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\\n\\t\\t}\\n\\t\\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\\n\\t\\t#ifdef ENVMAP_MODE_REFLECTION\\n\\t\\t\\tvReflect = reflect( cameraToVertex, worldNormal );\\n\\t\\t#else\\n\\t\\t\\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\\n\\t\\t#endif\\n\\t#endif\\n#endif\";\n\nvar fog_vertex = \"#ifdef USE_FOG\\n\\tvFogDepth = - mvPosition.z;\\n#endif\";\n\nvar fog_pars_vertex = \"#ifdef USE_FOG\\n\\tvarying float vFogDepth;\\n#endif\";\n\nvar fog_fragment = \"#ifdef USE_FOG\\n\\t#ifdef FOG_EXP2\\n\\t\\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\\n\\t#else\\n\\t\\tfloat fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\\n\\t#endif\\n\\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\\n#endif\";\n\nvar fog_pars_fragment = \"#ifdef USE_FOG\\n\\tuniform vec3 fogColor;\\n\\tvarying float vFogDepth;\\n\\t#ifdef FOG_EXP2\\n\\t\\tuniform float fogDensity;\\n\\t#else\\n\\t\\tuniform float fogNear;\\n\\t\\tuniform float fogFar;\\n\\t#endif\\n#endif\";\n\nvar gradientmap_pars_fragment = \"#ifdef USE_GRADIENTMAP\\n\\tuniform sampler2D gradientMap;\\n#endif\\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\\n\\tfloat dotNL = dot( normal, lightDirection );\\n\\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\\n\\t#ifdef USE_GRADIENTMAP\\n\\t\\treturn vec3( texture2D( gradientMap, coord ).r );\\n\\t#else\\n\\t\\tvec2 fw = fwidth( coord ) * 0.5;\\n\\t\\treturn mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\\n\\t#endif\\n}\";\n\nvar lightmap_pars_fragment = \"#ifdef USE_LIGHTMAP\\n\\tuniform sampler2D lightMap;\\n\\tuniform float lightMapIntensity;\\n#endif\";\n\nvar lights_lambert_fragment = \"LambertMaterial material;\\nmaterial.diffuseColor = diffuseColor.rgb;\\nmaterial.specularStrength = specularStrength;\";\n\nvar lights_lambert_pars_fragment = \"varying vec3 vViewPosition;\\nstruct LambertMaterial {\\n\\tvec3 diffuseColor;\\n\\tfloat specularStrength;\\n};\\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\\n\\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\\n\\tvec3 irradiance = dotNL * directLight.color;\\n\\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\\n}\\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\\n\\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\\n}\\n#define RE_Direct\\t\\t\\t\\tRE_Direct_Lambert\\n#define RE_IndirectDiffuse\\t\\tRE_IndirectDiffuse_Lambert\";\n\nvar lights_pars_begin = \"uniform bool receiveShadow;\\nuniform vec3 ambientLightColor;\\n#if defined( USE_LIGHT_PROBES )\\n\\tuniform vec3 lightProbe[ 9 ];\\n#endif\\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\\n\\tfloat x = normal.x, y = normal.y, z = normal.z;\\n\\tvec3 result = shCoefficients[ 0 ] * 0.886227;\\n\\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\\n\\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\\n\\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\\n\\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\\n\\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\\n\\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\\n\\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\\n\\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\\n\\treturn result;\\n}\\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\\n\\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\\n\\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\\n\\treturn irradiance;\\n}\\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\\n\\tvec3 irradiance = ambientLightColor;\\n\\treturn irradiance;\\n}\\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\\n\\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\\n\\tif ( cutoffDistance > 0.0 ) {\\n\\t\\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\\n\\t}\\n\\treturn distanceFalloff;\\n}\\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\\n\\treturn smoothstep( coneCosine, penumbraCosine, angleCosine );\\n}\\n#if NUM_DIR_LIGHTS > 0\\n\\tstruct DirectionalLight {\\n\\t\\tvec3 direction;\\n\\t\\tvec3 color;\\n\\t};\\n\\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\\n\\tvoid getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\\n\\t\\tlight.color = directionalLight.color;\\n\\t\\tlight.direction = directionalLight.direction;\\n\\t\\tlight.visible = true;\\n\\t}\\n#endif\\n#if NUM_POINT_LIGHTS > 0\\n\\tstruct PointLight {\\n\\t\\tvec3 position;\\n\\t\\tvec3 color;\\n\\t\\tfloat distance;\\n\\t\\tfloat decay;\\n\\t};\\n\\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\\n\\tvoid getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\\n\\t\\tvec3 lVector = pointLight.position - geometryPosition;\\n\\t\\tlight.direction = normalize( lVector );\\n\\t\\tfloat lightDistance = length( lVector );\\n\\t\\tlight.color = pointLight.color;\\n\\t\\tlight.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\\n\\t\\tlight.visible = ( light.color != vec3( 0.0 ) );\\n\\t}\\n#endif\\n#if NUM_SPOT_LIGHTS > 0\\n\\tstruct SpotLight {\\n\\t\\tvec3 position;\\n\\t\\tvec3 direction;\\n\\t\\tvec3 color;\\n\\t\\tfloat distance;\\n\\t\\tfloat decay;\\n\\t\\tfloat coneCos;\\n\\t\\tfloat penumbraCos;\\n\\t};\\n\\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\\n\\tvoid getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\\n\\t\\tvec3 lVector = spotLight.position - geometryPosition;\\n\\t\\tlight.direction = normalize( lVector );\\n\\t\\tfloat angleCos = dot( light.direction, spotLight.direction );\\n\\t\\tfloat spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\\n\\t\\tif ( spotAttenuation > 0.0 ) {\\n\\t\\t\\tfloat lightDistance = length( lVector );\\n\\t\\t\\tlight.color = spotLight.color * spotAttenuation;\\n\\t\\t\\tlight.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\\n\\t\\t\\tlight.visible = ( light.color != vec3( 0.0 ) );\\n\\t\\t} else {\\n\\t\\t\\tlight.color = vec3( 0.0 );\\n\\t\\t\\tlight.visible = false;\\n\\t\\t}\\n\\t}\\n#endif\\n#if NUM_RECT_AREA_LIGHTS > 0\\n\\tstruct RectAreaLight {\\n\\t\\tvec3 color;\\n\\t\\tvec3 position;\\n\\t\\tvec3 halfWidth;\\n\\t\\tvec3 halfHeight;\\n\\t};\\n\\tuniform sampler2D ltc_1;\\tuniform sampler2D ltc_2;\\n\\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\\n#endif\\n#if NUM_HEMI_LIGHTS > 0\\n\\tstruct HemisphereLight {\\n\\t\\tvec3 direction;\\n\\t\\tvec3 skyColor;\\n\\t\\tvec3 groundColor;\\n\\t};\\n\\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\\n\\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\\n\\t\\tfloat dotNL = dot( normal, hemiLight.direction );\\n\\t\\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\\n\\t\\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\\n\\t\\treturn irradiance;\\n\\t}\\n#endif\";\n\nvar envmap_physical_pars_fragment = \"#ifdef USE_ENVMAP\\n\\tvec3 getIBLIrradiance( const in vec3 normal ) {\\n\\t\\t#ifdef ENVMAP_TYPE_CUBE_UV\\n\\t\\t\\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\\n\\t\\t\\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );\\n\\t\\t\\treturn PI * envMapColor.rgb * envMapIntensity;\\n\\t\\t#else\\n\\t\\t\\treturn vec3( 0.0 );\\n\\t\\t#endif\\n\\t}\\n\\tvec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\\n\\t\\t#ifdef ENVMAP_TYPE_CUBE_UV\\n\\t\\t\\tvec3 reflectVec = reflect( - viewDir, normal );\\n\\t\\t\\treflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\\n\\t\\t\\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\\n\\t\\t\\tvec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );\\n\\t\\t\\treturn envMapColor.rgb * envMapIntensity;\\n\\t\\t#else\\n\\t\\t\\treturn vec3( 0.0 );\\n\\t\\t#endif\\n\\t}\\n\\t#ifdef USE_ANISOTROPY\\n\\t\\tvec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\\n\\t\\t\\t#ifdef ENVMAP_TYPE_CUBE_UV\\n\\t\\t\\t\\tvec3 bentNormal = cross( bitangent, viewDir );\\n\\t\\t\\t\\tbentNormal = normalize( cross( bentNormal, bitangent ) );\\n\\t\\t\\t\\tbentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\\n\\t\\t\\t\\treturn getIBLRadiance( viewDir, bentNormal, roughness );\\n\\t\\t\\t#else\\n\\t\\t\\t\\treturn vec3( 0.0 );\\n\\t\\t\\t#endif\\n\\t\\t}\\n\\t#endif\\n#endif\";\n\nvar lights_toon_fragment = \"ToonMaterial material;\\nmaterial.diffuseColor = diffuseColor.rgb;\";\n\nvar lights_toon_pars_fragment = \"varying vec3 vViewPosition;\\nstruct ToonMaterial {\\n\\tvec3 diffuseColor;\\n};\\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\\n\\tvec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\\n\\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\\n}\\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\\n\\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\\n}\\n#define RE_Direct\\t\\t\\t\\tRE_Direct_Toon\\n#define RE_IndirectDiffuse\\t\\tRE_IndirectDiffuse_Toon\";\n\nvar lights_phong_fragment = \"BlinnPhongMaterial material;\\nmaterial.diffuseColor = diffuseColor.rgb;\\nmaterial.specularColor = specular;\\nmaterial.specularShininess = shininess;\\nmaterial.specularStrength = specularStrength;\";\n\nvar lights_phong_pars_fragment = \"varying vec3 vViewPosition;\\nstruct BlinnPhongMaterial {\\n\\tvec3 diffuseColor;\\n\\tvec3 specularColor;\\n\\tfloat specularShininess;\\n\\tfloat specularStrength;\\n};\\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\\n\\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\\n\\tvec3 irradiance = dotNL * directLight.color;\\n\\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\\n\\treflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\\n}\\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\\n\\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\\n}\\n#define RE_Direct\\t\\t\\t\\tRE_Direct_BlinnPhong\\n#define RE_IndirectDiffuse\\t\\tRE_IndirectDiffuse_BlinnPhong\";\n\nvar lights_physical_fragment = \"PhysicalMaterial material;\\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\\nmaterial.roughness = min( material.roughness, 1.0 );\\n#ifdef IOR\\n\\tmaterial.ior = ior;\\n\\t#ifdef USE_SPECULAR\\n\\t\\tfloat specularIntensityFactor = specularIntensity;\\n\\t\\tvec3 specularColorFactor = specularColor;\\n\\t\\t#ifdef USE_SPECULAR_COLORMAP\\n\\t\\t\\tspecularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\\n\\t\\t#endif\\n\\t\\t#ifdef USE_SPECULAR_INTENSITYMAP\\n\\t\\t\\tspecularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\\n\\t\\t#endif\\n\\t\\tmaterial.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\\n\\t#else\\n\\t\\tfloat specularIntensityFactor = 1.0;\\n\\t\\tvec3 specularColorFactor = vec3( 1.0 );\\n\\t\\tmaterial.specularF90 = 1.0;\\n\\t#endif\\n\\tmaterial.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\\n#else\\n\\tmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\\n\\tmaterial.specularF90 = 1.0;\\n#endif\\n#ifdef USE_CLEARCOAT\\n\\tmaterial.clearcoat = clearcoat;\\n\\tmaterial.clearcoatRoughness = clearcoatRoughness;\\n\\tmaterial.clearcoatF0 = vec3( 0.04 );\\n\\tmaterial.clearcoatF90 = 1.0;\\n\\t#ifdef USE_CLEARCOATMAP\\n\\t\\tmaterial.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\\n\\t#endif\\n\\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\\n\\t\\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\\n\\t#endif\\n\\tmaterial.clearcoat = saturate( material.clearcoat );\\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\\n\\tmaterial.clearcoatRoughness += geometryRoughness;\\n\\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\\n#endif\\n#ifdef USE_DISPERSION\\n\\tmaterial.dispersion = dispersion;\\n#endif\\n#ifdef USE_IRIDESCENCE\\n\\tmaterial.iridescence = iridescence;\\n\\tmaterial.iridescenceIOR = iridescenceIOR;\\n\\t#ifdef USE_IRIDESCENCEMAP\\n\\t\\tmaterial.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\\n\\t#endif\\n\\t#ifdef USE_IRIDESCENCE_THICKNESSMAP\\n\\t\\tmaterial.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\\n\\t#else\\n\\t\\tmaterial.iridescenceThickness = iridescenceThicknessMaximum;\\n\\t#endif\\n#endif\\n#ifdef USE_SHEEN\\n\\tmaterial.sheenColor = sheenColor;\\n\\t#ifdef USE_SHEEN_COLORMAP\\n\\t\\tmaterial.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\\n\\t#endif\\n\\tmaterial.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\\n\\t#ifdef USE_SHEEN_ROUGHNESSMAP\\n\\t\\tmaterial.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\\n\\t#endif\\n#endif\\n#ifdef USE_ANISOTROPY\\n\\t#ifdef USE_ANISOTROPYMAP\\n\\t\\tmat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\\n\\t\\tvec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\\n\\t\\tvec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\\n\\t#else\\n\\t\\tvec2 anisotropyV = anisotropyVector;\\n\\t#endif\\n\\tmaterial.anisotropy = length( anisotropyV );\\n\\tif( material.anisotropy == 0.0 ) {\\n\\t\\tanisotropyV = vec2( 1.0, 0.0 );\\n\\t} else {\\n\\t\\tanisotropyV /= material.anisotropy;\\n\\t\\tmaterial.anisotropy = saturate( material.anisotropy );\\n\\t}\\n\\tmaterial.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\\n\\tmaterial.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;\\n\\tmaterial.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;\\n#endif\";\n\nvar lights_physical_pars_fragment = \"struct PhysicalMaterial {\\n\\tvec3 diffuseColor;\\n\\tfloat roughness;\\n\\tvec3 specularColor;\\n\\tfloat specularF90;\\n\\tfloat dispersion;\\n\\t#ifdef USE_CLEARCOAT\\n\\t\\tfloat clearcoat;\\n\\t\\tfloat clearcoatRoughness;\\n\\t\\tvec3 clearcoatF0;\\n\\t\\tfloat clearcoatF90;\\n\\t#endif\\n\\t#ifdef USE_IRIDESCENCE\\n\\t\\tfloat iridescence;\\n\\t\\tfloat iridescenceIOR;\\n\\t\\tfloat iridescenceThickness;\\n\\t\\tvec3 iridescenceFresnel;\\n\\t\\tvec3 iridescenceF0;\\n\\t#endif\\n\\t#ifdef USE_SHEEN\\n\\t\\tvec3 sheenColor;\\n\\t\\tfloat sheenRoughness;\\n\\t#endif\\n\\t#ifdef IOR\\n\\t\\tfloat ior;\\n\\t#endif\\n\\t#ifdef USE_TRANSMISSION\\n\\t\\tfloat transmission;\\n\\t\\tfloat transmissionAlpha;\\n\\t\\tfloat thickness;\\n\\t\\tfloat attenuationDistance;\\n\\t\\tvec3 attenuationColor;\\n\\t#endif\\n\\t#ifdef USE_ANISOTROPY\\n\\t\\tfloat anisotropy;\\n\\t\\tfloat alphaT;\\n\\t\\tvec3 anisotropyT;\\n\\t\\tvec3 anisotropyB;\\n\\t#endif\\n};\\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\\nvec3 sheenSpecularDirect = vec3( 0.0 );\\nvec3 sheenSpecularIndirect = vec3(0.0 );\\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\\n float x2 = x * x;\\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\\n}\\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\\n\\tfloat a2 = pow2( alpha );\\n\\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\\n\\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\\n\\treturn 0.5 / max( gv + gl, EPSILON );\\n}\\nfloat D_GGX( const in float alpha, const in float dotNH ) {\\n\\tfloat a2 = pow2( alpha );\\n\\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\\n\\treturn RECIPROCAL_PI * a2 / pow2( denom );\\n}\\n#ifdef USE_ANISOTROPY\\n\\tfloat V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\\n\\t\\tfloat gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\\n\\t\\tfloat gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\\n\\t\\tfloat v = 0.5 / ( gv + gl );\\n\\t\\treturn saturate(v);\\n\\t}\\n\\tfloat D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\\n\\t\\tfloat a2 = alphaT * alphaB;\\n\\t\\thighp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\\n\\t\\thighp float v2 = dot( v, v );\\n\\t\\tfloat w2 = a2 / v2;\\n\\t\\treturn RECIPROCAL_PI * a2 * pow2 ( w2 );\\n\\t}\\n#endif\\n#ifdef USE_CLEARCOAT\\n\\tvec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\\n\\t\\tvec3 f0 = material.clearcoatF0;\\n\\t\\tfloat f90 = material.clearcoatF90;\\n\\t\\tfloat roughness = material.clearcoatRoughness;\\n\\t\\tfloat alpha = pow2( roughness );\\n\\t\\tvec3 halfDir = normalize( lightDir + viewDir );\\n\\t\\tfloat dotNL = saturate( dot( normal, lightDir ) );\\n\\t\\tfloat dotNV = saturate( dot( normal, viewDir ) );\\n\\t\\tfloat dotNH = saturate( dot( normal, halfDir ) );\\n\\t\\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\\n\\t\\tvec3 F = F_Schlick( f0, f90, dotVH );\\n\\t\\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\\n\\t\\tfloat D = D_GGX( alpha, dotNH );\\n\\t\\treturn F * ( V * D );\\n\\t}\\n#endif\\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\\n\\tvec3 f0 = material.specularColor;\\n\\tfloat f90 = material.specularF90;\\n\\tfloat roughness = material.roughness;\\n\\tfloat alpha = pow2( roughness );\\n\\tvec3 halfDir = normalize( lightDir + viewDir );\\n\\tfloat dotNL = saturate( dot( normal, lightDir ) );\\n\\tfloat dotNV = saturate( dot( normal, viewDir ) );\\n\\tfloat dotNH = saturate( dot( normal, halfDir ) );\\n\\tfloat dotVH = saturate( dot( viewDir, halfDir ) );\\n\\tvec3 F = F_Schlick( f0, f90, dotVH );\\n\\t#ifdef USE_IRIDESCENCE\\n\\t\\tF = mix( F, material.iridescenceFresnel, material.iridescence );\\n\\t#endif\\n\\t#ifdef USE_ANISOTROPY\\n\\t\\tfloat dotTL = dot( material.anisotropyT, lightDir );\\n\\t\\tfloat dotTV = dot( material.anisotropyT, viewDir );\\n\\t\\tfloat dotTH = dot( material.anisotropyT, halfDir );\\n\\t\\tfloat dotBL = dot( material.anisotropyB, lightDir );\\n\\t\\tfloat dotBV = dot( material.anisotropyB, viewDir );\\n\\t\\tfloat dotBH = dot( material.anisotropyB, halfDir );\\n\\t\\tfloat V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\\n\\t\\tfloat D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\\n\\t#else\\n\\t\\tfloat V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\\n\\t\\tfloat D = D_GGX( alpha, dotNH );\\n\\t#endif\\n\\treturn F * ( V * D );\\n}\\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\\n\\tconst float LUT_SIZE = 64.0;\\n\\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\\n\\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\\n\\tfloat dotNV = saturate( dot( N, V ) );\\n\\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\\n\\tuv = uv * LUT_SCALE + LUT_BIAS;\\n\\treturn uv;\\n}\\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\\n\\tfloat l = length( f );\\n\\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\\n}\\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\\n\\tfloat x = dot( v1, v2 );\\n\\tfloat y = abs( x );\\n\\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\\n\\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\\n\\tfloat v = a / b;\\n\\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\\n\\treturn cross( v1, v2 ) * theta_sintheta;\\n}\\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\\n\\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\\n\\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\\n\\tvec3 lightNormal = cross( v1, v2 );\\n\\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\\n\\tvec3 T1, T2;\\n\\tT1 = normalize( V - N * dot( V, N ) );\\n\\tT2 = - cross( N, T1 );\\n\\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\\n\\tvec3 coords[ 4 ];\\n\\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\\n\\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\\n\\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\\n\\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\\n\\tcoords[ 0 ] = normalize( coords[ 0 ] );\\n\\tcoords[ 1 ] = normalize( coords[ 1 ] );\\n\\tcoords[ 2 ] = normalize( coords[ 2 ] );\\n\\tcoords[ 3 ] = normalize( coords[ 3 ] );\\n\\tvec3 vectorFormFactor = vec3( 0.0 );\\n\\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\\n\\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\\n\\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\\n\\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\\n\\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\\n\\treturn vec3( result );\\n}\\n#if defined( USE_SHEEN )\\nfloat D_Charlie( float roughness, float dotNH ) {\\n\\tfloat alpha = pow2( roughness );\\n\\tfloat invAlpha = 1.0 / alpha;\\n\\tfloat cos2h = dotNH * dotNH;\\n\\tfloat sin2h = max( 1.0 - cos2h, 0.0078125 );\\n\\treturn ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\\n}\\nfloat V_Neubelt( float dotNV, float dotNL ) {\\n\\treturn saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\\n}\\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\\n\\tvec3 halfDir = normalize( lightDir + viewDir );\\n\\tfloat dotNL = saturate( dot( normal, lightDir ) );\\n\\tfloat dotNV = saturate( dot( normal, viewDir ) );\\n\\tfloat dotNH = saturate( dot( normal, halfDir ) );\\n\\tfloat D = D_Charlie( sheenRoughness, dotNH );\\n\\tfloat V = V_Neubelt( dotNV, dotNL );\\n\\treturn sheenColor * ( D * V );\\n}\\n#endif\\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\\n\\tfloat dotNV = saturate( dot( normal, viewDir ) );\\n\\tfloat r2 = roughness * roughness;\\n\\tfloat a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\\n\\tfloat b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\\n\\tfloat DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\\n\\treturn saturate( DG * RECIPROCAL_PI );\\n}\\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\\n\\tfloat dotNV = saturate( dot( normal, viewDir ) );\\n\\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\\n\\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\\n\\tvec4 r = roughness * c0 + c1;\\n\\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\\n\\tvec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\\n\\treturn fab;\\n}\\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\\n\\tvec2 fab = DFGApprox( normal, viewDir, roughness );\\n\\treturn specularColor * fab.x + specularF90 * fab.y;\\n}\\n#ifdef USE_IRIDESCENCE\\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\\n#else\\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\\n#endif\\n\\tvec2 fab = DFGApprox( normal, viewDir, roughness );\\n\\t#ifdef USE_IRIDESCENCE\\n\\t\\tvec3 Fr = mix( specularColor, iridescenceF0, iridescence );\\n\\t#else\\n\\t\\tvec3 Fr = specularColor;\\n\\t#endif\\n\\tvec3 FssEss = Fr * fab.x + specularF90 * fab.y;\\n\\tfloat Ess = fab.x + fab.y;\\n\\tfloat Ems = 1.0 - Ess;\\n\\tvec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619;\\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\\n\\tsingleScatter += FssEss;\\n\\tmultiScatter += Fms * Ems;\\n}\\n#if NUM_RECT_AREA_LIGHTS > 0\\n\\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\\n\\t\\tvec3 normal = geometryNormal;\\n\\t\\tvec3 viewDir = geometryViewDir;\\n\\t\\tvec3 position = geometryPosition;\\n\\t\\tvec3 lightPos = rectAreaLight.position;\\n\\t\\tvec3 halfWidth = rectAreaLight.halfWidth;\\n\\t\\tvec3 halfHeight = rectAreaLight.halfHeight;\\n\\t\\tvec3 lightColor = rectAreaLight.color;\\n\\t\\tfloat roughness = material.roughness;\\n\\t\\tvec3 rectCoords[ 4 ];\\n\\t\\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\\t\\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\\n\\t\\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\\n\\t\\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\\n\\t\\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\\n\\t\\tvec4 t1 = texture2D( ltc_1, uv );\\n\\t\\tvec4 t2 = texture2D( ltc_2, uv );\\n\\t\\tmat3 mInv = mat3(\\n\\t\\t\\tvec3( t1.x, 0, t1.y ),\\n\\t\\t\\tvec3( 0, 1, 0 ),\\n\\t\\t\\tvec3( t1.z, 0, t1.w )\\n\\t\\t);\\n\\t\\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\\n\\t\\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\\n\\t\\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\\n\\t}\\n#endif\\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\\n\\tfloat dotNL = saturate( dot( geometryNormal, directLight.direction ) );\\n\\tvec3 irradiance = dotNL * directLight.color;\\n\\t#ifdef USE_CLEARCOAT\\n\\t\\tfloat dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\\n\\t\\tvec3 ccIrradiance = dotNLcc * directLight.color;\\n\\t\\tclearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\\n\\t#endif\\n\\t#ifdef USE_SHEEN\\n\\t\\tsheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\\n\\t#endif\\n\\treflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );\\n\\treflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\\n}\\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\\n\\treflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\\n}\\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\\n\\t#ifdef USE_CLEARCOAT\\n\\t\\tclearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\\n\\t#endif\\n\\t#ifdef USE_SHEEN\\n\\t\\tsheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\\n\\t#endif\\n\\tvec3 singleScattering = vec3( 0.0 );\\n\\tvec3 multiScattering = vec3( 0.0 );\\n\\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\\n\\t#ifdef USE_IRIDESCENCE\\n\\t\\tcomputeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\\n\\t#else\\n\\t\\tcomputeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\\n\\t#endif\\n\\tvec3 totalScattering = singleScattering + multiScattering;\\n\\tvec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );\\n\\treflectedLight.indirectSpecular += radiance * singleScattering;\\n\\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\\n\\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\\n}\\n#define RE_Direct\\t\\t\\t\\tRE_Direct_Physical\\n#define RE_Direct_RectArea\\t\\tRE_Direct_RectArea_Physical\\n#define RE_IndirectDiffuse\\t\\tRE_IndirectDiffuse_Physical\\n#define RE_IndirectSpecular\\t\\tRE_IndirectSpecular_Physical\\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\\n\\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\\n}\";\n\nvar lights_fragment_begin = \"\\nvec3 geometryPosition = - vViewPosition;\\nvec3 geometryNormal = normal;\\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\\nvec3 geometryClearcoatNormal = vec3( 0.0 );\\n#ifdef USE_CLEARCOAT\\n\\tgeometryClearcoatNormal = clearcoatNormal;\\n#endif\\n#ifdef USE_IRIDESCENCE\\n\\tfloat dotNVi = saturate( dot( normal, geometryViewDir ) );\\n\\tif ( material.iridescenceThickness == 0.0 ) {\\n\\t\\tmaterial.iridescence = 0.0;\\n\\t} else {\\n\\t\\tmaterial.iridescence = saturate( material.iridescence );\\n\\t}\\n\\tif ( material.iridescence > 0.0 ) {\\n\\t\\tmaterial.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\\n\\t\\tmaterial.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\\n\\t}\\n#endif\\nIncidentLight directLight;\\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\\n\\tPointLight pointLight;\\n\\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\\n\\tPointLightShadow pointLightShadow;\\n\\t#endif\\n\\t#pragma unroll_loop_start\\n\\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\\n\\t\\tpointLight = pointLights[ i ];\\n\\t\\tgetPointLightInfo( pointLight, geometryPosition, directLight );\\n\\t\\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\\n\\t\\tpointLightShadow = pointLightShadows[ i ];\\n\\t\\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\\n\\t\\t#endif\\n\\t\\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\\n\\t}\\n\\t#pragma unroll_loop_end\\n#endif\\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\\n\\tSpotLight spotLight;\\n\\tvec4 spotColor;\\n\\tvec3 spotLightCoord;\\n\\tbool inSpotLightMap;\\n\\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\\n\\tSpotLightShadow spotLightShadow;\\n\\t#endif\\n\\t#pragma unroll_loop_start\\n\\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\\n\\t\\tspotLight = spotLights[ i ];\\n\\t\\tgetSpotLightInfo( spotLight, geometryPosition, directLight );\\n\\t\\t#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\\n\\t\\t#define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\\n\\t\\t#elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\\n\\t\\t#define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\\n\\t\\t#else\\n\\t\\t#define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\\n\\t\\t#endif\\n\\t\\t#if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\\n\\t\\t\\tspotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\\n\\t\\t\\tinSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\\n\\t\\t\\tspotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\\n\\t\\t\\tdirectLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\\n\\t\\t#endif\\n\\t\\t#undef SPOT_LIGHT_MAP_INDEX\\n\\t\\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\\n\\t\\tspotLightShadow = spotLightShadows[ i ];\\n\\t\\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\\n\\t\\t#endif\\n\\t\\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\\n\\t}\\n\\t#pragma unroll_loop_end\\n#endif\\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\\n\\tDirectionalLight directionalLight;\\n\\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\\n\\tDirectionalLightShadow directionalLightShadow;\\n\\t#endif\\n\\t#pragma unroll_loop_start\\n\\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\\n\\t\\tdirectionalLight = directionalLights[ i ];\\n\\t\\tgetDirectionalLightInfo( directionalLight, directLight );\\n\\t\\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\\n\\t\\tdirectionalLightShadow = directionalLightShadows[ i ];\\n\\t\\tdirectLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\\n\\t\\t#endif\\n\\t\\tRE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\\n\\t}\\n\\t#pragma unroll_loop_end\\n#endif\\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\\n\\tRectAreaLight rectAreaLight;\\n\\t#pragma unroll_loop_start\\n\\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\\n\\t\\trectAreaLight = rectAreaLights[ i ];\\n\\t\\tRE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\\n\\t}\\n\\t#pragma unroll_loop_end\\n#endif\\n#if defined( RE_IndirectDiffuse )\\n\\tvec3 iblIrradiance = vec3( 0.0 );\\n\\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\\n\\t#if defined( USE_LIGHT_PROBES )\\n\\t\\tirradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\\n\\t#endif\\n\\t#if ( NUM_HEMI_LIGHTS > 0 )\\n\\t\\t#pragma unroll_loop_start\\n\\t\\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\\n\\t\\t\\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\\n\\t\\t}\\n\\t\\t#pragma unroll_loop_end\\n\\t#endif\\n#endif\\n#if defined( RE_IndirectSpecular )\\n\\tvec3 radiance = vec3( 0.0 );\\n\\tvec3 clearcoatRadiance = vec3( 0.0 );\\n#endif\";\n\nvar lights_fragment_maps = \"#if defined( RE_IndirectDiffuse )\\n\\t#ifdef USE_LIGHTMAP\\n\\t\\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\\n\\t\\tvec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\\n\\t\\tirradiance += lightMapIrradiance;\\n\\t#endif\\n\\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\\n\\t\\tiblIrradiance += getIBLIrradiance( geometryNormal );\\n\\t#endif\\n#endif\\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\\n\\t#ifdef USE_ANISOTROPY\\n\\t\\tradiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\\n\\t#else\\n\\t\\tradiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\\n\\t#endif\\n\\t#ifdef USE_CLEARCOAT\\n\\t\\tclearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\\n\\t#endif\\n#endif\";\n\nvar lights_fragment_end = \"#if defined( RE_IndirectDiffuse )\\n\\tRE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\\n#endif\\n#if defined( RE_IndirectSpecular )\\n\\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\\n#endif\";\n\nvar logdepthbuf_fragment = \"#if defined( USE_LOGDEPTHBUF )\\n\\tgl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\\n#endif\";\n\nvar logdepthbuf_pars_fragment = \"#if defined( USE_LOGDEPTHBUF )\\n\\tuniform float logDepthBufFC;\\n\\tvarying float vFragDepth;\\n\\tvarying float vIsPerspective;\\n#endif\";\n\nvar logdepthbuf_pars_vertex = \"#ifdef USE_LOGDEPTHBUF\\n\\tvarying float vFragDepth;\\n\\tvarying float vIsPerspective;\\n#endif\";\n\nvar logdepthbuf_vertex = \"#ifdef USE_LOGDEPTHBUF\\n\\tvFragDepth = 1.0 + gl_Position.w;\\n\\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\\n#endif\";\n\nvar map_fragment = \"#ifdef USE_MAP\\n\\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\\n\\t#ifdef DECODE_VIDEO_TEXTURE\\n\\t\\tsampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );\\n\\t\\n\\t#endif\\n\\tdiffuseColor *= sampledDiffuseColor;\\n#endif\";\n\nvar map_pars_fragment = \"#ifdef USE_MAP\\n\\tuniform sampler2D map;\\n#endif\";\n\nvar map_particle_fragment = \"#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\\n\\t#if defined( USE_POINTS_UV )\\n\\t\\tvec2 uv = vUv;\\n\\t#else\\n\\t\\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\\n\\t#endif\\n#endif\\n#ifdef USE_MAP\\n\\tdiffuseColor *= texture2D( map, uv );\\n#endif\\n#ifdef USE_ALPHAMAP\\n\\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\\n#endif\";\n\nvar map_particle_pars_fragment = \"#if defined( USE_POINTS_UV )\\n\\tvarying vec2 vUv;\\n#else\\n\\t#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\\n\\t\\tuniform mat3 uvTransform;\\n\\t#endif\\n#endif\\n#ifdef USE_MAP\\n\\tuniform sampler2D map;\\n#endif\\n#ifdef USE_ALPHAMAP\\n\\tuniform sampler2D alphaMap;\\n#endif\";\n\nvar metalnessmap_fragment = \"float metalnessFactor = metalness;\\n#ifdef USE_METALNESSMAP\\n\\tvec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\\n\\tmetalnessFactor *= texelMetalness.b;\\n#endif\";\n\nvar metalnessmap_pars_fragment = \"#ifdef USE_METALNESSMAP\\n\\tuniform sampler2D metalnessMap;\\n#endif\";\n\nvar morphinstance_vertex = \"#ifdef USE_INSTANCING_MORPH\\n\\tfloat morphTargetInfluences[ MORPHTARGETS_COUNT ];\\n\\tfloat morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;\\n\\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\\n\\t\\tmorphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;\\n\\t}\\n#endif\";\n\nvar morphcolor_vertex = \"#if defined( USE_MORPHCOLORS )\\n\\tvColor *= morphTargetBaseInfluence;\\n\\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\\n\\t\\t#if defined( USE_COLOR_ALPHA )\\n\\t\\t\\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\\n\\t\\t#elif defined( USE_COLOR )\\n\\t\\t\\tif ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\\n\\t\\t#endif\\n\\t}\\n#endif\";\n\nvar morphnormal_vertex = \"#ifdef USE_MORPHNORMALS\\n\\tobjectNormal *= morphTargetBaseInfluence;\\n\\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\\n\\t\\tif ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\\n\\t}\\n#endif\";\n\nvar morphtarget_pars_vertex = \"#ifdef USE_MORPHTARGETS\\n\\t#ifndef USE_INSTANCING_MORPH\\n\\t\\tuniform float morphTargetBaseInfluence;\\n\\t\\tuniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\\n\\t#endif\\n\\tuniform sampler2DArray morphTargetsTexture;\\n\\tuniform ivec2 morphTargetsTextureSize;\\n\\tvec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\\n\\t\\tint texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\\n\\t\\tint y = texelIndex / morphTargetsTextureSize.x;\\n\\t\\tint x = texelIndex - y * morphTargetsTextureSize.x;\\n\\t\\tivec3 morphUV = ivec3( x, y, morphTargetIndex );\\n\\t\\treturn texelFetch( morphTargetsTexture, morphUV, 0 );\\n\\t}\\n#endif\";\n\nvar morphtarget_vertex = \"#ifdef USE_MORPHTARGETS\\n\\ttransformed *= morphTargetBaseInfluence;\\n\\tfor ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\\n\\t\\tif ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\\n\\t}\\n#endif\";\n\nvar normal_fragment_begin = \"float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\\n#ifdef FLAT_SHADED\\n\\tvec3 fdx = dFdx( vViewPosition );\\n\\tvec3 fdy = dFdy( vViewPosition );\\n\\tvec3 normal = normalize( cross( fdx, fdy ) );\\n#else\\n\\tvec3 normal = normalize( vNormal );\\n\\t#ifdef DOUBLE_SIDED\\n\\t\\tnormal *= faceDirection;\\n\\t#endif\\n#endif\\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\\n\\t#ifdef USE_TANGENT\\n\\t\\tmat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\\n\\t#else\\n\\t\\tmat3 tbn = getTangentFrame( - vViewPosition, normal,\\n\\t\\t#if defined( USE_NORMALMAP )\\n\\t\\t\\tvNormalMapUv\\n\\t\\t#elif defined( USE_CLEARCOAT_NORMALMAP )\\n\\t\\t\\tvClearcoatNormalMapUv\\n\\t\\t#else\\n\\t\\t\\tvUv\\n\\t\\t#endif\\n\\t\\t);\\n\\t#endif\\n\\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\\n\\t\\ttbn[0] *= faceDirection;\\n\\t\\ttbn[1] *= faceDirection;\\n\\t#endif\\n#endif\\n#ifdef USE_CLEARCOAT_NORMALMAP\\n\\t#ifdef USE_TANGENT\\n\\t\\tmat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\\n\\t#else\\n\\t\\tmat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\\n\\t#endif\\n\\t#if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\\n\\t\\ttbn2[0] *= faceDirection;\\n\\t\\ttbn2[1] *= faceDirection;\\n\\t#endif\\n#endif\\nvec3 nonPerturbedNormal = normal;\";\n\nvar normal_fragment_maps = \"#ifdef USE_NORMALMAP_OBJECTSPACE\\n\\tnormal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\\n\\t#ifdef FLIP_SIDED\\n\\t\\tnormal = - normal;\\n\\t#endif\\n\\t#ifdef DOUBLE_SIDED\\n\\t\\tnormal = normal * faceDirection;\\n\\t#endif\\n\\tnormal = normalize( normalMatrix * normal );\\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\\n\\tvec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\\n\\tmapN.xy *= normalScale;\\n\\tnormal = normalize( tbn * mapN );\\n#elif defined( USE_BUMPMAP )\\n\\tnormal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\\n#endif\";\n\nvar normal_pars_fragment = \"#ifndef FLAT_SHADED\\n\\tvarying vec3 vNormal;\\n\\t#ifdef USE_TANGENT\\n\\t\\tvarying vec3 vTangent;\\n\\t\\tvarying vec3 vBitangent;\\n\\t#endif\\n#endif\";\n\nvar normal_pars_vertex = \"#ifndef FLAT_SHADED\\n\\tvarying vec3 vNormal;\\n\\t#ifdef USE_TANGENT\\n\\t\\tvarying vec3 vTangent;\\n\\t\\tvarying vec3 vBitangent;\\n\\t#endif\\n#endif\";\n\nvar normal_vertex = \"#ifndef FLAT_SHADED\\n\\tvNormal = normalize( transformedNormal );\\n\\t#ifdef USE_TANGENT\\n\\t\\tvTangent = normalize( transformedTangent );\\n\\t\\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\\n\\t#endif\\n#endif\";\n\nvar normalmap_pars_fragment = \"#ifdef USE_NORMALMAP\\n\\tuniform sampler2D normalMap;\\n\\tuniform vec2 normalScale;\\n#endif\\n#ifdef USE_NORMALMAP_OBJECTSPACE\\n\\tuniform mat3 normalMatrix;\\n#endif\\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\\n\\tmat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\\n\\t\\tvec3 q0 = dFdx( eye_pos.xyz );\\n\\t\\tvec3 q1 = dFdy( eye_pos.xyz );\\n\\t\\tvec2 st0 = dFdx( uv.st );\\n\\t\\tvec2 st1 = dFdy( uv.st );\\n\\t\\tvec3 N = surf_norm;\\n\\t\\tvec3 q1perp = cross( q1, N );\\n\\t\\tvec3 q0perp = cross( N, q0 );\\n\\t\\tvec3 T = q1perp * st0.x + q0perp * st1.x;\\n\\t\\tvec3 B = q1perp * st0.y + q0perp * st1.y;\\n\\t\\tfloat det = max( dot( T, T ), dot( B, B ) );\\n\\t\\tfloat scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\\n\\t\\treturn mat3( T * scale, B * scale, N );\\n\\t}\\n#endif\";\n\nvar clearcoat_normal_fragment_begin = \"#ifdef USE_CLEARCOAT\\n\\tvec3 clearcoatNormal = nonPerturbedNormal;\\n#endif\";\n\nvar clearcoat_normal_fragment_maps = \"#ifdef USE_CLEARCOAT_NORMALMAP\\n\\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\\n\\tclearcoatMapN.xy *= clearcoatNormalScale;\\n\\tclearcoatNormal = normalize( tbn2 * clearcoatMapN );\\n#endif\";\n\nvar clearcoat_pars_fragment = \"#ifdef USE_CLEARCOATMAP\\n\\tuniform sampler2D clearcoatMap;\\n#endif\\n#ifdef USE_CLEARCOAT_NORMALMAP\\n\\tuniform sampler2D clearcoatNormalMap;\\n\\tuniform vec2 clearcoatNormalScale;\\n#endif\\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\\n\\tuniform sampler2D clearcoatRoughnessMap;\\n#endif\";\n\nvar iridescence_pars_fragment = \"#ifdef USE_IRIDESCENCEMAP\\n\\tuniform sampler2D iridescenceMap;\\n#endif\\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\\n\\tuniform sampler2D iridescenceThicknessMap;\\n#endif\";\n\nvar opaque_fragment = \"#ifdef OPAQUE\\ndiffuseColor.a = 1.0;\\n#endif\\n#ifdef USE_TRANSMISSION\\ndiffuseColor.a *= material.transmissionAlpha;\\n#endif\\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );\";\n\nvar packing = \"vec3 packNormalToRGB( const in vec3 normal ) {\\n\\treturn normalize( normal ) * 0.5 + 0.5;\\n}\\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\\n\\treturn 2.0 * rgb.xyz - 1.0;\\n}\\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;\\nconst float Inv255 = 1. / 255.;\\nconst vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );\\nconst vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );\\nconst vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );\\nconst vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );\\nvec4 packDepthToRGBA( const in float v ) {\\n\\tif( v <= 0.0 )\\n\\t\\treturn vec4( 0., 0., 0., 0. );\\n\\tif( v >= 1.0 )\\n\\t\\treturn vec4( 1., 1., 1., 1. );\\n\\tfloat vuf;\\n\\tfloat af = modf( v * PackFactors.a, vuf );\\n\\tfloat bf = modf( vuf * ShiftRight8, vuf );\\n\\tfloat gf = modf( vuf * ShiftRight8, vuf );\\n\\treturn vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );\\n}\\nvec3 packDepthToRGB( const in float v ) {\\n\\tif( v <= 0.0 )\\n\\t\\treturn vec3( 0., 0., 0. );\\n\\tif( v >= 1.0 )\\n\\t\\treturn vec3( 1., 1., 1. );\\n\\tfloat vuf;\\n\\tfloat bf = modf( v * PackFactors.b, vuf );\\n\\tfloat gf = modf( vuf * ShiftRight8, vuf );\\n\\treturn vec3( vuf * Inv255, gf * PackUpscale, bf );\\n}\\nvec2 packDepthToRG( const in float v ) {\\n\\tif( v <= 0.0 )\\n\\t\\treturn vec2( 0., 0. );\\n\\tif( v >= 1.0 )\\n\\t\\treturn vec2( 1., 1. );\\n\\tfloat vuf;\\n\\tfloat gf = modf( v * 256., vuf );\\n\\treturn vec2( vuf * Inv255, gf );\\n}\\nfloat unpackRGBAToDepth( const in vec4 v ) {\\n\\treturn dot( v, UnpackFactors4 );\\n}\\nfloat unpackRGBToDepth( const in vec3 v ) {\\n\\treturn dot( v, UnpackFactors3 );\\n}\\nfloat unpackRGToDepth( const in vec2 v ) {\\n\\treturn v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;\\n}\\nvec4 pack2HalfToRGBA( const in vec2 v ) {\\n\\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\\n\\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\\n}\\nvec2 unpackRGBATo2Half( const in vec4 v ) {\\n\\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\\n}\\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\\n\\treturn ( viewZ + near ) / ( near - far );\\n}\\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\\n\\treturn depth * ( near - far ) - near;\\n}\\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\\n\\treturn ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\\n}\\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\\n\\treturn ( near * far ) / ( ( far - near ) * depth - far );\\n}\";\n\nvar premultiplied_alpha_fragment = \"#ifdef PREMULTIPLIED_ALPHA\\n\\tgl_FragColor.rgb *= gl_FragColor.a;\\n#endif\";\n\nvar project_vertex = \"vec4 mvPosition = vec4( transformed, 1.0 );\\n#ifdef USE_BATCHING\\n\\tmvPosition = batchingMatrix * mvPosition;\\n#endif\\n#ifdef USE_INSTANCING\\n\\tmvPosition = instanceMatrix * mvPosition;\\n#endif\\nmvPosition = modelViewMatrix * mvPosition;\\ngl_Position = projectionMatrix * mvPosition;\";\n\nvar dithering_fragment = \"#ifdef DITHERING\\n\\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\\n#endif\";\n\nvar dithering_pars_fragment = \"#ifdef DITHERING\\n\\tvec3 dithering( vec3 color ) {\\n\\t\\tfloat grid_position = rand( gl_FragCoord.xy );\\n\\t\\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\\n\\t\\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\\n\\t\\treturn color + dither_shift_RGB;\\n\\t}\\n#endif\";\n\nvar roughnessmap_fragment = \"float roughnessFactor = roughness;\\n#ifdef USE_ROUGHNESSMAP\\n\\tvec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\\n\\troughnessFactor *= texelRoughness.g;\\n#endif\";\n\nvar roughnessmap_pars_fragment = \"#ifdef USE_ROUGHNESSMAP\\n\\tuniform sampler2D roughnessMap;\\n#endif\";\n\nvar shadowmap_pars_fragment = \"#if NUM_SPOT_LIGHT_COORDS > 0\\n\\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\\n#endif\\n#if NUM_SPOT_LIGHT_MAPS > 0\\n\\tuniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\\n#endif\\n#ifdef USE_SHADOWMAP\\n\\t#if NUM_DIR_LIGHT_SHADOWS > 0\\n\\t\\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\\n\\t\\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\\n\\t\\tstruct DirectionalLightShadow {\\n\\t\\t\\tfloat shadowIntensity;\\n\\t\\t\\tfloat shadowBias;\\n\\t\\t\\tfloat shadowNormalBias;\\n\\t\\t\\tfloat shadowRadius;\\n\\t\\t\\tvec2 shadowMapSize;\\n\\t\\t};\\n\\t\\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\\n\\t#endif\\n\\t#if NUM_SPOT_LIGHT_SHADOWS > 0\\n\\t\\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\\n\\t\\tstruct SpotLightShadow {\\n\\t\\t\\tfloat shadowIntensity;\\n\\t\\t\\tfloat shadowBias;\\n\\t\\t\\tfloat shadowNormalBias;\\n\\t\\t\\tfloat shadowRadius;\\n\\t\\t\\tvec2 shadowMapSize;\\n\\t\\t};\\n\\t\\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\\n\\t#endif\\n\\t#if NUM_POINT_LIGHT_SHADOWS > 0\\n\\t\\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\\n\\t\\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\\n\\t\\tstruct PointLightShadow {\\n\\t\\t\\tfloat shadowIntensity;\\n\\t\\t\\tfloat shadowBias;\\n\\t\\t\\tfloat shadowNormalBias;\\n\\t\\t\\tfloat shadowRadius;\\n\\t\\t\\tvec2 shadowMapSize;\\n\\t\\t\\tfloat shadowCameraNear;\\n\\t\\t\\tfloat shadowCameraFar;\\n\\t\\t};\\n\\t\\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\\n\\t#endif\\n\\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\\n\\t\\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\\n\\t}\\n\\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\\n\\t\\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\\n\\t}\\n\\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\\n\\t\\tfloat occlusion = 1.0;\\n\\t\\tvec2 distribution = texture2DDistribution( shadow, uv );\\n\\t\\tfloat hard_shadow = step( compare , distribution.x );\\n\\t\\tif (hard_shadow != 1.0 ) {\\n\\t\\t\\tfloat distance = compare - distribution.x ;\\n\\t\\t\\tfloat variance = max( 0.00000, distribution.y * distribution.y );\\n\\t\\t\\tfloat softness_probability = variance / (variance + distance * distance );\\t\\t\\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\\t\\t\\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\\n\\t\\t}\\n\\t\\treturn occlusion;\\n\\t}\\n\\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\\n\\t\\tfloat shadow = 1.0;\\n\\t\\tshadowCoord.xyz /= shadowCoord.w;\\n\\t\\tshadowCoord.z += shadowBias;\\n\\t\\tbool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\\n\\t\\tbool frustumTest = inFrustum && shadowCoord.z <= 1.0;\\n\\t\\tif ( frustumTest ) {\\n\\t\\t#if defined( SHADOWMAP_TYPE_PCF )\\n\\t\\t\\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\\n\\t\\t\\tfloat dx0 = - texelSize.x * shadowRadius;\\n\\t\\t\\tfloat dy0 = - texelSize.y * shadowRadius;\\n\\t\\t\\tfloat dx1 = + texelSize.x * shadowRadius;\\n\\t\\t\\tfloat dy1 = + texelSize.y * shadowRadius;\\n\\t\\t\\tfloat dx2 = dx0 / 2.0;\\n\\t\\t\\tfloat dy2 = dy0 / 2.0;\\n\\t\\t\\tfloat dx3 = dx1 / 2.0;\\n\\t\\t\\tfloat dy3 = dy1 / 2.0;\\n\\t\\t\\tshadow = (\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\\n\\t\\t\\t) * ( 1.0 / 17.0 );\\n\\t\\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\\n\\t\\t\\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\\n\\t\\t\\tfloat dx = texelSize.x;\\n\\t\\t\\tfloat dy = texelSize.y;\\n\\t\\t\\tvec2 uv = shadowCoord.xy;\\n\\t\\t\\tvec2 f = fract( uv * shadowMapSize + 0.5 );\\n\\t\\t\\tuv -= f * texelSize;\\n\\t\\t\\tshadow = (\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\\n\\t\\t\\t\\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\\n\\t\\t\\t\\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t f.x ) +\\n\\t\\t\\t\\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t f.x ) +\\n\\t\\t\\t\\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t f.y ) +\\n\\t\\t\\t\\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t f.y ) +\\n\\t\\t\\t\\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t\\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t\\t f.x ),\\n\\t\\t\\t\\t\\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t\\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\\n\\t\\t\\t\\t\\t\\t f.x ),\\n\\t\\t\\t\\t\\t f.y )\\n\\t\\t\\t) * ( 1.0 / 9.0 );\\n\\t\\t#elif defined( SHADOWMAP_TYPE_VSM )\\n\\t\\t\\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\\n\\t\\t#else\\n\\t\\t\\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\\n\\t\\t#endif\\n\\t\\t}\\n\\t\\treturn mix( 1.0, shadow, shadowIntensity );\\n\\t}\\n\\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\\n\\t\\tvec3 absV = abs( v );\\n\\t\\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\\n\\t\\tabsV *= scaleToCube;\\n\\t\\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\\n\\t\\tvec2 planar = v.xy;\\n\\t\\tfloat almostATexel = 1.5 * texelSizeY;\\n\\t\\tfloat almostOne = 1.0 - almostATexel;\\n\\t\\tif ( absV.z >= almostOne ) {\\n\\t\\t\\tif ( v.z > 0.0 )\\n\\t\\t\\t\\tplanar.x = 4.0 - v.x;\\n\\t\\t} else if ( absV.x >= almostOne ) {\\n\\t\\t\\tfloat signX = sign( v.x );\\n\\t\\t\\tplanar.x = v.z * signX + 2.0 * signX;\\n\\t\\t} else if ( absV.y >= almostOne ) {\\n\\t\\t\\tfloat signY = sign( v.y );\\n\\t\\t\\tplanar.x = v.x + 2.0 * signY + 2.0;\\n\\t\\t\\tplanar.y = v.z * signY - 2.0;\\n\\t\\t}\\n\\t\\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\\n\\t}\\n\\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\\n\\t\\tfloat shadow = 1.0;\\n\\t\\tvec3 lightToPosition = shadowCoord.xyz;\\n\\t\\t\\n\\t\\tfloat lightToPositionLength = length( lightToPosition );\\n\\t\\tif ( lightToPositionLength - shadowCameraFar <= 0.0 && lightToPositionLength - shadowCameraNear >= 0.0 ) {\\n\\t\\t\\tfloat dp = ( lightToPositionLength - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\\t\\t\\tdp += shadowBias;\\n\\t\\t\\tvec3 bd3D = normalize( lightToPosition );\\n\\t\\t\\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\\n\\t\\t\\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\\n\\t\\t\\t\\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\\n\\t\\t\\t\\tshadow = (\\n\\t\\t\\t\\t\\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\\n\\t\\t\\t\\t\\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\\n\\t\\t\\t\\t\\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\\n\\t\\t\\t\\t\\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\\n\\t\\t\\t\\t\\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\\n\\t\\t\\t\\t\\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\\n\\t\\t\\t\\t\\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\\n\\t\\t\\t\\t\\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\\n\\t\\t\\t\\t\\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\\n\\t\\t\\t\\t) * ( 1.0 / 9.0 );\\n\\t\\t\\t#else\\n\\t\\t\\t\\tshadow = texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\\n\\t\\t\\t#endif\\n\\t\\t}\\n\\t\\treturn mix( 1.0, shadow, shadowIntensity );\\n\\t}\\n#endif\";\n\nvar shadowmap_pars_vertex = \"#if NUM_SPOT_LIGHT_COORDS > 0\\n\\tuniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\\n\\tvarying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\\n#endif\\n#ifdef USE_SHADOWMAP\\n\\t#if NUM_DIR_LIGHT_SHADOWS > 0\\n\\t\\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\\n\\t\\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\\n\\t\\tstruct DirectionalLightShadow {\\n\\t\\t\\tfloat shadowIntensity;\\n\\t\\t\\tfloat shadowBias;\\n\\t\\t\\tfloat shadowNormalBias;\\n\\t\\t\\tfloat shadowRadius;\\n\\t\\t\\tvec2 shadowMapSize;\\n\\t\\t};\\n\\t\\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\\n\\t#endif\\n\\t#if NUM_SPOT_LIGHT_SHADOWS > 0\\n\\t\\tstruct SpotLightShadow {\\n\\t\\t\\tfloat shadowIntensity;\\n\\t\\t\\tfloat shadowBias;\\n\\t\\t\\tfloat shadowNormalBias;\\n\\t\\t\\tfloat shadowRadius;\\n\\t\\t\\tvec2 shadowMapSize;\\n\\t\\t};\\n\\t\\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\\n\\t#endif\\n\\t#if NUM_POINT_LIGHT_SHADOWS > 0\\n\\t\\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\\n\\t\\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\\n\\t\\tstruct PointLightShadow {\\n\\t\\t\\tfloat shadowIntensity;\\n\\t\\t\\tfloat shadowBias;\\n\\t\\t\\tfloat shadowNormalBias;\\n\\t\\t\\tfloat shadowRadius;\\n\\t\\t\\tvec2 shadowMapSize;\\n\\t\\t\\tfloat shadowCameraNear;\\n\\t\\t\\tfloat shadowCameraFar;\\n\\t\\t};\\n\\t\\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\\n\\t#endif\\n#endif\";\n\nvar shadowmap_vertex = \"#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\\n\\tvec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\\n\\tvec4 shadowWorldPosition;\\n#endif\\n#if defined( USE_SHADOWMAP )\\n\\t#if NUM_DIR_LIGHT_SHADOWS > 0\\n\\t\\t#pragma unroll_loop_start\\n\\t\\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\\n\\t\\t\\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\\n\\t\\t\\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\\n\\t\\t}\\n\\t\\t#pragma unroll_loop_end\\n\\t#endif\\n\\t#if NUM_POINT_LIGHT_SHADOWS > 0\\n\\t\\t#pragma unroll_loop_start\\n\\t\\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\\n\\t\\t\\tshadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\\n\\t\\t\\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\\n\\t\\t}\\n\\t\\t#pragma unroll_loop_end\\n\\t#endif\\n#endif\\n#if NUM_SPOT_LIGHT_COORDS > 0\\n\\t#pragma unroll_loop_start\\n\\tfor ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\\n\\t\\tshadowWorldPosition = worldPosition;\\n\\t\\t#if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\\n\\t\\t\\tshadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\\n\\t\\t#endif\\n\\t\\tvSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\\n\\t}\\n\\t#pragma unroll_loop_end\\n#endif\";\n\nvar shadowmask_pars_fragment = \"float getShadowMask() {\\n\\tfloat shadow = 1.0;\\n\\t#ifdef USE_SHADOWMAP\\n\\t#if NUM_DIR_LIGHT_SHADOWS > 0\\n\\tDirectionalLightShadow directionalLight;\\n\\t#pragma unroll_loop_start\\n\\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\\n\\t\\tdirectionalLight = directionalLightShadows[ i ];\\n\\t\\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\\n\\t}\\n\\t#pragma unroll_loop_end\\n\\t#endif\\n\\t#if NUM_SPOT_LIGHT_SHADOWS > 0\\n\\tSpotLightShadow spotLight;\\n\\t#pragma unroll_loop_start\\n\\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\\n\\t\\tspotLight = spotLightShadows[ i ];\\n\\t\\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\\n\\t}\\n\\t#pragma unroll_loop_end\\n\\t#endif\\n\\t#if NUM_POINT_LIGHT_SHADOWS > 0\\n\\tPointLightShadow pointLight;\\n\\t#pragma unroll_loop_start\\n\\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\\n\\t\\tpointLight = pointLightShadows[ i ];\\n\\t\\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\\n\\t}\\n\\t#pragma unroll_loop_end\\n\\t#endif\\n\\t#endif\\n\\treturn shadow;\\n}\";\n\nvar skinbase_vertex = \"#ifdef USE_SKINNING\\n\\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\\n\\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\\n\\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\\n\\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\\n#endif\";\n\nvar skinning_pars_vertex = \"#ifdef USE_SKINNING\\n\\tuniform mat4 bindMatrix;\\n\\tuniform mat4 bindMatrixInverse;\\n\\tuniform highp sampler2D boneTexture;\\n\\tmat4 getBoneMatrix( const in float i ) {\\n\\t\\tint size = textureSize( boneTexture, 0 ).x;\\n\\t\\tint j = int( i ) * 4;\\n\\t\\tint x = j % size;\\n\\t\\tint y = j / size;\\n\\t\\tvec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );\\n\\t\\tvec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );\\n\\t\\tvec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );\\n\\t\\tvec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );\\n\\t\\treturn mat4( v1, v2, v3, v4 );\\n\\t}\\n#endif\";\n\nvar skinning_vertex = \"#ifdef USE_SKINNING\\n\\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\\n\\tvec4 skinned = vec4( 0.0 );\\n\\tskinned += boneMatX * skinVertex * skinWeight.x;\\n\\tskinned += boneMatY * skinVertex * skinWeight.y;\\n\\tskinned += boneMatZ * skinVertex * skinWeight.z;\\n\\tskinned += boneMatW * skinVertex * skinWeight.w;\\n\\ttransformed = ( bindMatrixInverse * skinned ).xyz;\\n#endif\";\n\nvar skinnormal_vertex = \"#ifdef USE_SKINNING\\n\\tmat4 skinMatrix = mat4( 0.0 );\\n\\tskinMatrix += skinWeight.x * boneMatX;\\n\\tskinMatrix += skinWeight.y * boneMatY;\\n\\tskinMatrix += skinWeight.z * boneMatZ;\\n\\tskinMatrix += skinWeight.w * boneMatW;\\n\\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\\n\\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\\n\\t#ifdef USE_TANGENT\\n\\t\\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\\n\\t#endif\\n#endif\";\n\nvar specularmap_fragment = \"float specularStrength;\\n#ifdef USE_SPECULARMAP\\n\\tvec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\\n\\tspecularStrength = texelSpecular.r;\\n#else\\n\\tspecularStrength = 1.0;\\n#endif\";\n\nvar specularmap_pars_fragment = \"#ifdef USE_SPECULARMAP\\n\\tuniform sampler2D specularMap;\\n#endif\";\n\nvar tonemapping_fragment = \"#if defined( TONE_MAPPING )\\n\\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\\n#endif\";\n\nvar tonemapping_pars_fragment = \"#ifndef saturate\\n#define saturate( a ) clamp( a, 0.0, 1.0 )\\n#endif\\nuniform float toneMappingExposure;\\nvec3 LinearToneMapping( vec3 color ) {\\n\\treturn saturate( toneMappingExposure * color );\\n}\\nvec3 ReinhardToneMapping( vec3 color ) {\\n\\tcolor *= toneMappingExposure;\\n\\treturn saturate( color / ( vec3( 1.0 ) + color ) );\\n}\\nvec3 CineonToneMapping( vec3 color ) {\\n\\tcolor *= toneMappingExposure;\\n\\tcolor = max( vec3( 0.0 ), color - 0.004 );\\n\\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\\n}\\nvec3 RRTAndODTFit( vec3 v ) {\\n\\tvec3 a = v * ( v + 0.0245786 ) - 0.000090537;\\n\\tvec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\\n\\treturn a / b;\\n}\\nvec3 ACESFilmicToneMapping( vec3 color ) {\\n\\tconst mat3 ACESInputMat = mat3(\\n\\t\\tvec3( 0.59719, 0.07600, 0.02840 ),\\t\\tvec3( 0.35458, 0.90834, 0.13383 ),\\n\\t\\tvec3( 0.04823, 0.01566, 0.83777 )\\n\\t);\\n\\tconst mat3 ACESOutputMat = mat3(\\n\\t\\tvec3( 1.60475, -0.10208, -0.00327 ),\\t\\tvec3( -0.53108, 1.10813, -0.07276 ),\\n\\t\\tvec3( -0.07367, -0.00605, 1.07602 )\\n\\t);\\n\\tcolor *= toneMappingExposure / 0.6;\\n\\tcolor = ACESInputMat * color;\\n\\tcolor = RRTAndODTFit( color );\\n\\tcolor = ACESOutputMat * color;\\n\\treturn saturate( color );\\n}\\nconst mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(\\n\\tvec3( 1.6605, - 0.1246, - 0.0182 ),\\n\\tvec3( - 0.5876, 1.1329, - 0.1006 ),\\n\\tvec3( - 0.0728, - 0.0083, 1.1187 )\\n);\\nconst mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(\\n\\tvec3( 0.6274, 0.0691, 0.0164 ),\\n\\tvec3( 0.3293, 0.9195, 0.0880 ),\\n\\tvec3( 0.0433, 0.0113, 0.8956 )\\n);\\nvec3 agxDefaultContrastApprox( vec3 x ) {\\n\\tvec3 x2 = x * x;\\n\\tvec3 x4 = x2 * x2;\\n\\treturn + 15.5 * x4 * x2\\n\\t\\t- 40.14 * x4 * x\\n\\t\\t+ 31.96 * x4\\n\\t\\t- 6.868 * x2 * x\\n\\t\\t+ 0.4298 * x2\\n\\t\\t+ 0.1191 * x\\n\\t\\t- 0.00232;\\n}\\nvec3 AgXToneMapping( vec3 color ) {\\n\\tconst mat3 AgXInsetMatrix = mat3(\\n\\t\\tvec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),\\n\\t\\tvec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),\\n\\t\\tvec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )\\n\\t);\\n\\tconst mat3 AgXOutsetMatrix = mat3(\\n\\t\\tvec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),\\n\\t\\tvec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),\\n\\t\\tvec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )\\n\\t);\\n\\tconst float AgxMinEv = - 12.47393;\\tconst float AgxMaxEv = 4.026069;\\n\\tcolor *= toneMappingExposure;\\n\\tcolor = LINEAR_SRGB_TO_LINEAR_REC2020 * color;\\n\\tcolor = AgXInsetMatrix * color;\\n\\tcolor = max( color, 1e-10 );\\tcolor = log2( color );\\n\\tcolor = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );\\n\\tcolor = clamp( color, 0.0, 1.0 );\\n\\tcolor = agxDefaultContrastApprox( color );\\n\\tcolor = AgXOutsetMatrix * color;\\n\\tcolor = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );\\n\\tcolor = LINEAR_REC2020_TO_LINEAR_SRGB * color;\\n\\tcolor = clamp( color, 0.0, 1.0 );\\n\\treturn color;\\n}\\nvec3 NeutralToneMapping( vec3 color ) {\\n\\tconst float StartCompression = 0.8 - 0.04;\\n\\tconst float Desaturation = 0.15;\\n\\tcolor *= toneMappingExposure;\\n\\tfloat x = min( color.r, min( color.g, color.b ) );\\n\\tfloat offset = x < 0.08 ? x - 6.25 * x * x : 0.04;\\n\\tcolor -= offset;\\n\\tfloat peak = max( color.r, max( color.g, color.b ) );\\n\\tif ( peak < StartCompression ) return color;\\n\\tfloat d = 1. - StartCompression;\\n\\tfloat newPeak = 1. - d * d / ( peak + d - StartCompression );\\n\\tcolor *= newPeak / peak;\\n\\tfloat g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );\\n\\treturn mix( color, vec3( newPeak ), g );\\n}\\nvec3 CustomToneMapping( vec3 color ) { return color; }\";\n\nvar transmission_fragment = \"#ifdef USE_TRANSMISSION\\n\\tmaterial.transmission = transmission;\\n\\tmaterial.transmissionAlpha = 1.0;\\n\\tmaterial.thickness = thickness;\\n\\tmaterial.attenuationDistance = attenuationDistance;\\n\\tmaterial.attenuationColor = attenuationColor;\\n\\t#ifdef USE_TRANSMISSIONMAP\\n\\t\\tmaterial.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\\n\\t#endif\\n\\t#ifdef USE_THICKNESSMAP\\n\\t\\tmaterial.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\\n\\t#endif\\n\\tvec3 pos = vWorldPosition;\\n\\tvec3 v = normalize( cameraPosition - pos );\\n\\tvec3 n = inverseTransformDirection( normal, viewMatrix );\\n\\tvec4 transmitted = getIBLVolumeRefraction(\\n\\t\\tn, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\\n\\t\\tpos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,\\n\\t\\tmaterial.attenuationColor, material.attenuationDistance );\\n\\tmaterial.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\\n\\ttotalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\\n#endif\";\n\nvar transmission_pars_fragment = \"#ifdef USE_TRANSMISSION\\n\\tuniform float transmission;\\n\\tuniform float thickness;\\n\\tuniform float attenuationDistance;\\n\\tuniform vec3 attenuationColor;\\n\\t#ifdef USE_TRANSMISSIONMAP\\n\\t\\tuniform sampler2D transmissionMap;\\n\\t#endif\\n\\t#ifdef USE_THICKNESSMAP\\n\\t\\tuniform sampler2D thicknessMap;\\n\\t#endif\\n\\tuniform vec2 transmissionSamplerSize;\\n\\tuniform sampler2D transmissionSamplerMap;\\n\\tuniform mat4 modelMatrix;\\n\\tuniform mat4 projectionMatrix;\\n\\tvarying vec3 vWorldPosition;\\n\\tfloat w0( float a ) {\\n\\t\\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\\n\\t}\\n\\tfloat w1( float a ) {\\n\\t\\treturn ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\\n\\t}\\n\\tfloat w2( float a ){\\n\\t\\treturn ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\\n\\t}\\n\\tfloat w3( float a ) {\\n\\t\\treturn ( 1.0 / 6.0 ) * ( a * a * a );\\n\\t}\\n\\tfloat g0( float a ) {\\n\\t\\treturn w0( a ) + w1( a );\\n\\t}\\n\\tfloat g1( float a ) {\\n\\t\\treturn w2( a ) + w3( a );\\n\\t}\\n\\tfloat h0( float a ) {\\n\\t\\treturn - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\\n\\t}\\n\\tfloat h1( float a ) {\\n\\t\\treturn 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\\n\\t}\\n\\tvec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\\n\\t\\tuv = uv * texelSize.zw + 0.5;\\n\\t\\tvec2 iuv = floor( uv );\\n\\t\\tvec2 fuv = fract( uv );\\n\\t\\tfloat g0x = g0( fuv.x );\\n\\t\\tfloat g1x = g1( fuv.x );\\n\\t\\tfloat h0x = h0( fuv.x );\\n\\t\\tfloat h1x = h1( fuv.x );\\n\\t\\tfloat h0y = h0( fuv.y );\\n\\t\\tfloat h1y = h1( fuv.y );\\n\\t\\tvec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\\n\\t\\tvec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\\n\\t\\tvec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\\n\\t\\tvec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\\n\\t\\treturn g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\\n\\t\\t\\tg1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\\n\\t}\\n\\tvec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\\n\\t\\tvec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\\n\\t\\tvec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\\n\\t\\tvec2 fLodSizeInv = 1.0 / fLodSize;\\n\\t\\tvec2 cLodSizeInv = 1.0 / cLodSize;\\n\\t\\tvec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\\n\\t\\tvec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\\n\\t\\treturn mix( fSample, cSample, fract( lod ) );\\n\\t}\\n\\tvec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\\n\\t\\tvec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\\n\\t\\tvec3 modelScale;\\n\\t\\tmodelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\\n\\t\\tmodelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\\n\\t\\tmodelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\\n\\t\\treturn normalize( refractionVector ) * thickness * modelScale;\\n\\t}\\n\\tfloat applyIorToRoughness( const in float roughness, const in float ior ) {\\n\\t\\treturn roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\\n\\t}\\n\\tvec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\\n\\t\\tfloat lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\\n\\t\\treturn textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\\n\\t}\\n\\tvec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\\n\\t\\tif ( isinf( attenuationDistance ) ) {\\n\\t\\t\\treturn vec3( 1.0 );\\n\\t\\t} else {\\n\\t\\t\\tvec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\\n\\t\\t\\tvec3 transmittance = exp( - attenuationCoefficient * transmissionDistance );\\t\\t\\treturn transmittance;\\n\\t\\t}\\n\\t}\\n\\tvec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\\n\\t\\tconst in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\\n\\t\\tconst in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,\\n\\t\\tconst in vec3 attenuationColor, const in float attenuationDistance ) {\\n\\t\\tvec4 transmittedLight;\\n\\t\\tvec3 transmittance;\\n\\t\\t#ifdef USE_DISPERSION\\n\\t\\t\\tfloat halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;\\n\\t\\t\\tvec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );\\n\\t\\t\\tfor ( int i = 0; i < 3; i ++ ) {\\n\\t\\t\\t\\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );\\n\\t\\t\\t\\tvec3 refractedRayExit = position + transmissionRay;\\n\\t\\t\\n\\t\\t\\t\\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\\n\\t\\t\\t\\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\\n\\t\\t\\t\\trefractionCoords += 1.0;\\n\\t\\t\\t\\trefractionCoords /= 2.0;\\n\\t\\t\\n\\t\\t\\t\\tvec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );\\n\\t\\t\\t\\ttransmittedLight[ i ] = transmissionSample[ i ];\\n\\t\\t\\t\\ttransmittedLight.a += transmissionSample.a;\\n\\t\\t\\t\\ttransmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];\\n\\t\\t\\t}\\n\\t\\t\\ttransmittedLight.a /= 3.0;\\n\\t\\t\\n\\t\\t#else\\n\\t\\t\\n\\t\\t\\tvec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\\n\\t\\t\\tvec3 refractedRayExit = position + transmissionRay;\\n\\t\\t\\tvec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\\n\\t\\t\\tvec2 refractionCoords = ndcPos.xy / ndcPos.w;\\n\\t\\t\\trefractionCoords += 1.0;\\n\\t\\t\\trefractionCoords /= 2.0;\\n\\t\\t\\ttransmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\\n\\t\\t\\ttransmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\\n\\t\\t\\n\\t\\t#endif\\n\\t\\tvec3 attenuatedColor = transmittance * transmittedLight.rgb;\\n\\t\\tvec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\\n\\t\\tfloat transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\\n\\t\\treturn vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\\n\\t}\\n#endif\";\n\nvar uv_pars_fragment = \"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\\n\\tvarying vec2 vUv;\\n#endif\\n#ifdef USE_MAP\\n\\tvarying vec2 vMapUv;\\n#endif\\n#ifdef USE_ALPHAMAP\\n\\tvarying vec2 vAlphaMapUv;\\n#endif\\n#ifdef USE_LIGHTMAP\\n\\tvarying vec2 vLightMapUv;\\n#endif\\n#ifdef USE_AOMAP\\n\\tvarying vec2 vAoMapUv;\\n#endif\\n#ifdef USE_BUMPMAP\\n\\tvarying vec2 vBumpMapUv;\\n#endif\\n#ifdef USE_NORMALMAP\\n\\tvarying vec2 vNormalMapUv;\\n#endif\\n#ifdef USE_EMISSIVEMAP\\n\\tvarying vec2 vEmissiveMapUv;\\n#endif\\n#ifdef USE_METALNESSMAP\\n\\tvarying vec2 vMetalnessMapUv;\\n#endif\\n#ifdef USE_ROUGHNESSMAP\\n\\tvarying vec2 vRoughnessMapUv;\\n#endif\\n#ifdef USE_ANISOTROPYMAP\\n\\tvarying vec2 vAnisotropyMapUv;\\n#endif\\n#ifdef USE_CLEARCOATMAP\\n\\tvarying vec2 vClearcoatMapUv;\\n#endif\\n#ifdef USE_CLEARCOAT_NORMALMAP\\n\\tvarying vec2 vClearcoatNormalMapUv;\\n#endif\\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\\n\\tvarying vec2 vClearcoatRoughnessMapUv;\\n#endif\\n#ifdef USE_IRIDESCENCEMAP\\n\\tvarying vec2 vIridescenceMapUv;\\n#endif\\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\\n\\tvarying vec2 vIridescenceThicknessMapUv;\\n#endif\\n#ifdef USE_SHEEN_COLORMAP\\n\\tvarying vec2 vSheenColorMapUv;\\n#endif\\n#ifdef USE_SHEEN_ROUGHNESSMAP\\n\\tvarying vec2 vSheenRoughnessMapUv;\\n#endif\\n#ifdef USE_SPECULARMAP\\n\\tvarying vec2 vSpecularMapUv;\\n#endif\\n#ifdef USE_SPECULAR_COLORMAP\\n\\tvarying vec2 vSpecularColorMapUv;\\n#endif\\n#ifdef USE_SPECULAR_INTENSITYMAP\\n\\tvarying vec2 vSpecularIntensityMapUv;\\n#endif\\n#ifdef USE_TRANSMISSIONMAP\\n\\tuniform mat3 transmissionMapTransform;\\n\\tvarying vec2 vTransmissionMapUv;\\n#endif\\n#ifdef USE_THICKNESSMAP\\n\\tuniform mat3 thicknessMapTransform;\\n\\tvarying vec2 vThicknessMapUv;\\n#endif\";\n\nvar uv_pars_vertex = \"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\\n\\tvarying vec2 vUv;\\n#endif\\n#ifdef USE_MAP\\n\\tuniform mat3 mapTransform;\\n\\tvarying vec2 vMapUv;\\n#endif\\n#ifdef USE_ALPHAMAP\\n\\tuniform mat3 alphaMapTransform;\\n\\tvarying vec2 vAlphaMapUv;\\n#endif\\n#ifdef USE_LIGHTMAP\\n\\tuniform mat3 lightMapTransform;\\n\\tvarying vec2 vLightMapUv;\\n#endif\\n#ifdef USE_AOMAP\\n\\tuniform mat3 aoMapTransform;\\n\\tvarying vec2 vAoMapUv;\\n#endif\\n#ifdef USE_BUMPMAP\\n\\tuniform mat3 bumpMapTransform;\\n\\tvarying vec2 vBumpMapUv;\\n#endif\\n#ifdef USE_NORMALMAP\\n\\tuniform mat3 normalMapTransform;\\n\\tvarying vec2 vNormalMapUv;\\n#endif\\n#ifdef USE_DISPLACEMENTMAP\\n\\tuniform mat3 displacementMapTransform;\\n\\tvarying vec2 vDisplacementMapUv;\\n#endif\\n#ifdef USE_EMISSIVEMAP\\n\\tuniform mat3 emissiveMapTransform;\\n\\tvarying vec2 vEmissiveMapUv;\\n#endif\\n#ifdef USE_METALNESSMAP\\n\\tuniform mat3 metalnessMapTransform;\\n\\tvarying vec2 vMetalnessMapUv;\\n#endif\\n#ifdef USE_ROUGHNESSMAP\\n\\tuniform mat3 roughnessMapTransform;\\n\\tvarying vec2 vRoughnessMapUv;\\n#endif\\n#ifdef USE_ANISOTROPYMAP\\n\\tuniform mat3 anisotropyMapTransform;\\n\\tvarying vec2 vAnisotropyMapUv;\\n#endif\\n#ifdef USE_CLEARCOATMAP\\n\\tuniform mat3 clearcoatMapTransform;\\n\\tvarying vec2 vClearcoatMapUv;\\n#endif\\n#ifdef USE_CLEARCOAT_NORMALMAP\\n\\tuniform mat3 clearcoatNormalMapTransform;\\n\\tvarying vec2 vClearcoatNormalMapUv;\\n#endif\\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\\n\\tuniform mat3 clearcoatRoughnessMapTransform;\\n\\tvarying vec2 vClearcoatRoughnessMapUv;\\n#endif\\n#ifdef USE_SHEEN_COLORMAP\\n\\tuniform mat3 sheenColorMapTransform;\\n\\tvarying vec2 vSheenColorMapUv;\\n#endif\\n#ifdef USE_SHEEN_ROUGHNESSMAP\\n\\tuniform mat3 sheenRoughnessMapTransform;\\n\\tvarying vec2 vSheenRoughnessMapUv;\\n#endif\\n#ifdef USE_IRIDESCENCEMAP\\n\\tuniform mat3 iridescenceMapTransform;\\n\\tvarying vec2 vIridescenceMapUv;\\n#endif\\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\\n\\tuniform mat3 iridescenceThicknessMapTransform;\\n\\tvarying vec2 vIridescenceThicknessMapUv;\\n#endif\\n#ifdef USE_SPECULARMAP\\n\\tuniform mat3 specularMapTransform;\\n\\tvarying vec2 vSpecularMapUv;\\n#endif\\n#ifdef USE_SPECULAR_COLORMAP\\n\\tuniform mat3 specularColorMapTransform;\\n\\tvarying vec2 vSpecularColorMapUv;\\n#endif\\n#ifdef USE_SPECULAR_INTENSITYMAP\\n\\tuniform mat3 specularIntensityMapTransform;\\n\\tvarying vec2 vSpecularIntensityMapUv;\\n#endif\\n#ifdef USE_TRANSMISSIONMAP\\n\\tuniform mat3 transmissionMapTransform;\\n\\tvarying vec2 vTransmissionMapUv;\\n#endif\\n#ifdef USE_THICKNESSMAP\\n\\tuniform mat3 thicknessMapTransform;\\n\\tvarying vec2 vThicknessMapUv;\\n#endif\";\n\nvar uv_vertex = \"#if defined( USE_UV ) || defined( USE_ANISOTROPY )\\n\\tvUv = vec3( uv, 1 ).xy;\\n#endif\\n#ifdef USE_MAP\\n\\tvMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_ALPHAMAP\\n\\tvAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_LIGHTMAP\\n\\tvLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_AOMAP\\n\\tvAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_BUMPMAP\\n\\tvBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_NORMALMAP\\n\\tvNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_DISPLACEMENTMAP\\n\\tvDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_EMISSIVEMAP\\n\\tvEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_METALNESSMAP\\n\\tvMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_ROUGHNESSMAP\\n\\tvRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_ANISOTROPYMAP\\n\\tvAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_CLEARCOATMAP\\n\\tvClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_CLEARCOAT_NORMALMAP\\n\\tvClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\\n\\tvClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_IRIDESCENCEMAP\\n\\tvIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\\n\\tvIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_SHEEN_COLORMAP\\n\\tvSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_SHEEN_ROUGHNESSMAP\\n\\tvSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_SPECULARMAP\\n\\tvSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_SPECULAR_COLORMAP\\n\\tvSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_SPECULAR_INTENSITYMAP\\n\\tvSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_TRANSMISSIONMAP\\n\\tvTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\\n#endif\\n#ifdef USE_THICKNESSMAP\\n\\tvThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\\n#endif\";\n\nvar worldpos_vertex = \"#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\\n\\tvec4 worldPosition = vec4( transformed, 1.0 );\\n\\t#ifdef USE_BATCHING\\n\\t\\tworldPosition = batchingMatrix * worldPosition;\\n\\t#endif\\n\\t#ifdef USE_INSTANCING\\n\\t\\tworldPosition = instanceMatrix * worldPosition;\\n\\t#endif\\n\\tworldPosition = modelMatrix * worldPosition;\\n#endif\";\n\nconst vertex$h = \"varying vec2 vUv;\\nuniform mat3 uvTransform;\\nvoid main() {\\n\\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\\n\\tgl_Position = vec4( position.xy, 1.0, 1.0 );\\n}\";\n\nconst fragment$h = \"uniform sampler2D t2D;\\nuniform float backgroundIntensity;\\nvarying vec2 vUv;\\nvoid main() {\\n\\tvec4 texColor = texture2D( t2D, vUv );\\n\\t#ifdef DECODE_VIDEO_TEXTURE\\n\\t\\ttexColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );\\n\\t#endif\\n\\ttexColor.rgb *= backgroundIntensity;\\n\\tgl_FragColor = texColor;\\n\\t#include \\n\\t#include \\n}\";\n\nconst vertex$g = \"varying vec3 vWorldDirection;\\n#include \\nvoid main() {\\n\\tvWorldDirection = transformDirection( position, modelMatrix );\\n\\t#include \\n\\t#include \\n\\tgl_Position.z = gl_Position.w;\\n}\";\n\nconst fragment$g = \"#ifdef ENVMAP_TYPE_CUBE\\n\\tuniform samplerCube envMap;\\n#elif defined( ENVMAP_TYPE_CUBE_UV )\\n\\tuniform sampler2D envMap;\\n#endif\\nuniform float flipEnvMap;\\nuniform float backgroundBlurriness;\\nuniform float backgroundIntensity;\\nuniform mat3 backgroundRotation;\\nvarying vec3 vWorldDirection;\\n#include \\nvoid main() {\\n\\t#ifdef ENVMAP_TYPE_CUBE\\n\\t\\tvec4 texColor = textureCube( envMap, backgroundRotation * vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\\n\\t#elif defined( ENVMAP_TYPE_CUBE_UV )\\n\\t\\tvec4 texColor = textureCubeUV( envMap, backgroundRotation * vWorldDirection, backgroundBlurriness );\\n\\t#else\\n\\t\\tvec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\\n\\t#endif\\n\\ttexColor.rgb *= backgroundIntensity;\\n\\tgl_FragColor = texColor;\\n\\t#include \\n\\t#include \\n}\";\n\nconst vertex$f = \"varying vec3 vWorldDirection;\\n#include \\nvoid main() {\\n\\tvWorldDirection = transformDirection( position, modelMatrix );\\n\\t#include \\n\\t#include \\n\\tgl_Position.z = gl_Position.w;\\n}\";\n\nconst fragment$f = \"uniform samplerCube tCube;\\nuniform float tFlip;\\nuniform float opacity;\\nvarying vec3 vWorldDirection;\\nvoid main() {\\n\\tvec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\\n\\tgl_FragColor = texColor;\\n\\tgl_FragColor.a *= opacity;\\n\\t#include \\n\\t#include \\n}\";\n\nconst vertex$e = \"#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\nvarying vec2 vHighPrecisionZW;\\nvoid main() {\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#ifdef USE_DISPLACEMENTMAP\\n\\t\\t#include \\n\\t\\t#include \\n\\t\\t#include \\n\\t#endif\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\tvHighPrecisionZW = gl_Position.zw;\\n}\";\n\nconst fragment$e = \"#if DEPTH_PACKING == 3200\\n\\tuniform float opacity;\\n#endif\\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\nvarying vec2 vHighPrecisionZW;\\nvoid main() {\\n\\tvec4 diffuseColor = vec4( 1.0 );\\n\\t#include \\n\\t#if DEPTH_PACKING == 3200\\n\\t\\tdiffuseColor.a = opacity;\\n\\t#endif\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\\n\\t#if DEPTH_PACKING == 3200\\n\\t\\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\\n\\t#elif DEPTH_PACKING == 3201\\n\\t\\tgl_FragColor = packDepthToRGBA( fragCoordZ );\\n\\t#elif DEPTH_PACKING == 3202\\n\\t\\tgl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );\\n\\t#elif DEPTH_PACKING == 3203\\n\\t\\tgl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );\\n\\t#endif\\n}\";\n\nconst vertex$d = \"#define DISTANCE\\nvarying vec3 vWorldPosition;\\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\nvoid main() {\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#ifdef USE_DISPLACEMENTMAP\\n\\t\\t#include \\n\\t\\t#include \\n\\t\\t#include \\n\\t#endif\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\tvWorldPosition = worldPosition.xyz;\\n}\";\n\nconst fragment$d = \"#define DISTANCE\\nuniform vec3 referencePosition;\\nuniform float nearDistance;\\nuniform float farDistance;\\nvarying vec3 vWorldPosition;\\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\nvoid main () {\\n\\tvec4 diffuseColor = vec4( 1.0 );\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\tfloat dist = length( vWorldPosition - referencePosition );\\n\\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\\n\\tdist = saturate( dist );\\n\\tgl_FragColor = packDepthToRGBA( dist );\\n}\";\n\nconst vertex$c = \"varying vec3 vWorldDirection;\\n#include \\nvoid main() {\\n\\tvWorldDirection = transformDirection( position, modelMatrix );\\n\\t#include \\n\\t#include \\n}\";\n\nconst fragment$c = \"uniform sampler2D tEquirect;\\nvarying vec3 vWorldDirection;\\n#include \\nvoid main() {\\n\\tvec3 direction = normalize( vWorldDirection );\\n\\tvec2 sampleUV = equirectUv( direction );\\n\\tgl_FragColor = texture2D( tEquirect, sampleUV );\\n\\t#include \\n\\t#include \\n}\";\n\nconst vertex$b = \"uniform float scale;\\nattribute float lineDistance;\\nvarying float vLineDistance;\\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\nvoid main() {\\n\\tvLineDistance = scale * lineDistance;\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n}\";\n\nconst fragment$b = \"uniform vec3 diffuse;\\nuniform float opacity;\\nuniform float dashSize;\\nuniform float totalSize;\\nvarying float vLineDistance;\\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\nvoid main() {\\n\\tvec4 diffuseColor = vec4( diffuse, opacity );\\n\\t#include \\n\\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\\n\\t\\tdiscard;\\n\\t}\\n\\tvec3 outgoingLight = vec3( 0.0 );\\n\\t#include \\n\\t#include \\n\\t#include \\n\\toutgoingLight = diffuseColor.rgb;\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n}\";\n\nconst vertex$a = \"#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\nvoid main() {\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\\n\\t\\t#include \\n\\t\\t#include \\n\\t\\t#include \\n\\t\\t#include \\n\\t\\t#include \\n\\t#endif\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n}\";\n\nconst fragment$a = \"uniform vec3 diffuse;\\nuniform float opacity;\\n#ifndef FLAT_SHADED\\n\\tvarying vec3 vNormal;\\n#endif\\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\nvoid main() {\\n\\tvec4 diffuseColor = vec4( diffuse, opacity );\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\\n\\t#ifdef USE_LIGHTMAP\\n\\t\\tvec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\\n\\t\\treflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\\n\\t#else\\n\\t\\treflectedLight.indirectDiffuse += vec3( 1.0 );\\n\\t#endif\\n\\t#include \\n\\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\\n\\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n}\";\n\nconst vertex$9 = \"#define LAMBERT\\nvarying vec3 vViewPosition;\\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\nvoid main() {\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n\\tvViewPosition = - mvPosition.xyz;\\n\\t#include \\n\\t#include \\n\\t#include \\n\\t#include \\n}\";\n\nconst fragment$9 = \"#define LAMBERT\\nuniform vec3 diffuse;\\nuniform vec3 emissive;\\nuniform float opacity;\\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\n#include \\nvoid main() {\\n\\tvec4 diffuseColor = vec4( diffuse, opacity );\\n\\t#include \\n\\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\\n\\tvec3 totalEmissiveRadiance = emissive;\\n\\t#include