Skip to content

Commit

Permalink
fix: propogate events over previous intersections on pointerLeave and…
Browse files Browse the repository at this point in the history
… pointerOut
  • Loading branch information
garrlker committed Jun 2, 2024
1 parent d2649f9 commit 66264fc
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/composables/useTresEventManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,23 @@ export function useTresEventManager(
// Current intersections mapped as meshes
const hits = event.intersections.map(({ object }) => object)

// Keep Backup of new intersections incase we overwrite due to a pointer out or leave event
const newIntersections = event.intersections as unknown as Intersection[]

// Previously intersected mesh is no longer intersected, fire onPointerLeave
prevIntersections.forEach((hit: Intersection) => {
prevIntersections.forEach(({ object: hit }) => {
if (
!hits.includes(hit as unknown as Object3D<Object3DEventMap>)
) {
event.intersections = prevIntersections
propogateEvent('onPointerLeave', event)
propogateEvent('onPointerOut', event)
}
})

// Reset intersections to newIntersections
event.intersections = newIntersections

// Newly intersected mesh is not in the previous intersections, fire onPointerEnter
event.intersections.forEach(({ object: hit }) => {
if (!prevIntersections.includes(hit as unknown as Intersection)) {
Expand All @@ -147,7 +154,7 @@ export function useTresEventManager(
propogateEvent('onPointerMove', event)

// Update previous intersections
prevIntersections = hits as unknown as Intersection[]
prevIntersections = event.intersections as unknown as Intersection[]
})

/**
Expand Down

0 comments on commit 66264fc

Please sign in to comment.