Skip to content

Commit 6f5d901

Browse files
i3eneMugen87
andauthored
OrbitControl: Fixed rotation toggle in KeyDown handler (#29834)
* Fixed rotation toggle in KeyDown handler Implemented the toggle via `enableRotate` also on `_handleKeyDown`. The previous behaviour seemed unexpected, allowing rotation via keys, even when rotating should be disabled if `enableRotate` was set to `false`. * Update OrbitControls.js Refactor `enablePan` in `_handleKeyDown()`. * Update OrbitControls.js Correctly set `needsUpdate` in `_handleKeyDown()`. * Update OrbitControls.js Revert `needsUpdate` change. --------- Co-authored-by: Michael Herzog <[email protected]>
1 parent beab9e8 commit 6f5d901

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

examples/jsm/controls/OrbitControls.js

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -784,11 +784,19 @@ class OrbitControls extends Controls {
784784

785785
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
786786

787-
this._rotateUp( _twoPI * this.rotateSpeed / this.domElement.clientHeight );
787+
if ( this.enableRotate ) {
788+
789+
this._rotateUp( _twoPI * this.rotateSpeed / this.domElement.clientHeight );
790+
791+
}
788792

789793
} else {
790794

791-
this._pan( 0, this.keyPanSpeed );
795+
if ( this.enablePan ) {
796+
797+
this._pan( 0, this.keyPanSpeed );
798+
799+
}
792800

793801
}
794802

@@ -799,11 +807,19 @@ class OrbitControls extends Controls {
799807

800808
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
801809

802-
this._rotateUp( - _twoPI * this.rotateSpeed / this.domElement.clientHeight );
810+
if ( this.enableRotate ) {
811+
812+
this._rotateUp( - _twoPI * this.rotateSpeed / this.domElement.clientHeight );
813+
814+
}
803815

804816
} else {
805817

806-
this._pan( 0, - this.keyPanSpeed );
818+
if ( this.enablePan ) {
819+
820+
this._pan( 0, - this.keyPanSpeed );
821+
822+
}
807823

808824
}
809825

@@ -814,11 +830,19 @@ class OrbitControls extends Controls {
814830

815831
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
816832

817-
this._rotateLeft( _twoPI * this.rotateSpeed / this.domElement.clientHeight );
833+
if ( this.enableRotate ) {
834+
835+
this._rotateLeft( _twoPI * this.rotateSpeed / this.domElement.clientHeight );
836+
837+
}
818838

819839
} else {
820840

821-
this._pan( this.keyPanSpeed, 0 );
841+
if ( this.enablePan ) {
842+
843+
this._pan( this.keyPanSpeed, 0 );
844+
845+
}
822846

823847
}
824848

@@ -829,11 +853,19 @@ class OrbitControls extends Controls {
829853

830854
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
831855

832-
this._rotateLeft( - _twoPI * this.rotateSpeed / this.domElement.clientHeight );
856+
if ( this.enableRotate ) {
857+
858+
this._rotateLeft( - _twoPI * this.rotateSpeed / this.domElement.clientHeight );
859+
860+
}
833861

834862
} else {
835863

836-
this._pan( - this.keyPanSpeed, 0 );
864+
if ( this.enablePan ) {
865+
866+
this._pan( - this.keyPanSpeed, 0 );
867+
868+
}
837869

838870
}
839871

@@ -1340,7 +1372,7 @@ function onMouseWheel( event ) {
13401372

13411373
function onKeyDown( event ) {
13421374

1343-
if ( this.enabled === false || this.enablePan === false ) return;
1375+
if ( this.enabled === false ) return;
13441376

13451377
this._handleKeyDown( event );
13461378

0 commit comments

Comments
 (0)