useRaycaster
Wraps Raycaster to simplify mouse picking operations.
Usage
ts
import { useRaycaster } from '@threeuse/core'
const { setFromMouse, raycast, intersects } = useRaycaster(app)
canvas.addEventListener('click', (e) => {
setFromMouse(e)
const hits = raycast([meshA, meshB])
if (hits.length > 0) {
console.log('Hit:', hits[0].object)
}
})Return Value
| Property | Type | Description |
|---|---|---|
intersects | Ref<Intersection[]> | Latest raycast results |
setFromMouse | (event) => Intersection[] | Update ray direction from mouse event |
raycast | (objects, recursive?) => Intersection[] | Execute raycast |
Demo
移动鼠标到立方体上