RayCaster intersects with lines but not meshes

My scene has a number of added objects that are created like this:

const lineMaterial = new THREE.LineBasicMaterial( { color: this.color } );
const lineGeometry = new THREE.BufferGeometry().setFromPoints( stPoints );			
const line = new THREE.Line( lineGeometry, lineMaterial );
scene.add(line);

And RayCaster finds intersections with these just fine. But RayCaster does find any intersections with any objects that I’ve created like this:

const mesh = new THREE.Mesh( new THREE.SphereGeometry( 0.06, 4, 4 ), new THREE.MeshPhongMaterial( { color: this.color } ) ); 
scene.add(mesh);

RayCaster is actually returning over 100 intersecting objects, but I set a type property in the scene child’s userData and only the first kind of objects above ever appear in the intersection list.

Do I need to do anything extra with the meshes to get them to show up in the intersection list?

It should be working. You can check if an object is a mesh with thing.isMesh.
The hits are sorted by depth so hit[0] should be what the user clicked.

If you can’t find the bug… I’d suggest starting with 1 ray and cast against 1 mesh to verify that your ray is getting set up correctly etc.

@manthrax I guess my problem is that I don’t know what the correct behavior is. Are objects in the intersect array always objects that were added directly to the scene or can their children be returned in the intersection array, too? If the ray intersects with 2 of an object’s children do the two children each get returned in the array , does the parent object get returned twice in the array or does the parent object get returned only once in the array? The doc isn’t quite clear.

Their children can be in the list too depending on whether you passed the “recursive” flag… which defaults to true. You can raycast against an object, an array of objects, or an object and its children (the default if you pass in an object). An object may be in the list twice I think… if the ray both enters and exits… so… for a plane you should only get 1 hit, but for a cube, you might get 2? Don’t quote me on that… but ya. . but generally the hits array is in the order that they are hit… so each subsequent hit is further along the ray.
Most of the time we only care about the first hit.