Browse Source

Camera: Move to let/const.

Mugen87 5 years ago
parent
commit
b3e86167bd

+ 1 - 1
src/cameras/Camera.js

@@ -51,7 +51,7 @@ Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 		this.updateMatrixWorld( true );
 
-		var e = this.matrixWorld.elements;
+		const e = this.matrixWorld.elements;
 
 		return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
 

+ 12 - 12
src/cameras/CubeCamera.js

@@ -9,7 +9,7 @@ import { PerspectiveCamera } from './PerspectiveCamera.js';
  * @author alteredq / http://alteredqualia.com/
  */
 
-var fov = 90, aspect = 1;
+const fov = 90, aspect = 1;
 
 function CubeCamera( near, far, renderTarget ) {
 
@@ -26,37 +26,37 @@ function CubeCamera( near, far, renderTarget ) {
 
 	this.renderTarget = renderTarget;
 
-	var cameraPX = new PerspectiveCamera( fov, aspect, near, far );
+	const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
 	cameraPX.layers = this.layers;
 	cameraPX.up.set( 0, - 1, 0 );
 	cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
 	this.add( cameraPX );
 
-	var cameraNX = new PerspectiveCamera( fov, aspect, near, far );
+	const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
 	cameraNX.layers = this.layers;
 	cameraNX.up.set( 0, - 1, 0 );
 	cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
 	this.add( cameraNX );
 
-	var cameraPY = new PerspectiveCamera( fov, aspect, near, far );
+	const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
 	cameraPY.layers = this.layers;
 	cameraPY.up.set( 0, 0, 1 );
 	cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
 	this.add( cameraPY );
 
-	var cameraNY = new PerspectiveCamera( fov, aspect, near, far );
+	const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
 	cameraNY.layers = this.layers;
 	cameraNY.up.set( 0, 0, - 1 );
 	cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
 	this.add( cameraNY );
 
-	var cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
+	const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
 	cameraPZ.layers = this.layers;
 	cameraPZ.up.set( 0, - 1, 0 );
 	cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
 	this.add( cameraPZ );
 
-	var cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
+	const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
 	cameraNZ.layers = this.layers;
 	cameraNZ.up.set( 0, - 1, 0 );
 	cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
@@ -66,12 +66,12 @@ function CubeCamera( near, far, renderTarget ) {
 
 		if ( this.parent === null ) this.updateMatrixWorld();
 
-		var currentXrEnabled = renderer.xr.enabled;
-		var currentRenderTarget = renderer.getRenderTarget();
+		const currentXrEnabled = renderer.xr.enabled;
+		const currentRenderTarget = renderer.getRenderTarget();
 
 		renderer.xr.enabled = false;
 
-		var generateMipmaps = renderTarget.texture.generateMipmaps;
+		const generateMipmaps = renderTarget.texture.generateMipmaps;
 
 		renderTarget.texture.generateMipmaps = false;
 
@@ -103,9 +103,9 @@ function CubeCamera( near, far, renderTarget ) {
 
 	this.clear = function ( renderer, color, depth, stencil ) {
 
-		var currentRenderTarget = renderer.getRenderTarget();
+		const currentRenderTarget = renderer.getRenderTarget();
 
-		for ( var i = 0; i < 6; i ++ ) {
+		for ( let i = 0; i < 6; i ++ ) {
 
 			renderer.setRenderTarget( renderTarget, i );
 

+ 1 - 1
src/cameras/OrthographicCamera.d.ts

@@ -4,7 +4,7 @@ import { Camera } from './Camera';
  * Camera with orthographic projection
  *
  * @example
- * var camera = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, 1, 1000 );
+ * const camera = new THREE.OrthographicCamera( width / - 2, width / 2, height / 2, height / - 2, 1, 1000 );
  * scene.add( camera );
  *
  * @see {@link https://github.com/mrdoob/three.js/blob/master/src/cameras/OrthographicCamera.js|src/cameras/OrthographicCamera.js}

+ 11 - 11
src/cameras/OrthographicCamera.js

@@ -93,20 +93,20 @@ OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 
 	updateProjectionMatrix: function () {
 
-		var dx = ( this.right - this.left ) / ( 2 * this.zoom );
-		var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
-		var cx = ( this.right + this.left ) / 2;
-		var cy = ( this.top + this.bottom ) / 2;
+		const dx = ( this.right - this.left ) / ( 2 * this.zoom );
+		const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
+		const cx = ( this.right + this.left ) / 2;
+		const cy = ( this.top + this.bottom ) / 2;
 
-		var left = cx - dx;
-		var right = cx + dx;
-		var top = cy + dy;
-		var bottom = cy - dy;
+		let left = cx - dx;
+		let right = cx + dx;
+		let top = cy + dy;
+		let bottom = cy - dy;
 
 		if ( this.view !== null && this.view.enabled ) {
 
-			var scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
-			var scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
+			const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
+			const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
 
 			left += scaleW * this.view.offsetX;
 			right = left + scaleW * this.view.width;
@@ -123,7 +123,7 @@ OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 
 	toJSON: function ( meta ) {
 
-		var data = Object3D.prototype.toJSON.call( this, meta );
+		const data = Object3D.prototype.toJSON.call( this, meta );
 
 		data.object.zoom = this.zoom;
 		data.object.left = this.left;

+ 4 - 4
src/cameras/PerspectiveCamera.d.ts

@@ -72,10 +72,10 @@ export class PerspectiveCamera extends Camera {
 	 *
 	 * then for each monitor you would call it like this:
 	 *
-	 *		 var w = 1920;
-	 *		 var h = 1080;
-	 *		 var fullWidth = w * 3;
-	 *		 var fullHeight = h * 2;
+	 *		 const w = 1920;
+	 *		 const h = 1080;
+	 *		 const fullWidth = w * 3;
+	 *		 const fullHeight = h * 2;
 	 *
 	 *		 // A
 	 *		 camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );

+ 10 - 10
src/cameras/PerspectiveCamera.js

@@ -70,7 +70,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 	setFocalLength: function ( focalLength ) {
 
 		// see http://www.bobatkins.com/photography/technical/field_of_view.html
-		var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
+		const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
 
 		this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope );
 		this.updateProjectionMatrix();
@@ -82,7 +82,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 	 */
 	getFocalLength: function () {
 
-		var vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
+		const vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
 
 		return 0.5 * this.getFilmHeight() / vExtentSlope;
 
@@ -124,10 +124,10 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 	 *
 	 * then for each monitor you would call it like this
 	 *
-	 *   var w = 1920;
-	 *   var h = 1080;
-	 *   var fullWidth = w * 3;
-	 *   var fullHeight = h * 2;
+	 *   const w = 1920;
+	 *   const h = 1080;
+	 *   const fullWidth = w * 3;
+	 *   const fullHeight = h * 2;
 	 *
 	 *   --A--
 	 *   camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
@@ -188,7 +188,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 
 	updateProjectionMatrix: function () {
 
-		var near = this.near,
+		let near = this.near,
 			top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom,
 			height = 2 * top,
 			width = this.aspect * height,
@@ -197,7 +197,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 
 		if ( this.view !== null && this.view.enabled ) {
 
-			var fullWidth = view.fullWidth,
+			const fullWidth = view.fullWidth,
 				fullHeight = view.fullHeight;
 
 			left += view.offsetX * width / fullWidth;
@@ -207,7 +207,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 
 		}
 
-		var skew = this.filmOffset;
+		const skew = this.filmOffset;
 		if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
 
 		this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
@@ -218,7 +218,7 @@ PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ),
 
 	toJSON: function ( meta ) {
 
-		var data = Object3D.prototype.toJSON.call( this, meta );
+		const data = Object3D.prototype.toJSON.call( this, meta );
 
 		data.object.fov = this.fov;
 		data.object.zoom = this.zoom;

+ 9 - 9
src/cameras/StereoCamera.js

@@ -2,8 +2,8 @@ import { Matrix4 } from '../math/Matrix4.js';
 import { MathUtils } from '../math/MathUtils.js';
 import { PerspectiveCamera } from './PerspectiveCamera.js';
 
-var _eyeRight = new Matrix4();
-var _eyeLeft = new Matrix4();
+const _eyeRight = new Matrix4();
+const _eyeLeft = new Matrix4();
 
 /**
  * @author mrdoob / http://mrdoob.com/
@@ -41,9 +41,9 @@ Object.assign( StereoCamera.prototype, {
 
 	update: function ( camera ) {
 
-		var cache = this._cache;
+		const cache = this._cache;
 
-		var needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
+		const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
 			cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
 			cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
 
@@ -60,11 +60,11 @@ Object.assign( StereoCamera.prototype, {
 			// Off-axis stereoscopic effect based on
 			// http://paulbourke.net/stereographics/stereorender/
 
-			var projectionMatrix = camera.projectionMatrix.clone();
-			var eyeSepHalf = cache.eyeSep / 2;
-			var eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
-			var ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
-			var xmin, xmax;
+			const projectionMatrix = camera.projectionMatrix.clone();
+			const eyeSepHalf = cache.eyeSep / 2;
+			const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
+			const ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
+			let xmin, xmax;
 
 			// translate xOffset