Просмотр исходного кода

ArcballControls: Derive from `Controls`. (#29109)

Michael Herzog 1 год назад
Родитель
Сommit
c8f870791a

+ 7 - 25
docs/examples/en/controls/ArcballControls.html

@@ -7,7 +7,7 @@
 		<link type="text/css" rel="stylesheet" href="page.css" />
 	</head>
 	<body>
-		[page:EventDispatcher] &rarr;
+		[page:Controls] &rarr;
 
 		<h1>[name]</h1>
 
@@ -78,9 +78,9 @@
 		<p>
 			[page:Camera camera]: (required) The camera to be controlled. The camera must not be a child of another object, unless that object is the scene itself.<br><br>
 
-			[page:HTMLDOMElement domElement]: The HTML element used for event listeners.<br><br>
+			[page:HTMLDOMElement domElement]: The HTML element used for event listeners. (optional)<br><br>
 
-			[page:Scene scene]: The scene rendered by the camera. If not given, gizmos cannot be shown.
+			[page:Scene scene]: The scene rendered by the camera. If not given, gizmos cannot be shown. (optional)
 		</p>
 
 		<h2>Events</h2>
@@ -102,6 +102,8 @@
 
 		<h2>Properties</h2>
 
+		<p>See the base [page:Controls] class for common properties.</p>
+
 		<h3>[property:Boolean adjustNearFar]</h3>
 		<p>
 			If true, camera's near and far values will be adjusted every time zoom is performed trying to mantain the same visible portion
@@ -125,17 +127,6 @@
 			The damping inertia used if [page:.enableAnimations] is set to true.
 		</p>
 
-		<h3>[property:HTMLDOMElement domElement]</h3>
-		<p>
-			The HTMLDOMElement used to listen for mouse / touch events. This must be passed in the constructor; changing it here will
-			not set up new event listeners.
-		</p>
-
-		<h3>[property:Boolean enabled]</h3>
-		<p>
-			When set to `false`, the controls will not respond to user input. Default is `true`.
-		</p>
-
 		<h3>[property:Boolean enableAnimations]</h3>
 		<p>
 			Set to true to enable animations for rotation (damping) and focus operation. Default is true.
@@ -211,9 +202,10 @@
 			Maximum angular velocity allowed on rotation animation start.
 		</p>
 
-
 		<h2>Methods</h2>
 
+		<p>See the base [page:Controls] class for common methods.</p>
+
 		<h3>[method:undefined activateGizmos] ( [param:Boolean isActive] )</h3>
 		<p>
 			Make gizmos more or less visible.
@@ -224,11 +216,6 @@
 			Copy the current state to clipboard (as a readable JSON text).
 		</p>
 
-		<h3>[method:undefined dispose] ()</h3>
-		<p>
-			Remove all the event listeners, cancel any pending animation and clean the scene from gizmos and grid.
-		</p>
-
 		<h3>[method:undefined pasteState] ()</h3>
 		<p>
 			Set the controls state from the clipboard, assumes that the clipboard stores a JSON text as saved from [page:.copyState].
@@ -274,11 +261,6 @@
 			Keyboard modifiers can be specified as 'CTRL', 'SHIFT' or null if not needed.
 		</p>
 
-		<h3>[method:undefined update] ()</h3>
-		<p>
-			Update the controls. Must be called after any manual changes to the camera's transform.
-		</p>
-
 		<h3>[method:Raycaster getRaycaster] ()</h3>
 		<p>
 			Returns the [page:Raycaster] object that is used for user interaction. This object is shared between all instances of

+ 2 - 2
docs/examples/en/controls/Controls.html

@@ -20,10 +20,10 @@
 		<h3>[name]( [param:Object3D object], [param:HTMLDOMElement domElement] )</h3>
 		
 		<p>
-		[page:Object3D object]: The object the controls should manage (usually the camera).
+		[page:Object3D object] - The object the controls should manage (usually the camera).
 		</p>
 		<p>
-		[page:HTMLDOMElement domElement]: The HTML element used for event listeners (optional).
+		[page:HTMLDOMElement domElement]: The HTML element used for event listeners. (optional)
 		</p>
 		<p>
 			Creates a new instance of [name].

+ 1 - 1
docs/examples/en/controls/DragControls.html

@@ -60,7 +60,7 @@
 			[page:Camera camera]: The camera of the rendered scene.
 			</p>
 			<p>
-			[page:HTMLDOMElement domElement]: The HTML element used for event listeners.
+			[page:HTMLDOMElement domElement]: The HTML element used for event listeners. (optional)
 			</p>
 			<p>
 				Creates a new instance of [name].

+ 1 - 1
docs/examples/en/controls/FirstPersonControls.html

@@ -38,7 +38,7 @@
 				[page:Camera object]: The camera to be controlled.
 			</p>
 			<p>
-				[page:HTMLDOMElement domElement]: The HTML element used for event listeners.
+				[page:HTMLDOMElement domElement]: The HTML element used for event listeners. (optional)
 			</p>
 			<p>
 				Creates a new instance of [name].

+ 1 - 1
docs/examples/en/controls/FlyControls.html

@@ -39,7 +39,7 @@
 				[page:Camera object]: The camera to be controlled.
 			</p>
 			<p>
-				[page:HTMLDOMElement domElement]: The HTML element used for event listeners.
+				[page:HTMLDOMElement domElement]: The HTML element used for event listeners. (optional)
 			</p>
 			<p>
 				Creates a new instance of [name].

+ 174 - 158
examples/jsm/controls/ArcballControls.js

@@ -12,9 +12,9 @@ import {
 	Vector2,
 	Vector3,
 	Matrix4,
-	MathUtils,
-	EventDispatcher
+	MathUtils
 } from 'three';
+import { Controls } from './Controls.js';
 
 //trackball state
 const STATE = {
@@ -76,13 +76,12 @@ const _scalePointTemp = new Vector3();
  * @param {HTMLElement} domElement Renderer's dom element
  * @param {Scene} scene The scene to be rendered
  */
-class ArcballControls extends EventDispatcher {
+class ArcballControls extends Controls {
 
-	constructor( camera, domElement, scene = null ) {
+	constructor( camera, domElement = null, scene = null ) {
+
+		super( camera, domElement );
 
-		super();
-		this.camera = null;
-		this.domElement = domElement;
 		this.scene = scene;
 		this.target = new Vector3();
 		this._currentTarget = new Vector3();
@@ -201,7 +200,6 @@ class ArcballControls extends EventDispatcher {
 		this.maxFov = 90;
 		this.rotateSpeed = 1;
 
-		this.enabled = true;
 		this.enablePan = true;
 		this.enableRotate = true;
 		this.enableZoom = true;
@@ -226,11 +224,10 @@ class ArcballControls extends EventDispatcher {
 
 		}
 
-		this.domElement.style.touchAction = 'none';
-		this._devPxRatio = window.devicePixelRatio;
-
 		this.initializeMouseActions();
 
+		// event listeners
+
 		this._onContextMenu = onContextMenu.bind( this );
 		this._onWheel = onWheel.bind( this );
 		this._onPointerUp = onPointerUp.bind( this );
@@ -239,6 +236,19 @@ class ArcballControls extends EventDispatcher {
 		this._onPointerCancel = onPointerCancel.bind( this );
 		this._onWindowResize = onWindowResize.bind( this );
 
+		if ( domElement !== null ) {
+
+			this.connect();
+
+		}
+
+	}
+
+	connect() {
+
+		this.domElement.style.touchAction = 'none';
+		this._devPxRatio = window.devicePixelRatio;
+
 		this.domElement.addEventListener( 'contextmenu', this._onContextMenu );
 		this.domElement.addEventListener( 'wheel', this._onWheel );
 		this.domElement.addEventListener( 'pointerdown', this._onPointerDown );
@@ -248,6 +258,20 @@ class ArcballControls extends EventDispatcher {
 
 	}
 
+	disconnect() {
+
+		this.domElement.removeEventListener( 'pointerdown', this._onPointerDown );
+		this.domElement.removeEventListener( 'pointercancel', this._onPointerCancel );
+		this.domElement.removeEventListener( 'wheel', this._onWheel );
+		this.domElement.removeEventListener( 'contextmenu', this._onContextMenu );
+
+		window.removeEventListener( 'pointermove', this._onPointerMove );
+		window.removeEventListener( 'pointerup', this._onPointerUp );
+
+		window.removeEventListener( 'resize', this._onWindowResize );
+
+	}
+
 	onSinglePanStart( event, operation ) {
 
 		if ( this.enabled ) {
@@ -278,7 +302,7 @@ class ArcballControls extends EventDispatcher {
 					}
 
 					this.updateTbState( STATE.PAN, true );
-					this._startCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ) );
+					this._startCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ) );
 					if ( this.enableGrid ) {
 
 						this.drawGrid();
@@ -305,7 +329,7 @@ class ArcballControls extends EventDispatcher {
 					}
 
 					this.updateTbState( STATE.ROTATE, true );
-					this._startCursorPosition.copy( this.unprojectOnTbSurface( this.camera, _center.x, _center.y, this.domElement, this._tbRadius ) );
+					this._startCursorPosition.copy( this.unprojectOnTbSurface( this.object, _center.x, _center.y, this.domElement, this._tbRadius ) );
 					this.activateGizmos( true );
 					if ( this.enableAnimations ) {
 
@@ -323,7 +347,7 @@ class ArcballControls extends EventDispatcher {
 
 				case 'FOV':
 
-					if ( ! this.camera.isPerspectiveCamera || ! this.enableZoom ) {
+					if ( ! this.object.isPerspectiveCamera || ! this.enableZoom ) {
 
 						return;
 
@@ -396,7 +420,7 @@ class ArcballControls extends EventDispatcher {
 							this.dispatchEvent( _startEvent );
 
 							this.updateTbState( opState, true );
-							this._startCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ) );
+							this._startCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ) );
 							if ( this.enableGrid ) {
 
 								this.drawGrid();
@@ -408,7 +432,7 @@ class ArcballControls extends EventDispatcher {
 						} else {
 
 							//continue with pan operation
-							this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ) );
+							this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ) );
 							this.applyTransformMatrix( this.pan( this._startCursorPosition, this._currentCursorPosition ) );
 
 						}
@@ -429,7 +453,7 @@ class ArcballControls extends EventDispatcher {
 							this.dispatchEvent( _startEvent );
 
 							this.updateTbState( opState, true );
-							this._startCursorPosition.copy( this.unprojectOnTbSurface( this.camera, _center.x, _center.y, this.domElement, this._tbRadius ) );
+							this._startCursorPosition.copy( this.unprojectOnTbSurface( this.object, _center.x, _center.y, this.domElement, this._tbRadius ) );
 
 							if ( this.enableGrid ) {
 
@@ -442,7 +466,7 @@ class ArcballControls extends EventDispatcher {
 						} else {
 
 							//continue with rotate operation
-							this._currentCursorPosition.copy( this.unprojectOnTbSurface( this.camera, _center.x, _center.y, this.domElement, this._tbRadius ) );
+							this._currentCursorPosition.copy( this.unprojectOnTbSurface( this.object, _center.x, _center.y, this.domElement, this._tbRadius ) );
 
 							const distance = this._startCursorPosition.distanceTo( this._currentCursorPosition );
 							const angle = this._startCursorPosition.angleTo( this._currentCursorPosition );
@@ -524,7 +548,7 @@ class ArcballControls extends EventDispatcher {
 
 				case STATE.FOV:
 
-					if ( this.enableZoom && this.camera.isPerspectiveCamera ) {
+					if ( this.enableZoom && this.object.isPerspectiveCamera ) {
 
 						if ( restart ) {
 
@@ -588,7 +612,7 @@ class ArcballControls extends EventDispatcher {
 							this.applyTransformMatrix( this.scale( size, this._v3_2, false ) );
 
 							//adjusting distance
-							_offset.copy( this._gizmos.position ).sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
+							_offset.copy( this._gizmos.position ).sub( this.object.position ).normalize().multiplyScalar( newDistance / x );
 							this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
 
 						}
@@ -678,7 +702,7 @@ class ArcballControls extends EventDispatcher {
 			this.dispatchEvent( _startEvent );
 
 			this.setCenter( event.clientX, event.clientY );
-			const hitP = this.unprojectOnObj( this.getCursorNDC( _center.x, _center.y, this.domElement ), this.camera );
+			const hitP = this.unprojectOnObj( this.getCursorNDC( _center.x, _center.y, this.domElement ), this.object );
 
 			if ( hitP != null && this.enableAnimations ) {
 
@@ -721,7 +745,7 @@ class ArcballControls extends EventDispatcher {
 			this.updateTbState( STATE.PAN, true );
 
 			this.setCenter( ( this._touchCurrent[ 0 ].clientX + this._touchCurrent[ 1 ].clientX ) / 2, ( this._touchCurrent[ 0 ].clientY + this._touchCurrent[ 1 ].clientY ) / 2 );
-			this._startCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement, true ) );
+			this._startCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement, true ) );
 			this._currentCursorPosition.copy( this._startCursorPosition );
 
 			this.activateGizmos( false );
@@ -743,7 +767,7 @@ class ArcballControls extends EventDispatcher {
 
 			}
 
-			this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement, true ) );
+			this._currentCursorPosition.copy( this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement, true ) );
 			this.applyTransformMatrix( this.pan( this._startCursorPosition, this._currentCursorPosition, true ) );
 			this.dispatchEvent( _changeEvent );
 
@@ -771,7 +795,7 @@ class ArcballControls extends EventDispatcher {
 			this._startFingerRotation = this.getAngle( this._touchCurrent[ 1 ], this._touchCurrent[ 0 ] ) + this.getAngle( this._touchStart[ 1 ], this._touchStart[ 0 ] );
 			this._currentFingerRotation = this._startFingerRotation;
 
-			this.camera.getWorldDirection( this._rotationAxis ); //rotation axis
+			this.object.getWorldDirection( this._rotationAxis ); //rotation axis
 
 			if ( ! this.enablePan && ! this.enableZoom ) {
 
@@ -807,7 +831,7 @@ class ArcballControls extends EventDispatcher {
 			} else {
 
 				this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
-				rotationPoint = this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement ).applyQuaternion( this.camera.quaternion ).multiplyScalar( 1 / this.camera.zoom ).add( this._v3_2 );
+				rotationPoint = this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement ).applyQuaternion( this.object.quaternion ).multiplyScalar( 1 / this.object.zoom ).add( this._v3_2 );
 
 			}
 
@@ -869,17 +893,17 @@ class ArcballControls extends EventDispatcher {
 
 			} else {
 
-				if ( this.camera.isOrthographicCamera ) {
+				if ( this.object.isOrthographicCamera ) {
 
-					scalePoint = this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement )
-						.applyQuaternion( this.camera.quaternion )
-						.multiplyScalar( 1 / this.camera.zoom )
+					scalePoint = this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement )
+						.applyQuaternion( this.object.quaternion )
+						.multiplyScalar( 1 / this.object.zoom )
 						.add( this._gizmos.position );
 
-				} else if ( this.camera.isPerspectiveCamera ) {
+				} else if ( this.object.isPerspectiveCamera ) {
 
-					scalePoint = this.unprojectOnTbPlane( this.camera, _center.x, _center.y, this.domElement )
-						.applyQuaternion( this.camera.quaternion )
+					scalePoint = this.unprojectOnTbPlane( this.object, _center.x, _center.y, this.domElement )
+						.applyQuaternion( this.object.quaternion )
 						.add( this._gizmos.position );
 
 				}
@@ -997,7 +1021,7 @@ class ArcballControls extends EventDispatcher {
 			this.applyTransformMatrix( this.scale( size, this._v3_2, false ) );
 
 			//adjusting distance
-			_offset.copy( this._gizmos.position ).sub( this.camera.position ).normalize().multiplyScalar( newDistance / x );
+			_offset.copy( this._gizmos.position ).sub( this.object.position ).normalize().multiplyScalar( newDistance / x );
 			this._m4_1.makeTranslation( _offset.x, _offset.y, _offset.z );
 
 			this.dispatchEvent( _changeEvent );
@@ -1297,13 +1321,13 @@ class ArcballControls extends EventDispatcher {
 		if ( transformation.camera != null ) {
 
 			this._m4_1.copy( this._cameraMatrixState ).premultiply( transformation.camera );
-			this._m4_1.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
-			this.camera.updateMatrix();
+			this._m4_1.decompose( this.object.position, this.object.quaternion, this.object.scale );
+			this.object.updateMatrix();
 
 			//update camera up vector
 			if ( this._state == STATE.ROTATE || this._state == STATE.ZROTATE || this._state == STATE.ANIMATION_ROTATE ) {
 
-				this.camera.up.copy( this._upState ).applyQuaternion( this.camera.quaternion );
+				this.object.up.copy( this._upState ).applyQuaternion( this.object.quaternion );
 
 			}
 
@@ -1319,11 +1343,11 @@ class ArcballControls extends EventDispatcher {
 
 		if ( this._state == STATE.SCALE || this._state == STATE.FOCUS || this._state == STATE.ANIMATION_FOCUS ) {
 
-			this._tbRadius = this.calculateTbRadius( this.camera );
+			this._tbRadius = this.calculateTbRadius( this.object );
 
 			if ( this.adjustNearFar ) {
 
-				const cameraDistance = this.camera.position.distanceTo( this._gizmos.position );
+				const cameraDistance = this.object.position.distanceTo( this._gizmos.position );
 
 				const bb = new Box3();
 				bb.setFromObject( this._gizmos );
@@ -1334,38 +1358,38 @@ class ArcballControls extends EventDispatcher {
 				const regularNearPosition = cameraDistance - this._initialNear;
 
 				const minNearPos = Math.min( adjustedNearPosition, regularNearPosition );
-				this.camera.near = cameraDistance - minNearPos;
+				this.object.near = cameraDistance - minNearPos;
 
 
 				const adjustedFarPosition = Math.min( this._farPos0, - sphere.radius + sphere.center.length() );
 				const regularFarPosition = cameraDistance - this._initialFar;
 
 				const minFarPos = Math.min( adjustedFarPosition, regularFarPosition );
-				this.camera.far = cameraDistance - minFarPos;
+				this.object.far = cameraDistance - minFarPos;
 
-				this.camera.updateProjectionMatrix();
+				this.object.updateProjectionMatrix();
 
 			} else {
 
 				let update = false;
 
-				if ( this.camera.near != this._initialNear ) {
+				if ( this.object.near != this._initialNear ) {
 
-					this.camera.near = this._initialNear;
+					this.object.near = this._initialNear;
 					update = true;
 
 				}
 
-				if ( this.camera.far != this._initialFar ) {
+				if ( this.object.far != this._initialFar ) {
 
-					this.camera.far = this._initialFar;
+					this.object.far = this._initialFar;
 					update = true;
 
 				}
 
 				if ( update ) {
 
-					this.camera.updateProjectionMatrix();
+					this.object.updateProjectionMatrix();
 
 				}
 
@@ -1465,7 +1489,7 @@ class ArcballControls extends EventDispatcher {
 
 		_cameraMatrixStateTemp.copy( this._cameraMatrixState );
 		this._cameraMatrixState.premultiply( this._translationMatrix );
-		this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
+		this._cameraMatrixState.decompose( this.object.position, this.object.quaternion, this.object.scale );
 
 		//apply zoom
 		if ( this.enableZoom ) {
@@ -1490,22 +1514,22 @@ class ArcballControls extends EventDispatcher {
 			const multiplier = 3;
 			let size, divisions, maxLength, tick;
 
-			if ( this.camera.isOrthographicCamera ) {
+			if ( this.object.isOrthographicCamera ) {
 
-				const width = this.camera.right - this.camera.left;
-				const height = this.camera.bottom - this.camera.top;
+				const width = this.object.right - this.object.left;
+				const height = this.object.bottom - this.object.top;
 
 				maxLength = Math.max( width, height );
 				tick = maxLength / 20;
 
-				size = maxLength / this.camera.zoom * multiplier;
-				divisions = size / tick * this.camera.zoom;
+				size = maxLength / this.object.zoom * multiplier;
+				divisions = size / tick * this.object.zoom;
 
-			} else if ( this.camera.isPerspectiveCamera ) {
+			} else if ( this.object.isPerspectiveCamera ) {
 
-				const distance = this.camera.position.distanceTo( this._gizmos.position );
-				const halfFovV = MathUtils.DEG2RAD * this.camera.fov * 0.5;
-				const halfFovH = Math.atan( ( this.camera.aspect ) * Math.tan( halfFovV ) );
+				const distance = this.object.position.distanceTo( this._gizmos.position );
+				const halfFovV = MathUtils.DEG2RAD * this.object.fov * 0.5;
+				const halfFovH = Math.atan( ( this.object.aspect ) * Math.tan( halfFovV ) );
 
 				maxLength = Math.tan( Math.max( halfFovV, halfFovH ) ) * distance * 2;
 				tick = maxLength / 20;
@@ -1520,7 +1544,7 @@ class ArcballControls extends EventDispatcher {
 				this._grid = new GridHelper( size, divisions, color, color );
 				this._grid.position.copy( this._gizmos.position );
 				this._gridPosition.copy( this._grid.position );
-				this._grid.quaternion.copy( this.camera.quaternion );
+				this._grid.quaternion.copy( this.object.quaternion );
 				this._grid.rotateX( Math.PI * 0.5 );
 
 				this.scene.add( this._grid );
@@ -1542,15 +1566,7 @@ class ArcballControls extends EventDispatcher {
 
 		}
 
-		this.domElement.removeEventListener( 'pointerdown', this._onPointerDown );
-		this.domElement.removeEventListener( 'pointercancel', this._onPointerCancel );
-		this.domElement.removeEventListener( 'wheel', this._onWheel );
-		this.domElement.removeEventListener( 'contextmenu', this._onContextMenu );
-
-		window.removeEventListener( 'pointermove', this._onPointerMove );
-		window.removeEventListener( 'pointerup', this._onPointerUp );
-
-		window.removeEventListener( 'resize', this._onWindowResize );
+		this.disconnect();
 
 		if ( this.scene !== null ) this.scene.remove( this._gizmos );
 		this.disposeGrid();
@@ -1634,8 +1650,8 @@ class ArcballControls extends EventDispatcher {
 	getCursorPosition( cursorX, cursorY, canvas ) {
 
 		this._v2_1.copy( this.getCursorNDC( cursorX, cursorY, canvas ) );
-		this._v2_1.x *= ( this.camera.right - this.camera.left ) * 0.5;
-		this._v2_1.y *= ( this.camera.top - this.camera.bottom ) * 0.5;
+		this._v2_1.x *= ( this.object.right - this.object.left ) * 0.5;
+		this._v2_1.y *= ( this.object.top - this.object.bottom ) * 0.5;
 		return this._v2_1.clone();
 
 	}
@@ -1674,8 +1690,8 @@ class ArcballControls extends EventDispatcher {
 		this._up0.copy( camera.up );
 		this._upState.copy( camera.up );
 
-		this.camera = camera;
-		this.camera.updateProjectionMatrix();
+		this.object = camera;
+		this.object.updateProjectionMatrix();
 
 		//making gizmos
 		this._tbRadius = this.calculateTbRadius( camera );
@@ -1701,7 +1717,7 @@ class ArcballControls extends EventDispatcher {
 	setTbRadius( value ) {
 
 		this.radiusFactor = value;
-		this._tbRadius = this.calculateTbRadius( this.camera );
+		this._tbRadius = this.calculateTbRadius( this.object );
 
 		const curve = new EllipseCurve( 0, 0, this._tbRadius, this._tbRadius );
 		const points = curve.getPoints( this._curvePts );
@@ -1750,10 +1766,10 @@ class ArcballControls extends EventDispatcher {
 		this._gizmoMatrixState0.identity().setPosition( tbCenter );
 		this._gizmoMatrixState.copy( this._gizmoMatrixState0 );
 
-		if ( this.camera.zoom !== 1 ) {
+		if ( this.object.zoom !== 1 ) {
 
 			//adapt gizmos size to camera zoom
-			const size = 1 / this.camera.zoom;
+			const size = 1 / this.object.zoom;
 			this._scaleMatrix.makeScale( size, size, size );
 			this._translationMatrix.makeTranslation( - tbCenter.x, - tbCenter.y, - tbCenter.z );
 
@@ -1931,22 +1947,22 @@ class ArcballControls extends EventDispatcher {
 
 		const movement = p0.clone().sub( p1 );
 
-		if ( this.camera.isOrthographicCamera ) {
+		if ( this.object.isOrthographicCamera ) {
 
 			//adjust movement amount
-			movement.multiplyScalar( 1 / this.camera.zoom );
+			movement.multiplyScalar( 1 / this.object.zoom );
 
-		} else if ( this.camera.isPerspectiveCamera && adjust ) {
+		} else if ( this.object.isPerspectiveCamera && adjust ) {
 
 			//adjust movement amount
 			this._v3_1.setFromMatrixPosition( this._cameraMatrixState0 );	//camera's initial position
 			this._v3_2.setFromMatrixPosition( this._gizmoMatrixState0 );	//gizmo's initial position
-			const distanceFactor = this._v3_1.distanceTo( this._v3_2 ) / this.camera.position.distanceTo( this._gizmos.position );
+			const distanceFactor = this._v3_1.distanceTo( this._v3_2 ) / this.object.position.distanceTo( this._gizmos.position );
 			movement.multiplyScalar( 1 / distanceFactor );
 
 		}
 
-		this._v3_1.set( movement.x, movement.y, 0 ).applyQuaternion( this.camera.quaternion );
+		this._v3_1.set( movement.x, movement.y, 0 ).applyQuaternion( this.object.quaternion );
 
 		this._m4_1.makeTranslation( this._v3_1.x, this._v3_1.y, this._v3_1.z );
 
@@ -1960,31 +1976,31 @@ class ArcballControls extends EventDispatcher {
 	 */
 	reset() {
 
-		this.camera.zoom = this._zoom0;
+		this.object.zoom = this._zoom0;
 
-		if ( this.camera.isPerspectiveCamera ) {
+		if ( this.object.isPerspectiveCamera ) {
 
-			this.camera.fov = this._fov0;
+			this.object.fov = this._fov0;
 
 		}
 
-		this.camera.near = this._nearPos;
-		this.camera.far = this._farPos;
+		this.object.near = this._nearPos;
+		this.object.far = this._farPos;
 		this._cameraMatrixState.copy( this._cameraMatrixState0 );
-		this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
-		this.camera.up.copy( this._up0 );
+		this._cameraMatrixState.decompose( this.object.position, this.object.quaternion, this.object.scale );
+		this.object.up.copy( this._up0 );
 
-		this.camera.updateMatrix();
-		this.camera.updateProjectionMatrix();
+		this.object.updateMatrix();
+		this.object.updateProjectionMatrix();
 
 		this._gizmoMatrixState.copy( this._gizmoMatrixState0 );
 		this._gizmoMatrixState0.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
 		this._gizmos.updateMatrix();
 
-		this._tbRadius = this.calculateTbRadius( this.camera );
+		this._tbRadius = this.calculateTbRadius( this.object );
 		this.makeGizmos( this._gizmos.position, this._tbRadius );
 
-		this.camera.lookAt( this._gizmos.position );
+		this.object.lookAt( this._gizmos.position );
 
 		this.updateTbState( STATE.IDLE, false );
 
@@ -2018,28 +2034,28 @@ class ArcballControls extends EventDispatcher {
 	copyState() {
 
 		let state;
-		if ( this.camera.isOrthographicCamera ) {
+		if ( this.object.isOrthographicCamera ) {
 
 			state = JSON.stringify( { arcballState: {
 
-				cameraFar: this.camera.far,
-				cameraMatrix: this.camera.matrix,
-				cameraNear: this.camera.near,
-				cameraUp: this.camera.up,
-				cameraZoom: this.camera.zoom,
+				cameraFar: this.object.far,
+				cameraMatrix: this.object.matrix,
+				cameraNear: this.object.near,
+				cameraUp: this.object.up,
+				cameraZoom: this.object.zoom,
 				gizmoMatrix: this._gizmos.matrix
 
 			} } );
 
-		} else if ( this.camera.isPerspectiveCamera ) {
+		} else if ( this.object.isPerspectiveCamera ) {
 
 			state = JSON.stringify( { arcballState: {
-				cameraFar: this.camera.far,
-				cameraFov: this.camera.fov,
-				cameraMatrix: this.camera.matrix,
-				cameraNear: this.camera.near,
-				cameraUp: this.camera.up,
-				cameraZoom: this.camera.zoom,
+				cameraFar: this.object.far,
+				cameraFov: this.object.fov,
+				cameraMatrix: this.object.matrix,
+				cameraNear: this.object.near,
+				cameraUp: this.object.up,
+				cameraZoom: this.object.zoom,
 				gizmoMatrix: this._gizmos.matrix
 
 			} } );
@@ -2066,16 +2082,16 @@ class ArcballControls extends EventDispatcher {
 	 */
 	saveState() {
 
-		this._cameraMatrixState0.copy( this.camera.matrix );
+		this._cameraMatrixState0.copy( this.object.matrix );
 		this._gizmoMatrixState0.copy( this._gizmos.matrix );
-		this._nearPos = this.camera.near;
-		this._farPos = this.camera.far;
-		this._zoom0 = this.camera.zoom;
-		this._up0.copy( this.camera.up );
+		this._nearPos = this.object.near;
+		this._farPos = this.object.far;
+		this._zoom0 = this.object.zoom;
+		this._up0.copy( this.object.up );
 
-		if ( this.camera.isPerspectiveCamera ) {
+		if ( this.object.isPerspectiveCamera ) {
 
-			this._fov0 = this.camera.fov;
+			this._fov0 = this.object.fov;
 
 		}
 
@@ -2093,26 +2109,26 @@ class ArcballControls extends EventDispatcher {
 		_scalePointTemp.copy( point );
 		let sizeInverse = 1 / size;
 
-		if ( this.camera.isOrthographicCamera ) {
+		if ( this.object.isOrthographicCamera ) {
 
 			//camera zoom
-			this.camera.zoom = this._zoomState;
-			this.camera.zoom *= size;
+			this.object.zoom = this._zoomState;
+			this.object.zoom *= size;
 
 			//check min and max zoom
-			if ( this.camera.zoom > this.maxZoom ) {
+			if ( this.object.zoom > this.maxZoom ) {
 
-				this.camera.zoom = this.maxZoom;
+				this.object.zoom = this.maxZoom;
 				sizeInverse = this._zoomState / this.maxZoom;
 
-			} else if ( this.camera.zoom < this.minZoom ) {
+			} else if ( this.object.zoom < this.minZoom ) {
 
-				this.camera.zoom = this.minZoom;
+				this.object.zoom = this.minZoom;
 				sizeInverse = this._zoomState / this.minZoom;
 
 			}
 
-			this.camera.updateProjectionMatrix();
+			this.object.updateProjectionMatrix();
 
 			this._v3_1.setFromMatrixPosition( this._gizmoMatrixState );	//gizmos position
 
@@ -2136,7 +2152,7 @@ class ArcballControls extends EventDispatcher {
 			this.setTransformationMatrices( this._m4_1, this._m4_2 );
 			return _transformation;
 
-		} else if ( this.camera.isPerspectiveCamera ) {
+		} else if ( this.object.isPerspectiveCamera ) {
 
 			this._v3_1.setFromMatrixPosition( this._cameraMatrixState );
 			this._v3_2.setFromMatrixPosition( this._gizmoMatrixState );
@@ -2203,10 +2219,10 @@ class ArcballControls extends EventDispatcher {
 	 */
 	setFov( value ) {
 
-		if ( this.camera.isPerspectiveCamera ) {
+		if ( this.object.isPerspectiveCamera ) {
 
-			this.camera.fov = MathUtils.clamp( value, this.minFov, this.maxFov );
-			this.camera.updateProjectionMatrix();
+			this.object.fov = MathUtils.clamp( value, this.minFov, this.maxFov );
+			this.object.updateProjectionMatrix();
 
 		}
 
@@ -2536,18 +2552,18 @@ class ArcballControls extends EventDispatcher {
 	updateMatrixState() {
 
 		//update camera and gizmos state
-		this._cameraMatrixState.copy( this.camera.matrix );
+		this._cameraMatrixState.copy( this.object.matrix );
 		this._gizmoMatrixState.copy( this._gizmos.matrix );
 
-		if ( this.camera.isOrthographicCamera ) {
+		if ( this.object.isOrthographicCamera ) {
 
-			this._cameraProjectionState.copy( this.camera.projectionMatrix );
-			this.camera.updateProjectionMatrix();
-			this._zoomState = this.camera.zoom;
+			this._cameraProjectionState.copy( this.object.projectionMatrix );
+			this.object.updateProjectionMatrix();
+			this._zoomState = this.object.zoom;
 
-		} else if ( this.camera.isPerspectiveCamera ) {
+		} else if ( this.object.isPerspectiveCamera ) {
 
-			this._fovState = this.camera.fov;
+			this._fovState = this.object.fov;
 
 		}
 
@@ -2576,27 +2592,27 @@ class ArcballControls extends EventDispatcher {
 		if ( this.target.equals( this._currentTarget ) === false ) {
 
 			this._gizmos.position.copy( this.target );	//for correct radius calculation
-			this._tbRadius = this.calculateTbRadius( this.camera );
+			this._tbRadius = this.calculateTbRadius( this.object );
 			this.makeGizmos( this.target, this._tbRadius );
 			this._currentTarget.copy( this.target );
 
 		}
 
 		//check min/max parameters
-		if ( this.camera.isOrthographicCamera ) {
+		if ( this.object.isOrthographicCamera ) {
 
 			//check zoom
-			if ( this.camera.zoom > this.maxZoom || this.camera.zoom < this.minZoom ) {
+			if ( this.object.zoom > this.maxZoom || this.object.zoom < this.minZoom ) {
 
-				const newZoom = MathUtils.clamp( this.camera.zoom, this.minZoom, this.maxZoom );
-				this.applyTransformMatrix( this.scale( newZoom / this.camera.zoom, this._gizmos.position, true ) );
+				const newZoom = MathUtils.clamp( this.object.zoom, this.minZoom, this.maxZoom );
+				this.applyTransformMatrix( this.scale( newZoom / this.object.zoom, this._gizmos.position, true ) );
 
 			}
 
-		} else if ( this.camera.isPerspectiveCamera ) {
+		} else if ( this.object.isPerspectiveCamera ) {
 
 			//check distance
-			const distance = this.camera.position.distanceTo( this._gizmos.position );
+			const distance = this.object.position.distanceTo( this._gizmos.position );
 
 			if ( distance > this.maxDistance + EPS || distance < this.minDistance - EPS ) {
 
@@ -2607,15 +2623,15 @@ class ArcballControls extends EventDispatcher {
 			 }
 
 			//check fov
-			if ( this.camera.fov < this.minFov || this.camera.fov > this.maxFov ) {
+			if ( this.object.fov < this.minFov || this.object.fov > this.maxFov ) {
 
-				this.camera.fov = MathUtils.clamp( this.camera.fov, this.minFov, this.maxFov );
-				this.camera.updateProjectionMatrix();
+				this.object.fov = MathUtils.clamp( this.object.fov, this.minFov, this.maxFov );
+				this.object.updateProjectionMatrix();
 
 			}
 
 			const oldRadius = this._tbRadius;
-			this._tbRadius = this.calculateTbRadius( this.camera );
+			this._tbRadius = this.calculateTbRadius( this.object );
 
 			if ( oldRadius < this._tbRadius - EPS || oldRadius > this._tbRadius + EPS ) {
 
@@ -2635,7 +2651,7 @@ class ArcballControls extends EventDispatcher {
 
 		}
 
-		this.camera.lookAt( this._gizmos.position );
+		this.object.lookAt( this._gizmos.position );
 
 	}
 
@@ -2646,34 +2662,34 @@ class ArcballControls extends EventDispatcher {
 		if ( state.arcballState != undefined ) {
 
 			this._cameraMatrixState.fromArray( state.arcballState.cameraMatrix.elements );
-			this._cameraMatrixState.decompose( this.camera.position, this.camera.quaternion, this.camera.scale );
+			this._cameraMatrixState.decompose( this.object.position, this.object.quaternion, this.object.scale );
 
-			this.camera.up.copy( state.arcballState.cameraUp );
-			this.camera.near = state.arcballState.cameraNear;
-			this.camera.far = state.arcballState.cameraFar;
+			this.object.up.copy( state.arcballState.cameraUp );
+			this.object.near = state.arcballState.cameraNear;
+			this.object.far = state.arcballState.cameraFar;
 
-			this.camera.zoom = state.arcballState.cameraZoom;
+			this.object.zoom = state.arcballState.cameraZoom;
 
-			if ( this.camera.isPerspectiveCamera ) {
+			if ( this.object.isPerspectiveCamera ) {
 
-				this.camera.fov = state.arcballState.cameraFov;
+				this.object.fov = state.arcballState.cameraFov;
 
 			}
 
 			this._gizmoMatrixState.fromArray( state.arcballState.gizmoMatrix.elements );
 			this._gizmoMatrixState.decompose( this._gizmos.position, this._gizmos.quaternion, this._gizmos.scale );
 
-			this.camera.updateMatrix();
-			this.camera.updateProjectionMatrix();
+			this.object.updateMatrix();
+			this.object.updateProjectionMatrix();
 
 			this._gizmos.updateMatrix();
 
-			this._tbRadius = this.calculateTbRadius( this.camera );
+			this._tbRadius = this.calculateTbRadius( this.object );
 			const gizmoTmp = new Matrix4().copy( this._gizmoMatrixState0 );
 			this.makeGizmos( this._gizmos.position, this._tbRadius );
 			this._gizmoMatrixState0.copy( gizmoTmp );
 
-			this.camera.lookAt( this._gizmos.position );
+			this.object.lookAt( this._gizmos.position );
 			this.updateTbState( STATE.IDLE, false );
 
 			this.dispatchEvent( _changeEvent );
@@ -2689,7 +2705,7 @@ class ArcballControls extends EventDispatcher {
 function onWindowResize() {
 
 	const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
-	this._tbRadius = this.calculateTbRadius( this.camera );
+	this._tbRadius = this.calculateTbRadius( this.object );
 
 	const newRadius = this._tbRadius / scale;
 	const curve = new EllipseCurve( 0, 0, newRadius, newRadius );
@@ -3098,13 +3114,13 @@ function onWheel( event ) {
 
 						let scalePoint;
 
-						if ( this.camera.isOrthographicCamera ) {
+						if ( this.object.isOrthographicCamera ) {
 
-							scalePoint = this.unprojectOnTbPlane( this.camera, event.clientX, event.clientY, this.domElement ).applyQuaternion( this.camera.quaternion ).multiplyScalar( 1 / this.camera.zoom ).add( this._gizmos.position );
+							scalePoint = this.unprojectOnTbPlane( this.object, event.clientX, event.clientY, this.domElement ).applyQuaternion( this.object.quaternion ).multiplyScalar( 1 / this.object.zoom ).add( this._gizmos.position );
 
-						} else if ( this.camera.isPerspectiveCamera ) {
+						} else if ( this.object.isPerspectiveCamera ) {
 
-							scalePoint = this.unprojectOnTbPlane( this.camera, event.clientX, event.clientY, this.domElement ).applyQuaternion( this.camera.quaternion ).add( this._gizmos.position );
+							scalePoint = this.unprojectOnTbPlane( this.object, event.clientX, event.clientY, this.domElement ).applyQuaternion( this.object.quaternion ).add( this._gizmos.position );
 
 						}
 
@@ -3132,7 +3148,7 @@ function onWheel( event ) {
 
 				case 'FOV':
 
-					if ( this.camera.isPerspectiveCamera ) {
+					if ( this.object.isPerspectiveCamera ) {
 
 						this.updateTbState( STATE.FOV, true );
 
@@ -3175,7 +3191,7 @@ function onWheel( event ) {
 						//check min and max distance
 						xNew = MathUtils.clamp( xNew, this.minDistance, this.maxDistance );
 
-						const y = x * Math.tan( MathUtils.DEG2RAD * this.camera.fov * 0.5 );
+						const y = x * Math.tan( MathUtils.DEG2RAD * this.object.fov * 0.5 );
 
 						//calculate new fov
 						let newFov = MathUtils.RAD2DEG * ( Math.atan( y / xNew ) * 2 );

+ 1 - 1
examples/jsm/controls/Controls.js

@@ -25,7 +25,7 @@ class Controls extends EventDispatcher {
 
 	dispose() {}
 
-	update() {}
+	update( /* delta */ ) {}
 
 }
 

粤ICP备19079148号