Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrbitControls: Implement Pointer Events. #20161

Merged
merged 1 commit into from
Aug 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 62 additions & 12 deletions examples/js/controls/OrbitControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,16 @@ THREE.OrbitControls = function ( object, domElement ) {
this.dispose = function () {

scope.domElement.removeEventListener( 'contextmenu', onContextMenu, false );
scope.domElement.removeEventListener( 'mousedown', onMouseDown, false );

scope.domElement.removeEventListener( 'pointerdown', onPointerDown, false );
scope.domElement.removeEventListener( 'wheel', onMouseWheel, false );

scope.domElement.removeEventListener( 'touchstart', onTouchStart, false );
scope.domElement.removeEventListener( 'touchend', onTouchEnd, false );
scope.domElement.removeEventListener( 'touchmove', onTouchMove, false );

scope.domElement.ownerDocument.removeEventListener( 'mousemove', onMouseMove, false );
scope.domElement.ownerDocument.removeEventListener( 'mouseup', onMouseUp, false );
scope.domElement.ownerDocument.removeEventListener( 'pointermove', onPointerMove, false );
scope.domElement.ownerDocument.removeEventListener( 'pointerup', onPointerUp, false );

scope.domElement.removeEventListener( 'keydown', onKeyDown, false );

Expand Down Expand Up @@ -765,10 +766,58 @@ THREE.OrbitControls = function ( object, domElement ) {
// event handlers - FSM: listen for events and reset state
//

function onMouseDown( event ) {
function onPointerDown( event ) {

if ( scope.enabled === false ) return;

switch ( event.pointerType ) {

case 'mouse':
onMouseDown( event );
break;

// TODO touch

}

}

function onPointerMove( event ) {

if ( scope.enabled === false ) return;

switch ( event.pointerType ) {

case 'mouse':
onMouseMove( event );
break;

// TODO touch

}

}

function onPointerUp( event ) {

if ( scope.enabled === false ) return;

switch ( event.pointerType ) {

case 'mouse':
onMouseUp( event );
break;

// TODO touch

}

}

var isMouseDown = false;

function onMouseDown( event ) {

// Prevent the browser from scrolling.
event.preventDefault();

Expand Down Expand Up @@ -866,8 +915,7 @@ THREE.OrbitControls = function ( object, domElement ) {

if ( state !== STATE.NONE ) {

scope.domElement.ownerDocument.addEventListener( 'mousemove', onMouseMove, false );
scope.domElement.ownerDocument.addEventListener( 'mouseup', onMouseUp, false );
isMouseDown = true;

scope.dispatchEvent( startEvent );

Expand All @@ -877,7 +925,7 @@ THREE.OrbitControls = function ( object, domElement ) {

function onMouseMove( event ) {

if ( scope.enabled === false ) return;
if ( isMouseDown === false ) return;

event.preventDefault();

Expand Down Expand Up @@ -913,17 +961,16 @@ THREE.OrbitControls = function ( object, domElement ) {

function onMouseUp( event ) {

if ( scope.enabled === false ) return;
if ( isMouseDown === false ) return;

handleMouseUp( event );

scope.domElement.ownerDocument.removeEventListener( 'mousemove', onMouseMove, false );
scope.domElement.ownerDocument.removeEventListener( 'mouseup', onMouseUp, false );

scope.dispatchEvent( endEvent );

state = STATE.NONE;

isMouseDown = false;

}

function onMouseWheel( event ) {
Expand Down Expand Up @@ -1116,13 +1163,16 @@ THREE.OrbitControls = function ( object, domElement ) {

scope.domElement.addEventListener( 'contextmenu', onContextMenu, false );

scope.domElement.addEventListener( 'mousedown', onMouseDown, false );
scope.domElement.addEventListener( 'pointerdown', onPointerDown, false );
scope.domElement.addEventListener( 'wheel', onMouseWheel, false );

scope.domElement.addEventListener( 'touchstart', onTouchStart, false );
scope.domElement.addEventListener( 'touchend', onTouchEnd, false );
scope.domElement.addEventListener( 'touchmove', onTouchMove, false );

scope.domElement.ownerDocument.addEventListener( 'pointermove', onPointerMove, false );
scope.domElement.ownerDocument.addEventListener( 'pointerup', onPointerUp, false );

scope.domElement.addEventListener( 'keydown', onKeyDown, false );

// make sure element can receive keys.
Expand Down
74 changes: 62 additions & 12 deletions examples/jsm/controls/OrbitControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,16 @@ var OrbitControls = function ( object, domElement ) {
this.dispose = function () {

scope.domElement.removeEventListener( 'contextmenu', onContextMenu, false );
scope.domElement.removeEventListener( 'mousedown', onMouseDown, false );

scope.domElement.removeEventListener( 'pointerdown', onPointerDown, false );
scope.domElement.removeEventListener( 'wheel', onMouseWheel, false );

scope.domElement.removeEventListener( 'touchstart', onTouchStart, false );
scope.domElement.removeEventListener( 'touchend', onTouchEnd, false );
scope.domElement.removeEventListener( 'touchmove', onTouchMove, false );

scope.domElement.ownerDocument.removeEventListener( 'mousemove', onMouseMove, false );
scope.domElement.ownerDocument.removeEventListener( 'mouseup', onMouseUp, false );
scope.domElement.ownerDocument.removeEventListener( 'pointermove', onPointerMove, false );
scope.domElement.ownerDocument.removeEventListener( 'pointerup', onPointerUp, false );

scope.domElement.removeEventListener( 'keydown', onKeyDown, false );

Expand Down Expand Up @@ -773,10 +774,58 @@ var OrbitControls = function ( object, domElement ) {
// event handlers - FSM: listen for events and reset state
//

function onMouseDown( event ) {
function onPointerDown( event ) {

if ( scope.enabled === false ) return;

switch ( event.pointerType ) {

case 'mouse':
onMouseDown( event );
break;

// TODO touch

}

}

function onPointerMove( event ) {

if ( scope.enabled === false ) return;

switch ( event.pointerType ) {

case 'mouse':
onMouseMove( event );
break;

// TODO touch

}

}

function onPointerUp( event ) {

if ( scope.enabled === false ) return;

switch ( event.pointerType ) {

case 'mouse':
onMouseUp( event );
break;

// TODO touch

}

}

var isMouseDown = false;

function onMouseDown( event ) {

// Prevent the browser from scrolling.
event.preventDefault();

Expand Down Expand Up @@ -874,8 +923,7 @@ var OrbitControls = function ( object, domElement ) {

if ( state !== STATE.NONE ) {

scope.domElement.ownerDocument.addEventListener( 'mousemove', onMouseMove, false );
scope.domElement.ownerDocument.addEventListener( 'mouseup', onMouseUp, false );
isMouseDown = true;

scope.dispatchEvent( startEvent );

Expand All @@ -885,7 +933,7 @@ var OrbitControls = function ( object, domElement ) {

function onMouseMove( event ) {

if ( scope.enabled === false ) return;
if ( isMouseDown === false ) return;

event.preventDefault();

Expand Down Expand Up @@ -921,17 +969,16 @@ var OrbitControls = function ( object, domElement ) {

function onMouseUp( event ) {

if ( scope.enabled === false ) return;
if ( isMouseDown === false ) return;

handleMouseUp( event );

scope.domElement.ownerDocument.removeEventListener( 'mousemove', onMouseMove, false );
scope.domElement.ownerDocument.removeEventListener( 'mouseup', onMouseUp, false );

scope.dispatchEvent( endEvent );

state = STATE.NONE;

isMouseDown = false;

}

function onMouseWheel( event ) {
Expand Down Expand Up @@ -1124,13 +1171,16 @@ var OrbitControls = function ( object, domElement ) {

scope.domElement.addEventListener( 'contextmenu', onContextMenu, false );

scope.domElement.addEventListener( 'mousedown', onMouseDown, false );
scope.domElement.addEventListener( 'pointerdown', onPointerDown, false );
scope.domElement.addEventListener( 'wheel', onMouseWheel, false );

scope.domElement.addEventListener( 'touchstart', onTouchStart, false );
scope.domElement.addEventListener( 'touchend', onTouchEnd, false );
scope.domElement.addEventListener( 'touchmove', onTouchMove, false );

scope.domElement.ownerDocument.addEventListener( 'pointermove', onPointerMove, false );
scope.domElement.ownerDocument.addEventListener( 'pointerup', onPointerUp, false );

scope.domElement.addEventListener( 'keydown', onKeyDown, false );

// make sure element can receive keys.
Expand Down