|
@@ -11025,10 +11025,6 @@ var _inverseMatrix = new Matrix4();
|
|
var _ray = new Ray();
|
|
var _ray = new Ray();
|
|
var _sphere = new Sphere();
|
|
var _sphere = new Sphere();
|
|
|
|
|
|
-var _matrixWorld = new Matrix4();
|
|
|
|
-var _instanceMatrix = new Matrix4();
|
|
|
|
-var _executionTimes = 1;
|
|
|
|
-
|
|
|
|
var _vA = new Vector3();
|
|
var _vA = new Vector3();
|
|
var _vB = new Vector3();
|
|
var _vB = new Vector3();
|
|
var _vC = new Vector3();
|
|
var _vC = new Vector3();
|
|
@@ -11151,194 +11147,163 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
if ( material === undefined ) return;
|
|
if ( material === undefined ) return;
|
|
|
|
|
|
- //Determine how many times raycast will execute
|
|
|
|
-
|
|
|
|
- if ( this.isInstancedMesh ) {
|
|
|
|
-
|
|
|
|
- _executionTimes = this.count;
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- _executionTimes = 1;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for ( var instanceId = 0; instanceId < _executionTimes; instanceId ++ ) {
|
|
|
|
-
|
|
|
|
- //Determine the world matrix for this calculation
|
|
|
|
-
|
|
|
|
- if ( this.isInstancedMesh ) {
|
|
|
|
-
|
|
|
|
- _instanceMatrix = this.getMatrixAt( instanceId );
|
|
|
|
- _matrixWorld.multiplyMatrices( matrixWorld, _instanceMatrix );
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- _matrixWorld = matrixWorld;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ // Checking boundingSphere distance to ray
|
|
|
|
|
|
- // Checking boundingSphere distance to ray
|
|
|
|
|
|
+ if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
|
|
|
|
|
|
- if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
|
|
|
|
|
|
+ _sphere.copy( geometry.boundingSphere );
|
|
|
|
+ _sphere.applyMatrix4( matrixWorld );
|
|
|
|
|
|
- _sphere.copy( geometry.boundingSphere );
|
|
|
|
- _sphere.applyMatrix4( _matrixWorld );
|
|
|
|
|
|
+ if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
|
|
|
|
|
|
- if ( raycaster.ray.intersectsSphere( _sphere ) === false ) continue;
|
|
|
|
|
|
+ //
|
|
|
|
|
|
- //Transform the ray into the local space of the model
|
|
|
|
|
|
+ _inverseMatrix.getInverse( matrixWorld );
|
|
|
|
+ _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
|
|
|
|
|
|
- _inverseMatrix.getInverse( _matrixWorld );
|
|
|
|
- _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
|
|
|
|
|
|
+ // Check boundingBox before continuing
|
|
|
|
|
|
- // Check boundingBox before continuing
|
|
|
|
|
|
+ if ( geometry.boundingBox !== null ) {
|
|
|
|
|
|
- if ( geometry.boundingBox !== null ) {
|
|
|
|
|
|
+ if ( _ray.intersectsBox( geometry.boundingBox ) === false ) return;
|
|
|
|
|
|
- if ( _ray.intersectsBox( geometry.boundingBox ) === false ) continue;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ // check unsupported draw modes
|
|
|
|
|
|
- var intersection;
|
|
|
|
|
|
+ if ( this.drawMode !== TrianglesDrawMode ) {
|
|
|
|
|
|
- if ( geometry.isBufferGeometry ) {
|
|
|
|
|
|
+ console.warn( 'THREE.Mesh: TriangleStripDrawMode and TriangleFanDrawMode are not supported by .raycast().' );
|
|
|
|
+ return;
|
|
|
|
|
|
- var a, b, c;
|
|
|
|
- var index = geometry.index;
|
|
|
|
- var position = geometry.attributes.position;
|
|
|
|
- var morphPosition = geometry.morphAttributes.position;
|
|
|
|
- var uv = geometry.attributes.uv;
|
|
|
|
- var uv2 = geometry.attributes.uv2;
|
|
|
|
- var groups = geometry.groups;
|
|
|
|
- var drawRange = geometry.drawRange;
|
|
|
|
- var i, j, il, jl;
|
|
|
|
- var group, groupMaterial;
|
|
|
|
- var start, end;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- if ( index !== null ) {
|
|
|
|
|
|
+ var intersection;
|
|
|
|
|
|
- // indexed buffer geometry
|
|
|
|
|
|
+ if ( geometry.isBufferGeometry ) {
|
|
|
|
|
|
- if ( Array.isArray( material ) ) {
|
|
|
|
|
|
+ var a, b, c;
|
|
|
|
+ var index = geometry.index;
|
|
|
|
+ var position = geometry.attributes.position;
|
|
|
|
+ var morphPosition = geometry.morphAttributes.position;
|
|
|
|
+ var morphTargetsRelative = geometry.morphTargetsRelative;
|
|
|
|
+ var uv = geometry.attributes.uv;
|
|
|
|
+ var uv2 = geometry.attributes.uv2;
|
|
|
|
+ var groups = geometry.groups;
|
|
|
|
+ var drawRange = geometry.drawRange;
|
|
|
|
+ var i, j, il, jl;
|
|
|
|
+ var group, groupMaterial;
|
|
|
|
+ var start, end;
|
|
|
|
|
|
- for ( i = 0, il = groups.length; i < il; i ++ ) {
|
|
|
|
|
|
+ if ( index !== null ) {
|
|
|
|
|
|
- group = groups[ i ];
|
|
|
|
- groupMaterial = material[ group.materialIndex ];
|
|
|
|
|
|
+ // indexed buffer geometry
|
|
|
|
|
|
- start = Math.max( group.start, drawRange.start );
|
|
|
|
- end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
|
|
|
|
|
|
+ if ( Array.isArray( material ) ) {
|
|
|
|
|
|
- for ( j = start, jl = end; j < jl; j += 3 ) {
|
|
|
|
|
|
+ for ( i = 0, il = groups.length; i < il; i ++ ) {
|
|
|
|
|
|
- a = index.getX( j );
|
|
|
|
- b = index.getX( j + 1 );
|
|
|
|
- c = index.getX( j + 2 );
|
|
|
|
|
|
+ group = groups[ i ];
|
|
|
|
+ groupMaterial = material[ group.materialIndex ];
|
|
|
|
|
|
- intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c );
|
|
|
|
|
|
+ start = Math.max( group.start, drawRange.start );
|
|
|
|
+ end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
|
|
|
|
|
|
- if ( intersection ) {
|
|
|
|
|
|
+ for ( j = start, jl = end; j < jl; j += 3 ) {
|
|
|
|
|
|
- intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
|
|
|
|
- intersection.face.materialIndex = group.materialIndex;
|
|
|
|
|
|
+ a = index.getX( j );
|
|
|
|
+ b = index.getX( j + 1 );
|
|
|
|
+ c = index.getX( j + 2 );
|
|
|
|
|
|
- intersection.instanceId = instanceId;
|
|
|
|
|
|
+ intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
|
|
|
|
|
|
- intersects.push( intersection );
|
|
|
|
|
|
+ if ( intersection ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
|
|
|
|
+ intersection.face.materialIndex = group.materialIndex;
|
|
|
|
+ intersects.push( intersection );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- start = Math.max( 0, drawRange.start );
|
|
|
|
- end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
|
|
|
|
-
|
|
|
|
- for ( i = start, il = end; i < il; i += 3 ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- a = index.getX( i );
|
|
|
|
- b = index.getX( i + 1 );
|
|
|
|
- c = index.getX( i + 2 );
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c );
|
|
|
|
|
|
+ start = Math.max( 0, drawRange.start );
|
|
|
|
+ end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
|
|
|
|
|
|
- if ( intersection ) {
|
|
|
|
|
|
+ for ( i = start, il = end; i < il; i += 3 ) {
|
|
|
|
|
|
- intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
|
|
|
|
|
|
+ a = index.getX( i );
|
|
|
|
+ b = index.getX( i + 1 );
|
|
|
|
+ c = index.getX( i + 2 );
|
|
|
|
|
|
- intersection.instanceId = instanceId;
|
|
|
|
|
|
+ intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
|
|
|
|
|
|
- intersects.push( intersection );
|
|
|
|
|
|
+ if ( intersection ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
|
|
|
|
+ intersects.push( intersection );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- } else if ( position !== undefined ) {
|
|
|
|
-
|
|
|
|
- // non-indexed buffer geometry
|
|
|
|
-
|
|
|
|
- if ( Array.isArray( material ) ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- for ( i = 0, il = groups.length; i < il; i ++ ) {
|
|
|
|
|
|
+ } else if ( position !== undefined ) {
|
|
|
|
|
|
- group = groups[ i ];
|
|
|
|
- groupMaterial = material[ group.materialIndex ];
|
|
|
|
|
|
+ // non-indexed buffer geometry
|
|
|
|
|
|
- start = Math.max( group.start, drawRange.start );
|
|
|
|
- end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
|
|
|
|
|
|
+ if ( Array.isArray( material ) ) {
|
|
|
|
|
|
- for ( j = start, jl = end; j < jl; j += 3 ) {
|
|
|
|
|
|
+ for ( i = 0, il = groups.length; i < il; i ++ ) {
|
|
|
|
|
|
- a = j;
|
|
|
|
- b = j + 1;
|
|
|
|
- c = j + 2;
|
|
|
|
|
|
+ group = groups[ i ];
|
|
|
|
+ groupMaterial = material[ group.materialIndex ];
|
|
|
|
|
|
- intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c );
|
|
|
|
|
|
+ start = Math.max( group.start, drawRange.start );
|
|
|
|
+ end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
|
|
|
|
|
|
- if ( intersection ) {
|
|
|
|
|
|
+ for ( j = start, jl = end; j < jl; j += 3 ) {
|
|
|
|
|
|
- intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
|
|
|
|
- intersection.face.materialIndex = group.materialIndex;
|
|
|
|
|
|
+ a = j;
|
|
|
|
+ b = j + 1;
|
|
|
|
+ c = j + 2;
|
|
|
|
|
|
- intersection.instanceId = instanceId;
|
|
|
|
|
|
+ intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
|
|
|
|
|
|
- intersects.push( intersection );
|
|
|
|
|
|
+ if ( intersection ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
|
|
|
|
+ intersection.face.materialIndex = group.materialIndex;
|
|
|
|
+ intersects.push( intersection );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- start = Math.max( 0, drawRange.start );
|
|
|
|
- end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
|
|
|
|
-
|
|
|
|
- for ( i = start, il = end; i < il; i += 3 ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- a = i;
|
|
|
|
- b = i + 1;
|
|
|
|
- c = i + 2;
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, uv, uv2, a, b, c );
|
|
|
|
|
|
+ start = Math.max( 0, drawRange.start );
|
|
|
|
+ end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
|
|
|
|
|
|
- if ( intersection ) {
|
|
|
|
|
|
+ for ( i = start, il = end; i < il; i += 3 ) {
|
|
|
|
|
|
- intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
|
|
|
|
|
|
+ a = i;
|
|
|
|
+ b = i + 1;
|
|
|
|
+ c = i + 2;
|
|
|
|
|
|
- intersection.instanceId = instanceId;
|
|
|
|
|
|
+ intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
|
|
|
|
|
|
- intersects.push( intersection );
|
|
|
|
|
|
+ if ( intersection ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
|
|
|
|
+ intersects.push( intersection );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -11346,50 +11311,50 @@ Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- } else if ( geometry.isGeometry ) {
|
|
|
|
-
|
|
|
|
- var fvA, fvB, fvC;
|
|
|
|
- var isMultiMaterial = Array.isArray( material );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- var vertices = geometry.vertices;
|
|
|
|
- var faces = geometry.faces;
|
|
|
|
- var uvs;
|
|
|
|
|
|
+ } else if ( geometry.isGeometry ) {
|
|
|
|
|
|
- var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
|
|
|
|
- if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
|
|
|
|
|
|
+ var fvA, fvB, fvC;
|
|
|
|
+ var isMultiMaterial = Array.isArray( material );
|
|
|
|
|
|
- for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
|
|
|
|
|
|
+ var vertices = geometry.vertices;
|
|
|
|
+ var faces = geometry.faces;
|
|
|
|
+ var uvs;
|
|
|
|
|
|
- var face = faces[ f ];
|
|
|
|
- var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
|
|
|
|
|
|
+ var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
|
|
|
|
+ if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
|
|
|
|
|
|
- if ( faceMaterial === undefined ) continue;
|
|
|
|
|
|
+ for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
|
|
|
|
|
|
- fvA = vertices[ face.a ];
|
|
|
|
- fvB = vertices[ face.b ];
|
|
|
|
- fvC = vertices[ face.c ];
|
|
|
|
|
|
+ var face = faces[ f ];
|
|
|
|
+ var faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
|
|
|
|
|
|
- intersection = checkIntersection( this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint );
|
|
|
|
|
|
+ if ( faceMaterial === undefined ) continue;
|
|
|
|
|
|
- if ( intersection ) {
|
|
|
|
|
|
+ fvA = vertices[ face.a ];
|
|
|
|
+ fvB = vertices[ face.b ];
|
|
|
|
+ fvC = vertices[ face.c ];
|
|
|
|
|
|
- if ( uvs && uvs[ f ] ) {
|
|
|
|
|
|
+ intersection = checkIntersection( this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint );
|
|
|
|
|
|
- var uvs_f = uvs[ f ];
|
|
|
|
- _uvA.copy( uvs_f[ 0 ] );
|
|
|
|
- _uvB.copy( uvs_f[ 1 ] );
|
|
|
|
- _uvC.copy( uvs_f[ 2 ] );
|
|
|
|
|
|
+ if ( intersection ) {
|
|
|
|
|
|
- intersection.uv = Triangle.getUV( _intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2() );
|
|
|
|
|
|
+ if ( uvs && uvs[ f ] ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ var uvs_f = uvs[ f ];
|
|
|
|
+ _uvA.copy( uvs_f[ 0 ] );
|
|
|
|
+ _uvB.copy( uvs_f[ 1 ] );
|
|
|
|
+ _uvC.copy( uvs_f[ 2 ] );
|
|
|
|
|
|
- intersection.face = face;
|
|
|
|
- intersection.faceIndex = f;
|
|
|
|
- intersects.push( intersection );
|
|
|
|
|
|
+ intersection.uv = Triangle.getUV( _intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2() );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ intersection.face = face;
|
|
|
|
+ intersection.faceIndex = f;
|
|
|
|
+ intersects.push( intersection );
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -11423,7 +11388,7 @@ function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point
|
|
if ( intersect === null ) return null;
|
|
if ( intersect === null ) return null;
|
|
|
|
|
|
_intersectionPointWorld.copy( point );
|
|
_intersectionPointWorld.copy( point );
|
|
- _intersectionPointWorld.applyMatrix4( _matrixWorld );
|
|
|
|
|
|
+ _intersectionPointWorld.applyMatrix4( object.matrixWorld );
|
|
|
|
|
|
var distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
|
|
var distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
|
|
|
|
|
|
@@ -11437,7 +11402,7 @@ function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, uv, uv2, a, b, c ) {
|
|
|
|
|
|
+function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) {
|
|
|
|
|
|
_vA.fromBufferAttribute( position, a );
|
|
_vA.fromBufferAttribute( position, a );
|
|
_vB.fromBufferAttribute( position, b );
|
|
_vB.fromBufferAttribute( position, b );
|
|
@@ -11462,9 +11427,19 @@ function checkBufferGeometryIntersection( object, material, raycaster, ray, posi
|
|
_tempB.fromBufferAttribute( morphAttribute, b );
|
|
_tempB.fromBufferAttribute( morphAttribute, b );
|
|
_tempC.fromBufferAttribute( morphAttribute, c );
|
|
_tempC.fromBufferAttribute( morphAttribute, c );
|
|
|
|
|
|
- _morphA.addScaledVector( _tempA.sub( _vA ), influence );
|
|
|
|
- _morphB.addScaledVector( _tempB.sub( _vB ), influence );
|
|
|
|
- _morphC.addScaledVector( _tempC.sub( _vC ), influence );
|
|
|
|
|
|
+ if ( morphTargetsRelative ) {
|
|
|
|
+
|
|
|
|
+ _morphA.addScaledVector( _tempA, influence );
|
|
|
|
+ _morphB.addScaledVector( _tempB, influence );
|
|
|
|
+ _morphC.addScaledVector( _tempC, influence );
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ _morphA.addScaledVector( _tempA.sub( _vA ), influence );
|
|
|
|
+ _morphB.addScaledVector( _tempB.sub( _vB ), influence );
|
|
|
|
+ _morphC.addScaledVector( _tempC.sub( _vC ), influence );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -27329,15 +27304,7 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
|
|
|
|
|
|
isInstancedMesh: true,
|
|
isInstancedMesh: true,
|
|
|
|
|
|
- getMatrixAt: function ( index, matrix ) {
|
|
|
|
-
|
|
|
|
- var matrix = matrix || new Matrix4();
|
|
|
|
-
|
|
|
|
- matrix.fromArray( this.instanceMatrix.array, index * 16 );
|
|
|
|
-
|
|
|
|
- return matrix;
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
|
|
+ raycast: function () {},
|
|
|
|
|
|
setMatrixAt: function ( index, matrix ) {
|
|
setMatrixAt: function ( index, matrix ) {
|
|
|
|
|
|
@@ -27345,9 +27312,7 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- // updateMorphTargets: function () {
|
|
|
|
- //
|
|
|
|
- // }
|
|
|
|
|
|
+ updateMorphTargets: function () {}
|
|
|
|
|
|
} );
|
|
} );
|
|
|
|
|