In my current project, I have found that raycasting selection works perfectly fine for static meshes. However, when it comes to animated meshes, I have encountered an issue where the ray selection does not take into account the movement of the mesh. Instead, it only responds to the mesh's non-animated or original position.
The selection code I am using is as shown below:
element.addEventListener( 'mouseup', function ( event )
{
var vector = new THREE.Vector3(( event.clientX / window.innerWidth ) * 2 - 1, -( event.clientY / window.innerHeight ) * 2 + 1, 0.5);
vector = vector.unproject(camera);
var raycaster = new THREE.Raycaster(camera.position, vector.sub(camera.position).normalize());
var intersects = raycaster.intersectObjects(pickable_objects, true);
if (intersects.length > 0)
{
//I modify the object's material color to visualize the selection
}
}
Here, the pickable_objects
array contains three.js mesh objects that are selectable. However, these objects do not incorporate animation information, which might explain the issue I am facing.
I have omitted the code related to color change and JSON mesh reader as I believe it is not relevant to this discussion.
While the ray casting works accurately for static meshes, for animated meshes, I have observed that I need to click directly at the center of the object or locate its original non-animated position to make the selection function correctly.