Browse Source

optimized getWorldDirection

mbredif 7 years ago
parent
commit
98b120306e
2 changed files with 18 additions and 27 deletions
  1. 9 14
      src/cameras/Camera.js
  2. 9 13
      src/core/Object3D.js

+ 9 - 14
src/cameras/Camera.js

@@ -5,7 +5,6 @@
 */
 */
 
 
 import { Matrix4 } from '../math/Matrix4.js';
 import { Matrix4 } from '../math/Matrix4.js';
-import { Quaternion } from '../math/Quaternion.js';
 import { Object3D } from '../core/Object3D.js';
 import { Object3D } from '../core/Object3D.js';
 import { Vector3 } from '../math/Vector3.js';
 import { Vector3 } from '../math/Vector3.js';
 
 
@@ -37,26 +36,22 @@ Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 
 	},
 	},
 
 
-	getWorldDirection: function () {
+	getWorldDirection: function ( target ) {
 
 
-		var quaternion = new Quaternion();
+		if ( target === undefined ) {
 
 
-		return function getWorldDirection( target ) {
+			console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
+			target = new Vector3();
 
 
-			if ( target === undefined ) {
+		}
 
 
-				console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
-				target = new Vector3();
+		this.updateMatrixWorld( true );
 
 
-			}
+		var e = this.matrixWorld.elements;
 
 
-			this.getWorldQuaternion( quaternion );
+		return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
 
 
-			return target.set( 0, 0, - 1 ).applyQuaternion( quaternion );
-
-		};
-
-	}(),
+	},
 
 
 	updateMatrixWorld: function ( force ) {
 	updateMatrixWorld: function ( force ) {
 
 

+ 9 - 13
src/core/Object3D.js

@@ -506,26 +506,22 @@ Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
 
 
 	}(),
 	}(),
 
 
-	getWorldDirection: function () {
+	getWorldDirection: function ( target ) {
 
 
-		var quaternion = new Quaternion();
-
-		return function getWorldDirection( target ) {
-
-			if ( target === undefined ) {
+		if ( target === undefined ) {
 
 
-				console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
-				target = new Vector3();
+			console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
+			target = new Vector3();
 
 
-			}
+		}
 
 
-			this.getWorldQuaternion( quaternion );
+		this.updateMatrixWorld( true );
 
 
-			return target.set( 0, 0, 1 ).applyQuaternion( quaternion );
+		var e = this.matrixWorld.elements;
 
 
-		};
+		return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
 
 
-	}(),
+	},
 
 
 	raycast: function () {},
 	raycast: function () {},