S
S
Sergey Nikolaev2016-04-02 12:53:47
JavaScript
Sergey Nikolaev, 2016-04-02 12:53:47

How to find the object closest to Raycaster in three.js?

Would you like to make THREE.Raycaster() "thicker", so that not only would a direct intersection work, but it would also be possible to find the object closest to the Raycaster?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolai, 2016-04-04
@Devastor

1. Call the intersectObjects method, get an array of intersection points with the model, take the nearest one
2. Take the vector where they shot (denoted by A), for example, at two points (where they shot from and where they hit)
3. According to some criteria, we get a list of objects that according to a rough estimate, they may be of interest to us (for example, they are not farther than a certain distance, etc.)
4. For each suitable object, we look for a direction vector from the point where the shot was fired from to the center of the object (we denote Bi)
5. We normalize all vectors, we look for the angle between the vectors A and Bi
6. Select the object with the smallest deviation angle

X
xmoonlight, 2016-04-02
@xmoonlight

This is usually done through the collision of an invisible cylinder (ray, as a pointer) with other objects...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question