1 line
32 KiB
Plaintext
1 line
32 KiB
Plaintext
|
|
{"version":3,"file":"TrackballControls.cjs","sources":["../../src/controls/TrackballControls.ts"],"sourcesContent":["import { MOUSE, Quaternion, Vector2, Vector3, PerspectiveCamera, OrthographicCamera } from 'three'\nimport { EventDispatcher } from './EventDispatcher'\nimport { StandardControlsEventMap } from './StandardControlsEventMap'\n\nclass TrackballControls extends EventDispatcher<StandardControlsEventMap> {\n public enabled = true\n\n public screen = { left: 0, top: 0, width: 0, height: 0 }\n\n public rotateSpeed = 1.0\n public zoomSpeed = 1.2\n public panSpeed = 0.3\n\n public noRotate = false\n public noZoom = false\n public noPan = false\n\n public staticMoving = false\n public dynamicDampingFactor = 0.2\n\n public minDistance = 0\n public maxDistance = Infinity\n\n public keys: [string, string, string] = ['KeyA' /*A*/, 'KeyS' /*S*/, 'KeyD' /*D*/]\n\n public mouseButtons = {\n LEFT: MOUSE.ROTATE,\n MIDDLE: MOUSE.DOLLY,\n RIGHT: MOUSE.PAN,\n }\n\n public object: PerspectiveCamera | OrthographicCamera\n public domElement: HTMLElement | undefined\n public cursorZoom: boolean = false\n\n readonly target = new Vector3()\n private mousePosition = new Vector2()\n\n // internals\n private STATE = {\n NONE: -1,\n ROTATE: 0,\n ZOOM: 1,\n PAN: 2,\n TOUCH_ROTATE: 3,\n TOUCH_ZOOM_PAN: 4,\n }\n\n private EPS = 0.000001\n private lastZoom = 1\n\n private lastPosition = new Vector3()\n private cursorVector = new Vector3()\n private targetVector = new Vector3()\n\n private _state = this.STATE.NONE\n private _keyState = this.STATE.NONE\n private _eye = new Vector3()\n private _movePrev = new Vector2()\n private _moveCurr = new Vector2()\n private _lastAxis = new Vector3()\n private _lastAngle = 0\n private _zoomStart = new Vector2()\n private _zoomEnd = new Vector2()\n private _touchZoomDistanceStart = 0\n private _touchZoomDistanceEnd = 0\n private _panStart = new Vector2()\n private _panEnd = new Vector2()\n\n private target0: Vector3\n private position0: Vector3\n private up0: Vector3\n private zoom0: number\n\n // events\n\n private changeEvent = { type: 'change' }\n private startEvent = { type: 'start' }\n private endEvent = { type: 'end' }\n\n constructor(object: PerspectiveCamera | OrthographicCamera, domElement?: HTMLElement) {\n super()\n this.object = object\n\n // for reset\n\n this.target0 = this.target.clone()\n this.position0 = this.object.position.clone()\n this.up0 = this.object.up.clone()\n this.zoom0 = this.object.zoom\n\n // connect events\n if (domElement !== undefined) this.connect(domElement)\n\n // force an update at start\n this.update()\n }\n\n private onScreenVector = new Vector2()\n\n private getMouseOnScreen = (pageX: number, pageY: number): Vector2 => {\n this.onScreenVector.set(\n (pageX - this.screen.left) / this.screen.width,\n (pageY - this.screen.top) / this.screen.height,\n )\n\n return this.onScreenVector\n }\n\n private onCircleVector = new Vector2()\n\n private getMouseOnCircle = (pageX: number, pageY: number): Vector2 => {\n this.onCircleVector.set(\n (pageX - this.screen.width * 0.5 - this.screen.left) / (this.screen.width * 0.5),\n (this.screen.height + 2 * (this.screen.top - pageY)) / this.screen.width, // screen.width intentional\n )\n\n return this.onCircleVector\n }\n\n private axis = new Vector3()\n private quaternion = new Quaternion()\n private eyeDirection = new Vector3()\n private objectUpDirection = new Vector3()\n private objectSidewaysDirection = new Vector3()\n private moveDirection = new Vector3()\n private angle: number = 0\n\n private rotateCamera = (): void => {\n this.moveDirection.set(this._moveCurr.x - this._movePrev.x, this._moveCurr.y - this._movePrev.y, 0)\n this.angle = this.moveDirection.length()\n\n if (this.angle) {\n this._eye.copy(this.object.position).sub(this.target)\n\n this.eyeDirection.copy(this._eye).normalize()\n this.objectUpDirection.copy(this.object.up).normalize()
|