{
  "name": "create-viewer",
  "description": "Create a renderer, a camera and a control, along basic rendering loop logic.",
  "dependencies": [
    "three"
  ],
  "devDependencies": [
    "@types/three"
  ],
  "registryDependencies": [
    "dispose-tracker"
  ],
  "files": [
    {
      "path": "create-viewer.ts",
      "content": "import { Clock, EventDispatcher, Scene, WebGLRenderer } from 'three';\nimport createRenderer from './create-renderer';\nimport { createCamera } from './create-camera/create-camera';\nimport OffsetCamera from './create-camera/offset-camera';\nimport { disposeTracked } from '@3dvf/dispose-tracker/dispose-tracked';\nimport { OrbitControls } from './create-camera/orbit-controls';\n\nexport type Task = () => Promise<void>;\n\nexport type ViewerEvent = {\n  taskCompleted: { progression: number };\n  updated: object;\n  updatePreprocesses: {\n    camera: OffsetCamera;\n    renderer: WebGLRenderer;\n  };\n  resize: {\n    width: number;\n    height: number;\n  };\n  animate: {\n    delta: number;\n  };\n};\n\nexport type CreateViewerReturnType = {\n  launch: () => void,\n  addTasks: (tasks: Task[]) => void,\n  launchTasks: () => Promise<void>,\n  pause: () => void,\n  play: () => void,\n  dispose: () => void,\n  disableScene: () => void,\n  enableScene: () => void,\n  eventDispatcher: EventDispatcher<ViewerEvent>,\n  renderer: WebGLRenderer,\n  scene: Scene,\n  camera: OffsetCamera,\n  controls: OrbitControls\n}\n\nexport const createViewer = (element: HTMLElement) => {\n  if (!element) {\n    throw new Error('init: element not found');\n  }\n\n  const clock = new Clock();\n  const eventDispatcher = new EventDispatcher<ViewerEvent>();\n  let animationFrameHandle: number = -1;\n\n  const renderer = createRenderer(element);\n  const { camera, controls } = createCamera(renderer);\n\n  const scene = new Scene();\n\n  const tasks: Task[] = [];\n\n  const disableScene = () => {\n    scene.userData[\"disabled\"] = true;\n  }\n\n  const enableScene = () => {\n    scene.userData[\"disabled\"] = false;\n  }\n\n  const render = () => {\n    eventDispatcher.dispatchEvent({\n      type: 'updatePreprocesses',\n      camera,\n      renderer\n    });\n\n    if (scene.userData[\"disabled\"]) {\n      return;\n    }\n\n    renderer.render(scene, camera);\n  };\n\n  const update = () => {\n    // 1. Update animations\n    const delta = clock.getDelta();\n    eventDispatcher.dispatchEvent({ type: 'animate', delta });\n\n    // 2. Update controls after animations in case camera itself is animated\n    controls.update(0);\n\n    // 3. Render the scene\n    render();\n\n    eventDispatcher.dispatchEvent({ type: 'updated' });\n  };\n\n  const requestUpdate = () => {\n    animationFrameHandle = requestAnimationFrame(() => update());\n  };\n\n  const resize = () => {\n    const { parentElement } = renderer.domElement;\n    if (!parentElement) {\n      throw new Error('dom element has no parent');\n    }\n    const { clientWidth, clientHeight } = parentElement;\n    camera.aspect = clientWidth / clientHeight;\n    const isHorizontal = camera.aspect <= camera.verticalRatio;\n    camera.fov = isHorizontal\n      ? (Math.atan(\n        (Math.tan((camera.absoluteFov * Math.PI) / 360) * camera.verticalRatio) / camera.aspect\n      ) *\n        360) /\n      Math.PI\n      : camera.absoluteFov;\n    camera.updateProjectionMatrix();\n    renderer.setSize(clientWidth, clientHeight);\n\n    eventDispatcher.dispatchEvent({\n      type: 'resize',\n      width: clientWidth,\n      height: clientHeight\n    });\n    render();\n  };\n\n  // Enable looping behaviour but does not actually call the render loop\n  const activateRenderLoop = () => {\n    eventDispatcher.addEventListener('updated', requestUpdate);\n    clock.getDelta();\n  };\n\n  const launch = () => {\n    activateRenderLoop();\n\n    window.addEventListener('resize', resize, false);\n    resize();\n    update();\n  };\n\n  const pause = () => {\n    eventDispatcher.removeEventListener('updated', requestUpdate);\n    cancelAnimationFrame(animationFrameHandle);\n  };\n\n  const play = () => {\n    activateRenderLoop();\n    update();\n  };\n\n  const dispose = () => {\n    pause();\n    window.removeEventListener('resize', resize, false);\n\n    disposeTracked(scene);\n\n    controls.disconnect();\n    controls.dispose();\n\n    renderer.dispose();\n  };\n\n  const addTasks = (addedTasks: Task[]) => {\n    tasks.push(...addedTasks);\n  }\n\n  const launchTasks = async () => {\n    const taskCount = tasks.length;\n    let completedTaskCount = 0;\n    eventDispatcher.dispatchEvent({\n      type: \"taskCompleted\",\n      progression: 0,\n    });\n    await Promise.all(tasks.map(async (task: Task) => {\n      await task();\n      completedTaskCount++;\n      eventDispatcher.dispatchEvent({\n        type: \"taskCompleted\",\n        progression: completedTaskCount / taskCount,\n      });\n    }));\n\n    tasks.length = 0;\n  }\n\n  return {\n    launch,\n    addTasks,\n    launchTasks,\n    pause,\n    play,\n    dispose,\n    eventDispatcher,\n    renderer,\n    scene,\n    disableScene,\n    enableScene,\n    camera,\n    controls\n  };\n};\n"
    },
    {
      "path": "create-renderer.ts",
      "content": "import {\n  Color,\n  LinearSRGBColorSpace,\n  NoToneMapping,\n  WebGLRenderer,\n} from \"three\";\n\nexport default function createRenderer(element: HTMLElement): WebGLRenderer {\n  const renderer = new WebGLRenderer({\n    antialias: true,\n    alpha: true,\n    preserveDrawingBuffer: true,\n    stencil: true\n  });\n\n  renderer.setSize(element.clientWidth, element.clientHeight);\n  renderer.setClearColor(new Color(0, 0, 0), 0);\n\n  renderer.outputColorSpace = LinearSRGBColorSpace;\n  renderer.toneMapping = NoToneMapping;\n\n  renderer.clearColor();\n\n  element.appendChild(renderer.domElement);\n\n  return renderer;\n}\n"
    },
    {
      "path": "create-camera/create-camera.ts",
      "content": "import { WebGLRenderer } from \"three\";\nimport OffsetCamera from \"./offset-camera\";\nimport { OrbitControls } from \"./orbit-controls\";\n\nexport const createCamera = (renderer: WebGLRenderer) => {\n  const camera = new OffsetCamera(\n    75,\n    window.innerWidth / window.innerHeight,\n    0.1,\n    100,\n  );\n\n  const controls = new OrbitControls(camera, renderer.domElement);\n  controls.enableDamping = true;\n  controls.enablePan = false;\n  controls.minDistance = 1;\n  controls.maxDistance = 100;\n  controls.maxPolarAngle = 1.5;\n\n  camera.position.set(0, 1, 5);\n  controls.update(0);\n\n  return { camera, controls };\n};\n"
    },
    {
      "path": "create-camera/orbit-controls.ts",
      "content": "import {\n\tEventDispatcher,\n\tMatrix4,\n\tMOUSE,\n\tPerspectiveCamera,\n\tQuaternion,\n\tSpherical,\n\tTOUCH,\n\tVector2,\n\tVector3\n} from 'three';\n\ntype OrbitControlsEvent = {\n\ttype: 'change' | 'start' | 'end';\n};\n\n/**\n * Fires when the camera has been transformed by the controls.\n *\n * @event OrbitControls#change\n */\nconst _changeEvent: OrbitControlsEvent = { type: 'change' };\n\n/**\n * Fires when an interaction was initiated.\n *\n * @event OrbitControls#start\n */\nconst _startEvent: OrbitControlsEvent = { type: 'start' };\n\n/**\n * Fires when an interaction has finished.\n *\n * @event OrbitControls#end\n */\nconst _endEvent: OrbitControlsEvent = { type: 'end' };\n\nconst _v = new Vector3();\nconst _twoPI = 2 * Math.PI;\n\nconst _STATE = {\n\tNONE: -1,\n\tROTATE: 0,\n\tDOLLY: 1,\n\tPAN: 2,\n\tTOUCH_ROTATE: 3,\n\tTOUCH_PAN: 4,\n\tTOUCH_DOLLY_PAN: 5,\n\tTOUCH_DOLLY_ROTATE: 6\n};\nconst _EPS = 0.00001;\n\nconst MOUSE_MOVE_DOLLY_FACTOR = 0.03;\n\n/**\n * Orbit controls allow the camera to orbit around a target.\n *\n * Modified from https://github.com/mrdoob/three.js/blob/master/examples/jsm/controls/OrbitControls.js\n *\n * The coordinates system is as follow :\n * - right-handed, with Y as up, X as right and Z as backward\n * - Pitch goes to from PI when facing up, to 0 when facing down\n * - Yaw is at 0 when looking at origin from +Z axis, and goes to -PI when rotating left, and PI when rotating right. A yaw of -PI or PI is therefore equivalent, when looking at origin from the -Z axis.\n *\n * OrbitControls performs orbiting, dollying (zooming), and panning. Unlike {@link TrackballControls},\n * it maintains the \"up\" direction `object.up` (+Y by default).\n *\n * - Orbit: Left mouse / touch: one-finger move.\n * - Zoom: Middle mouse, or mousewheel / touch: two-finger spread or squish.\n * - Pan: Right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move.\n *\n * ```js\n * const controls = new OrbitControls( camera, renderer.domElement );\n *\n * // controls.update() must be called after any manual changes to the camera's transform\n * camera.position.set( 0, 20, 100 );\n * controls.update();\n *\n * function animate() {\n *\n * \t// required if controls.enableDamping or controls.autoRotate are set to true\n * \tcontrols.update();\n *\n * \trenderer.render( scene, camera );\n *\n * }\n * ```\n *\n * @augments Controls\n * @three_import import { OrbitControls } from 'three/addons/controls/OrbitControls.js';\n */\nclass OrbitControls extends EventDispatcher<{\n\tchange: OrbitControlsEvent;\n\tstart: OrbitControlsEvent;\n\tend: OrbitControlsEvent;\n}> {\n\tpublic camera: PerspectiveCamera;\n\n\tpublic domElement: HTMLElement | null = null;\n\n\tpublic state = _STATE.NONE;\n\n\t/**\n\t * The focus point of the controls, the `object` orbits around this.\n\t * It can be updated manually at any point to change the focus of the controls.\n\t */\n\tpublic target = new Vector3();\n\n\t/**\n\t * How far you can dolly in (perspective camera only).\n\t */\n\tpublic minDistance = 0;\n\n\t/**\n\t * How far you can dolly out (perspective camera only).\n\t */\n\tpublic maxDistance = Infinity;\n\n\t/**\n\t * How far you can zoom in (orthographic camera only).\n\t */\n\tpublic minZoom = 0;\n\n\t/**\n\t * How far you can zoom out (orthographic camera only).\n\t */\n\tpublic maxZoom = Infinity;\n\n\t/**\n\t * The scene reference center, from which the target bounding box revolve around\n\t */\n\tpublic sceneCenter = new Vector3(0, 0, 0);\n\n\tpublic sceneSize = 1;\n\n\t/**\n\t * The rotation of the target bounding box around the up axis\n\t *\n\t * @type {number}\n\t */\n\tpublic targetYaw = 0;\n\n\tpublic minTarget = new Vector3(-Infinity, -Infinity, -Infinity);\n\tpublic maxTarget = new Vector3(Infinity, Infinity, Infinity);\n\n\t/**\n\t * How far you can orbit vertically, lower limit. Range is `[0, Math.PI]` radians.\n\t */\n\tpublic minPolarAngle = 0;\n\n\t/**\n\t * How far you can orbit vertically, upper limit. Range is `[0, Math.PI]` radians.\n\t */\n\tpublic maxPolarAngle = Math.PI;\n\n\t/**\n\t * How far you can orbit horizontally, lower limit. If set, the interval `[ min, max ]`\n\t * must be a sub-interval of `[ - 2 PI, 2 PI ]`, with `( max - min < 2 PI )`.\n\t */\n\tpublic minAzimuthAngle = -Infinity;\n\n\t/**\n\t * How far you can orbit horizontally, upper limit. If set, the interval `[ min, max ]`\n\t * must be a sub-interval of `[ - 2 PI, 2 PI ]`, with `( max - min < 2 PI )`.\n\t */\n\tpublic maxAzimuthAngle = Infinity;\n\n\t/**\n\t * Set to `true` to enable damping (inertia), which can be used to give a sense of weight\n\t * to the controls. Note that if this is enabled, you must call `update()` in your animation\n\t * loop.\n\t */\n\tpublic enableDamping = false;\n\n\t/**\n\t * The damping inertia used if `enableDamping` is set to `true`.\n\t *\n\t * Note that for this to work, you must call `update()` in your animation loop.\n\t */\n\tpublic dampingFactor = 0.05;\n\n\t/**\n\t * The zoom damping inertia used if `enableDamping` is set to `true`.\n\t *\n\t * Note that for this to work, you must call `update()` in your animation loop.\n\t */\n\tpublic zoomDampingFactor = 0.05;\n\n\t/**\n\t * Enable or disable zooming (dollying) of the camera.\n\t */\n\tpublic enableZoom = true;\n\n\t/**\n\t * Speed of zooming / dollying.\n\t */\n\tpublic zoomSpeed = 1.0;\n\n\t/**\n\t * Enable or disable horizontal and vertical rotation of the camera.\n\t *\n\t * Note that it is possible to disable a single axis by setting the min and max of the\n\t * `minPolarAngle` or `minAzimuthAngle` to the same value, which will cause the vertical\n\t * or horizontal rotation to be fixed at that value.\n\t */\n\tpublic enableRotate = true;\n\n\t/**\n\t * Speed of rotation.\n\t */\n\tpublic rotateSpeed = 1.0;\n\n\t/**\n\t * How fast to rotate the camera when the keyboard is used.\n\t */\n\tpublic keyRotateSpeed = 1.0;\n\n\t/**\n\t * Enable or disable camera panning.\n\t */\n\tpublic enablePan = true;\n\n\t/**\n\t * Speed of panning.\n\t */\n\tpublic panSpeed = 1.0;\n\n\t/**\n\t * How fast to pan the camera when the keyboard is used in\n\t * pixels per keypress.\n\t */\n\tpublic keyPanSpeed = 7.0;\n\n\t/**\n\t * Set to true to automatically rotate around the target\n\t *\n\t * Note that if this is enabled, you must call `update()` in your animation loop.\n\t * If you want the auto-rotate speed to be independent of the frame rate (the refresh\n\t * rate of the display), you must pass the time `deltaTime`, in seconds, to `update()`.\n\t */\n\tpublic autoRotate = false;\n\n\t/**\n\t * How fast to rotate around the target if `autoRotate` is `true`. The default  equates to 30 seconds\n\t * per orbit at 60fps.\n\t *\n\t * Note that if `autoRotate` is enabled, you must call `update()` in your animation loop.\n\t */\n\tpublic autoRotateSpeed = 2.0;\n\n\t/**\n\t * This object contains references to the keycodes for controlling camera panning.\n\t *\n\t * ```js\n\t * controls.keys = {\n\t * \tLEFT: 'ArrowLeft', //left arrow\n\t * \tUP: 'ArrowUp', // up arrow\n\t * \tRIGHT: 'ArrowRight', // right arrow\n\t * \tBOTTOM: 'ArrowDown' // down arrow\n\t * }\n\t * ```\n\t */\n\tpublic keys = { LEFT: 'ArrowLeft', UP: 'ArrowUp', RIGHT: 'ArrowRight', BOTTOM: 'ArrowDown' };\n\n\t/**\n\t * This object contains references to the mouse actions used by the controls.\n\t *\n\t * ```js\n\t * controls.mouseButtons = {\n\t * \tLEFT: THREE.MOUSE.ROTATE,\n\t * \tMIDDLE: THREE.MOUSE.DOLLY,\n\t * \tRIGHT: THREE.MOUSE.PAN\n\t * }\n\t * ```\n\t */\n\tpublic mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };\n\n\t/**\n\t * This object contains references to the touch actions used by the controls.\n\t *\n\t * ```js\n\t * controls.mouseButtons = {\n\t * \tONE: THREE.TOUCH.ROTATE,\n\t * \tTWO: THREE.TOUCH.DOLLY_PAN\n\t * }\n\t * ```\n\t */\n\tpublic touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };\n\n\t// the target DOM element for key events\n\tprivate _domElementKeyEvents: HTMLElement | null = null;\n\n\t// internals\n\n\tprivate _lastPosition = new Vector3();\n\tprivate _lastQuaternion = new Quaternion();\n\tprivate _lastTargetPosition = new Vector3();\n\n\t// so camera.up is the orbit axis\n\tprivate _quat = new Quaternion();\n\tprivate _quatInverse = new Quaternion();\n\n\t// current position in spherical coordinates\n\tprivate _spherical = new Spherical();\n\tprivate _sphericalDelta = new Spherical();\n\n\tprivate _scale = 1;\n\tprivate _scaleDelta = 0;\n\tprivate _panOffset = new Vector3();\n\n\tprivate _rotateStart = new Vector2();\n\tprivate _rotateEnd = new Vector2();\n\tprivate _rotateDelta = new Vector2();\n\n\tprivate _panStart = new Vector2();\n\tprivate _panEnd = new Vector2();\n\tprivate _panDelta = new Vector2();\n\n\tprivate _dollyStart = new Vector2();\n\tprivate _dollyEnd = new Vector2();\n\tprivate _dollyDelta = new Vector2();\n\n\tprivate _pointers: number[] = [];\n\tprivate _pointerPositions: Record<number, Vector2> = {};\n\n\tprivate _controlActive = false;\n\n\t/**\n\t * Constructs a new controls instance.\n\t *\n\t * @param {PerspectiveCamera} camera - The camera that is managed by the controls.\n\t * @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.\n\t */\n\tconstructor(camera: PerspectiveCamera, domElement: HTMLElement | null = null) {\n\t\tsuper();\n\n\t\tthis.camera = camera;\n\n\t\tthis._quat = new Quaternion().setFromUnitVectors(camera.up, new Vector3(0, 1, 0));\n\t\tthis._quatInverse = this._quat.clone().invert();\n\n\t\tif (domElement !== null) {\n\t\t\tthis.connect(domElement);\n\t\t}\n\n\t\tthis.update(0);\n\t}\n\n\tprivate _onPointerDownListener = (event: PointerEvent) => {\n\t\tthis._onPointerDown(event);\n\t};\n\n\tprivate _onPointerMoveListener = (event: PointerEvent) => {\n\t\tthis._onPointerMove(event);\n\t};\n\n\tprivate _onPointerUpListener = (event: PointerEvent) => {\n\t\tthis._onPointerUp(event);\n\t};\n\n\tprivate _onContextMenuListener = (event: MouseEvent) => {\n\t\tthis._onContextMenu(event);\n\t};\n\n\tprivate _onMouseWheelListener = (event: WheelEvent) => {\n\t\tthis._onMouseWheel(event);\n\t};\n\n\tprivate _interceptControlDownListener = (event: KeyboardEvent) => {\n\t\tthis._interceptControlDown(event);\n\t};\n\n\tprivate _interceptControlUpListener = (event: KeyboardEvent) => {\n\t\tthis._interceptControlUp(event);\n\t};\n\n\tprivate _onKeyDownListener = (event: KeyboardEvent) => {\n\t\tthis._onKeyDown(event);\n\t};\n\n\tpublic connect(element: HTMLElement) {\n\t\tthis.domElement = element;\n\n\t\telement.addEventListener('pointerdown', this._onPointerDownListener);\n\t\telement.addEventListener('pointermove', this._onPointerMoveListener);\n\t\telement.addEventListener('pointerup', this._onPointerUpListener);\n\t\telement.addEventListener('pointercancel', this._onPointerUpListener);\n\n\t\telement.addEventListener('contextmenu', this._onContextMenuListener);\n\t\telement.addEventListener('wheel', this._onMouseWheelListener, { passive: false });\n\n\t\twindow.addEventListener('keydown', this._interceptControlDownListener, {\n\t\t\tpassive: true,\n\t\t\tcapture: true\n\t\t});\n\n\t\telement.style.touchAction = 'none'; // disable touch scroll\n\t}\n\n\tpublic disconnect() {\n\t\tif (!this.domElement) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.domElement.removeEventListener('pointerdown', this._onPointerDownListener);\n\t\tthis.domElement.removeEventListener('pointermove', this._onPointerMoveListener);\n\t\tthis.domElement.removeEventListener('pointerup', this._onPointerUpListener);\n\t\tthis.domElement.removeEventListener('pointercancel', this._onPointerUpListener);\n\n\t\tthis.domElement.removeEventListener('wheel', this._onMouseWheelListener);\n\t\tthis.domElement.removeEventListener('contextmenu', this._onContextMenuListener);\n\n\t\tthis.stopListenToKeyEvents();\n\n\t\twindow.removeEventListener('keydown', this._interceptControlDownListener, { capture: true });\n\n\t\tthis.domElement.style.touchAction = 'auto';\n\t}\n\n\tpublic dispose() {\n\t\tthis.disconnect();\n\t}\n\n\t/**\n\t * Get the current vertical rotation, in radians.\n\t *\n\t * @return The current vertical rotation, in radians.\n\t */\n\tpublic getPolarAngle() {\n\t\treturn this._spherical.phi;\n\t}\n\n\t/**\n\t * Get the current horizontal rotation, in radians.\n\t *\n\t * @return The current horizontal rotation, in radians.\n\t */\n\tpublic getAzimuthalAngle() {\n\t\treturn this._spherical.theta;\n\t}\n\n\t/**\n\t * Returns the distance from the camera to the target.\n\t *\n\t * @return The distance from the camera to the target.\n\t */\n\tpublic getDistance() {\n\t\treturn this.camera.position.distanceTo(this.target);\n\t}\n\n\t/**\n\t * Adds key event listeners to the given DOM element.\n\t * `window` is a recommended argument for using this method.\n\t *\n\t * @param domElement - The DOM element\n\t */\n\tpublic listenToKeyEvents(domElement: HTMLElement) {\n\t\tdomElement.addEventListener('keydown', this._onKeyDownListener);\n\t\tthis._domElementKeyEvents = domElement;\n\t}\n\n\t/**\n\t * Removes the key event listener previously defined with `listenToKeyEvents()`.\n\t */\n\tpublic stopListenToKeyEvents() {\n\t\tif (this._domElementKeyEvents !== null) {\n\t\t\tthis._domElementKeyEvents.removeEventListener('keydown', this._onKeyDownListener);\n\t\t\tthis._domElementKeyEvents = null;\n\t\t}\n\t}\n\n\t/**\n\t * @param deltaTime - The time since the last update in seconds.\n\t */\n\tpublic update(deltaTime: number) {\n\t\tconst position = this.camera.position;\n\n\t\t_v.copy(position).sub(this.target);\n\n\t\t// rotate offset to \"y-axis-is-up\" space\n\t\t_v.applyQuaternion(this._quat);\n\n\t\t// angle from z-axis around y-axis\n\t\tthis._spherical.setFromVector3(_v);\n\n\t\tif (this.autoRotate && this.state === _STATE.NONE) {\n\t\t\tthis._rotateLeft(this._getAutoRotationAngle(deltaTime));\n\t\t}\n\n\t\tlet min = this.minAzimuthAngle;\n\t\tlet max = this.maxAzimuthAngle;\n\n\t\tif (isFinite(min) && isFinite(max)) {\n\t\t\tif (min < -Math.PI) min += _twoPI;\n\t\t\telse if (min > Math.PI) min -= _twoPI;\n\n\t\t\tif (max < -Math.PI) max += _twoPI;\n\t\t\telse if (max > Math.PI) max -= _twoPI;\n\n\t\t\tif (min <= max) {\n\t\t\t\tthis._spherical.theta = Math.max(min, Math.min(max, this._spherical.theta));\n\t\t\t} else {\n\t\t\t\tthis._spherical.theta =\n\t\t\t\t\tthis._spherical.theta > (min + max) / 2\n\t\t\t\t\t\t? Math.max(min, this._spherical.theta)\n\t\t\t\t\t\t: Math.min(max, this._spherical.theta);\n\t\t\t}\n\t\t}\n\n\t\t// Since we do integrations AFTER contraints, they will act as a spring effect.\n\n\t\t// restrict phi to be between desired limits\n\t\tthis._spherical.phi = Math.max(\n\t\t\tthis.minPolarAngle,\n\t\t\tMath.min(this.maxPolarAngle, this._spherical.phi)\n\t\t);\n\n\t\t// restrict theta to be between desired limits\n\t\tif (this.enableDamping) {\n\t\t\tthis._spherical.theta += this._sphericalDelta.theta * this.dampingFactor;\n\t\t\tthis._spherical.phi += this._sphericalDelta.phi * this.dampingFactor;\n\t\t} else {\n\t\t\tthis._spherical.theta += this._sphericalDelta.theta;\n\t\t\tthis._spherical.phi += this._sphericalDelta.phi;\n\t\t}\n\n\t\tthis._spherical.makeSafe();\n\n\t\tthis.target.sub(this.sceneCenter);\n\t\tthis.target.applyAxisAngle(new Vector3(0, 1, 0), -this.targetYaw);\n\t\tthis.target.clamp(this.minTarget, this.maxTarget);\n\t\tthis.target.applyAxisAngle(new Vector3(0, 1, 0), this.targetYaw);\n\t\tthis.target.add(this.sceneCenter);\n\n\t\t// move target to panned location\n\n\t\tif (this.enableDamping === true) {\n\t\t\tthis.target.addScaledVector(this._panOffset, this.dampingFactor);\n\t\t} else {\n\t\t\tthis.target.add(this._panOffset);\n\t\t}\n\n\t\tlet zoomChanged = false;\n\t\tconst zoomDampingFactor = this.enableDamping ? this.zoomDampingFactor : 1;\n\n\t\tconst prevRadius = this._spherical.radius;\n\t\tthis._spherical.radius = this._clampDistance(this._spherical.radius);\n\t\tthis._scale =\n\t\t\tthis._scaleDelta > 0\n\t\t\t\t? this._scale / (1 + this._scaleDelta * zoomDampingFactor)\n\t\t\t\t: this._scale * (1 - this._scaleDelta * zoomDampingFactor);\n\t\tthis._spherical.radius = this._spherical.radius * this._scale;\n\t\tzoomChanged = Math.abs(prevRadius - this._spherical.radius) > _EPS * this.sceneSize;\n\n\t\t_v.setFromSpherical(this._spherical);\n\n\t\t// rotate offset back to \"camera-up-vector-is-up\" space\n\t\t_v.applyQuaternion(this._quatInverse);\n\n\t\tposition.copy(this.target).add(_v);\n\n\t\tthis.camera.lookAt(this.target);\n\n\t\tif (this.enableDamping === true) {\n\t\t\tthis._sphericalDelta.theta *= 1 - this.dampingFactor;\n\t\t\tthis._sphericalDelta.phi *= 1 - this.dampingFactor;\n\n\t\t\tthis._scaleDelta *= 1 - zoomDampingFactor;\n\n\t\t\tthis._panOffset.multiplyScalar(1 - this.dampingFactor);\n\t\t} else {\n\t\t\tthis._sphericalDelta.set(0, 0, 0);\n\n\t\t\tthis._scaleDelta = 0;\n\n\t\t\tthis._panOffset.set(0, 0, 0);\n\t\t}\n\n\t\tthis._scale = 1;\n\n\t\t// update condition is:\n\t\t// min(camera displacement, camera rotation in radians)^2 > EPS\n\t\t// using small-angle approximation cos(x/2) = 1 - x^2 / 8\n\n\t\tif (\n\t\t\tzoomChanged ||\n\t\t\tthis._lastPosition.distanceToSquared(this.camera.position) > _EPS * this.sceneSize ||\n\t\t\t8 * (1 - this._lastQuaternion.dot(this.camera.quaternion)) > _EPS * this.sceneSize ||\n\t\t\tthis._lastTargetPosition.distanceToSquared(this.target) > _EPS * this.sceneSize\n\t\t) {\n\t\t\tthis.dispatchEvent(_changeEvent);\n\n\t\t\tthis._lastPosition.copy(this.camera.position);\n\t\t\tthis._lastQuaternion.copy(this.camera.quaternion);\n\t\t\tthis._lastTargetPosition.copy(this.target);\n\n\t\t\treturn true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprivate _getAutoRotationAngle(deltaTime: number) {\n\t\tif (deltaTime !== null) {\n\t\t\treturn (_twoPI / 60) * this.autoRotateSpeed * deltaTime;\n\t\t} else {\n\t\t\treturn (_twoPI / 60 / 60) * this.autoRotateSpeed;\n\t\t}\n\t}\n\n\tprivate _getZoomScale(delta: number) {\n\t\tconst normalizedDelta = Math.abs(delta * 0.01);\n\t\treturn Math.pow(0.95, this.zoomSpeed * normalizedDelta);\n\t}\n\n\tprivate _rotateLeft(angle: number) {\n\t\tthis._sphericalDelta.theta -= angle;\n\t}\n\n\tprivate _rotateUp(angle: number) {\n\t\tthis._sphericalDelta.phi -= angle;\n\t}\n\n\tprivate _panLeft(distance: number, objectMatrix: Matrix4) {\n\t\t_v.setFromMatrixColumn(objectMatrix, 0); // get X column of objectMatrix\n\t\t_v.multiplyScalar(-distance);\n\n\t\tthis._panOffset.add(_v);\n\t}\n\n\tprivate _panUp(distance: number, objectMatrix: Matrix4) {\n\t\t_v.setFromMatrixColumn(objectMatrix, 1);\n\n\t\t_v.multiplyScalar(distance);\n\n\t\tthis._panOffset.add(_v);\n\t}\n\n\t// deltaX and deltaY are in pixels; right and down are positive\n\tprivate _pan(deltaX: number, deltaY: number) {\n\t\tconst element = this.domElement;\n\n\t\tif (!element) {\n\t\t\treturn;\n\t\t}\n\n\t\t// perspective\n\t\tconst position = this.camera.position;\n\t\t_v.copy(position).sub(this.target);\n\t\tlet targetDistance = _v.length();\n\n\t\t// half of the fov is center to top of screen\n\t\ttargetDistance *= Math.tan(((this.camera.fov / 2) * Math.PI) / 180.0);\n\n\t\t// we use only clientHeight here so aspect ratio does not distort speed\n\t\tthis._panLeft((2 * deltaX * targetDistance) / element.clientHeight, this.camera.matrix);\n\t\tthis._panUp((2 * deltaY * targetDistance) / element.clientHeight, this.camera.matrix);\n\t}\n\n\tprivate _dollyOut(dollyScale: number) {\n\t\tthis._scaleDelta -= dollyScale;\n\t}\n\n\tprivate _dollyIn(dollyScale: number) {\n\t\tthis._scaleDelta += dollyScale;\n\t}\n\n\tprivate _clampDistance(dist: number) {\n\t\treturn Math.max(this.minDistance, Math.min(this.maxDistance, dist));\n\t}\n\n\t//\n\t// event callbacks - update the object state\n\t//\n\n\tprivate _handleMouseDownRotate(event: MouseEvent) {\n\t\tthis._rotateStart.set(event.clientX, event.clientY);\n\t}\n\n\tprivate _handleMouseDownDolly(event: MouseEvent) {\n\t\tthis._dollyStart.set(event.clientX, event.clientY);\n\t}\n\n\tprivate _handleMouseDownPan(event: MouseEvent) {\n\t\tthis._panStart.set(event.clientX, event.clientY);\n\t}\n\n\tprivate _handleMouseMoveRotate(event: MouseEvent) {\n\t\tconst element = this.domElement;\n\n\t\tif (!element) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._rotateEnd.set(event.clientX, event.clientY);\n\n\t\tthis._rotateDelta\n\t\t\t.subVectors(this._rotateEnd, this._rotateStart)\n\t\t\t.multiplyScalar(this.rotateSpeed);\n\n\t\tthis._rotateLeft((_twoPI * this._rotateDelta.x) / element.clientHeight); // yes, height\n\n\t\tthis._rotateUp((_twoPI * this._rotateDelta.y) / element.clientHeight);\n\n\t\tthis._rotateStart.copy(this._rotateEnd);\n\n\t\tthis.update(0);\n\t}\n\n\tprivate _handleMouseMoveDolly(event: MouseEvent) {\n\t\tthis._dollyEnd.set(event.clientX, event.clientY);\n\n\t\tthis._dollyDelta.subVectors(this._dollyEnd, this._dollyStart);\n\n\t\tif (this._dollyDelta.y > 0) {\n\t\t\tthis._dollyOut(this._getZoomScale(this._dollyDelta.y) * MOUSE_MOVE_DOLLY_FACTOR);\n\t\t} else if (this._dollyDelta.y < 0) {\n\t\t\tthis._dollyIn(this._getZoomScale(this._dollyDelta.y) * MOUSE_MOVE_DOLLY_FACTOR);\n\t\t}\n\n\t\tthis._dollyStart.copy(this._dollyEnd);\n\n\t\tthis.update(0);\n\t}\n\n\tprivate _handleMouseMovePan(event: MouseEvent) {\n\t\tthis._panEnd.set(event.clientX, event.clientY);\n\n\t\tthis._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed);\n\n\t\tthis._pan(this._panDelta.x, this._panDelta.y);\n\n\t\tthis._panStart.copy(this._panEnd);\n\n\t\tthis.update(0);\n\t}\n\n\tprivate _handleMouseWheel(event: { deltaY: number }) {\n\t\tif (event.deltaY < 0) {\n\t\t\tthis._dollyIn(this._getZoomScale(event.deltaY));\n\t\t} else if (event.deltaY > 0) {\n\t\t\tthis._dollyOut(this._getZoomScale(event.deltaY));\n\t\t}\n\n\t\tthis.update(0);\n\t}\n\n\tprivate _handleKeyDown(event: KeyboardEvent) {\n\t\tlet needsUpdate = false;\n\n\t\tconst element = this.domElement;\n\t\tif (!element) {\n\t\t\treturn;\n\t\t}\n\n\t\tswitch (event.code) {\n\t\t\tcase this.keys.UP:\n\t\t\t\tif (event.ctrlKey || event.metaKey || event.shiftKey) {\n\t\t\t\t\tif (this.enableRotate) {\n\t\t\t\t\t\tthis._rotateUp((_twoPI * this.keyRotateSpeed) / element.clientHeight);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (this.enablePan) {\n\t\t\t\t\t\tthis._pan(0, this.keyPanSpeed);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tneedsUpdate = true;\n\t\t\t\tbreak;\n\n\t\t\tcase this.keys.BOTTOM:\n\t\t\t\tif (event.ctrlKey || event.metaKey || event.shiftKey) {\n\t\t\t\t\tif (this.enableRotate) {\n\t\t\t\t\t\tthis._rotateUp((-_twoPI * this.keyRotateSpeed) / element.clientHeight);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (this.enablePan) {\n\t\t\t\t\t\tthis._pan(0, -this.keyPanSpeed);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tneedsUpdate = true;\n\t\t\t\tbreak;\n\n\t\t\tcase this.keys.LEFT:\n\t\t\t\tif (event.ctrlKey || event.metaKey || event.shiftKey) {\n\t\t\t\t\tif (this.enableRotate) {\n\t\t\t\t\t\tthis._rotateLeft((_twoPI * this.keyRotateSpeed) / element.clientHeight);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (this.enablePan) {\n\t\t\t\t\t\tthis._pan(this.keyPanSpeed, 0);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tneedsUpdate = true;\n\t\t\t\tbreak;\n\n\t\t\tcase this.keys.RIGHT:\n\t\t\t\tif (event.ctrlKey || event.metaKey || event.shiftKey) {\n\t\t\t\t\tif (this.enableRotate) {\n\t\t\t\t\t\tthis._rotateLeft((-_twoPI * this.keyRotateSpeed) / element.clientHeight);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (this.enablePan) {\n\t\t\t\t\t\tthis._pan(-this.keyPanSpeed, 0);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tneedsUpdate = true;\n\t\t\t\tbreak;\n\t\t}\n\n\t\tif (needsUpdate) {\n\t\t\t// prevent the browser from scrolling on cursor keys\n\t\t\tevent.preventDefault();\n\n\t\t\tthis.update(0);\n\t\t}\n\t}\n\n\tprivate _handleTouchStartRotate(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tif (this._pointers.length === 1) {\n\t\t\tthis._rotateStart.set(event.pageX, event.pageY);\n\t\t} else {\n\t\t\tconst position = this._getSecondPointerPosition(event);\n\n\t\t\tconst x = 0.5 * (event.pageX + position.x);\n\t\t\tconst y = 0.5 * (event.pageY + position.y);\n\n\t\t\tthis._rotateStart.set(x, y);\n\t\t}\n\t}\n\n\tprivate _handleTouchStartPan(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tif (this._pointers.length === 1) {\n\t\t\tthis._panStart.set(event.pageX, event.pageY);\n\t\t} else {\n\t\t\tconst position = this._getSecondPointerPosition(event);\n\n\t\t\tconst x = 0.5 * (event.pageX + position.x);\n\t\t\tconst y = 0.5 * (event.pageY + position.y);\n\n\t\t\tthis._panStart.set(x, y);\n\t\t}\n\t}\n\n\tprivate _handleTouchStartDolly(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tconst position = this._getSecondPointerPosition(event);\n\n\t\tconst dx = event.pageX - position.x;\n\t\tconst dy = event.pageY - position.y;\n\n\t\tconst distance = Math.sqrt(dx * dx + dy * dy);\n\n\t\tthis._dollyStart.set(0, distance);\n\t}\n\n\tprivate _handleTouchStartDollyPan(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tif (this.enableZoom) this._handleTouchStartDolly(event);\n\n\t\tif (this.enablePan) this._handleTouchStartPan(event);\n\t}\n\n\tprivate _handleTouchStartDollyRotate(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tif (this.enableZoom) this._handleTouchStartDolly(event);\n\n\t\tif (this.enableRotate) this._handleTouchStartRotate(event);\n\t}\n\n\tprivate _handleTouchMoveRotate(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tif (this._pointers.length == 1) {\n\t\t\tthis._rotateEnd.set(event.pageX, event.pageY);\n\t\t} else {\n\t\t\tconst position = this._getSecondPointerPosition(event);\n\n\t\t\tconst x = 0.5 * (event.pageX + position.x);\n\t\t\tconst y = 0.5 * (event.pageY + position.y);\n\n\t\t\tthis._rotateEnd.set(x, y);\n\t\t}\n\n\t\tthis._rotateDelta\n\t\t\t.subVectors(this._rotateEnd, this._rotateStart)\n\t\t\t.multiplyScalar(this.rotateSpeed);\n\n\t\tconst element = this.domElement;\n\n\t\tif (!element) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._rotateLeft((_twoPI * this._rotateDelta.x) / element.clientHeight); // yes, height\n\n\t\tthis._rotateUp((_twoPI * this._rotateDelta.y) / element.clientHeight);\n\n\t\tthis._rotateStart.copy(this._rotateEnd);\n\t}\n\n\tprivate _handleTouchMovePan(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tif (this._pointers.length === 1) {\n\t\t\tthis._panEnd.set(event.pageX, event.pageY);\n\t\t} else {\n\t\t\tconst position = this._getSecondPointerPosition(event);\n\n\t\t\tconst x = 0.5 * (event.pageX + position.x);\n\t\t\tconst y = 0.5 * (event.pageY + position.y);\n\n\t\t\tthis._panEnd.set(x, y);\n\t\t}\n\n\t\tthis._panDelta.subVectors(this._panEnd, this._panStart).multiplyScalar(this.panSpeed);\n\n\t\tthis._pan(this._panDelta.x, this._panDelta.y);\n\n\t\tthis._panStart.copy(this._panEnd);\n\t}\n\n\tprivate _handleTouchMoveDolly(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tconst position = this._getSecondPointerPosition(event);\n\n\t\tconst dx = event.pageX - position.x;\n\t\tconst dy = event.pageY - position.y;\n\n\t\tconst distance = Math.sqrt(dx * dx + dy * dy);\n\n\t\tthis._dollyEnd.set(0, distance);\n\n\t\tthis._dollyDelta.set(0, (this._dollyEnd.y - this._dollyStart.y) / distance);\n\n\t\tthis._dollyIn(this._dollyDelta.y);\n\n\t\tthis._dollyStart.copy(this._dollyEnd);\n\t}\n\n\tprivate _handleTouchMoveDollyPan(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tif (this.enableZoom) this._handleTouchMoveDolly(event);\n\n\t\tif (this.enablePan) this._handleTouchMovePan(event);\n\t}\n\n\tprivate _handleTouchMoveDollyRotate(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tif (this.enableZoom) this._handleTouchMoveDolly(event);\n\n\t\tif (this.enableRotate) this._handleTouchMoveRotate(event);\n\t}\n\n\t// pointers\n\n\tprivate _addPointer(event: { pointerId: number }) {\n\t\tthis._pointers.push(event.pointerId);\n\t}\n\n\tprivate _removePointer(event: { pointerId: number }) {\n\t\tdelete this._pointerPositions[event.pointerId];\n\n\t\tfor (let i = 0; i < this._pointers.length; i++) {\n\t\t\tif (this._pointers[i] == event.pointerId) {\n\t\t\t\tthis._pointers.splice(i, 1);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _isTrackingPointer(event: { pointerId: number }) {\n\t\tfor (let i = 0; i < this._pointers.length; i++) {\n\t\t\tif (this._pointers[i] == event.pointerId) return true;\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprivate _trackPointer(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tlet position = this._pointerPositions[event.pointerId];\n\n\t\tif (position === undefined) {\n\t\t\tposition = new Vector2();\n\t\t\tthis._pointerPositions[event.pointerId] = position;\n\t\t}\n\n\t\tposition.set(event.pageX, event.pageY);\n\t}\n\n\tprivate _getSecondPointerPosition(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tconst pointerId = event.pointerId === this._pointers[0] ? this._pointers[1] : this._pointers[0];\n\n\t\treturn this._pointerPositions[pointerId];\n\t}\n\n\t//\n\n\tprivate _customWheelEvent(event: WheelEvent) {\n\t\tconst mode = event.deltaMode;\n\n\t\t// minimal wheel event altered to meet delta-zoom demand\n\t\tconst newEvent = {\n\t\t\tclientX: event.clientX,\n\t\t\tclientY: event.clientY,\n\t\t\tdeltaY: event.deltaY\n\t\t};\n\n\t\tswitch (mode) {\n\t\t\tcase 1: // LINE_MODE\n\t\t\t\tnewEvent.deltaY *= 16;\n\t\t\t\tbreak;\n\n\t\t\tcase 2: // PAGE_MODE\n\t\t\t\tnewEvent.deltaY *= 100;\n\t\t\t\tbreak;\n\t\t}\n\n\t\t// detect if event was triggered by pinching\n\t\tif (event.ctrlKey && !this._controlActive) {\n\t\t\tnewEvent.deltaY *= 10;\n\t\t}\n\n\t\treturn newEvent;\n\t}\n\n\tprivate _onPointerDown = (event: PointerEvent) => {\n\t\tif (this._pointers.length === 0) {\n\t\t\tif (!this.domElement) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.domElement.setPointerCapture(event.pointerId);\n\n\t\t\tthis.domElement.addEventListener('pointermove', this._onPointerMoveListener);\n\t\t\tthis.domElement.addEventListener('pointerup', this._onPointerUpListener);\n\t\t}\n\n\t\t//\n\n\t\tif (this._isTrackingPointer(event)) return;\n\n\t\t//\n\n\t\tthis._addPointer(event);\n\n\t\tif (event.pointerType === 'touch') {\n\t\t\tthis._onTouchStart(event);\n\t\t} else {\n\t\t\tthis._onMouseDown(event);\n\t\t}\n\t};\n\n\tprivate _onPointerMove(event: PointerEvent) {\n\t\tif (event.pointerType === 'touch') {\n\t\t\tthis._onTouchMove(event);\n\t\t} else {\n\t\t\tthis._onMouseMove(event);\n\t\t}\n\t}\n\n\tprivate _onPointerUp(event: PointerEvent) {\n\t\tthis._removePointer(event);\n\n\t\tswitch (this._pointers.length) {\n\t\t\tcase 0:\n\t\t\t\tif (!this.domElement) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tthis.domElement.releasePointerCapture(event.pointerId);\n\n\t\t\t\tthis.domElement.removeEventListener('pointermove', this._onPointerMove);\n\t\t\t\tthis.domElement.removeEventListener('pointerup', this._onPointerUp);\n\n\t\t\t\tthis.dispatchEvent(_endEvent);\n\n\t\t\t\tthis.state = _STATE.NONE;\n\n\t\t\t\tbreak;\n\n\t\t\tcase 1: {\n\t\t\t\tconst pointerId = this._pointers[0];\n\t\t\t\tconst position = this._pointerPositions[pointerId];\n\n\t\t\t\t// minimal placeholder event - allows state correction on pointer-up\n\t\t\t\tthis._onTouchStart({ pointerId: pointerId, pageX: position.x, pageY: position.y });\n\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate _onMouseDown(event: MouseEvent) {\n\t\tlet mouseAction;\n\n\t\tswitch (event.button) {\n\t\t\tcase 0:\n\t\t\t\tmouseAction = this.mouseButtons.LEFT;\n\t\t\t\tbreak;\n\n\t\t\tcase 1:\n\t\t\t\tmouseAction = this.mouseButtons.MIDDLE;\n\t\t\t\tbreak;\n\n\t\t\tcase 2:\n\t\t\t\tmouseAction = this.mouseButtons.RIGHT;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tmouseAction = -1;\n\t\t}\n\n\t\tswitch (mouseAction) {\n\t\t\tcase MOUSE.DOLLY:\n\t\t\t\tif (this.enableZoom === false) return;\n\n\t\t\t\tthis._handleMouseDownDolly(event);\n\n\t\t\t\tthis.state = _STATE.DOLLY;\n\n\t\t\t\tbreak;\n\n\t\t\tcase MOUSE.ROTATE:\n\t\t\t\tif (event.ctrlKey || event.metaKey || event.shiftKey) {\n\t\t\t\t\tif (this.enablePan === false) return;\n\n\t\t\t\t\tthis._handleMouseDownPan(event);\n\n\t\t\t\t\tthis.state = _STATE.PAN;\n\t\t\t\t} else {\n\t\t\t\t\tif (this.enableRotate === false) return;\n\n\t\t\t\t\tthis._handleMouseDownRotate(event);\n\n\t\t\t\t\tthis.state = _STATE.ROTATE;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tcase MOUSE.PAN:\n\t\t\t\tif (event.ctrlKey || event.metaKey || event.shiftKey) {\n\t\t\t\t\tif (this.enableRotate === false) return;\n\n\t\t\t\t\tthis._handleMouseDownRotate(event);\n\n\t\t\t\t\tthis.state = _STATE.ROTATE;\n\t\t\t\t} else {\n\t\t\t\t\tif (this.enablePan === false) return;\n\n\t\t\t\t\tthis._handleMouseDownPan(event);\n\n\t\t\t\t\tthis.state = _STATE.PAN;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tthis.state = _STATE.NONE;\n\t\t}\n\n\t\tif (this.state !== _STATE.NONE) {\n\t\t\tthis.dispatchEvent(_startEvent);\n\t\t}\n\t}\n\n\tprivate _onMouseMove(event: MouseEvent) {\n\t\tswitch (this.state) {\n\t\t\tcase _STATE.ROTATE:\n\t\t\t\tif (this.enableRotate === false) return;\n\n\t\t\t\tthis._handleMouseMoveRotate(event);\n\n\t\t\t\tbreak;\n\n\t\t\tcase _STATE.DOLLY:\n\t\t\t\tif (this.enableZoom === false) return;\n\n\t\t\t\tthis._handleMouseMoveDolly(event);\n\n\t\t\t\tbreak;\n\n\t\t\tcase _STATE.PAN:\n\t\t\t\tif (this.enablePan === false) return;\n\n\t\t\t\tthis._handleMouseMovePan(event);\n\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate _onMouseWheel(event: WheelEvent) {\n\t\tif (this.enableZoom === false || (this.state !== _STATE.NONE && this.state !== _STATE.DOLLY))\n\t\t\treturn;\n\n\t\tevent.preventDefault();\n\n\t\tthis.dispatchEvent(_startEvent);\n\n\t\tthis._handleMouseWheel(this._customWheelEvent(event));\n\n\t\tthis.dispatchEvent(_endEvent);\n\t}\n\n\tprivate _onKeyDown(event: KeyboardEvent) {\n\t\tthis._handleKeyDown(event);\n\t}\n\n\tprivate _onTouchStart(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tthis._trackPointer(event);\n\n\t\tswitch (this._pointers.length) {\n\t\t\tcase 1:\n\t\t\t\tswitch (this.touches.ONE) {\n\t\t\t\t\tcase TOUCH.ROTATE:\n\t\t\t\t\t\tif (this.enableRotate === false) return;\n\n\t\t\t\t\t\tthis._handleTouchStartRotate(event);\n\n\t\t\t\t\t\tthis.state = _STATE.TOUCH_ROTATE;\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase TOUCH.PAN:\n\t\t\t\t\t\tif (this.enablePan === false) return;\n\n\t\t\t\t\t\tthis._handleTouchStartPan(event);\n\n\t\t\t\t\t\tthis.state = _STATE.TOUCH_PAN;\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthis.state = _STATE.NONE;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tcase 2:\n\t\t\t\tswitch (this.touches.TWO) {\n\t\t\t\t\tcase TOUCH.DOLLY_PAN:\n\t\t\t\t\t\tif (this.enableZoom === false && this.enablePan === false) return;\n\n\t\t\t\t\t\tthis._handleTouchStartDollyPan(event);\n\n\t\t\t\t\t\tthis.state = _STATE.TOUCH_DOLLY_PAN;\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase TOUCH.DOLLY_ROTATE:\n\t\t\t\t\t\tif (this.enableZoom === false && this.enableRotate === false) return;\n\n\t\t\t\t\t\tthis._handleTouchStartDollyRotate(event);\n\n\t\t\t\t\t\tthis.state = _STATE.TOUCH_DOLLY_ROTATE;\n\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tthis.state = _STATE.NONE;\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tthis.state = _STATE.NONE;\n\t\t}\n\n\t\tif (this.state !== _STATE.NONE) {\n\t\t\tthis.dispatchEvent(_startEvent);\n\t\t}\n\t}\n\n\tprivate _onTouchMove(event: { pointerId: number; pageX: number; pageY: number }) {\n\t\tthis._trackPointer(event);\n\n\t\tswitch (this.state) {\n\t\t\tcase _STATE.TOUCH_ROTATE:\n\t\t\t\tif (this.enableRotate === false) return;\n\n\t\t\t\tthis._handleTouchMoveRotate(event);\n\n\t\t\t\tthis.update(0);\n\n\t\t\t\tbreak;\n\n\t\t\tcase _STATE.TOUCH_PAN:\n\t\t\t\tif (this.enablePan === false) return;\n\n\t\t\t\tthis._handleTouchMovePan(event);\n\n\t\t\t\tthis.update(0);\n\n\t\t\t\tbreak;\n\n\t\t\tcase _STATE.TOUCH_DOLLY_PAN:\n\t\t\t\tif (this.enableZoom === false && this.enablePan === false) return;\n\n\t\t\t\tthis._handleTouchMoveDollyPan(event);\n\n\t\t\t\tthis.update(0);\n\n\t\t\t\tbreak;\n\n\t\t\tcase _STATE.TOUCH_DOLLY_ROTATE:\n\t\t\t\tif (this.enableZoom === false && this.enableRotate === false) return;\n\n\t\t\t\tthis._handleTouchMoveDollyRotate(event);\n\n\t\t\t\tthis.update(0);\n\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\tthis.state = _STATE.NONE;\n\t\t}\n\t}\n\n\tprivate _onContextMenu(event: MouseEvent) {\n\t\tevent.preventDefault();\n\t}\n\n\tprivate _interceptControlDown(event: KeyboardEvent) {\n\t\tif (event.key === 'Control') {\n\t\t\tthis._controlActive = true;\n\n\t\t\twindow.addEventListener('keyup', this._interceptControlUpListener, {\n\t\t\t\tpassive: true,\n\t\t\t\tcapture: true\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate _interceptControlUp(event: KeyboardEvent) {\n\t\tif (event.key === 'Control') {\n\t\t\tthis._controlActive = false;\n\n\t\t\twindow.removeEventListener('keyup', this._interceptControlUpListener, {\n\t\t\t\tcapture: true\n\t\t\t});\n\t\t}\n\t}\n}\n\nexport { OrbitControls };\n"
    },
    {
      "path": "create-camera/offset-camera.ts",
      "content": "import { MathUtils, Matrix4, PerspectiveCamera, Vector3 } from \"three\";\n\nexport default class OffsetCamera extends PerspectiveCamera {\n  public verticalRatio: number = 1.0;\n  public absoluteFov: number = 75;\n\n  public xOffset: number = 0;\n  public yOffset: number = 0;\n\n  override updateProjectionMatrix() {\n    const near = this.near;\n    let top = (near * Math.tan(MathUtils.DEG2RAD * 0.5 * this.fov)) / this.zoom;\n    let height = 2 * top;\n    let width = this.aspect * height;\n    let left = -0.5 * width;\n\n    if (this.view !== null && this.view.enabled) {\n      const view = this.view;\n      const fullWidth = view.fullWidth,\n        fullHeight = view.fullHeight;\n\n      left += (view.offsetX * width) / fullWidth;\n      top -= (view.offsetY * height) / fullHeight;\n      width *= view.width / fullWidth;\n      height *= view.height / fullHeight;\n    }\n\n    const skew = this.filmOffset;\n    if (skew !== 0) left += (near * skew) / this.getFilmWidth();\n\n    this.projectionMatrix.makePerspective(\n      left,\n      left + width,\n      top,\n      top - height,\n      near,\n      this.far,\n      this.coordinateSystem,\n    );\n\n    const offsetMatrix = new Matrix4().makeTranslation(\n      new Vector3(this.xOffset, this.yOffset, 0),\n    );\n\n    this.projectionMatrix.premultiply(offsetMatrix);\n\n    this.projectionMatrixInverse.copy(this.projectionMatrix).invert();\n  }\n}\n"
    }
  ]
}