最新代码
This commit is contained in:
3224
public/sdk/three/jsm/controls/ArcballControls.js
Normal file
3224
public/sdk/three/jsm/controls/ArcballControls.js
Normal file
File diff suppressed because it is too large
Load Diff
282
public/sdk/three/jsm/controls/DragControls.js
Normal file
282
public/sdk/three/jsm/controls/DragControls.js
Normal file
@ -0,0 +1,282 @@
|
||||
import {
|
||||
EventDispatcher,
|
||||
Matrix4,
|
||||
Plane,
|
||||
Raycaster,
|
||||
Vector2,
|
||||
Vector3
|
||||
} from 'three';
|
||||
|
||||
const _plane = new Plane();
|
||||
const _raycaster = new Raycaster();
|
||||
|
||||
const _pointer = new Vector2();
|
||||
const _offset = new Vector3();
|
||||
const _diff = new Vector2();
|
||||
const _previousPointer = new Vector2();
|
||||
const _intersection = new Vector3();
|
||||
const _worldPosition = new Vector3();
|
||||
const _inverseMatrix = new Matrix4();
|
||||
|
||||
const _up = new Vector3();
|
||||
const _right = new Vector3();
|
||||
|
||||
class DragControls extends EventDispatcher {
|
||||
|
||||
constructor( _objects, _camera, _domElement ) {
|
||||
|
||||
super();
|
||||
|
||||
_domElement.style.touchAction = 'none'; // disable touch scroll
|
||||
|
||||
let _selected = null, _hovered = null;
|
||||
|
||||
const _intersections = [];
|
||||
|
||||
this.mode = 'translate';
|
||||
|
||||
this.rotateSpeed = 1;
|
||||
|
||||
//
|
||||
|
||||
const scope = this;
|
||||
|
||||
function activate() {
|
||||
|
||||
_domElement.addEventListener( 'pointermove', onPointerMove );
|
||||
_domElement.addEventListener( 'pointerdown', onPointerDown );
|
||||
_domElement.addEventListener( 'pointerup', onPointerCancel );
|
||||
_domElement.addEventListener( 'pointerleave', onPointerCancel );
|
||||
|
||||
}
|
||||
|
||||
function deactivate() {
|
||||
|
||||
_domElement.removeEventListener( 'pointermove', onPointerMove );
|
||||
_domElement.removeEventListener( 'pointerdown', onPointerDown );
|
||||
_domElement.removeEventListener( 'pointerup', onPointerCancel );
|
||||
_domElement.removeEventListener( 'pointerleave', onPointerCancel );
|
||||
|
||||
_domElement.style.cursor = '';
|
||||
|
||||
}
|
||||
|
||||
function dispose() {
|
||||
|
||||
deactivate();
|
||||
|
||||
}
|
||||
|
||||
function getObjects() {
|
||||
|
||||
return _objects;
|
||||
|
||||
}
|
||||
|
||||
function setObjects( objects ) {
|
||||
|
||||
_objects = objects;
|
||||
|
||||
}
|
||||
|
||||
function getRaycaster() {
|
||||
|
||||
return _raycaster;
|
||||
|
||||
}
|
||||
|
||||
function onPointerMove( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
updatePointer( event );
|
||||
|
||||
_raycaster.setFromCamera( _pointer, _camera );
|
||||
|
||||
if ( _selected ) {
|
||||
|
||||
if ( scope.mode === 'translate' ) {
|
||||
|
||||
if ( _raycaster.ray.intersectPlane( _plane, _intersection ) ) {
|
||||
|
||||
_selected.position.copy( _intersection.sub( _offset ).applyMatrix4( _inverseMatrix ) );
|
||||
|
||||
}
|
||||
|
||||
} else if ( scope.mode === 'rotate' ) {
|
||||
|
||||
_diff.subVectors( _pointer, _previousPointer ).multiplyScalar( scope.rotateSpeed );
|
||||
_selected.rotateOnWorldAxis( _up, _diff.x );
|
||||
_selected.rotateOnWorldAxis( _right.normalize(), - _diff.y );
|
||||
|
||||
}
|
||||
|
||||
scope.dispatchEvent( { type: 'drag', object: _selected } );
|
||||
|
||||
_previousPointer.copy( _pointer );
|
||||
|
||||
} else {
|
||||
|
||||
// hover support
|
||||
|
||||
if ( event.pointerType === 'mouse' || event.pointerType === 'pen' ) {
|
||||
|
||||
_intersections.length = 0;
|
||||
|
||||
_raycaster.setFromCamera( _pointer, _camera );
|
||||
_raycaster.intersectObjects( _objects, scope.recursive, _intersections );
|
||||
|
||||
if ( _intersections.length > 0 ) {
|
||||
|
||||
const object = _intersections[ 0 ].object;
|
||||
|
||||
_plane.setFromNormalAndCoplanarPoint( _camera.getWorldDirection( _plane.normal ), _worldPosition.setFromMatrixPosition( object.matrixWorld ) );
|
||||
|
||||
if ( _hovered !== object && _hovered !== null ) {
|
||||
|
||||
scope.dispatchEvent( { type: 'hoveroff', object: _hovered } );
|
||||
|
||||
_domElement.style.cursor = 'auto';
|
||||
_hovered = null;
|
||||
|
||||
}
|
||||
|
||||
if ( _hovered !== object ) {
|
||||
|
||||
scope.dispatchEvent( { type: 'hoveron', object: object } );
|
||||
|
||||
_domElement.style.cursor = 'pointer';
|
||||
_hovered = object;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if ( _hovered !== null ) {
|
||||
|
||||
scope.dispatchEvent( { type: 'hoveroff', object: _hovered } );
|
||||
|
||||
_domElement.style.cursor = 'auto';
|
||||
_hovered = null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_previousPointer.copy( _pointer );
|
||||
|
||||
}
|
||||
|
||||
function onPointerDown( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
updatePointer( event );
|
||||
|
||||
_intersections.length = 0;
|
||||
|
||||
_raycaster.setFromCamera( _pointer, _camera );
|
||||
_raycaster.intersectObjects( _objects, scope.recursive, _intersections );
|
||||
|
||||
if ( _intersections.length > 0 ) {
|
||||
|
||||
if ( scope.transformGroup === true ) {
|
||||
|
||||
// look for the outermost group in the object's upper hierarchy
|
||||
|
||||
_selected = findGroup( _intersections[ 0 ].object );
|
||||
|
||||
} else {
|
||||
|
||||
_selected = _intersections[ 0 ].object;
|
||||
|
||||
}
|
||||
|
||||
_plane.setFromNormalAndCoplanarPoint( _camera.getWorldDirection( _plane.normal ), _worldPosition.setFromMatrixPosition( _selected.matrixWorld ) );
|
||||
|
||||
if ( _raycaster.ray.intersectPlane( _plane, _intersection ) ) {
|
||||
|
||||
if ( scope.mode === 'translate' ) {
|
||||
|
||||
_inverseMatrix.copy( _selected.parent.matrixWorld ).invert();
|
||||
_offset.copy( _intersection ).sub( _worldPosition.setFromMatrixPosition( _selected.matrixWorld ) );
|
||||
|
||||
} else if ( scope.mode === 'rotate' ) {
|
||||
|
||||
// the controls only support Y+ up
|
||||
_up.set( 0, 1, 0 ).applyQuaternion( _camera.quaternion ).normalize();
|
||||
_right.set( 1, 0, 0 ).applyQuaternion( _camera.quaternion ).normalize();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_domElement.style.cursor = 'move';
|
||||
|
||||
scope.dispatchEvent( { type: 'dragstart', object: _selected } );
|
||||
|
||||
}
|
||||
|
||||
_previousPointer.copy( _pointer );
|
||||
|
||||
}
|
||||
|
||||
function onPointerCancel() {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
if ( _selected ) {
|
||||
|
||||
scope.dispatchEvent( { type: 'dragend', object: _selected } );
|
||||
|
||||
_selected = null;
|
||||
|
||||
}
|
||||
|
||||
_domElement.style.cursor = _hovered ? 'pointer' : 'auto';
|
||||
|
||||
}
|
||||
|
||||
function updatePointer( event ) {
|
||||
|
||||
const rect = _domElement.getBoundingClientRect();
|
||||
|
||||
_pointer.x = ( event.clientX - rect.left ) / rect.width * 2 - 1;
|
||||
_pointer.y = - ( event.clientY - rect.top ) / rect.height * 2 + 1;
|
||||
|
||||
}
|
||||
|
||||
function findGroup( obj, group = null ) {
|
||||
|
||||
if ( obj.isGroup ) group = obj;
|
||||
|
||||
if ( obj.parent === null ) return group;
|
||||
|
||||
return findGroup( obj.parent, group );
|
||||
|
||||
}
|
||||
|
||||
activate();
|
||||
|
||||
// API
|
||||
|
||||
this.enabled = true;
|
||||
this.recursive = true;
|
||||
this.transformGroup = false;
|
||||
|
||||
this.activate = activate;
|
||||
this.deactivate = deactivate;
|
||||
this.dispose = dispose;
|
||||
this.getObjects = getObjects;
|
||||
this.getRaycaster = getRaycaster;
|
||||
this.setObjects = setObjects;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { DragControls };
|
325
public/sdk/three/jsm/controls/FirstPersonControls.js
Normal file
325
public/sdk/three/jsm/controls/FirstPersonControls.js
Normal file
@ -0,0 +1,325 @@
|
||||
import {
|
||||
MathUtils,
|
||||
Spherical,
|
||||
Vector3
|
||||
} from 'three';
|
||||
|
||||
const _lookDirection = new Vector3();
|
||||
const _spherical = new Spherical();
|
||||
const _target = new Vector3();
|
||||
|
||||
class FirstPersonControls {
|
||||
|
||||
constructor( object, domElement ) {
|
||||
|
||||
this.object = object;
|
||||
this.domElement = domElement;
|
||||
|
||||
// API
|
||||
|
||||
this.enabled = true;
|
||||
|
||||
this.movementSpeed = 1.0;
|
||||
this.lookSpeed = 0.005;
|
||||
|
||||
this.lookVertical = true;
|
||||
this.autoForward = false;
|
||||
|
||||
this.activeLook = true;
|
||||
|
||||
this.heightSpeed = false;
|
||||
this.heightCoef = 1.0;
|
||||
this.heightMin = 0.0;
|
||||
this.heightMax = 1.0;
|
||||
|
||||
this.constrainVertical = false;
|
||||
this.verticalMin = 0;
|
||||
this.verticalMax = Math.PI;
|
||||
|
||||
this.mouseDragOn = false;
|
||||
|
||||
// internals
|
||||
|
||||
this.autoSpeedFactor = 0.0;
|
||||
|
||||
this.pointerX = 0;
|
||||
this.pointerY = 0;
|
||||
|
||||
this.moveForward = false;
|
||||
this.moveBackward = false;
|
||||
this.moveLeft = false;
|
||||
this.moveRight = false;
|
||||
|
||||
this.viewHalfX = 0;
|
||||
this.viewHalfY = 0;
|
||||
|
||||
// private variables
|
||||
|
||||
let lat = 0;
|
||||
let lon = 0;
|
||||
|
||||
//
|
||||
|
||||
this.handleResize = function () {
|
||||
|
||||
if ( this.domElement === document ) {
|
||||
|
||||
this.viewHalfX = window.innerWidth / 2;
|
||||
this.viewHalfY = window.innerHeight / 2;
|
||||
|
||||
} else {
|
||||
|
||||
this.viewHalfX = this.domElement.offsetWidth / 2;
|
||||
this.viewHalfY = this.domElement.offsetHeight / 2;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.onPointerDown = function ( event ) {
|
||||
|
||||
if ( this.domElement !== document ) {
|
||||
|
||||
this.domElement.focus();
|
||||
|
||||
}
|
||||
|
||||
if ( this.activeLook ) {
|
||||
|
||||
switch ( event.button ) {
|
||||
|
||||
case 0: this.moveForward = true; break;
|
||||
case 2: this.moveBackward = true; break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.mouseDragOn = true;
|
||||
|
||||
};
|
||||
|
||||
this.onPointerUp = function ( event ) {
|
||||
|
||||
if ( this.activeLook ) {
|
||||
|
||||
switch ( event.button ) {
|
||||
|
||||
case 0: this.moveForward = false; break;
|
||||
case 2: this.moveBackward = false; break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.mouseDragOn = false;
|
||||
|
||||
};
|
||||
|
||||
this.onPointerMove = function ( event ) {
|
||||
|
||||
if ( this.domElement === document ) {
|
||||
|
||||
this.pointerX = event.pageX - this.viewHalfX;
|
||||
this.pointerY = event.pageY - this.viewHalfY;
|
||||
|
||||
} else {
|
||||
|
||||
this.pointerX = event.pageX - this.domElement.offsetLeft - this.viewHalfX;
|
||||
this.pointerY = event.pageY - this.domElement.offsetTop - this.viewHalfY;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.onKeyDown = function ( event ) {
|
||||
|
||||
switch ( event.code ) {
|
||||
|
||||
case 'ArrowUp':
|
||||
case 'KeyW': this.moveForward = true; break;
|
||||
|
||||
case 'ArrowLeft':
|
||||
case 'KeyA': this.moveLeft = true; break;
|
||||
|
||||
case 'ArrowDown':
|
||||
case 'KeyS': this.moveBackward = true; break;
|
||||
|
||||
case 'ArrowRight':
|
||||
case 'KeyD': this.moveRight = true; break;
|
||||
|
||||
case 'KeyR': this.moveUp = true; break;
|
||||
case 'KeyF': this.moveDown = true; break;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.onKeyUp = function ( event ) {
|
||||
|
||||
switch ( event.code ) {
|
||||
|
||||
case 'ArrowUp':
|
||||
case 'KeyW': this.moveForward = false; break;
|
||||
|
||||
case 'ArrowLeft':
|
||||
case 'KeyA': this.moveLeft = false; break;
|
||||
|
||||
case 'ArrowDown':
|
||||
case 'KeyS': this.moveBackward = false; break;
|
||||
|
||||
case 'ArrowRight':
|
||||
case 'KeyD': this.moveRight = false; break;
|
||||
|
||||
case 'KeyR': this.moveUp = false; break;
|
||||
case 'KeyF': this.moveDown = false; break;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.lookAt = function ( x, y, z ) {
|
||||
|
||||
if ( x.isVector3 ) {
|
||||
|
||||
_target.copy( x );
|
||||
|
||||
} else {
|
||||
|
||||
_target.set( x, y, z );
|
||||
|
||||
}
|
||||
|
||||
this.object.lookAt( _target );
|
||||
|
||||
setOrientation( this );
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
this.update = function () {
|
||||
|
||||
const targetPosition = new Vector3();
|
||||
|
||||
return function update( delta ) {
|
||||
|
||||
if ( this.enabled === false ) return;
|
||||
|
||||
if ( this.heightSpeed ) {
|
||||
|
||||
const y = MathUtils.clamp( this.object.position.y, this.heightMin, this.heightMax );
|
||||
const heightDelta = y - this.heightMin;
|
||||
|
||||
this.autoSpeedFactor = delta * ( heightDelta * this.heightCoef );
|
||||
|
||||
} else {
|
||||
|
||||
this.autoSpeedFactor = 0.0;
|
||||
|
||||
}
|
||||
|
||||
const actualMoveSpeed = delta * this.movementSpeed;
|
||||
|
||||
if ( this.moveForward || ( this.autoForward && ! this.moveBackward ) ) this.object.translateZ( - ( actualMoveSpeed + this.autoSpeedFactor ) );
|
||||
if ( this.moveBackward ) this.object.translateZ( actualMoveSpeed );
|
||||
|
||||
if ( this.moveLeft ) this.object.translateX( - actualMoveSpeed );
|
||||
if ( this.moveRight ) this.object.translateX( actualMoveSpeed );
|
||||
|
||||
if ( this.moveUp ) this.object.translateY( actualMoveSpeed );
|
||||
if ( this.moveDown ) this.object.translateY( - actualMoveSpeed );
|
||||
|
||||
let actualLookSpeed = delta * this.lookSpeed;
|
||||
|
||||
if ( ! this.activeLook ) {
|
||||
|
||||
actualLookSpeed = 0;
|
||||
|
||||
}
|
||||
|
||||
let verticalLookRatio = 1;
|
||||
|
||||
if ( this.constrainVertical ) {
|
||||
|
||||
verticalLookRatio = Math.PI / ( this.verticalMax - this.verticalMin );
|
||||
|
||||
}
|
||||
|
||||
lon -= this.pointerX * actualLookSpeed;
|
||||
if ( this.lookVertical ) lat -= this.pointerY * actualLookSpeed * verticalLookRatio;
|
||||
|
||||
lat = Math.max( - 85, Math.min( 85, lat ) );
|
||||
|
||||
let phi = MathUtils.degToRad( 90 - lat );
|
||||
const theta = MathUtils.degToRad( lon );
|
||||
|
||||
if ( this.constrainVertical ) {
|
||||
|
||||
phi = MathUtils.mapLinear( phi, 0, Math.PI, this.verticalMin, this.verticalMax );
|
||||
|
||||
}
|
||||
|
||||
const position = this.object.position;
|
||||
|
||||
targetPosition.setFromSphericalCoords( 1, phi, theta ).add( position );
|
||||
|
||||
this.object.lookAt( targetPosition );
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
this.dispose = function () {
|
||||
|
||||
this.domElement.removeEventListener( 'contextmenu', contextmenu );
|
||||
this.domElement.removeEventListener( 'pointerdown', _onPointerDown );
|
||||
this.domElement.removeEventListener( 'pointermove', _onPointerMove );
|
||||
this.domElement.removeEventListener( 'pointerup', _onPointerUp );
|
||||
|
||||
window.removeEventListener( 'keydown', _onKeyDown );
|
||||
window.removeEventListener( 'keyup', _onKeyUp );
|
||||
|
||||
};
|
||||
|
||||
const _onPointerMove = this.onPointerMove.bind( this );
|
||||
const _onPointerDown = this.onPointerDown.bind( this );
|
||||
const _onPointerUp = this.onPointerUp.bind( this );
|
||||
const _onKeyDown = this.onKeyDown.bind( this );
|
||||
const _onKeyUp = this.onKeyUp.bind( this );
|
||||
|
||||
this.domElement.addEventListener( 'contextmenu', contextmenu );
|
||||
this.domElement.addEventListener( 'pointerdown', _onPointerDown );
|
||||
this.domElement.addEventListener( 'pointermove', _onPointerMove );
|
||||
this.domElement.addEventListener( 'pointerup', _onPointerUp );
|
||||
|
||||
window.addEventListener( 'keydown', _onKeyDown );
|
||||
window.addEventListener( 'keyup', _onKeyUp );
|
||||
|
||||
function setOrientation( controls ) {
|
||||
|
||||
const quaternion = controls.object.quaternion;
|
||||
|
||||
_lookDirection.set( 0, 0, - 1 ).applyQuaternion( quaternion );
|
||||
_spherical.setFromVector3( _lookDirection );
|
||||
|
||||
lat = 90 - MathUtils.radToDeg( _spherical.phi );
|
||||
lon = MathUtils.radToDeg( _spherical.theta );
|
||||
|
||||
}
|
||||
|
||||
this.handleResize();
|
||||
|
||||
setOrientation( this );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function contextmenu( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
}
|
||||
|
||||
export { FirstPersonControls };
|
326
public/sdk/three/jsm/controls/FlyControls.js
Normal file
326
public/sdk/three/jsm/controls/FlyControls.js
Normal file
@ -0,0 +1,326 @@
|
||||
import {
|
||||
EventDispatcher,
|
||||
Quaternion,
|
||||
Vector3
|
||||
} from 'three';
|
||||
|
||||
const _changeEvent = { type: 'change' };
|
||||
|
||||
class FlyControls extends EventDispatcher {
|
||||
|
||||
constructor( object, domElement ) {
|
||||
|
||||
super();
|
||||
|
||||
this.object = object;
|
||||
this.domElement = domElement;
|
||||
|
||||
// API
|
||||
|
||||
// Set to false to disable this control
|
||||
this.enabled = true;
|
||||
|
||||
this.movementSpeed = 1.0;
|
||||
this.rollSpeed = 0.005;
|
||||
|
||||
this.dragToLook = false;
|
||||
this.autoForward = false;
|
||||
|
||||
// disable default target object behavior
|
||||
|
||||
// internals
|
||||
|
||||
const scope = this;
|
||||
|
||||
const EPS = 0.000001;
|
||||
|
||||
const lastQuaternion = new Quaternion();
|
||||
const lastPosition = new Vector3();
|
||||
|
||||
this.tmpQuaternion = new Quaternion();
|
||||
|
||||
this.status = 0;
|
||||
|
||||
this.moveState = { up: 0, down: 0, left: 0, right: 0, forward: 0, back: 0, pitchUp: 0, pitchDown: 0, yawLeft: 0, yawRight: 0, rollLeft: 0, rollRight: 0 };
|
||||
this.moveVector = new Vector3( 0, 0, 0 );
|
||||
this.rotationVector = new Vector3( 0, 0, 0 );
|
||||
|
||||
this.keydown = function ( event ) {
|
||||
|
||||
if ( event.altKey || this.enabled === false ) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
switch ( event.code ) {
|
||||
|
||||
case 'ShiftLeft':
|
||||
case 'ShiftRight': this.movementSpeedMultiplier = .1; break;
|
||||
|
||||
case 'KeyW': this.moveState.forward = 1; break;
|
||||
case 'KeyS': this.moveState.back = 1; break;
|
||||
|
||||
case 'KeyA': this.moveState.left = 1; break;
|
||||
case 'KeyD': this.moveState.right = 1; break;
|
||||
|
||||
case 'KeyR': this.moveState.up = 1; break;
|
||||
case 'KeyF': this.moveState.down = 1; break;
|
||||
|
||||
case 'ArrowUp': this.moveState.pitchUp = 1; break;
|
||||
case 'ArrowDown': this.moveState.pitchDown = 1; break;
|
||||
|
||||
case 'ArrowLeft': this.moveState.yawLeft = 1; break;
|
||||
case 'ArrowRight': this.moveState.yawRight = 1; break;
|
||||
|
||||
case 'KeyQ': this.moveState.rollLeft = 1; break;
|
||||
case 'KeyE': this.moveState.rollRight = 1; break;
|
||||
|
||||
}
|
||||
|
||||
this.updateMovementVector();
|
||||
this.updateRotationVector();
|
||||
|
||||
};
|
||||
|
||||
this.keyup = function ( event ) {
|
||||
|
||||
if ( this.enabled === false ) return;
|
||||
|
||||
switch ( event.code ) {
|
||||
|
||||
case 'ShiftLeft':
|
||||
case 'ShiftRight': this.movementSpeedMultiplier = 1; break;
|
||||
|
||||
case 'KeyW': this.moveState.forward = 0; break;
|
||||
case 'KeyS': this.moveState.back = 0; break;
|
||||
|
||||
case 'KeyA': this.moveState.left = 0; break;
|
||||
case 'KeyD': this.moveState.right = 0; break;
|
||||
|
||||
case 'KeyR': this.moveState.up = 0; break;
|
||||
case 'KeyF': this.moveState.down = 0; break;
|
||||
|
||||
case 'ArrowUp': this.moveState.pitchUp = 0; break;
|
||||
case 'ArrowDown': this.moveState.pitchDown = 0; break;
|
||||
|
||||
case 'ArrowLeft': this.moveState.yawLeft = 0; break;
|
||||
case 'ArrowRight': this.moveState.yawRight = 0; break;
|
||||
|
||||
case 'KeyQ': this.moveState.rollLeft = 0; break;
|
||||
case 'KeyE': this.moveState.rollRight = 0; break;
|
||||
|
||||
}
|
||||
|
||||
this.updateMovementVector();
|
||||
this.updateRotationVector();
|
||||
|
||||
};
|
||||
|
||||
this.pointerdown = function ( event ) {
|
||||
|
||||
if ( this.enabled === false ) return;
|
||||
|
||||
if ( this.dragToLook ) {
|
||||
|
||||
this.status ++;
|
||||
|
||||
} else {
|
||||
|
||||
switch ( event.button ) {
|
||||
|
||||
case 0: this.moveState.forward = 1; break;
|
||||
case 2: this.moveState.back = 1; break;
|
||||
|
||||
}
|
||||
|
||||
this.updateMovementVector();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.pointermove = function ( event ) {
|
||||
|
||||
if ( this.enabled === false ) return;
|
||||
|
||||
if ( ! this.dragToLook || this.status > 0 ) {
|
||||
|
||||
const container = this.getContainerDimensions();
|
||||
const halfWidth = container.size[ 0 ] / 2;
|
||||
const halfHeight = container.size[ 1 ] / 2;
|
||||
|
||||
this.moveState.yawLeft = - ( ( event.pageX - container.offset[ 0 ] ) - halfWidth ) / halfWidth;
|
||||
this.moveState.pitchDown = ( ( event.pageY - container.offset[ 1 ] ) - halfHeight ) / halfHeight;
|
||||
|
||||
this.updateRotationVector();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.pointerup = function ( event ) {
|
||||
|
||||
if ( this.enabled === false ) return;
|
||||
|
||||
if ( this.dragToLook ) {
|
||||
|
||||
this.status --;
|
||||
|
||||
this.moveState.yawLeft = this.moveState.pitchDown = 0;
|
||||
|
||||
} else {
|
||||
|
||||
switch ( event.button ) {
|
||||
|
||||
case 0: this.moveState.forward = 0; break;
|
||||
case 2: this.moveState.back = 0; break;
|
||||
|
||||
}
|
||||
|
||||
this.updateMovementVector();
|
||||
|
||||
}
|
||||
|
||||
this.updateRotationVector();
|
||||
|
||||
};
|
||||
|
||||
this.pointercancel = function () {
|
||||
|
||||
if ( this.enabled === false ) return;
|
||||
|
||||
if ( this.dragToLook ) {
|
||||
|
||||
this.status = 0;
|
||||
|
||||
this.moveState.yawLeft = this.moveState.pitchDown = 0;
|
||||
|
||||
} else {
|
||||
|
||||
this.moveState.forward = 0;
|
||||
this.moveState.back = 0;
|
||||
|
||||
this.updateMovementVector();
|
||||
|
||||
}
|
||||
|
||||
this.updateRotationVector();
|
||||
|
||||
};
|
||||
|
||||
this.contextMenu = function ( event ) {
|
||||
|
||||
if ( this.enabled === false ) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
};
|
||||
|
||||
this.update = function ( delta ) {
|
||||
|
||||
if ( this.enabled === false ) return;
|
||||
|
||||
const moveMult = delta * scope.movementSpeed;
|
||||
const rotMult = delta * scope.rollSpeed;
|
||||
|
||||
scope.object.translateX( scope.moveVector.x * moveMult );
|
||||
scope.object.translateY( scope.moveVector.y * moveMult );
|
||||
scope.object.translateZ( scope.moveVector.z * moveMult );
|
||||
|
||||
scope.tmpQuaternion.set( scope.rotationVector.x * rotMult, scope.rotationVector.y * rotMult, scope.rotationVector.z * rotMult, 1 ).normalize();
|
||||
scope.object.quaternion.multiply( scope.tmpQuaternion );
|
||||
|
||||
if (
|
||||
lastPosition.distanceToSquared( scope.object.position ) > EPS ||
|
||||
8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS
|
||||
) {
|
||||
|
||||
scope.dispatchEvent( _changeEvent );
|
||||
lastQuaternion.copy( scope.object.quaternion );
|
||||
lastPosition.copy( scope.object.position );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.updateMovementVector = function () {
|
||||
|
||||
const forward = ( this.moveState.forward || ( this.autoForward && ! this.moveState.back ) ) ? 1 : 0;
|
||||
|
||||
this.moveVector.x = ( - this.moveState.left + this.moveState.right );
|
||||
this.moveVector.y = ( - this.moveState.down + this.moveState.up );
|
||||
this.moveVector.z = ( - forward + this.moveState.back );
|
||||
|
||||
//console.log( 'move:', [ this.moveVector.x, this.moveVector.y, this.moveVector.z ] );
|
||||
|
||||
};
|
||||
|
||||
this.updateRotationVector = function () {
|
||||
|
||||
this.rotationVector.x = ( - this.moveState.pitchDown + this.moveState.pitchUp );
|
||||
this.rotationVector.y = ( - this.moveState.yawRight + this.moveState.yawLeft );
|
||||
this.rotationVector.z = ( - this.moveState.rollRight + this.moveState.rollLeft );
|
||||
|
||||
//console.log( 'rotate:', [ this.rotationVector.x, this.rotationVector.y, this.rotationVector.z ] );
|
||||
|
||||
};
|
||||
|
||||
this.getContainerDimensions = function () {
|
||||
|
||||
if ( this.domElement != document ) {
|
||||
|
||||
return {
|
||||
size: [ this.domElement.offsetWidth, this.domElement.offsetHeight ],
|
||||
offset: [ this.domElement.offsetLeft, this.domElement.offsetTop ]
|
||||
};
|
||||
|
||||
} else {
|
||||
|
||||
return {
|
||||
size: [ window.innerWidth, window.innerHeight ],
|
||||
offset: [ 0, 0 ]
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.dispose = function () {
|
||||
|
||||
this.domElement.removeEventListener( 'contextmenu', _contextmenu );
|
||||
this.domElement.removeEventListener( 'pointerdown', _pointerdown );
|
||||
this.domElement.removeEventListener( 'pointermove', _pointermove );
|
||||
this.domElement.removeEventListener( 'pointerup', _pointerup );
|
||||
this.domElement.removeEventListener( 'pointercancel', _pointercancel );
|
||||
|
||||
window.removeEventListener( 'keydown', _keydown );
|
||||
window.removeEventListener( 'keyup', _keyup );
|
||||
|
||||
};
|
||||
|
||||
const _contextmenu = this.contextMenu.bind( this );
|
||||
const _pointermove = this.pointermove.bind( this );
|
||||
const _pointerdown = this.pointerdown.bind( this );
|
||||
const _pointerup = this.pointerup.bind( this );
|
||||
const _pointercancel = this.pointercancel.bind( this );
|
||||
const _keydown = this.keydown.bind( this );
|
||||
const _keyup = this.keyup.bind( this );
|
||||
|
||||
this.domElement.addEventListener( 'contextmenu', _contextmenu );
|
||||
this.domElement.addEventListener( 'pointerdown', _pointerdown );
|
||||
this.domElement.addEventListener( 'pointermove', _pointermove );
|
||||
this.domElement.addEventListener( 'pointerup', _pointerup );
|
||||
this.domElement.addEventListener( 'pointercancel', _pointercancel );
|
||||
|
||||
window.addEventListener( 'keydown', _keydown );
|
||||
window.addEventListener( 'keyup', _keyup );
|
||||
|
||||
this.updateMovementVector();
|
||||
this.updateRotationVector();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { FlyControls };
|
28
public/sdk/three/jsm/controls/MapControls.js
Normal file
28
public/sdk/three/jsm/controls/MapControls.js
Normal file
@ -0,0 +1,28 @@
|
||||
import { MOUSE, TOUCH } from 'three';
|
||||
|
||||
import { OrbitControls } from './OrbitControls.js';
|
||||
|
||||
// MapControls performs orbiting, dollying (zooming), and panning.
|
||||
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
|
||||
//
|
||||
// Orbit - right mouse, or left mouse + ctrl/meta/shiftKey / touch: two-finger rotate
|
||||
// Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
|
||||
// Pan - left mouse, or arrow keys / touch: one-finger move
|
||||
|
||||
class MapControls extends OrbitControls {
|
||||
|
||||
constructor( object, domElement ) {
|
||||
|
||||
super( object, domElement );
|
||||
|
||||
this.screenSpacePanning = false; // pan orthogonal to world-space direction camera.up
|
||||
|
||||
this.mouseButtons = { LEFT: MOUSE.PAN, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.ROTATE };
|
||||
|
||||
this.touches = { ONE: TOUCH.PAN, TWO: TOUCH.DOLLY_ROTATE };
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { MapControls };
|
1532
public/sdk/three/jsm/controls/OrbitControls.js
Normal file
1532
public/sdk/three/jsm/controls/OrbitControls.js
Normal file
File diff suppressed because it is too large
Load Diff
162
public/sdk/three/jsm/controls/PointerLockControls.js
Normal file
162
public/sdk/three/jsm/controls/PointerLockControls.js
Normal file
@ -0,0 +1,162 @@
|
||||
import {
|
||||
Euler,
|
||||
EventDispatcher,
|
||||
Vector3
|
||||
} from 'three';
|
||||
|
||||
const _euler = new Euler( 0, 0, 0, 'YXZ' );
|
||||
const _vector = new Vector3();
|
||||
|
||||
const _changeEvent = { type: 'change' };
|
||||
const _lockEvent = { type: 'lock' };
|
||||
const _unlockEvent = { type: 'unlock' };
|
||||
|
||||
const _PI_2 = Math.PI / 2;
|
||||
|
||||
class PointerLockControls extends EventDispatcher {
|
||||
|
||||
constructor( camera, domElement ) {
|
||||
|
||||
super();
|
||||
|
||||
this.camera = camera;
|
||||
this.domElement = domElement;
|
||||
|
||||
this.isLocked = false;
|
||||
|
||||
// Set to constrain the pitch of the camera
|
||||
// Range is 0 to Math.PI radians
|
||||
this.minPolarAngle = 0; // radians
|
||||
this.maxPolarAngle = Math.PI; // radians
|
||||
|
||||
this.pointerSpeed = 1.0;
|
||||
|
||||
this._onMouseMove = onMouseMove.bind( this );
|
||||
this._onPointerlockChange = onPointerlockChange.bind( this );
|
||||
this._onPointerlockError = onPointerlockError.bind( this );
|
||||
|
||||
this.connect();
|
||||
|
||||
}
|
||||
|
||||
connect() {
|
||||
|
||||
this.domElement.ownerDocument.addEventListener( 'mousemove', this._onMouseMove );
|
||||
this.domElement.ownerDocument.addEventListener( 'pointerlockchange', this._onPointerlockChange );
|
||||
this.domElement.ownerDocument.addEventListener( 'pointerlockerror', this._onPointerlockError );
|
||||
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
|
||||
this.domElement.ownerDocument.removeEventListener( 'mousemove', this._onMouseMove );
|
||||
this.domElement.ownerDocument.removeEventListener( 'pointerlockchange', this._onPointerlockChange );
|
||||
this.domElement.ownerDocument.removeEventListener( 'pointerlockerror', this._onPointerlockError );
|
||||
|
||||
}
|
||||
|
||||
dispose() {
|
||||
|
||||
this.disconnect();
|
||||
|
||||
}
|
||||
|
||||
getObject() { // retaining this method for backward compatibility
|
||||
|
||||
return this.camera;
|
||||
|
||||
}
|
||||
|
||||
getDirection( v ) {
|
||||
|
||||
return v.set( 0, 0, - 1 ).applyQuaternion( this.camera.quaternion );
|
||||
|
||||
}
|
||||
|
||||
moveForward( distance ) {
|
||||
|
||||
// move forward parallel to the xz-plane
|
||||
// assumes camera.up is y-up
|
||||
|
||||
const camera = this.camera;
|
||||
|
||||
_vector.setFromMatrixColumn( camera.matrix, 0 );
|
||||
|
||||
_vector.crossVectors( camera.up, _vector );
|
||||
|
||||
camera.position.addScaledVector( _vector, distance );
|
||||
|
||||
}
|
||||
|
||||
moveRight( distance ) {
|
||||
|
||||
const camera = this.camera;
|
||||
|
||||
_vector.setFromMatrixColumn( camera.matrix, 0 );
|
||||
|
||||
camera.position.addScaledVector( _vector, distance );
|
||||
|
||||
}
|
||||
|
||||
lock() {
|
||||
|
||||
this.domElement.requestPointerLock();
|
||||
|
||||
}
|
||||
|
||||
unlock() {
|
||||
|
||||
this.domElement.ownerDocument.exitPointerLock();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// event listeners
|
||||
|
||||
function onMouseMove( event ) {
|
||||
|
||||
if ( this.isLocked === false ) return;
|
||||
|
||||
const movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
||||
const movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
|
||||
|
||||
const camera = this.camera;
|
||||
_euler.setFromQuaternion( camera.quaternion );
|
||||
|
||||
_euler.y -= movementX * 0.002 * this.pointerSpeed;
|
||||
_euler.x -= movementY * 0.002 * this.pointerSpeed;
|
||||
|
||||
_euler.x = Math.max( _PI_2 - this.maxPolarAngle, Math.min( _PI_2 - this.minPolarAngle, _euler.x ) );
|
||||
|
||||
camera.quaternion.setFromEuler( _euler );
|
||||
|
||||
this.dispatchEvent( _changeEvent );
|
||||
|
||||
}
|
||||
|
||||
function onPointerlockChange() {
|
||||
|
||||
if ( this.domElement.ownerDocument.pointerLockElement === this.domElement ) {
|
||||
|
||||
this.dispatchEvent( _lockEvent );
|
||||
|
||||
this.isLocked = true;
|
||||
|
||||
} else {
|
||||
|
||||
this.dispatchEvent( _unlockEvent );
|
||||
|
||||
this.isLocked = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onPointerlockError() {
|
||||
|
||||
console.error( 'THREE.PointerLockControls: Unable to use Pointer Lock API' );
|
||||
|
||||
}
|
||||
|
||||
export { PointerLockControls };
|
828
public/sdk/three/jsm/controls/TrackballControls.js
Normal file
828
public/sdk/three/jsm/controls/TrackballControls.js
Normal file
@ -0,0 +1,828 @@
|
||||
import {
|
||||
EventDispatcher,
|
||||
MathUtils,
|
||||
MOUSE,
|
||||
Quaternion,
|
||||
Vector2,
|
||||
Vector3
|
||||
} from 'three';
|
||||
|
||||
const _changeEvent = { type: 'change' };
|
||||
const _startEvent = { type: 'start' };
|
||||
const _endEvent = { type: 'end' };
|
||||
|
||||
class TrackballControls extends EventDispatcher {
|
||||
|
||||
constructor( object, domElement ) {
|
||||
|
||||
super();
|
||||
|
||||
const scope = this;
|
||||
const STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
|
||||
|
||||
this.object = object;
|
||||
this.domElement = domElement;
|
||||
this.domElement.style.touchAction = 'none'; // disable touch scroll
|
||||
|
||||
// API
|
||||
|
||||
this.enabled = true;
|
||||
|
||||
this.screen = { left: 0, top: 0, width: 0, height: 0 };
|
||||
|
||||
this.rotateSpeed = 1.0;
|
||||
this.zoomSpeed = 1.2;
|
||||
this.panSpeed = 0.3;
|
||||
|
||||
this.noRotate = false;
|
||||
this.noZoom = false;
|
||||
this.noPan = false;
|
||||
|
||||
this.staticMoving = false;
|
||||
this.dynamicDampingFactor = 0.2;
|
||||
|
||||
this.minDistance = 0;
|
||||
this.maxDistance = Infinity;
|
||||
|
||||
this.minZoom = 0;
|
||||
this.maxZoom = Infinity;
|
||||
|
||||
this.keys = [ 'KeyA' /*A*/, 'KeyS' /*S*/, 'KeyD' /*D*/ ];
|
||||
|
||||
this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
|
||||
|
||||
// internals
|
||||
|
||||
this.target = new Vector3();
|
||||
|
||||
const EPS = 0.000001;
|
||||
|
||||
const lastPosition = new Vector3();
|
||||
let lastZoom = 1;
|
||||
|
||||
let _state = STATE.NONE,
|
||||
_keyState = STATE.NONE,
|
||||
|
||||
_touchZoomDistanceStart = 0,
|
||||
_touchZoomDistanceEnd = 0,
|
||||
|
||||
_lastAngle = 0;
|
||||
|
||||
const _eye = new Vector3(),
|
||||
|
||||
_movePrev = new Vector2(),
|
||||
_moveCurr = new Vector2(),
|
||||
|
||||
_lastAxis = new Vector3(),
|
||||
|
||||
_zoomStart = new Vector2(),
|
||||
_zoomEnd = new Vector2(),
|
||||
|
||||
_panStart = new Vector2(),
|
||||
_panEnd = new Vector2(),
|
||||
|
||||
_pointers = [],
|
||||
_pointerPositions = {};
|
||||
|
||||
// for reset
|
||||
|
||||
this.target0 = this.target.clone();
|
||||
this.position0 = this.object.position.clone();
|
||||
this.up0 = this.object.up.clone();
|
||||
this.zoom0 = this.object.zoom;
|
||||
|
||||
// methods
|
||||
|
||||
this.handleResize = function () {
|
||||
|
||||
const box = scope.domElement.getBoundingClientRect();
|
||||
// adjustments come from similar code in the jquery offset() function
|
||||
const d = scope.domElement.ownerDocument.documentElement;
|
||||
scope.screen.left = box.left + window.pageXOffset - d.clientLeft;
|
||||
scope.screen.top = box.top + window.pageYOffset - d.clientTop;
|
||||
scope.screen.width = box.width;
|
||||
scope.screen.height = box.height;
|
||||
|
||||
};
|
||||
|
||||
const getMouseOnScreen = ( function () {
|
||||
|
||||
const vector = new Vector2();
|
||||
|
||||
return function getMouseOnScreen( pageX, pageY ) {
|
||||
|
||||
vector.set(
|
||||
( pageX - scope.screen.left ) / scope.screen.width,
|
||||
( pageY - scope.screen.top ) / scope.screen.height
|
||||
);
|
||||
|
||||
return vector;
|
||||
|
||||
};
|
||||
|
||||
}() );
|
||||
|
||||
const getMouseOnCircle = ( function () {
|
||||
|
||||
const vector = new Vector2();
|
||||
|
||||
return function getMouseOnCircle( pageX, pageY ) {
|
||||
|
||||
vector.set(
|
||||
( ( pageX - scope.screen.width * 0.5 - scope.screen.left ) / ( scope.screen.width * 0.5 ) ),
|
||||
( ( scope.screen.height + 2 * ( scope.screen.top - pageY ) ) / scope.screen.width ) // screen.width intentional
|
||||
);
|
||||
|
||||
return vector;
|
||||
|
||||
};
|
||||
|
||||
}() );
|
||||
|
||||
this.rotateCamera = ( function () {
|
||||
|
||||
const axis = new Vector3(),
|
||||
quaternion = new Quaternion(),
|
||||
eyeDirection = new Vector3(),
|
||||
objectUpDirection = new Vector3(),
|
||||
objectSidewaysDirection = new Vector3(),
|
||||
moveDirection = new Vector3();
|
||||
|
||||
return function rotateCamera() {
|
||||
|
||||
moveDirection.set( _moveCurr.x - _movePrev.x, _moveCurr.y - _movePrev.y, 0 );
|
||||
let angle = moveDirection.length();
|
||||
|
||||
if ( angle ) {
|
||||
|
||||
_eye.copy( scope.object.position ).sub( scope.target );
|
||||
|
||||
eyeDirection.copy( _eye ).normalize();
|
||||
objectUpDirection.copy( scope.object.up ).normalize();
|
||||
objectSidewaysDirection.crossVectors( objectUpDirection, eyeDirection ).normalize();
|
||||
|
||||
objectUpDirection.setLength( _moveCurr.y - _movePrev.y );
|
||||
objectSidewaysDirection.setLength( _moveCurr.x - _movePrev.x );
|
||||
|
||||
moveDirection.copy( objectUpDirection.add( objectSidewaysDirection ) );
|
||||
|
||||
axis.crossVectors( moveDirection, _eye ).normalize();
|
||||
|
||||
angle *= scope.rotateSpeed;
|
||||
quaternion.setFromAxisAngle( axis, angle );
|
||||
|
||||
_eye.applyQuaternion( quaternion );
|
||||
scope.object.up.applyQuaternion( quaternion );
|
||||
|
||||
_lastAxis.copy( axis );
|
||||
_lastAngle = angle;
|
||||
|
||||
} else if ( ! scope.staticMoving && _lastAngle ) {
|
||||
|
||||
_lastAngle *= Math.sqrt( 1.0 - scope.dynamicDampingFactor );
|
||||
_eye.copy( scope.object.position ).sub( scope.target );
|
||||
quaternion.setFromAxisAngle( _lastAxis, _lastAngle );
|
||||
_eye.applyQuaternion( quaternion );
|
||||
scope.object.up.applyQuaternion( quaternion );
|
||||
|
||||
}
|
||||
|
||||
_movePrev.copy( _moveCurr );
|
||||
|
||||
};
|
||||
|
||||
}() );
|
||||
|
||||
|
||||
this.zoomCamera = function () {
|
||||
|
||||
let factor;
|
||||
|
||||
if ( _state === STATE.TOUCH_ZOOM_PAN ) {
|
||||
|
||||
factor = _touchZoomDistanceStart / _touchZoomDistanceEnd;
|
||||
_touchZoomDistanceStart = _touchZoomDistanceEnd;
|
||||
|
||||
if ( scope.object.isPerspectiveCamera ) {
|
||||
|
||||
_eye.multiplyScalar( factor );
|
||||
|
||||
} else if ( scope.object.isOrthographicCamera ) {
|
||||
|
||||
scope.object.zoom = MathUtils.clamp( scope.object.zoom / factor, scope.minZoom, scope.maxZoom );
|
||||
|
||||
if ( lastZoom !== scope.object.zoom ) {
|
||||
|
||||
scope.object.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
console.warn( 'THREE.TrackballControls: Unsupported camera type' );
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
factor = 1.0 + ( _zoomEnd.y - _zoomStart.y ) * scope.zoomSpeed;
|
||||
|
||||
if ( factor !== 1.0 && factor > 0.0 ) {
|
||||
|
||||
if ( scope.object.isPerspectiveCamera ) {
|
||||
|
||||
_eye.multiplyScalar( factor );
|
||||
|
||||
} else if ( scope.object.isOrthographicCamera ) {
|
||||
|
||||
scope.object.zoom = MathUtils.clamp( scope.object.zoom / factor, scope.minZoom, scope.maxZoom );
|
||||
|
||||
if ( lastZoom !== scope.object.zoom ) {
|
||||
|
||||
scope.object.updateProjectionMatrix();
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
console.warn( 'THREE.TrackballControls: Unsupported camera type' );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( scope.staticMoving ) {
|
||||
|
||||
_zoomStart.copy( _zoomEnd );
|
||||
|
||||
} else {
|
||||
|
||||
_zoomStart.y += ( _zoomEnd.y - _zoomStart.y ) * this.dynamicDampingFactor;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.panCamera = ( function () {
|
||||
|
||||
const mouseChange = new Vector2(),
|
||||
objectUp = new Vector3(),
|
||||
pan = new Vector3();
|
||||
|
||||
return function panCamera() {
|
||||
|
||||
mouseChange.copy( _panEnd ).sub( _panStart );
|
||||
|
||||
if ( mouseChange.lengthSq() ) {
|
||||
|
||||
if ( scope.object.isOrthographicCamera ) {
|
||||
|
||||
const scale_x = ( scope.object.right - scope.object.left ) / scope.object.zoom / scope.domElement.clientWidth;
|
||||
const scale_y = ( scope.object.top - scope.object.bottom ) / scope.object.zoom / scope.domElement.clientWidth;
|
||||
|
||||
mouseChange.x *= scale_x;
|
||||
mouseChange.y *= scale_y;
|
||||
|
||||
}
|
||||
|
||||
mouseChange.multiplyScalar( _eye.length() * scope.panSpeed );
|
||||
|
||||
pan.copy( _eye ).cross( scope.object.up ).setLength( mouseChange.x );
|
||||
pan.add( objectUp.copy( scope.object.up ).setLength( mouseChange.y ) );
|
||||
|
||||
scope.object.position.add( pan );
|
||||
scope.target.add( pan );
|
||||
|
||||
if ( scope.staticMoving ) {
|
||||
|
||||
_panStart.copy( _panEnd );
|
||||
|
||||
} else {
|
||||
|
||||
_panStart.add( mouseChange.subVectors( _panEnd, _panStart ).multiplyScalar( scope.dynamicDampingFactor ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}() );
|
||||
|
||||
this.checkDistances = function () {
|
||||
|
||||
if ( ! scope.noZoom || ! scope.noPan ) {
|
||||
|
||||
if ( _eye.lengthSq() > scope.maxDistance * scope.maxDistance ) {
|
||||
|
||||
scope.object.position.addVectors( scope.target, _eye.setLength( scope.maxDistance ) );
|
||||
_zoomStart.copy( _zoomEnd );
|
||||
|
||||
}
|
||||
|
||||
if ( _eye.lengthSq() < scope.minDistance * scope.minDistance ) {
|
||||
|
||||
scope.object.position.addVectors( scope.target, _eye.setLength( scope.minDistance ) );
|
||||
_zoomStart.copy( _zoomEnd );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.update = function () {
|
||||
|
||||
_eye.subVectors( scope.object.position, scope.target );
|
||||
|
||||
if ( ! scope.noRotate ) {
|
||||
|
||||
scope.rotateCamera();
|
||||
|
||||
}
|
||||
|
||||
if ( ! scope.noZoom ) {
|
||||
|
||||
scope.zoomCamera();
|
||||
|
||||
}
|
||||
|
||||
if ( ! scope.noPan ) {
|
||||
|
||||
scope.panCamera();
|
||||
|
||||
}
|
||||
|
||||
scope.object.position.addVectors( scope.target, _eye );
|
||||
|
||||
if ( scope.object.isPerspectiveCamera ) {
|
||||
|
||||
scope.checkDistances();
|
||||
|
||||
scope.object.lookAt( scope.target );
|
||||
|
||||
if ( lastPosition.distanceToSquared( scope.object.position ) > EPS ) {
|
||||
|
||||
scope.dispatchEvent( _changeEvent );
|
||||
|
||||
lastPosition.copy( scope.object.position );
|
||||
|
||||
}
|
||||
|
||||
} else if ( scope.object.isOrthographicCamera ) {
|
||||
|
||||
scope.object.lookAt( scope.target );
|
||||
|
||||
if ( lastPosition.distanceToSquared( scope.object.position ) > EPS || lastZoom !== scope.object.zoom ) {
|
||||
|
||||
scope.dispatchEvent( _changeEvent );
|
||||
|
||||
lastPosition.copy( scope.object.position );
|
||||
lastZoom = scope.object.zoom;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
console.warn( 'THREE.TrackballControls: Unsupported camera type' );
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.reset = function () {
|
||||
|
||||
_state = STATE.NONE;
|
||||
_keyState = STATE.NONE;
|
||||
|
||||
scope.target.copy( scope.target0 );
|
||||
scope.object.position.copy( scope.position0 );
|
||||
scope.object.up.copy( scope.up0 );
|
||||
scope.object.zoom = scope.zoom0;
|
||||
|
||||
scope.object.updateProjectionMatrix();
|
||||
|
||||
_eye.subVectors( scope.object.position, scope.target );
|
||||
|
||||
scope.object.lookAt( scope.target );
|
||||
|
||||
scope.dispatchEvent( _changeEvent );
|
||||
|
||||
lastPosition.copy( scope.object.position );
|
||||
lastZoom = scope.object.zoom;
|
||||
|
||||
};
|
||||
|
||||
// listeners
|
||||
|
||||
function onPointerDown( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
if ( _pointers.length === 0 ) {
|
||||
|
||||
scope.domElement.setPointerCapture( event.pointerId );
|
||||
|
||||
scope.domElement.addEventListener( 'pointermove', onPointerMove );
|
||||
scope.domElement.addEventListener( 'pointerup', onPointerUp );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
addPointer( event );
|
||||
|
||||
if ( event.pointerType === 'touch' ) {
|
||||
|
||||
onTouchStart( event );
|
||||
|
||||
} else {
|
||||
|
||||
onMouseDown( event );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onPointerMove( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
if ( event.pointerType === 'touch' ) {
|
||||
|
||||
onTouchMove( event );
|
||||
|
||||
} else {
|
||||
|
||||
onMouseMove( event );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onPointerUp( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
if ( event.pointerType === 'touch' ) {
|
||||
|
||||
onTouchEnd( event );
|
||||
|
||||
} else {
|
||||
|
||||
onMouseUp();
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
removePointer( event );
|
||||
|
||||
if ( _pointers.length === 0 ) {
|
||||
|
||||
scope.domElement.releasePointerCapture( event.pointerId );
|
||||
|
||||
scope.domElement.removeEventListener( 'pointermove', onPointerMove );
|
||||
scope.domElement.removeEventListener( 'pointerup', onPointerUp );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function onPointerCancel( event ) {
|
||||
|
||||
removePointer( event );
|
||||
|
||||
}
|
||||
|
||||
function keydown( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
window.removeEventListener( 'keydown', keydown );
|
||||
|
||||
if ( _keyState !== STATE.NONE ) {
|
||||
|
||||
return;
|
||||
|
||||
} else if ( event.code === scope.keys[ STATE.ROTATE ] && ! scope.noRotate ) {
|
||||
|
||||
_keyState = STATE.ROTATE;
|
||||
|
||||
} else if ( event.code === scope.keys[ STATE.ZOOM ] && ! scope.noZoom ) {
|
||||
|
||||
_keyState = STATE.ZOOM;
|
||||
|
||||
} else if ( event.code === scope.keys[ STATE.PAN ] && ! scope.noPan ) {
|
||||
|
||||
_keyState = STATE.PAN;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function keyup() {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
_keyState = STATE.NONE;
|
||||
|
||||
window.addEventListener( 'keydown', keydown );
|
||||
|
||||
}
|
||||
|
||||
function onMouseDown( event ) {
|
||||
|
||||
if ( _state === STATE.NONE ) {
|
||||
|
||||
switch ( event.button ) {
|
||||
|
||||
case scope.mouseButtons.LEFT:
|
||||
_state = STATE.ROTATE;
|
||||
break;
|
||||
|
||||
case scope.mouseButtons.MIDDLE:
|
||||
_state = STATE.ZOOM;
|
||||
break;
|
||||
|
||||
case scope.mouseButtons.RIGHT:
|
||||
_state = STATE.PAN;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const state = ( _keyState !== STATE.NONE ) ? _keyState : _state;
|
||||
|
||||
if ( state === STATE.ROTATE && ! scope.noRotate ) {
|
||||
|
||||
_moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
|
||||
_movePrev.copy( _moveCurr );
|
||||
|
||||
} else if ( state === STATE.ZOOM && ! scope.noZoom ) {
|
||||
|
||||
_zoomStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
|
||||
_zoomEnd.copy( _zoomStart );
|
||||
|
||||
} else if ( state === STATE.PAN && ! scope.noPan ) {
|
||||
|
||||
_panStart.copy( getMouseOnScreen( event.pageX, event.pageY ) );
|
||||
_panEnd.copy( _panStart );
|
||||
|
||||
}
|
||||
|
||||
scope.dispatchEvent( _startEvent );
|
||||
|
||||
}
|
||||
|
||||
function onMouseMove( event ) {
|
||||
|
||||
const state = ( _keyState !== STATE.NONE ) ? _keyState : _state;
|
||||
|
||||
if ( state === STATE.ROTATE && ! scope.noRotate ) {
|
||||
|
||||
_movePrev.copy( _moveCurr );
|
||||
_moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
|
||||
|
||||
} else if ( state === STATE.ZOOM && ! scope.noZoom ) {
|
||||
|
||||
_zoomEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
|
||||
|
||||
} else if ( state === STATE.PAN && ! scope.noPan ) {
|
||||
|
||||
_panEnd.copy( getMouseOnScreen( event.pageX, event.pageY ) );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onMouseUp() {
|
||||
|
||||
_state = STATE.NONE;
|
||||
|
||||
scope.dispatchEvent( _endEvent );
|
||||
|
||||
}
|
||||
|
||||
function onMouseWheel( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
if ( scope.noZoom === true ) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
switch ( event.deltaMode ) {
|
||||
|
||||
case 2:
|
||||
// Zoom in pages
|
||||
_zoomStart.y -= event.deltaY * 0.025;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
// Zoom in lines
|
||||
_zoomStart.y -= event.deltaY * 0.01;
|
||||
break;
|
||||
|
||||
default:
|
||||
// undefined, 0, assume pixels
|
||||
_zoomStart.y -= event.deltaY * 0.00025;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
scope.dispatchEvent( _startEvent );
|
||||
scope.dispatchEvent( _endEvent );
|
||||
|
||||
}
|
||||
|
||||
function onTouchStart( event ) {
|
||||
|
||||
trackPointer( event );
|
||||
|
||||
switch ( _pointers.length ) {
|
||||
|
||||
case 1:
|
||||
_state = STATE.TOUCH_ROTATE;
|
||||
_moveCurr.copy( getMouseOnCircle( _pointers[ 0 ].pageX, _pointers[ 0 ].pageY ) );
|
||||
_movePrev.copy( _moveCurr );
|
||||
break;
|
||||
|
||||
default: // 2 or more
|
||||
_state = STATE.TOUCH_ZOOM_PAN;
|
||||
const dx = _pointers[ 0 ].pageX - _pointers[ 1 ].pageX;
|
||||
const dy = _pointers[ 0 ].pageY - _pointers[ 1 ].pageY;
|
||||
_touchZoomDistanceEnd = _touchZoomDistanceStart = Math.sqrt( dx * dx + dy * dy );
|
||||
|
||||
const x = ( _pointers[ 0 ].pageX + _pointers[ 1 ].pageX ) / 2;
|
||||
const y = ( _pointers[ 0 ].pageY + _pointers[ 1 ].pageY ) / 2;
|
||||
_panStart.copy( getMouseOnScreen( x, y ) );
|
||||
_panEnd.copy( _panStart );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
scope.dispatchEvent( _startEvent );
|
||||
|
||||
}
|
||||
|
||||
function onTouchMove( event ) {
|
||||
|
||||
trackPointer( event );
|
||||
|
||||
switch ( _pointers.length ) {
|
||||
|
||||
case 1:
|
||||
_movePrev.copy( _moveCurr );
|
||||
_moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
|
||||
break;
|
||||
|
||||
default: // 2 or more
|
||||
|
||||
const position = getSecondPointerPosition( event );
|
||||
|
||||
const dx = event.pageX - position.x;
|
||||
const dy = event.pageY - position.y;
|
||||
_touchZoomDistanceEnd = Math.sqrt( dx * dx + dy * dy );
|
||||
|
||||
const x = ( event.pageX + position.x ) / 2;
|
||||
const y = ( event.pageY + position.y ) / 2;
|
||||
_panEnd.copy( getMouseOnScreen( x, y ) );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onTouchEnd( event ) {
|
||||
|
||||
switch ( _pointers.length ) {
|
||||
|
||||
case 0:
|
||||
_state = STATE.NONE;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
_state = STATE.TOUCH_ROTATE;
|
||||
_moveCurr.copy( getMouseOnCircle( event.pageX, event.pageY ) );
|
||||
_movePrev.copy( _moveCurr );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
_state = STATE.TOUCH_ZOOM_PAN;
|
||||
|
||||
for ( let i = 0; i < _pointers.length; i ++ ) {
|
||||
|
||||
if ( _pointers[ i ].pointerId !== event.pointerId ) {
|
||||
|
||||
const position = _pointerPositions[ _pointers[ i ].pointerId ];
|
||||
_moveCurr.copy( getMouseOnCircle( position.x, position.y ) );
|
||||
_movePrev.copy( _moveCurr );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
scope.dispatchEvent( _endEvent );
|
||||
|
||||
}
|
||||
|
||||
function contextmenu( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
}
|
||||
|
||||
function addPointer( event ) {
|
||||
|
||||
_pointers.push( event );
|
||||
|
||||
}
|
||||
|
||||
function removePointer( event ) {
|
||||
|
||||
delete _pointerPositions[ event.pointerId ];
|
||||
|
||||
for ( let i = 0; i < _pointers.length; i ++ ) {
|
||||
|
||||
if ( _pointers[ i ].pointerId == event.pointerId ) {
|
||||
|
||||
_pointers.splice( i, 1 );
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function trackPointer( event ) {
|
||||
|
||||
let position = _pointerPositions[ event.pointerId ];
|
||||
|
||||
if ( position === undefined ) {
|
||||
|
||||
position = new Vector2();
|
||||
_pointerPositions[ event.pointerId ] = position;
|
||||
|
||||
}
|
||||
|
||||
position.set( event.pageX, event.pageY );
|
||||
|
||||
}
|
||||
|
||||
function getSecondPointerPosition( event ) {
|
||||
|
||||
const pointer = ( event.pointerId === _pointers[ 0 ].pointerId ) ? _pointers[ 1 ] : _pointers[ 0 ];
|
||||
|
||||
return _pointerPositions[ pointer.pointerId ];
|
||||
|
||||
}
|
||||
|
||||
this.dispose = function () {
|
||||
|
||||
scope.domElement.removeEventListener( 'contextmenu', contextmenu );
|
||||
|
||||
scope.domElement.removeEventListener( 'pointerdown', onPointerDown );
|
||||
scope.domElement.removeEventListener( 'pointercancel', onPointerCancel );
|
||||
scope.domElement.removeEventListener( 'wheel', onMouseWheel );
|
||||
|
||||
scope.domElement.removeEventListener( 'pointermove', onPointerMove );
|
||||
scope.domElement.removeEventListener( 'pointerup', onPointerUp );
|
||||
|
||||
window.removeEventListener( 'keydown', keydown );
|
||||
window.removeEventListener( 'keyup', keyup );
|
||||
|
||||
};
|
||||
|
||||
this.domElement.addEventListener( 'contextmenu', contextmenu );
|
||||
|
||||
this.domElement.addEventListener( 'pointerdown', onPointerDown );
|
||||
this.domElement.addEventListener( 'pointercancel', onPointerCancel );
|
||||
this.domElement.addEventListener( 'wheel', onMouseWheel, { passive: false } );
|
||||
|
||||
|
||||
window.addEventListener( 'keydown', keydown );
|
||||
window.addEventListener( 'keyup', keyup );
|
||||
|
||||
this.handleResize();
|
||||
|
||||
// force an update at start
|
||||
this.update();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { TrackballControls };
|
1573
public/sdk/three/jsm/controls/TransformControls.js
Normal file
1573
public/sdk/three/jsm/controls/TransformControls.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user