pmndrs-pointer-events
Installation
SKILL.md
@pmndrs/pointer-events
Objects receive events through three's own addEventListener, with the same names and semantics as DOM pointer events: pointerdown/up/move/over/out/enter/leave/cancel, click, dblclick, contextmenu, wheel. Every event source — mouse, touch, an XR ray, a grabbing hand — is a pointer, so one listener works for all of them.
Choosing an entry point
- Screen input (mouse, touch, pen):
forwardHtmlEvents(canvas, () => camera, scene). - Events hitting a mesh that shows another scene (a render-target screen, a portal, an in-world editor viewport):
forwardObjectEvents(mesh, () => innerCamera, innerScene). The hit'suvbecomes the screen coordinate for the inner camera, so the mesh needs UVs. - A tracked object that points or touches (XR controller, hand, a tool in the scene):
createRayPointerfor a straight ray along the object's -Z,createLinesPointerfor a curved/polyline ray (teleport arcs),createGrabPointerfor a sphere you press withdown/upyourself (squeeze to grab),createTouchPointerfor a fingertip sphere that presses on its own when close enough. - Several pointers on the same hand: register them in one
CombinedPointerso the scene is traversed once per frame instead of once per pointer, and only the nearest pointer stays active when constructed withenableMultiplePointers = false.
Wiring
const { update, destroy } = forwardHtmlEvents(canvas, () => camera, scene)
mesh.addEventListener('click', (e) => console.log(e.point))