|
@@ -17,6 +17,9 @@ class FlyControls extends EventDispatcher {
|
|
|
|
|
|
// API
|
|
// API
|
|
|
|
|
|
|
|
+ // Set to false to disable this control
|
|
|
|
+ this.enabled = true;
|
|
|
|
+
|
|
this.movementSpeed = 1.0;
|
|
this.movementSpeed = 1.0;
|
|
this.rollSpeed = 0.005;
|
|
this.rollSpeed = 0.005;
|
|
|
|
|
|
@@ -44,7 +47,7 @@ class FlyControls extends EventDispatcher {
|
|
|
|
|
|
this.keydown = function ( event ) {
|
|
this.keydown = function ( event ) {
|
|
|
|
|
|
- if ( event.altKey ) {
|
|
|
|
|
|
+ if ( event.altKey || this.enabled === false ) {
|
|
|
|
|
|
return;
|
|
return;
|
|
|
|
|
|
@@ -82,6 +85,8 @@ class FlyControls extends EventDispatcher {
|
|
|
|
|
|
this.keyup = function ( event ) {
|
|
this.keyup = function ( event ) {
|
|
|
|
|
|
|
|
+ if ( this.enabled === false ) return;
|
|
|
|
+
|
|
switch ( event.code ) {
|
|
switch ( event.code ) {
|
|
|
|
|
|
case 'ShiftLeft':
|
|
case 'ShiftLeft':
|
|
@@ -114,6 +119,8 @@ class FlyControls extends EventDispatcher {
|
|
|
|
|
|
this.pointerdown = function ( event ) {
|
|
this.pointerdown = function ( event ) {
|
|
|
|
|
|
|
|
+ if ( this.enabled === false ) return;
|
|
|
|
+
|
|
if ( this.dragToLook ) {
|
|
if ( this.dragToLook ) {
|
|
|
|
|
|
this.status ++;
|
|
this.status ++;
|
|
@@ -135,6 +142,8 @@ class FlyControls extends EventDispatcher {
|
|
|
|
|
|
this.pointermove = function ( event ) {
|
|
this.pointermove = function ( event ) {
|
|
|
|
|
|
|
|
+ if ( this.enabled === false ) return;
|
|
|
|
+
|
|
if ( ! this.dragToLook || this.status > 0 ) {
|
|
if ( ! this.dragToLook || this.status > 0 ) {
|
|
|
|
|
|
const container = this.getContainerDimensions();
|
|
const container = this.getContainerDimensions();
|
|
@@ -152,6 +161,8 @@ class FlyControls extends EventDispatcher {
|
|
|
|
|
|
this.pointerup = function ( event ) {
|
|
this.pointerup = function ( event ) {
|
|
|
|
|
|
|
|
+ if ( this.enabled === false ) return;
|
|
|
|
+
|
|
if ( this.dragToLook ) {
|
|
if ( this.dragToLook ) {
|
|
|
|
|
|
this.status --;
|
|
this.status --;
|
|
@@ -175,8 +186,18 @@ class FlyControls extends EventDispatcher {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ this.contextMenu = function ( event ) {
|
|
|
|
+
|
|
|
|
+ if ( this.enabled === false ) return;
|
|
|
|
+
|
|
|
|
+ event.preventDefault();
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
+
|
|
this.update = function ( delta ) {
|
|
this.update = function ( delta ) {
|
|
|
|
|
|
|
|
+ if ( this.enabled === false ) return;
|
|
|
|
+
|
|
const moveMult = delta * scope.movementSpeed;
|
|
const moveMult = delta * scope.movementSpeed;
|
|
const rotMult = delta * scope.rollSpeed;
|
|
const rotMult = delta * scope.rollSpeed;
|
|
|
|
|
|
@@ -244,7 +265,7 @@ class FlyControls extends EventDispatcher {
|
|
|
|
|
|
this.dispose = function () {
|
|
this.dispose = function () {
|
|
|
|
|
|
- this.domElement.removeEventListener( 'contextmenu', contextmenu );
|
|
|
|
|
|
+ this.domElement.removeEventListener( 'contextmenu', _contextmenu );
|
|
this.domElement.removeEventListener( 'pointerdown', _pointerdown );
|
|
this.domElement.removeEventListener( 'pointerdown', _pointerdown );
|
|
this.domElement.removeEventListener( 'pointermove', _pointermove );
|
|
this.domElement.removeEventListener( 'pointermove', _pointermove );
|
|
this.domElement.removeEventListener( 'pointerup', _pointerup );
|
|
this.domElement.removeEventListener( 'pointerup', _pointerup );
|
|
@@ -254,13 +275,14 @@ class FlyControls extends EventDispatcher {
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const _contextmenu = this.contextMenu.bind( this );
|
|
const _pointermove = this.pointermove.bind( this );
|
|
const _pointermove = this.pointermove.bind( this );
|
|
const _pointerdown = this.pointerdown.bind( this );
|
|
const _pointerdown = this.pointerdown.bind( this );
|
|
const _pointerup = this.pointerup.bind( this );
|
|
const _pointerup = this.pointerup.bind( this );
|
|
const _keydown = this.keydown.bind( this );
|
|
const _keydown = this.keydown.bind( this );
|
|
const _keyup = this.keyup.bind( this );
|
|
const _keyup = this.keyup.bind( this );
|
|
|
|
|
|
- this.domElement.addEventListener( 'contextmenu', contextmenu );
|
|
|
|
|
|
+ this.domElement.addEventListener( 'contextmenu', _contextmenu );
|
|
this.domElement.addEventListener( 'pointerdown', _pointerdown );
|
|
this.domElement.addEventListener( 'pointerdown', _pointerdown );
|
|
this.domElement.addEventListener( 'pointermove', _pointermove );
|
|
this.domElement.addEventListener( 'pointermove', _pointermove );
|
|
this.domElement.addEventListener( 'pointerup', _pointerup );
|
|
this.domElement.addEventListener( 'pointerup', _pointerup );
|
|
@@ -275,10 +297,4 @@ class FlyControls extends EventDispatcher {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-function contextmenu( event ) {
|
|
|
|
-
|
|
|
|
- event.preventDefault();
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
export { FlyControls };
|
|
export { FlyControls };
|