瀏覽代碼

improve performance of Vector3.(un)project, Matrix4.multiplyMatrices is more expensive than Vector3.applyMatrix4

zhaoy 7 年之前
父節點
當前提交
2c86988ecb
共有 1 個文件被更改,包括 3 次插入11 次删除
  1. 3 11
      src/math/Vector3.js

+ 3 - 11
src/math/Vector3.js

@@ -312,16 +312,9 @@ Object.assign( Vector3.prototype, {
 
 	},
 
-	project: function () {
+	project: function ( camera ) {
 
-		var matrix = new Matrix4();
-
-		return function project( camera ) {
-
-			matrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
-			return this.applyMatrix4( matrix );
-
-		};
+		return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
 
 	}(),
 
@@ -331,8 +324,7 @@ Object.assign( Vector3.prototype, {
 
 		return function unproject( camera ) {
 
-			matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
-			return this.applyMatrix4( matrix );
+			return this.applyMatrix4( matrix.getInverse( camera.projectionMatrix ) ).applyMatrix4( camera.matrixWorld );
 
 		};