Browse Source

Updated `Ray` with the material.side change.

Mr.doob 13 years ago
parent
commit
895c94337b
1 changed files with 12 additions and 2 deletions
  1. 12 2
      src/core/Ray.js

+ 12 - 2
src/core/Ray.js

@@ -138,7 +138,12 @@ THREE.Ray = function ( origin, direction, near, far ) {
 			rangeSq = this.range * this.range,
 			geometry = object.geometry,
 			vertices = geometry.vertices,
-			objMatrix;
+			objMatrix, geometryMaterials,
+			isFaceMaterial, material, side;
+
+			geometryMaterials = object.geometry.materials;
+			isFaceMaterial = object.material instanceof THREE.MeshFaceMaterial;
+			side = object.material.side;
 
 			object.matrixRotationWorld.extractRotation( object.matrixWorld );
 
@@ -146,6 +151,11 @@ THREE.Ray = function ( origin, direction, near, far ) {
 
 				face = geometry.faces[ f ];
 
+				material = isFaceMaterial === true ? geometryMaterials[ face.materialIndex ] : object.material;
+				if ( material === undefined ) continue;
+
+				side = material.side;
+
 				originCopy.copy( this.origin );
 				directionCopy.copy( this.direction );
 
@@ -170,7 +180,7 @@ THREE.Ray = function ( origin, direction, near, far ) {
 
 				if ( scalar < 0 ) continue;
 
-				if ( object.doubleSided || ( object.flipSided ? dot > 0 : dot < 0 ) ) {
+				if ( side === THREE.DoubleSide || ( side === THREE.FrontSide ? dot < 0 : dot > 0 ) ) {
 
 					intersectPoint.add( originCopy, directionCopy.multiplyScalar( scalar ) );