InputMiddleweight
Pointer & raycasting
Which 3D object is under the cursor.
Finding which 3D object is under the cursor. A line is shot from the camera through the mouse position, and whatever it hits can glow, open or be dragged. Touch screens have no hover, so plan a second cue.
- Breaks when
- raycasting thousands of meshes per frametouch has no hover
- Also called
- Raycaster, onPointerMove, mouse follow, cursor
Prompts
Hover states for a product cluster
Three.js Raycaster from the pointer against 12 product meshes (not the floor, not the lights: keep a pickable array). On hover, the hit mesh’s emissive rises to 0.25 over 150 ms and an HTML label follows its projected position (project() → CSS transform). Throttle the raycast to pointer moves (no raycast on idle frames) and give each mesh a bounding sphere. On touch devices, tap selects and a second tap opens; state the difference in a comment.
Drag on a plane
Drag a 3D object across the floor: on pointerdown raycast to pick, then on move intersect the ray with a horizontal plane at the object’s height (Plane.intersectLine or ray.intersectPlane) and move the object to that point minus the grab offset. Damped follow, drop shadow scales with lift on grab. Use setPointerCapture so fast drags do not lose the object.
GPU picking for thousands
Replace CPU raycasting with GPU picking for 20,000 instanced objects: render an ID pass to a 1×1 target under the pointer with a per-instance color, readPixels, and map back to the instance index. Explain the async readback cost and when CPU raycasting is still the better choice.
Related
Resources · 2
- WebGL Fluid SimulationThe cursor-fluid everyone forks. Stable Fluids in one file.PavelDoGreatGitHub · code · demoAug 30, 2026
- three.js example: raycasting pointsmrdoobsite · code · demoMar 28, 2026