|
@@ -73,6 +73,8 @@ THREE.Mesh.prototype.raycast = ( function () {
|
|
|
var uvA = new THREE.Vector2();
|
|
|
var uvB = new THREE.Vector2();
|
|
|
var uvC = new THREE.Vector2();
|
|
|
+ var bary = new THREE.Vector3();
|
|
|
+ var pInter = new THREE.Vector3();
|
|
|
|
|
|
return function raycast( raycaster, intersects ) {
|
|
|
|
|
@@ -113,7 +115,7 @@ THREE.Mesh.prototype.raycast = ( function () {
|
|
|
|
|
|
var textureIntersection = function ( pIntersection, p1, p2, p3, uv1, uv2, uv3 ) {
|
|
|
|
|
|
- var bary = THREE.Triangle.barycoordFromPoint( pIntersection, p1, p2, p3 );
|
|
|
+ THREE.Triangle.barycoordFromPoint( pIntersection, p1, p2, p3, bary );
|
|
|
|
|
|
uv1.multiplyScalar( bary.x );
|
|
|
uv2.multiplyScalar( bary.y );
|
|
@@ -171,21 +173,24 @@ THREE.Mesh.prototype.raycast = ( function () {
|
|
|
|
|
|
if ( intersectionPoint === null ) continue;
|
|
|
|
|
|
+ pInter.copy(intersectionPoint);
|
|
|
+ intersectionPoint.applyMatrix4( this.matrixWorld );
|
|
|
+
|
|
|
+ var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
|
|
|
+
|
|
|
+ if ( distance < raycaster.near || distance > raycaster.far ) continue;
|
|
|
+
|
|
|
// intersectionPoint in UV coordinates.
|
|
|
var uv = undefined;
|
|
|
if ( material.map && attributes.uv !== undefined ) {
|
|
|
+
|
|
|
var uvs = attributes.uv.array;
|
|
|
uvA.fromArray( uvs, a * 2 );
|
|
|
uvB.fromArray( uvs, b * 2 );
|
|
|
uvC.fromArray( uvs, c * 2 );
|
|
|
- uv = textureIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC )
|
|
|
- }
|
|
|
+ uv = textureIntersection( pInter, vA, vB, vC, uvA, uvB, uvC );
|
|
|
|
|
|
- intersectionPoint.applyMatrix4( this.matrixWorld );
|
|
|
-
|
|
|
- var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
|
|
|
-
|
|
|
- if ( distance < raycaster.near || distance > raycaster.far ) continue;
|
|
|
+ }
|
|
|
|
|
|
intersects.push( {
|
|
|
|
|
@@ -224,21 +229,24 @@ THREE.Mesh.prototype.raycast = ( function () {
|
|
|
|
|
|
if ( intersectionPoint === null ) continue;
|
|
|
|
|
|
+ pInter.copy(intersectionPoint);
|
|
|
+ intersectionPoint.applyMatrix4( this.matrixWorld );
|
|
|
+
|
|
|
+ var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
|
|
|
+
|
|
|
+ if ( distance < raycaster.near || distance > raycaster.far ) continue;
|
|
|
+
|
|
|
// intersectionPoint in UV coordinates.
|
|
|
var uv = undefined;
|
|
|
if ( material.map && attributes.uv !== undefined ) {
|
|
|
+
|
|
|
var uvs = attributes.uv.array;
|
|
|
uvA.fromArray( uvs, i );
|
|
|
uvB.fromArray( uvs, i + 2 );
|
|
|
uvC.fromArray( uvs, i + 4 );
|
|
|
- uv = textureIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC )
|
|
|
- }
|
|
|
-
|
|
|
- intersectionPoint.applyMatrix4( this.matrixWorld );
|
|
|
+ uv = textureIntersection( pInter, vA, vB, vC, uvA, uvB, uvC );
|
|
|
|
|
|
- var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
|
|
|
-
|
|
|
- if ( distance < raycaster.near || distance > raycaster.far ) continue;
|
|
|
+ }
|
|
|
|
|
|
a = i / 3;
|
|
|
b = a + 1;
|
|
@@ -323,21 +331,24 @@ THREE.Mesh.prototype.raycast = ( function () {
|
|
|
|
|
|
if ( intersectionPoint === null ) continue;
|
|
|
|
|
|
+ pInter.copy(intersectionPoint);
|
|
|
+ intersectionPoint.applyMatrix4( this.matrixWorld );
|
|
|
+
|
|
|
+ var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
|
|
|
+
|
|
|
+ if ( distance < raycaster.near || distance > raycaster.far ) continue;
|
|
|
+
|
|
|
// intersectionPoint in UV coordinates.
|
|
|
var uv = undefined;
|
|
|
if ( material.map && geometry.faceVertexUvs[ 0 ] !== undefined ) {
|
|
|
+
|
|
|
var uvs = geometry.faceVertexUvs[ 0 ][ f ];
|
|
|
uvA.copy( uvs[ 0 ] );
|
|
|
uvB.copy( uvs[ 1 ] );
|
|
|
uvC.copy( uvs[ 2 ] );
|
|
|
- uv = textureIntersection( intersectionPoint, a, b, c, uvA, uvB, uvC )
|
|
|
- }
|
|
|
-
|
|
|
- intersectionPoint.applyMatrix4( this.matrixWorld );
|
|
|
-
|
|
|
- var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
|
|
|
+ uv = textureIntersection( pInter, a, b, c, uvA, uvB, uvC );
|
|
|
|
|
|
- if ( distance < raycaster.near || distance > raycaster.far ) continue;
|
|
|
+ }
|
|
|
|
|
|
intersects.push( {
|
|
|
|