From 635d56d36bf90cde2278c31ca975b3121751977d Mon Sep 17 00:00:00 2001 From: AntoninRousset Date: Sat, 12 Oct 2024 16:43:38 +0200 Subject: [PATCH] fix(useRaycaster): set delta on pointer-missed events --- src/composables/useRaycaster/index.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/composables/useRaycaster/index.ts b/src/composables/useRaycaster/index.ts index da7795009..56dd3b541 100644 --- a/src/composables/useRaycaster/index.ts +++ b/src/composables/useRaycaster/index.ts @@ -133,20 +133,20 @@ export const useRaycaster = ( const onPointerUp = (event: MouseEvent) => { if (!(event instanceof PointerEvent)) { return } // prevents triggering twice on mobile devices + mouseUpPosition = new Vector2( + event?.clientX ?? x.value, + event?.clientY ?? y.value, + ) + + // Compute the distance between the mouse down and mouse up events + delta = mouseDownPosition?.distanceTo(mouseUpPosition) + // We missed every object, trigger the pointer missed event if (intersects.value.length === 0) { triggerEventHook(eventHookPointerMissed, event) } if (mouseDownObject === intersects.value[0]?.object) { - mouseUpPosition = new Vector2( - event?.clientX ?? x.value, - event?.clientY ?? y.value, - ) - - // Compute the distance between the mouse down and mouse up events - delta = mouseDownPosition?.distanceTo(mouseUpPosition) - if (event.button === 0) { // Left click triggerEventHook(eventHookClick, event)