Browse Source

Applies controls changes to the js versions and builds the jsm

Gianmarco Simone 5 years ago
parent
commit
60a906b399

+ 29 - 11
examples/js/controls/DeviceOrientationControls.js

@@ -9,6 +9,8 @@ console.warn( "THREE.DeviceOrientationControls: As part of the transition to ES6
 THREE.DeviceOrientationControls = function ( object ) {
 
 	var scope = this;
+	var changeEvent = { type: "change" };
+	var EPS = 0.000001;
 
 	this.object = object;
 	this.object.rotation.reorder( 'YXZ' );
@@ -101,28 +103,41 @@ THREE.DeviceOrientationControls = function ( object ) {
 
 	};
 
-	this.update = function () {
+	this.update = ( function () {
 
-		if ( scope.enabled === false ) return;
+		var lastQuaternion = new THREE.Quaternion();
 
-		var device = scope.deviceOrientation;
+		return function () {
 
-		if ( device ) {
+			if ( scope.enabled === false ) return;
 
-			var alpha = device.alpha ? THREE.MathUtils.degToRad( device.alpha ) + scope.alphaOffset : 0; // Z
+			var device = scope.deviceOrientation;
 
-			var beta = device.beta ? THREE.MathUtils.degToRad( device.beta ) : 0; // X'
+			if ( device ) {
 
-			var gamma = device.gamma ? THREE.MathUtils.degToRad( device.gamma ) : 0; // Y''
+				var alpha = device.alpha ? THREE.MathUtils.degToRad( device.alpha ) + scope.alphaOffset : 0; // Z
 
-			var orient = scope.screenOrientation ? THREE.MathUtils.degToRad( scope.screenOrientation ) : 0; // O
+				var beta = device.beta ? THREE.MathUtils.degToRad( device.beta ) : 0; // X'
 
-			setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient );
+				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 () {
 
@@ -133,3 +148,6 @@ THREE.DeviceOrientationControls = function ( object ) {
 	this.connect();
 
 };
+
+THREE.DeviceOrientationControls.prototype = Object.create( THREE.EventDispatcher.prototype );
+THREE.DeviceOrientationControls.prototype.constructor = THREE.DeviceOrientationControls;

+ 35 - 11
examples/js/controls/FlyControls.js

@@ -29,6 +29,10 @@ THREE.FlyControls = function ( object, domElement ) {
 
 	// internals
 
+	var scope = this;
+	var changeEvent = { type: "change" };
+	var EPS = 0.000001;
+
 	this.tmpQuaternion = new THREE.Quaternion();
 
 	this.mouseStatus = 0;
@@ -182,23 +186,40 @@ THREE.FlyControls = function ( object, domElement ) {
 
 	};
 
-	this.update = function ( delta ) {
+	this.update = function () {
 
-		var moveMult = delta * this.movementSpeed;
-		var rotMult = delta * this.rollSpeed;
+		var lastQuaternion = new THREE.Quaternion();
+		var lastPosition = new THREE.Vector3();
 
-		this.object.translateX( this.moveVector.x * moveMult );
-		this.object.translateY( this.moveVector.y * moveMult );
-		this.object.translateZ( this.moveVector.z * moveMult );
+		return function ( delta ) {
 
-		this.tmpQuaternion.set( this.rotationVector.x * rotMult, this.rotationVector.y * rotMult, this.rotationVector.z * rotMult, 1 ).normalize();
-		this.object.quaternion.multiply( this.tmpQuaternion );
+			var moveMult = delta * scope.movementSpeed;
+			var rotMult = delta * scope.rollSpeed;
 
-		// expose the rotation vector for convenience
-		this.object.rotation.setFromQuaternion( this.object.quaternion, this.object.rotation.order );
+			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 );
 
-	};
+			// expose the rotation vector for convenience
+			scope.object.rotation.setFromQuaternion( scope.object.quaternion, scope.object.rotation.order );
+
+			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 () {
 
@@ -289,3 +310,6 @@ THREE.FlyControls = function ( object, domElement ) {
 	this.updateRotationVector();
 
 };
+
+THREE.FlyControls.prototype = Object.create( THREE.EventDispatcher.prototype );
+THREE.FlyControls.prototype.constructor = THREE.FlyControls;

+ 14 - 9
examples/jsm/controls/DeviceOrientationControls.js

@@ -5,11 +5,19 @@
  * W3C Device Orientation control (http://w3c.github.io/deviceorientation/spec-source-orientation.html)
  */
 
-import { EventDispatcher, Euler, MathUtils, Quaternion, Vector3 } from '../../../build/three.module.js';
+import {
+	Euler,
+	EventDispatcher,
+	MathUtils,
+	Quaternion,
+	Vector3
+} from "../../../build/three.module.js";
 
 var DeviceOrientationControls = function ( object ) {
 
 	var scope = this;
+	var changeEvent = { type: "change" };
+	var EPS = 0.000001;
 
 	this.object = object;
 	this.object.rotation.reorder( 'YXZ' );
@@ -21,10 +29,6 @@ var DeviceOrientationControls = function ( object ) {
 
 	this.alphaOffset = 0; // radians
 
-	var changeEvent = { type: 'change' };
-
-	var EPS = 0.000001;
-
 	var onDeviceOrientationChangeEvent = function ( event ) {
 
 		scope.deviceOrientation = event;
@@ -39,7 +43,7 @@ var DeviceOrientationControls = function ( object ) {
 
 	// The angles alpha, beta and gamma form a set of intrinsic Tait-Bryan angles of type Z-X'-Y''
 
-	var setObjectQuaternion = (function () {
+	var setObjectQuaternion = function () {
 
 		var zee = new Vector3( 0, 0, 1 );
 
@@ -61,7 +65,7 @@ var DeviceOrientationControls = function ( object ) {
 
 		};
 
-	})();
+	}();
 
 	this.connect = function () {
 
@@ -108,9 +112,9 @@ var DeviceOrientationControls = function ( object ) {
 
 	this.update = ( function () {
 
-		const lastQuaternion = new Quaternion();
+		var lastQuaternion = new Quaternion();
 
-		return () => {
+		return function () {
 
 			if ( scope.enabled === false ) return;
 
@@ -139,6 +143,7 @@ var DeviceOrientationControls = function ( object ) {
 
 		};
 
+
 	} )();
 
 	this.dispose = function () {

+ 23 - 19
examples/jsm/controls/FlyControls.js

@@ -2,7 +2,11 @@
  * @author James Baicoianu / http://www.baicoianu.com/
  */
 
-import { EventDispatcher, Quaternion, Vector3 } from '../../../build/three.module.js';
+import {
+	EventDispatcher,
+	Quaternion,
+	Vector3
+} from "../../../build/three.module.js";
 
 var FlyControls = function ( object, domElement ) {
 
@@ -30,8 +34,8 @@ var FlyControls = function ( object, domElement ) {
 
 	// internals
 
-	var changeEvent = { type: 'change' };
-
+	var scope = this;
+	var changeEvent = { type: "change" };
 	var EPS = 0.000001;
 
 	this.tmpQuaternion = new Quaternion();
@@ -187,40 +191,40 @@ var FlyControls = function ( object, domElement ) {
 
 	};
 
-	this.update = ( () => {
+	this.update = function () {
 
 		var lastQuaternion = new Quaternion();
 		var lastPosition = new Vector3();
 
-		return ( delta ) => {
+		return function ( delta ) {
 
-			var moveMult = delta * this.movementSpeed;
-			var rotMult = delta * this.rollSpeed;
+			var moveMult = delta * scope.movementSpeed;
+			var rotMult = delta * scope.rollSpeed;
 
-			this.object.translateX( this.moveVector.x * moveMult );
-			this.object.translateY( this.moveVector.y * moveMult );
-			this.object.translateZ( this.moveVector.z * moveMult );
+			scope.object.translateX( scope.moveVector.x * moveMult );
+			scope.object.translateY( scope.moveVector.y * moveMult );
+			scope.object.translateZ( scope.moveVector.z * moveMult );
 
-			this.tmpQuaternion.set( this.rotationVector.x * rotMult, this.rotationVector.y * rotMult, this.rotationVector.z * rotMult, 1 ).normalize();
-			this.object.quaternion.multiply( this.tmpQuaternion );
+			scope.tmpQuaternion.set( scope.rotationVector.x * rotMult, scope.rotationVector.y * rotMult, scope.rotationVector.z * rotMult, 1 ).normalize();
+			scope.object.quaternion.multiply( scope.tmpQuaternion );
 
 			// expose the rotation vector for convenience
-			this.object.rotation.setFromQuaternion( this.object.quaternion, this.object.rotation.order );
+			scope.object.rotation.setFromQuaternion( scope.object.quaternion, scope.object.rotation.order );
 
 			if (
-				lastPosition.distanceToSquared( this.object.position ) > EPS ||
-				8 * ( 1 - lastQuaternion.dot( this.object.quaternion ) ) > EPS
+				lastPosition.distanceToSquared( scope.object.position ) > EPS ||
+				8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS
 			) {
 
-				this.dispatchEvent( changeEvent );
-				lastQuaternion.copy( this.object.quaternion );
-				lastPosition.copy( this.object.position );
+				scope.dispatchEvent( changeEvent );
+				lastQuaternion.copy( scope.object.quaternion );
+				lastPosition.copy( scope.object.position );
 
 			}
 
 		};
 
-	} )();
+	}();
 
 	this.updateMovementVector = function () {