Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting rays intersecting a sprite

Tags:

three.js

On mouse clicks, I project a ray to see which objects are intersected by the click. I have a bunch of Mesh objects that this works with. When I add a Sprite to the list of objects however, the Sprite is never detected.

1) Should Sprites be detected? Is there something that makes them not detectable? Is there something that I need to do to make them appear 'solid'? 2) If Sprites cannot be detected, what's the best approach to making them clickable? Add invisible cylinders around them?

Here's some partial code that works with Mesh.

var containerPosition = $container.position();
var vector = new THREE.Vector3(((event.clientX - containerPosition.left) / scene.WIDTH) * 2 - 1, - ((event.clientY - containerPosition.top) / scene.HEIGHT) * 2 + 1, 0.5);
new THREE.Projector().unprojectVector(vector, scene.camera);
var ray = new THREE.Ray(scene.camera.position, vector.subSelf(scene.camera.position).normalize());
var intersects = ray.intersectObjects(scene.solidObjects);
if (intersects.length > 0) {
like image 254
user1518845 Avatar asked Jul 16 '12 20:07

user1518845


1 Answers

It seems as though the intersectObject method in the Raycaster class is only configured to look for collisions with THREE.Particle and THREE.Mesh. See the current source code at:

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

like image 159
Stemkoski Avatar answered Nov 15 '22 11:11

Stemkoski