Browse Source

Merge pull request #15996 from WestLangley/dev-unproject

Vector3.unproject(): Avoid computing inverse
Mr.doob 6 years ago
parent
commit
a7d80a0d59
2 changed files with 5 additions and 12 deletions
  1. 2 2
      src/helpers/CameraHelper.js
  2. 3 10
      src/math/Vector3.js

+ 2 - 2
src/helpers/CameraHelper.js

@@ -158,10 +158,10 @@ CameraHelper.prototype.update = function () {
 
 
 		var w = 1, h = 1;
 		var w = 1, h = 1;
 
 
-		// we need just camera projection matrix
+		// we need just camera projection matrix inverse
 		// world matrix must be identity
 		// world matrix must be identity
 
 
-		camera.projectionMatrix.copy( this.camera.projectionMatrix );
+		camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
 
 
 		// center / target
 		// center / target
 
 

+ 3 - 10
src/math/Vector3.js

@@ -1,5 +1,4 @@
 import { _Math } from './Math.js';
 import { _Math } from './Math.js';
-import { Matrix4 } from './Matrix4.js';
 import { Quaternion } from './Quaternion.js';
 import { Quaternion } from './Quaternion.js';
 
 
 /**
 /**
@@ -318,17 +317,11 @@ Object.assign( Vector3.prototype, {
 
 
 	},
 	},
 
 
-	unproject: function () {
+	unproject: function ( camera ) {
 
 
-		var matrix = new Matrix4();
+		return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
 
 
-		return function unproject( camera ) {
-
-			return this.applyMatrix4( matrix.getInverse( camera.projectionMatrix ) ).applyMatrix4( camera.matrixWorld );
-
-		};
-
-	}(),
+	},
 
 
 	transformDirection: function ( m ) {
 	transformDirection: function ( m ) {