Browse Source

this is further optimatisation on ray.js

libra guest 13 years ago
parent
commit
3275429ea9
1 changed files with 17 additions and 20 deletions
  1. 17 20
      src/core/Ray.js

+ 17 - 20
src/core/Ray.js

@@ -11,13 +11,13 @@ THREE.Ray = function ( origin, direction, near, far ) {
 
 	//
 
-	var a = new THREE.Vector3();
-	var b = new THREE.Vector3();
-	var c = new THREE.Vector3();
-	var d = new THREE.Vector3();
+	var a;// = new THREE.Vector3();
+	var b;// = new THREE.Vector3();
+	var c;// = new THREE.Vector3();
+	var d;// = new THREE.Vector3();
 
 	var originCopy = new THREE.Vector3();
-	var directionCopy = new THREE.Vector3();
+//	var directionCopy = new THREE.Vector3();
 	
 	var localOriginCopy = new THREE.Vector3();
 	var localDirectionCopy = new THREE.Vector3();
@@ -126,8 +126,8 @@ THREE.Ray = function ( origin, direction, near, far ) {
 
 			// Checking boundingSphere
 
-			var scale = THREE.Frustum.__v1.set( object.matrixWorld.getColumnX().length(), object.matrixWorld.getColumnY().length(), object.matrixWorld.getColumnZ().length() );
-			var scaledRadius = object.geometry.boundingSphere.radius * Math.max( scale.x, Math.max( scale.y, scale.z ) );
+			//var scale = THREE.Frustum.__v1.set( object.matrixWorld.getColumnX().length(), object.matrixWorld.getColumnY().length(), object.matrixWorld.getColumnZ().length() );
+			var scaledRadius = object.geometry.boundingSphere.radius * object.matrixWorld.getMaxScaleOnAxis();
 
 			// Checking distance to ray
 
@@ -154,17 +154,15 @@ THREE.Ray = function ( origin, direction, near, far ) {
 			object.matrixRotationWorld.extractRotation( object.matrixWorld );
 			
 			originCopy.copy( this.origin );
-			directionCopy.copy( this.direction );
+			//directionCopy.copy( this.direction );
 
 			objMatrix = object.matrixWorld;
 			inverseMatrix.getInverse(objMatrix);
 			
-			
-			
 			localOriginCopy.copy(originCopy);
 			inverseMatrix.multiplyVector3(localOriginCopy);
 			
-			localDirectionCopy.copy(directionCopy);
+			localDirectionCopy.copy(this.direction);
 			inverseMatrix.rotateAxis(localDirectionCopy).normalize();
 
 			for ( f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
@@ -173,11 +171,10 @@ THREE.Ray = function ( origin, direction, near, far ) {
 
 				material = isFaceMaterial === true ? geometryMaterials[ face.materialIndex ] : object.material;
 				if ( material === undefined ) continue;
-
 				side = material.side;
 
 				vector.sub( face.centroid, localOriginCopy );
-				normal.copy( face.normal );
+				normal = face.normal;
 				dot = localDirectionCopy.dot( normal );
 
 
@@ -199,9 +196,9 @@ THREE.Ray = function ( origin, direction, near, far ) {
 
 					if ( face instanceof THREE.Face3 ) {
 
-						a.copy( vertices[ face.a ] );
-						b.copy( vertices[ face.b ] );
-						c.copy( vertices[ face.c ] );
+						a = vertices[ face.a ];
+						b = vertices[ face.b ];
+						c = vertices[ face.c ];
 
 						if ( pointInFace3( intersectPoint, a, b, c ) ) {
 
@@ -228,10 +225,10 @@ THREE.Ray = function ( origin, direction, near, far ) {
 
 					} else if ( face instanceof THREE.Face4 ) {
 
-						a.copy( vertices[ face.a ] );
-						b.copy( vertices[ face.b ] );
-						c.copy( vertices[ face.c ] );
-						d.copy( vertices[ face.d ] );
+						a = vertices[ face.a ];
+						b = vertices[ face.b ];
+						c = vertices[ face.c ];
+						d = vertices[ face.d ];
 
 						if ( pointInFace3( intersectPoint, a, b, d ) || pointInFace3( intersectPoint, b, c, d ) ) {