mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 10:49:36 +02:00
This commit is contained in:
parent
f0f62670c5
commit
7e26256cac
4563 changed files with 1246712 additions and 17558 deletions
149
node_modules/three/examples/js/controls/DeviceOrientationControls.js
generated
vendored
Normal file
149
node_modules/three/examples/js/controls/DeviceOrientationControls.js
generated
vendored
Normal file
|
@ -0,0 +1,149 @@
|
|||
/**
|
||||
* W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
|
||||
*/
|
||||
|
||||
THREE.DeviceOrientationControls = function ( object ) {
|
||||
|
||||
var scope = this;
|
||||
var changeEvent = { type: 'change' };
|
||||
var EPS = 0.000001;
|
||||
|
||||
this.object = object;
|
||||
this.object.rotation.reorder( 'YXZ' );
|
||||
|
||||
this.enabled = true;
|
||||
|
||||
this.deviceOrientation = {};
|
||||
this.screenOrientation = 0;
|
||||
|
||||
this.alphaOffset = 0; // radians
|
||||
|
||||
var onDeviceOrientationChangeEvent = function ( event ) {
|
||||
|
||||
scope.deviceOrientation = event;
|
||||
|
||||
};
|
||||
|
||||
var onScreenOrientationChangeEvent = function () {
|
||||
|
||||
scope.screenOrientation = window.orientation || 0;
|
||||
|
||||
};
|
||||
|
||||
// The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''
|
||||
|
||||
var setObjectQuaternion = function () {
|
||||
|
||||
var zee = new THREE.Vector3( 0, 0, 1 );
|
||||
|
||||
var euler = new THREE.Euler();
|
||||
|
||||
var q0 = new THREE.Quaternion();
|
||||
|
||||
var q1 = new THREE.Quaternion( - Math.sqrt( 0.5 ), 0, 0, Math.sqrt( 0.5 ) ); // - PI/2 around the x-axis
|
||||
|
||||
return function ( quaternion, alpha, beta, gamma, orient ) {
|
||||
|
||||
euler.set( beta, alpha, - gamma, 'YXZ' ); // 'ZXY' for the device, but 'YXZ' for us
|
||||
|
||||
quaternion.setFromEuler( euler ); // orient the device
|
||||
|
||||
quaternion.multiply( q1 ); // camera looks out the back of the device, not the top
|
||||
|
||||
quaternion.multiply( q0.setFromAxisAngle( zee, - orient ) ); // adjust for screen orientation
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
this.connect = function () {
|
||||
|
||||
onScreenOrientationChangeEvent(); // run once on load
|
||||
|
||||
// iOS 13+
|
||||
|
||||
if ( window.DeviceOrientationEvent !== undefined && typeof window.DeviceOrientationEvent.requestPermission === 'function' ) {
|
||||
|
||||
window.DeviceOrientationEvent.requestPermission().then( function ( response ) {
|
||||
|
||||
if ( response == 'granted' ) {
|
||||
|
||||
window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent );
|
||||
window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent );
|
||||
|
||||
}
|
||||
|
||||
} ).catch( function ( error ) {
|
||||
|
||||
console.error( 'THREE.DeviceOrientationControls: Unable to use DeviceOrientation API:', error );
|
||||
|
||||
} );
|
||||
|
||||
} else {
|
||||
|
||||
window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent );
|
||||
window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent );
|
||||
|
||||
}
|
||||
|
||||
scope.enabled = true;
|
||||
|
||||
};
|
||||
|
||||
this.disconnect = function () {
|
||||
|
||||
window.removeEventListener( 'orientationchange', onScreenOrientationChangeEvent );
|
||||
window.removeEventListener( 'deviceorientation', onDeviceOrientationChangeEvent );
|
||||
|
||||
scope.enabled = false;
|
||||
|
||||
};
|
||||
|
||||
this.update = ( function () {
|
||||
|
||||
var lastQuaternion = new THREE.Quaternion();
|
||||
|
||||
return function () {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
var device = scope.deviceOrientation;
|
||||
|
||||
if ( device ) {
|
||||
|
||||
var alpha = device.alpha ? THREE.MathUtils.degToRad( device.alpha ) + scope.alphaOffset : 0; // Z
|
||||
|
||||
var beta = device.beta ? THREE.MathUtils.degToRad( device.beta ) : 0; // X'
|
||||
|
||||
var gamma = device.gamma ? THREE.MathUtils.degToRad( device.gamma ) : 0; // Y''
|
||||
|
||||
var orient = scope.screenOrientation ? THREE.MathUtils.degToRad( scope.screenOrientation ) : 0; // O
|
||||
|
||||
setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient );
|
||||
|
||||
if ( 8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
|
||||
|
||||
lastQuaternion.copy( scope.object.quaternion );
|
||||
scope.dispatchEvent( changeEvent );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
} )();
|
||||
|
||||
this.dispose = function () {
|
||||
|
||||
scope.disconnect();
|
||||
|
||||
};
|
||||
|
||||
this.connect();
|
||||
|
||||
};
|
||||
|
||||
THREE.DeviceOrientationControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
THREE.DeviceOrientationControls.prototype.constructor = THREE.DeviceOrientationControls;
|
307
node_modules/three/examples/js/controls/DragControls.js
generated
vendored
Normal file
307
node_modules/three/examples/js/controls/DragControls.js
generated
vendored
Normal file
|
@ -0,0 +1,307 @@
|
|||
THREE.DragControls = function ( _objects, _camera, _domElement ) {
|
||||
|
||||
var _plane = new THREE.Plane();
|
||||
var _raycaster = new THREE.Raycaster();
|
||||
|
||||
var _mouse = new THREE.Vector2();
|
||||
var _offset = new THREE.Vector3();
|
||||
var _intersection = new THREE.Vector3();
|
||||
var _worldPosition = new THREE.Vector3();
|
||||
var _inverseMatrix = new THREE.Matrix4();
|
||||
var _intersections = [];
|
||||
|
||||
var _selected = null, _hovered = null;
|
||||
|
||||
//
|
||||
|
||||
var scope = this;
|
||||
|
||||
function activate() {
|
||||
|
||||
_domElement.addEventListener( 'pointermove', onPointerMove );
|
||||
_domElement.addEventListener( 'pointerdown', onPointerDown );
|
||||
_domElement.addEventListener( 'pointerup', onPointerCancel );
|
||||
_domElement.addEventListener( 'pointerleave', onPointerCancel );
|
||||
_domElement.addEventListener( 'touchmove', onTouchMove );
|
||||
_domElement.addEventListener( 'touchstart', onTouchStart );
|
||||
_domElement.addEventListener( 'touchend', onTouchEnd );
|
||||
|
||||
}
|
||||
|
||||
function deactivate() {
|
||||
|
||||
_domElement.removeEventListener( 'pointermove', onPointerMove );
|
||||
_domElement.removeEventListener( 'pointerdown', onPointerDown );
|
||||
_domElement.removeEventListener( 'pointerup', onPointerCancel );
|
||||
_domElement.removeEventListener( 'pointerleave', onPointerCancel );
|
||||
_domElement.removeEventListener( 'touchmove', onTouchMove );
|
||||
_domElement.removeEventListener( 'touchstart', onTouchStart );
|
||||
_domElement.removeEventListener( 'touchend', onTouchEnd );
|
||||
|
||||
_domElement.style.cursor = '';
|
||||
|
||||
}
|
||||
|
||||
function dispose() {
|
||||
|
||||
deactivate();
|
||||
|
||||
}
|
||||
|
||||
function getObjects() {
|
||||
|
||||
return _objects;
|
||||
|
||||
}
|
||||
|
||||
function onPointerMove( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
switch ( event.pointerType ) {
|
||||
|
||||
case 'mouse':
|
||||
case 'pen':
|
||||
onMouseMove( event );
|
||||
break;
|
||||
|
||||
// TODO touch
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onMouseMove( event ) {
|
||||
|
||||
var rect = _domElement.getBoundingClientRect();
|
||||
|
||||
_mouse.x = ( ( event.clientX - rect.left ) / rect.width ) * 2 - 1;
|
||||
_mouse.y = - ( ( event.clientY - rect.top ) / rect.height ) * 2 + 1;
|
||||
|
||||
_raycaster.setFromCamera( _mouse, _camera );
|
||||
|
||||
if ( _selected && scope.enabled ) {
|
||||
|
||||
if ( _raycaster.ray.intersectPlane( _plane, _intersection ) ) {
|
||||
|
||||
_selected.position.copy( _intersection.sub( _offset ).applyMatrix4( _inverseMatrix ) );
|
||||
|
||||
}
|
||||
|
||||
scope.dispatchEvent( { type: 'drag', object: _selected } );
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
_intersections.length = 0;
|
||||
|
||||
_raycaster.setFromCamera( _mouse, _camera );
|
||||
_raycaster.intersectObjects( _objects, true, _intersections );
|
||||
|
||||
if ( _intersections.length > 0 ) {
|
||||
|
||||
var object = _intersections[ 0 ].object;
|
||||
|
||||
_plane.setFromNormalAndCoplanarPoint( _camera.getWorldDirection( _plane.normal ), _worldPosition.setFromMatrixPosition( object.matrixWorld ) );
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onPointerDown( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
switch ( event.pointerType ) {
|
||||
|
||||
case 'mouse':
|
||||
case 'pen':
|
||||
onMouseDown( event );
|
||||
break;
|
||||
|
||||
// TODO touch
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onMouseDown( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
_intersections.length = 0;
|
||||
|
||||
_raycaster.setFromCamera( _mouse, _camera );
|
||||
_raycaster.intersectObjects( _objects, true, _intersections );
|
||||
|
||||
if ( _intersections.length > 0 ) {
|
||||
|
||||
_selected = ( scope.transformGroup === true ) ? _objects[ 0 ] : _intersections[ 0 ].object;
|
||||
|
||||
if ( _raycaster.ray.intersectPlane( _plane, _intersection ) ) {
|
||||
|
||||
_inverseMatrix.copy( _selected.parent.matrixWorld ).invert();
|
||||
_offset.copy( _intersection ).sub( _worldPosition.setFromMatrixPosition( _selected.matrixWorld ) );
|
||||
|
||||
}
|
||||
|
||||
_domElement.style.cursor = 'move';
|
||||
|
||||
scope.dispatchEvent( { type: 'dragstart', object: _selected } );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function onPointerCancel( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
switch ( event.pointerType ) {
|
||||
|
||||
case 'mouse':
|
||||
case 'pen':
|
||||
onMouseCancel( event );
|
||||
break;
|
||||
|
||||
// TODO touch
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onMouseCancel( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if ( _selected ) {
|
||||
|
||||
scope.dispatchEvent( { type: 'dragend', object: _selected } );
|
||||
|
||||
_selected = null;
|
||||
|
||||
}
|
||||
|
||||
_domElement.style.cursor = _hovered ? 'pointer' : 'auto';
|
||||
|
||||
}
|
||||
|
||||
function onTouchMove( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
event = event.changedTouches[ 0 ];
|
||||
|
||||
var rect = _domElement.getBoundingClientRect();
|
||||
|
||||
_mouse.x = ( ( event.clientX - rect.left ) / rect.width ) * 2 - 1;
|
||||
_mouse.y = - ( ( event.clientY - rect.top ) / rect.height ) * 2 + 1;
|
||||
|
||||
_raycaster.setFromCamera( _mouse, _camera );
|
||||
|
||||
if ( _selected && scope.enabled ) {
|
||||
|
||||
if ( _raycaster.ray.intersectPlane( _plane, _intersection ) ) {
|
||||
|
||||
_selected.position.copy( _intersection.sub( _offset ).applyMatrix4( _inverseMatrix ) );
|
||||
|
||||
}
|
||||
|
||||
scope.dispatchEvent( { type: 'drag', object: _selected } );
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onTouchStart( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
event = event.changedTouches[ 0 ];
|
||||
|
||||
var rect = _domElement.getBoundingClientRect();
|
||||
|
||||
_mouse.x = ( ( event.clientX - rect.left ) / rect.width ) * 2 - 1;
|
||||
_mouse.y = - ( ( event.clientY - rect.top ) / rect.height ) * 2 + 1;
|
||||
|
||||
_intersections.length = 0;
|
||||
|
||||
_raycaster.setFromCamera( _mouse, _camera );
|
||||
_raycaster.intersectObjects( _objects, true, _intersections );
|
||||
|
||||
if ( _intersections.length > 0 ) {
|
||||
|
||||
_selected = ( scope.transformGroup === true ) ? _objects[ 0 ] : _intersections[ 0 ].object;
|
||||
|
||||
_plane.setFromNormalAndCoplanarPoint( _camera.getWorldDirection( _plane.normal ), _worldPosition.setFromMatrixPosition( _selected.matrixWorld ) );
|
||||
|
||||
if ( _raycaster.ray.intersectPlane( _plane, _intersection ) ) {
|
||||
|
||||
_inverseMatrix.copy( _selected.parent.matrixWorld ).invert();
|
||||
_offset.copy( _intersection ).sub( _worldPosition.setFromMatrixPosition( _selected.matrixWorld ) );
|
||||
|
||||
}
|
||||
|
||||
_domElement.style.cursor = 'move';
|
||||
|
||||
scope.dispatchEvent( { type: 'dragstart', object: _selected } );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
function onTouchEnd( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
if ( _selected ) {
|
||||
|
||||
scope.dispatchEvent( { type: 'dragend', object: _selected } );
|
||||
|
||||
_selected = null;
|
||||
|
||||
}
|
||||
|
||||
_domElement.style.cursor = 'auto';
|
||||
|
||||
}
|
||||
|
||||
activate();
|
||||
|
||||
// API
|
||||
|
||||
this.enabled = true;
|
||||
this.transformGroup = false;
|
||||
|
||||
this.activate = activate;
|
||||
this.deactivate = deactivate;
|
||||
this.dispose = dispose;
|
||||
this.getObjects = getObjects;
|
||||
|
||||
};
|
||||
|
||||
THREE.DragControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
THREE.DragControls.prototype.constructor = THREE.DragControls;
|
346
node_modules/three/examples/js/controls/FirstPersonControls.js
generated
vendored
Normal file
346
node_modules/three/examples/js/controls/FirstPersonControls.js
generated
vendored
Normal file
|
@ -0,0 +1,346 @@
|
|||
THREE.FirstPersonControls = function ( object, domElement ) {
|
||||
|
||||
if ( domElement === undefined ) {
|
||||
|
||||
console.warn( 'THREE.FirstPersonControls: The second parameter "domElement" is now mandatory.' );
|
||||
domElement = document;
|
||||
|
||||
}
|
||||
|
||||
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.mouseX = 0;
|
||||
this.mouseY = 0;
|
||||
|
||||
this.moveForward = false;
|
||||
this.moveBackward = false;
|
||||
this.moveLeft = false;
|
||||
this.moveRight = false;
|
||||
|
||||
this.viewHalfX = 0;
|
||||
this.viewHalfY = 0;
|
||||
|
||||
// private variables
|
||||
|
||||
var lat = 0;
|
||||
var lon = 0;
|
||||
|
||||
var lookDirection = new THREE.Vector3();
|
||||
var spherical = new THREE.Spherical();
|
||||
var target = new THREE.Vector3();
|
||||
|
||||
//
|
||||
|
||||
if ( this.domElement !== document ) {
|
||||
|
||||
this.domElement.setAttribute( 'tabindex', - 1 );
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
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.onMouseDown = function ( event ) {
|
||||
|
||||
if ( this.domElement !== document ) {
|
||||
|
||||
this.domElement.focus();
|
||||
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if ( this.activeLook ) {
|
||||
|
||||
switch ( event.button ) {
|
||||
|
||||
case 0: this.moveForward = true; break;
|
||||
case 2: this.moveBackward = true; break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.mouseDragOn = true;
|
||||
|
||||
};
|
||||
|
||||
this.onMouseUp = function ( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if ( this.activeLook ) {
|
||||
|
||||
switch ( event.button ) {
|
||||
|
||||
case 0: this.moveForward = false; break;
|
||||
case 2: this.moveBackward = false; break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.mouseDragOn = false;
|
||||
|
||||
};
|
||||
|
||||
this.onMouseMove = function ( event ) {
|
||||
|
||||
if ( this.domElement === document ) {
|
||||
|
||||
this.mouseX = event.pageX - this.viewHalfX;
|
||||
this.mouseY = event.pageY - this.viewHalfY;
|
||||
|
||||
} else {
|
||||
|
||||
this.mouseX = event.pageX - this.domElement.offsetLeft - this.viewHalfX;
|
||||
this.mouseY = event.pageY - this.domElement.offsetTop - this.viewHalfY;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.onKeyDown = function ( event ) {
|
||||
|
||||
//event.preventDefault();
|
||||
|
||||
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 () {
|
||||
|
||||
var targetPosition = new THREE.Vector3();
|
||||
|
||||
return function update( delta ) {
|
||||
|
||||
if ( this.enabled === false ) return;
|
||||
|
||||
if ( this.heightSpeed ) {
|
||||
|
||||
var y = THREE.MathUtils.clamp( this.object.position.y, this.heightMin, this.heightMax );
|
||||
var heightDelta = y - this.heightMin;
|
||||
|
||||
this.autoSpeedFactor = delta * ( heightDelta * this.heightCoef );
|
||||
|
||||
} else {
|
||||
|
||||
this.autoSpeedFactor = 0.0;
|
||||
|
||||
}
|
||||
|
||||
var 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 );
|
||||
|
||||
var actualLookSpeed = delta * this.lookSpeed;
|
||||
|
||||
if ( ! this.activeLook ) {
|
||||
|
||||
actualLookSpeed = 0;
|
||||
|
||||
}
|
||||
|
||||
var verticalLookRatio = 1;
|
||||
|
||||
if ( this.constrainVertical ) {
|
||||
|
||||
verticalLookRatio = Math.PI / ( this.verticalMax - this.verticalMin );
|
||||
|
||||
}
|
||||
|
||||
lon -= this.mouseX * actualLookSpeed;
|
||||
if ( this.lookVertical ) lat -= this.mouseY * actualLookSpeed * verticalLookRatio;
|
||||
|
||||
lat = Math.max( - 85, Math.min( 85, lat ) );
|
||||
|
||||
var phi = THREE.MathUtils.degToRad( 90 - lat );
|
||||
var theta = THREE.MathUtils.degToRad( lon );
|
||||
|
||||
if ( this.constrainVertical ) {
|
||||
|
||||
phi = THREE.MathUtils.mapLinear( phi, 0, Math.PI, this.verticalMin, this.verticalMax );
|
||||
|
||||
}
|
||||
|
||||
var position = this.object.position;
|
||||
|
||||
targetPosition.setFromSphericalCoords( 1, phi, theta ).add( position );
|
||||
|
||||
this.object.lookAt( targetPosition );
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
function contextmenu( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
}
|
||||
|
||||
this.dispose = function () {
|
||||
|
||||
this.domElement.removeEventListener( 'contextmenu', contextmenu );
|
||||
this.domElement.removeEventListener( 'mousedown', _onMouseDown );
|
||||
this.domElement.removeEventListener( 'mousemove', _onMouseMove );
|
||||
this.domElement.removeEventListener( 'mouseup', _onMouseUp );
|
||||
|
||||
window.removeEventListener( 'keydown', _onKeyDown );
|
||||
window.removeEventListener( 'keyup', _onKeyUp );
|
||||
|
||||
};
|
||||
|
||||
var _onMouseMove = bind( this, this.onMouseMove );
|
||||
var _onMouseDown = bind( this, this.onMouseDown );
|
||||
var _onMouseUp = bind( this, this.onMouseUp );
|
||||
var _onKeyDown = bind( this, this.onKeyDown );
|
||||
var _onKeyUp = bind( this, this.onKeyUp );
|
||||
|
||||
this.domElement.addEventListener( 'contextmenu', contextmenu );
|
||||
this.domElement.addEventListener( 'mousemove', _onMouseMove );
|
||||
this.domElement.addEventListener( 'mousedown', _onMouseDown );
|
||||
this.domElement.addEventListener( 'mouseup', _onMouseUp );
|
||||
|
||||
window.addEventListener( 'keydown', _onKeyDown );
|
||||
window.addEventListener( 'keyup', _onKeyUp );
|
||||
|
||||
function bind( scope, fn ) {
|
||||
|
||||
return function () {
|
||||
|
||||
fn.apply( scope, arguments );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
function setOrientation( controls ) {
|
||||
|
||||
var quaternion = controls.object.quaternion;
|
||||
|
||||
lookDirection.set( 0, 0, - 1 ).applyQuaternion( quaternion );
|
||||
spherical.setFromVector3( lookDirection );
|
||||
|
||||
lat = 90 - THREE.MathUtils.radToDeg( spherical.phi );
|
||||
lon = THREE.MathUtils.radToDeg( spherical.theta );
|
||||
|
||||
}
|
||||
|
||||
this.handleResize();
|
||||
|
||||
setOrientation( this );
|
||||
|
||||
};
|
309
node_modules/three/examples/js/controls/FlyControls.js
generated
vendored
Normal file
309
node_modules/three/examples/js/controls/FlyControls.js
generated
vendored
Normal file
|
@ -0,0 +1,309 @@
|
|||
THREE.FlyControls = function ( object, domElement ) {
|
||||
|
||||
if ( domElement === undefined ) {
|
||||
|
||||
console.warn( 'THREE.FlyControls: The second parameter "domElement" is now mandatory.' );
|
||||
domElement = document;
|
||||
|
||||
}
|
||||
|
||||
this.object = object;
|
||||
this.domElement = domElement;
|
||||
|
||||
if ( domElement ) this.domElement.setAttribute( 'tabindex', - 1 );
|
||||
|
||||
// API
|
||||
|
||||
this.movementSpeed = 1.0;
|
||||
this.rollSpeed = 0.005;
|
||||
|
||||
this.dragToLook = false;
|
||||
this.autoForward = false;
|
||||
|
||||
// disable default target object behavior
|
||||
|
||||
// internals
|
||||
|
||||
var scope = this;
|
||||
var changeEvent = { type: 'change' };
|
||||
var EPS = 0.000001;
|
||||
|
||||
this.tmpQuaternion = new THREE.Quaternion();
|
||||
|
||||
this.mouseStatus = 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 THREE.Vector3( 0, 0, 0 );
|
||||
this.rotationVector = new THREE.Vector3( 0, 0, 0 );
|
||||
|
||||
this.keydown = function ( event ) {
|
||||
|
||||
if ( event.altKey ) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
//event.preventDefault();
|
||||
|
||||
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 ) {
|
||||
|
||||
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.mousedown = function ( event ) {
|
||||
|
||||
if ( this.domElement !== document ) {
|
||||
|
||||
this.domElement.focus();
|
||||
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if ( this.dragToLook ) {
|
||||
|
||||
this.mouseStatus ++;
|
||||
|
||||
} else {
|
||||
|
||||
switch ( event.button ) {
|
||||
|
||||
case 0: this.moveState.forward = 1; break;
|
||||
case 2: this.moveState.back = 1; break;
|
||||
|
||||
}
|
||||
|
||||
this.updateMovementVector();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.mousemove = function ( event ) {
|
||||
|
||||
if ( ! this.dragToLook || this.mouseStatus > 0 ) {
|
||||
|
||||
var container = this.getContainerDimensions();
|
||||
var halfWidth = container.size[ 0 ] / 2;
|
||||
var 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.mouseup = function ( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if ( this.dragToLook ) {
|
||||
|
||||
this.mouseStatus --;
|
||||
|
||||
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.update = function () {
|
||||
|
||||
var lastQuaternion = new THREE.Quaternion();
|
||||
var lastPosition = new THREE.Vector3();
|
||||
|
||||
return function ( delta ) {
|
||||
|
||||
var moveMult = delta * scope.movementSpeed;
|
||||
var 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 () {
|
||||
|
||||
var 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 ]
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function bind( scope, fn ) {
|
||||
|
||||
return function () {
|
||||
|
||||
fn.apply( scope, arguments );
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
function contextmenu( event ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
}
|
||||
|
||||
this.dispose = function () {
|
||||
|
||||
this.domElement.removeEventListener( 'contextmenu', contextmenu );
|
||||
this.domElement.removeEventListener( 'mousedown', _mousedown );
|
||||
this.domElement.removeEventListener( 'mousemove', _mousemove );
|
||||
this.domElement.removeEventListener( 'mouseup', _mouseup );
|
||||
|
||||
window.removeEventListener( 'keydown', _keydown );
|
||||
window.removeEventListener( 'keyup', _keyup );
|
||||
|
||||
};
|
||||
|
||||
var _mousemove = bind( this, this.mousemove );
|
||||
var _mousedown = bind( this, this.mousedown );
|
||||
var _mouseup = bind( this, this.mouseup );
|
||||
var _keydown = bind( this, this.keydown );
|
||||
var _keyup = bind( this, this.keyup );
|
||||
|
||||
this.domElement.addEventListener( 'contextmenu', contextmenu );
|
||||
|
||||
this.domElement.addEventListener( 'mousemove', _mousemove );
|
||||
this.domElement.addEventListener( 'mousedown', _mousedown );
|
||||
this.domElement.addEventListener( 'mouseup', _mouseup );
|
||||
|
||||
window.addEventListener( 'keydown', _keydown );
|
||||
window.addEventListener( 'keyup', _keyup );
|
||||
|
||||
this.updateMovementVector();
|
||||
this.updateRotationVector();
|
||||
|
||||
};
|
||||
|
||||
THREE.FlyControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
THREE.FlyControls.prototype.constructor = THREE.FlyControls;
|
1217
node_modules/three/examples/js/controls/OrbitControls.js
generated
vendored
Normal file
1217
node_modules/three/examples/js/controls/OrbitControls.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
156
node_modules/three/examples/js/controls/PointerLockControls.js
generated
vendored
Normal file
156
node_modules/three/examples/js/controls/PointerLockControls.js
generated
vendored
Normal file
|
@ -0,0 +1,156 @@
|
|||
THREE.PointerLockControls = function ( camera, domElement ) {
|
||||
|
||||
if ( domElement === undefined ) {
|
||||
|
||||
console.warn( 'THREE.PointerLockControls: The second parameter "domElement" is now mandatory.' );
|
||||
domElement = document.body;
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
//
|
||||
// internals
|
||||
//
|
||||
|
||||
var scope = this;
|
||||
|
||||
var changeEvent = { type: 'change' };
|
||||
var lockEvent = { type: 'lock' };
|
||||
var unlockEvent = { type: 'unlock' };
|
||||
|
||||
var euler = new THREE.Euler( 0, 0, 0, 'YXZ' );
|
||||
|
||||
var PI_2 = Math.PI / 2;
|
||||
|
||||
var vec = new THREE.Vector3();
|
||||
|
||||
function onMouseMove( event ) {
|
||||
|
||||
if ( scope.isLocked === false ) return;
|
||||
|
||||
var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
|
||||
var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
|
||||
|
||||
euler.setFromQuaternion( camera.quaternion );
|
||||
|
||||
euler.y -= movementX * 0.002;
|
||||
euler.x -= movementY * 0.002;
|
||||
|
||||
euler.x = Math.max( PI_2 - scope.maxPolarAngle, Math.min( PI_2 - scope.minPolarAngle, euler.x ) );
|
||||
|
||||
camera.quaternion.setFromEuler( euler );
|
||||
|
||||
scope.dispatchEvent( changeEvent );
|
||||
|
||||
}
|
||||
|
||||
function onPointerlockChange() {
|
||||
|
||||
if ( scope.domElement.ownerDocument.pointerLockElement === scope.domElement ) {
|
||||
|
||||
scope.dispatchEvent( lockEvent );
|
||||
|
||||
scope.isLocked = true;
|
||||
|
||||
} else {
|
||||
|
||||
scope.dispatchEvent( unlockEvent );
|
||||
|
||||
scope.isLocked = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onPointerlockError() {
|
||||
|
||||
console.error( 'THREE.PointerLockControls: Unable to use Pointer Lock API' );
|
||||
|
||||
}
|
||||
|
||||
this.connect = function () {
|
||||
|
||||
scope.domElement.ownerDocument.addEventListener( 'mousemove', onMouseMove );
|
||||
scope.domElement.ownerDocument.addEventListener( 'pointerlockchange', onPointerlockChange );
|
||||
scope.domElement.ownerDocument.addEventListener( 'pointerlockerror', onPointerlockError );
|
||||
|
||||
};
|
||||
|
||||
this.disconnect = function () {
|
||||
|
||||
scope.domElement.ownerDocument.removeEventListener( 'mousemove', onMouseMove );
|
||||
scope.domElement.ownerDocument.removeEventListener( 'pointerlockchange', onPointerlockChange );
|
||||
scope.domElement.ownerDocument.removeEventListener( 'pointerlockerror', onPointerlockError );
|
||||
|
||||
};
|
||||
|
||||
this.dispose = function () {
|
||||
|
||||
this.disconnect();
|
||||
|
||||
};
|
||||
|
||||
this.getObject = function () { // retaining this method for backward compatibility
|
||||
|
||||
return camera;
|
||||
|
||||
};
|
||||
|
||||
this.getDirection = function () {
|
||||
|
||||
var direction = new THREE.Vector3( 0, 0, - 1 );
|
||||
|
||||
return function ( v ) {
|
||||
|
||||
return v.copy( direction ).applyQuaternion( camera.quaternion );
|
||||
|
||||
};
|
||||
|
||||
}();
|
||||
|
||||
this.moveForward = function ( distance ) {
|
||||
|
||||
// move forward parallel to the xz-plane
|
||||
// assumes camera.up is y-up
|
||||
|
||||
vec.setFromMatrixColumn( camera.matrix, 0 );
|
||||
|
||||
vec.crossVectors( camera.up, vec );
|
||||
|
||||
camera.position.addScaledVector( vec, distance );
|
||||
|
||||
};
|
||||
|
||||
this.moveRight = function ( distance ) {
|
||||
|
||||
vec.setFromMatrixColumn( camera.matrix, 0 );
|
||||
|
||||
camera.position.addScaledVector( vec, distance );
|
||||
|
||||
};
|
||||
|
||||
this.lock = function () {
|
||||
|
||||
this.domElement.requestPointerLock();
|
||||
|
||||
};
|
||||
|
||||
this.unlock = function () {
|
||||
|
||||
scope.domElement.ownerDocument.exitPointerLock();
|
||||
|
||||
};
|
||||
|
||||
this.connect();
|
||||
|
||||
};
|
||||
|
||||
THREE.PointerLockControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
THREE.PointerLockControls.prototype.constructor = THREE.PointerLockControls;
|
744
node_modules/three/examples/js/controls/TrackballControls.js
generated
vendored
Normal file
744
node_modules/three/examples/js/controls/TrackballControls.js
generated
vendored
Normal file
|
@ -0,0 +1,744 @@
|
|||
THREE.TrackballControls = function ( object, domElement ) {
|
||||
|
||||
if ( domElement === undefined ) console.warn( 'THREE.TrackballControls: The second parameter "domElement" is now mandatory.' );
|
||||
if ( domElement === document ) console.error( 'THREE.TrackballControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.' );
|
||||
|
||||
var scope = this;
|
||||
var STATE = { NONE: - 1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 };
|
||||
|
||||
this.object = object;
|
||||
this.domElement = domElement;
|
||||
|
||||
// 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.keys = [ 65 /*A*/, 83 /*S*/, 68 /*D*/ ];
|
||||
|
||||
this.mouseButtons = { LEFT: THREE.MOUSE.ROTATE, MIDDLE: THREE.MOUSE.DOLLY, RIGHT: THREE.MOUSE.PAN };
|
||||
|
||||
// internals
|
||||
|
||||
this.target = new THREE.Vector3();
|
||||
|
||||
var EPS = 0.000001;
|
||||
|
||||
var lastPosition = new THREE.Vector3();
|
||||
var lastZoom = 1;
|
||||
|
||||
var _state = STATE.NONE,
|
||||
_keyState = STATE.NONE,
|
||||
|
||||
_eye = new THREE.Vector3(),
|
||||
|
||||
_movePrev = new THREE.Vector2(),
|
||||
_moveCurr = new THREE.Vector2(),
|
||||
|
||||
_lastAxis = new THREE.Vector3(),
|
||||
_lastAngle = 0,
|
||||
|
||||
_zoomStart = new THREE.Vector2(),
|
||||
_zoomEnd = new THREE.Vector2(),
|
||||
|
||||
_touchZoomDistanceStart = 0,
|
||||
_touchZoomDistanceEnd = 0,
|
||||
|
||||
_panStart = new THREE.Vector2(),
|
||||
_panEnd = new THREE.Vector2();
|
||||
|
||||
// for reset
|
||||
|
||||
this.target0 = this.target.clone();
|
||||
this.position0 = this.object.position.clone();
|
||||
this.up0 = this.object.up.clone();
|
||||
this.zoom0 = this.object.zoom;
|
||||
|
||||
// events
|
||||
|
||||
var changeEvent = { type: 'change' };
|
||||
var startEvent = { type: 'start' };
|
||||
var endEvent = { type: 'end' };
|
||||
|
||||
|
||||
// methods
|
||||
|
||||
this.handleResize = function () {
|
||||
|
||||
var box = scope.domElement.getBoundingClientRect();
|
||||
// adjustments come from similar code in the jquery offset() function
|
||||
var 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;
|
||||
|
||||
};
|
||||
|
||||
var getMouseOnScreen = ( function () {
|
||||
|
||||
var vector = new THREE.Vector2();
|
||||
|
||||
return function getMouseOnScreen( pageX, pageY ) {
|
||||
|
||||
vector.set(
|
||||
( pageX - scope.screen.left ) / scope.screen.width,
|
||||
( pageY - scope.screen.top ) / scope.screen.height
|
||||
);
|
||||
|
||||
return vector;
|
||||
|
||||
};
|
||||
|
||||
}() );
|
||||
|
||||
var getMouseOnCircle = ( function () {
|
||||
|
||||
var vector = new THREE.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 () {
|
||||
|
||||
var axis = new THREE.Vector3(),
|
||||
quaternion = new THREE.Quaternion(),
|
||||
eyeDirection = new THREE.Vector3(),
|
||||
objectUpDirection = new THREE.Vector3(),
|
||||
objectSidewaysDirection = new THREE.Vector3(),
|
||||
moveDirection = new THREE.Vector3(),
|
||||
angle;
|
||||
|
||||
return function rotateCamera() {
|
||||
|
||||
moveDirection.set( _moveCurr.x - _movePrev.x, _moveCurr.y - _movePrev.y, 0 );
|
||||
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 () {
|
||||
|
||||
var 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 *= factor;
|
||||
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 /= factor;
|
||||
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 () {
|
||||
|
||||
var mouseChange = new THREE.Vector2(),
|
||||
objectUp = new THREE.Vector3(),
|
||||
pan = new THREE.Vector3();
|
||||
|
||||
return function panCamera() {
|
||||
|
||||
mouseChange.copy( _panEnd ).sub( _panStart );
|
||||
|
||||
if ( mouseChange.lengthSq() ) {
|
||||
|
||||
if ( scope.object.isOrthographicCamera ) {
|
||||
|
||||
var scale_x = ( scope.object.right - scope.object.left ) / scope.object.zoom / scope.domElement.clientWidth;
|
||||
var 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;
|
||||
|
||||
switch ( event.pointerType ) {
|
||||
|
||||
case 'mouse':
|
||||
case 'pen':
|
||||
onMouseDown( event );
|
||||
break;
|
||||
|
||||
// TODO touch
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onPointerMove( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
switch ( event.pointerType ) {
|
||||
|
||||
case 'mouse':
|
||||
case 'pen':
|
||||
onMouseMove( event );
|
||||
break;
|
||||
|
||||
// TODO touch
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function onPointerUp( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
switch ( event.pointerType ) {
|
||||
|
||||
case 'mouse':
|
||||
case 'pen':
|
||||
onMouseUp( event );
|
||||
break;
|
||||
|
||||
// TODO touch
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function keydown( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
window.removeEventListener( 'keydown', keydown );
|
||||
|
||||
if ( _keyState !== STATE.NONE ) {
|
||||
|
||||
return;
|
||||
|
||||
} else if ( event.keyCode === scope.keys[ STATE.ROTATE ] && ! scope.noRotate ) {
|
||||
|
||||
_keyState = STATE.ROTATE;
|
||||
|
||||
} else if ( event.keyCode === scope.keys[ STATE.ZOOM ] && ! scope.noZoom ) {
|
||||
|
||||
_keyState = STATE.ZOOM;
|
||||
|
||||
} else if ( event.keyCode === 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 ) {
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
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;
|
||||
|
||||
default:
|
||||
_state = STATE.NONE;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var 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.domElement.ownerDocument.addEventListener( 'pointermove', onPointerMove );
|
||||
scope.domElement.ownerDocument.addEventListener( 'pointerup', onPointerUp );
|
||||
|
||||
scope.dispatchEvent( startEvent );
|
||||
|
||||
}
|
||||
|
||||
function onMouseMove( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
var 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( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
_state = STATE.NONE;
|
||||
|
||||
scope.domElement.ownerDocument.removeEventListener( 'pointermove', onPointerMove );
|
||||
scope.domElement.ownerDocument.removeEventListener( 'pointerup', onPointerUp );
|
||||
|
||||
scope.dispatchEvent( endEvent );
|
||||
|
||||
}
|
||||
|
||||
function mousewheel( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
if ( scope.noZoom === true ) return;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
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 touchstart( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
switch ( event.touches.length ) {
|
||||
|
||||
case 1:
|
||||
_state = STATE.TOUCH_ROTATE;
|
||||
_moveCurr.copy( getMouseOnCircle( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
|
||||
_movePrev.copy( _moveCurr );
|
||||
break;
|
||||
|
||||
default: // 2 or more
|
||||
_state = STATE.TOUCH_ZOOM_PAN;
|
||||
var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
|
||||
var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
|
||||
_touchZoomDistanceEnd = _touchZoomDistanceStart = Math.sqrt( dx * dx + dy * dy );
|
||||
|
||||
var x = ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX ) / 2;
|
||||
var y = ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY ) / 2;
|
||||
_panStart.copy( getMouseOnScreen( x, y ) );
|
||||
_panEnd.copy( _panStart );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
scope.dispatchEvent( startEvent );
|
||||
|
||||
}
|
||||
|
||||
function touchmove( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
switch ( event.touches.length ) {
|
||||
|
||||
case 1:
|
||||
_movePrev.copy( _moveCurr );
|
||||
_moveCurr.copy( getMouseOnCircle( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
|
||||
break;
|
||||
|
||||
default: // 2 or more
|
||||
var dx = event.touches[ 0 ].pageX - event.touches[ 1 ].pageX;
|
||||
var dy = event.touches[ 0 ].pageY - event.touches[ 1 ].pageY;
|
||||
_touchZoomDistanceEnd = Math.sqrt( dx * dx + dy * dy );
|
||||
|
||||
var x = ( event.touches[ 0 ].pageX + event.touches[ 1 ].pageX ) / 2;
|
||||
var y = ( event.touches[ 0 ].pageY + event.touches[ 1 ].pageY ) / 2;
|
||||
_panEnd.copy( getMouseOnScreen( x, y ) );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function touchend( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
switch ( event.touches.length ) {
|
||||
|
||||
case 0:
|
||||
_state = STATE.NONE;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
_state = STATE.TOUCH_ROTATE;
|
||||
_moveCurr.copy( getMouseOnCircle( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY ) );
|
||||
_movePrev.copy( _moveCurr );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
scope.dispatchEvent( endEvent );
|
||||
|
||||
}
|
||||
|
||||
function contextmenu( event ) {
|
||||
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
}
|
||||
|
||||
this.dispose = function () {
|
||||
|
||||
scope.domElement.removeEventListener( 'contextmenu', contextmenu );
|
||||
|
||||
scope.domElement.removeEventListener( 'pointerdown', onPointerDown );
|
||||
scope.domElement.removeEventListener( 'wheel', mousewheel );
|
||||
|
||||
scope.domElement.removeEventListener( 'touchstart', touchstart );
|
||||
scope.domElement.removeEventListener( 'touchend', touchend );
|
||||
scope.domElement.removeEventListener( 'touchmove', touchmove );
|
||||
|
||||
scope.domElement.ownerDocument.removeEventListener( 'pointermove', onPointerMove );
|
||||
scope.domElement.ownerDocument.removeEventListener( 'pointerup', onPointerUp );
|
||||
|
||||
window.removeEventListener( 'keydown', keydown );
|
||||
window.removeEventListener( 'keyup', keyup );
|
||||
|
||||
};
|
||||
|
||||
this.domElement.addEventListener( 'contextmenu', contextmenu );
|
||||
|
||||
this.domElement.addEventListener( 'pointerdown', onPointerDown );
|
||||
this.domElement.addEventListener( 'wheel', mousewheel );
|
||||
|
||||
this.domElement.addEventListener( 'touchstart', touchstart );
|
||||
this.domElement.addEventListener( 'touchend', touchend );
|
||||
this.domElement.addEventListener( 'touchmove', touchmove );
|
||||
|
||||
this.domElement.ownerDocument.addEventListener( 'pointermove', onPointerMove );
|
||||
this.domElement.ownerDocument.addEventListener( 'pointerup', onPointerUp );
|
||||
|
||||
window.addEventListener( 'keydown', keydown );
|
||||
window.addEventListener( 'keyup', keyup );
|
||||
|
||||
this.handleResize();
|
||||
|
||||
// force an update at start
|
||||
this.update();
|
||||
|
||||
};
|
||||
|
||||
THREE.TrackballControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
THREE.TrackballControls.prototype.constructor = THREE.TrackballControls;
|
1663
node_modules/three/examples/js/controls/TransformControls.js
generated
vendored
Normal file
1663
node_modules/three/examples/js/controls/TransformControls.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue