Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Pointer Leave and Out events not being called #716

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading