Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intersect Sprites with Raycaster

Tags:

three.js

I want to realize a 3D interactive globe with three.js and I wonder if there is a way to intersect over Sprites primitive with the Raycaster?

like image 585
neeh Avatar asked Oct 22 '22 13:10

neeh


1 Answers

If you check the source code for RayCaster at

https://github.com/mrdoob/three.js/blob/master/src/core/Raycaster.js

it would appear that the intersectObject function only checks objects that are instances of THREE.Particle or THREE.Mesh, not THREE.Sprite. Possibly this is because sprites could be set to use screen coordinates, and so a ray that projects into your 3d scene wouldn't make sense in this situation, or if placed in the scene as the sprite image always faces the camera, it doesn't act like your standard 3d mesh.

Perhaps you could attach a PlaneGeometry or a very thin CubeGeometry to the position of your sprite, set its rotation to the rotation of the camera so that it is always parallel to the view plane of the camera like the sprite is, and then check for intersections with the mesh instead?

like image 109
Stemkoski Avatar answered Oct 25 '22 17:10

Stemkoski