提交 3a59e4bd 编写于 作者: M Mr.doob

Implemented @WestLangley Ray improvements.

上级 d7747258
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -103,30 +103,35 @@ THREE.Ray = function ( origin, direction ) {
objMatrix = object.matrixWorld;
// check if face.centroid is behind the origin
// determine if ray intersects the plane of the face
// note: this works regardless of the direction of the face normal
vector = objMatrix.multiplyVector3( vector.copy( face.centroid ) ).subSelf( originCopy );
dot = vector.dot( directionCopy );
normal = object.matrixRotationWorld.multiplyVector3( normal.copy( face.normal ) );
dot = directionCopy.dot( normal );
if ( dot <= 0 ) continue;
// bail if ray and plane are parallel
//
if ( Math.abs( dot ) < 0.0001 ) continue;
a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ].position ) );
b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ].position ) );
c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ].position ) );
if ( face instanceof THREE.Face4 ) d = objMatrix.multiplyVector3( d.copy( vertices[ face.d ].position ) );
// calc distance to plane
normal = object.matrixRotationWorld.multiplyVector3( normal.copy( face.normal ) );
dot = directionCopy.dot( normal );
scalar = normal.dot( vector ) / dot;
if ( object.doubleSided || ( object.flipSided ? dot > 0 : dot < 0 ) ) { // Math.abs( dot ) > 0.0001
// if negative distance, then plane is behind ray
if ( scalar < 0 ) continue;
if ( object.doubleSided || ( object.flipSided ? dot > 0 : dot < 0 ) ) {
scalar = normal.dot( vector.sub( a, originCopy ) ) / dot;
intersectPoint.add( originCopy, directionCopy.multiplyScalar( scalar ) );
if ( face instanceof THREE.Face3 ) {
a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ].position ) );
b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ].position ) );
c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ].position ) );
if ( pointInFace3( intersectPoint, a, b, c ) ) {
intersect = {
......@@ -144,6 +149,11 @@ THREE.Ray = function ( origin, direction ) {
} else if ( face instanceof THREE.Face4 ) {
a = objMatrix.multiplyVector3( a.copy( vertices[ face.a ].position ) );
b = objMatrix.multiplyVector3( b.copy( vertices[ face.b ].position ) );
c = objMatrix.multiplyVector3( c.copy( vertices[ face.c ].position ) );
d = objMatrix.multiplyVector3( d.copy( vertices[ face.d ].position ) );
if ( pointInFace3( intersectPoint, a, b, d ) || pointInFace3( intersectPoint, b, c, d ) ) {
intersect = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册