@@ -155,13 +155,15 @@ class Mesh extends Object3D {
155155
156156 if ( material === undefined ) return ;
157157
158- // Checking boundingSphere distance to ray
158+ // test with bounding sphere in world space
159159
160160 if ( geometry . boundingSphere === null ) geometry . computeBoundingSphere ( ) ;
161161
162162 _sphere . copy ( geometry . boundingSphere ) ;
163163 _sphere . applyMatrix4 ( matrixWorld ) ;
164164
165+ // check distance from ray origin to bounding sphere
166+
165167 _ray . copy ( raycaster . ray ) . recast ( raycaster . near ) ;
166168
167169 if ( _sphere . containsPoint ( _ray . origin ) === false ) {
@@ -172,24 +174,26 @@ class Mesh extends Object3D {
172174
173175 }
174176
175- //
177+ // convert ray to local space of mesh
176178
177179 _inverseMatrix . copy ( matrixWorld ) . invert ( ) ;
178180 _ray . copy ( raycaster . ray ) . applyMatrix4 ( _inverseMatrix ) ;
179181
180- // Check boundingBox before continuing
182+ // test with bounding box in local space
181183
182184 if ( geometry . boundingBox !== null ) {
183185
184186 if ( _ray . intersectsBox ( geometry . boundingBox ) === false ) return ;
185187
186188 }
187189
188- this . _computeIntersections ( raycaster , intersects ) ;
190+ // test for intersections with geometry
191+
192+ this . _computeIntersections ( raycaster , intersects , _ray ) ;
189193
190194 }
191195
192- _computeIntersections ( raycaster , intersects ) {
196+ _computeIntersections ( raycaster , intersects , rayLocalSpace ) {
193197
194198 let intersection ;
195199
@@ -224,7 +228,7 @@ class Mesh extends Object3D {
224228 const b = index . getX ( j + 1 ) ;
225229 const c = index . getX ( j + 2 ) ;
226230
227- intersection = checkGeometryIntersection ( this , groupMaterial , raycaster , _ray , uv , uv1 , normal , a , b , c ) ;
231+ intersection = checkGeometryIntersection ( this , groupMaterial , raycaster , rayLocalSpace , uv , uv1 , normal , a , b , c ) ;
228232
229233 if ( intersection ) {
230234
@@ -249,7 +253,7 @@ class Mesh extends Object3D {
249253 const b = index . getX ( i + 1 ) ;
250254 const c = index . getX ( i + 2 ) ;
251255
252- intersection = checkGeometryIntersection ( this , material , raycaster , _ray , uv , uv1 , normal , a , b , c ) ;
256+ intersection = checkGeometryIntersection ( this , material , raycaster , rayLocalSpace , uv , uv1 , normal , a , b , c ) ;
253257
254258 if ( intersection ) {
255259
@@ -282,7 +286,7 @@ class Mesh extends Object3D {
282286 const b = j + 1 ;
283287 const c = j + 2 ;
284288
285- intersection = checkGeometryIntersection ( this , groupMaterial , raycaster , _ray , uv , uv1 , normal , a , b , c ) ;
289+ intersection = checkGeometryIntersection ( this , groupMaterial , raycaster , rayLocalSpace , uv , uv1 , normal , a , b , c ) ;
286290
287291 if ( intersection ) {
288292
@@ -307,7 +311,7 @@ class Mesh extends Object3D {
307311 const b = i + 1 ;
308312 const c = i + 2 ;
309313
310- intersection = checkGeometryIntersection ( this , material , raycaster , _ray , uv , uv1 , normal , a , b , c ) ;
314+ intersection = checkGeometryIntersection ( this , material , raycaster , rayLocalSpace , uv , uv1 , normal , a , b , c ) ;
311315
312316 if ( intersection ) {
313317
0 commit comments