Bläddra i källkod

Merge pull request #716 from Tresjs/bugfix/713-pointer-leave-not-calling

Garrett Walker 1 år sedan
förälder
incheckning
0fb51ed6be
1 ändrade filer med 9 tillägg och 2 borttagningar
  1. 9 2
      src/composables/useTresEventManager/index.ts

+ 9 - 2
src/composables/useTresEventManager/index.ts

@@ -125,16 +125,23 @@ export function useTresEventManager(
     // Current intersections mapped as meshes
     // Current intersections mapped as meshes
     const hits = event.intersections.map(({ object }) => object)
     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
     // Previously intersected mesh is no longer intersected, fire onPointerLeave
-    prevIntersections.forEach((hit: Intersection) => {
+    prevIntersections.forEach(({ object: hit }) => {
       if (
       if (
         !hits.includes(hit as unknown as Object3D<Object3DEventMap>)
         !hits.includes(hit as unknown as Object3D<Object3DEventMap>)
       ) {
       ) {
+        event.intersections = prevIntersections
         propogateEvent('onPointerLeave', event)
         propogateEvent('onPointerLeave', event)
         propogateEvent('onPointerOut', event)
         propogateEvent('onPointerOut', event)
       }
       }
     })
     })
 
 
+    // Reset intersections to newIntersections
+    event.intersections = newIntersections
+
     // Newly intersected mesh is not in the previous intersections, fire onPointerEnter
     // Newly intersected mesh is not in the previous intersections, fire onPointerEnter
     event.intersections.forEach(({ object: hit }) => {
     event.intersections.forEach(({ object: hit }) => {
       if (!prevIntersections.includes(hit as unknown as Intersection)) {
       if (!prevIntersections.includes(hit as unknown as Intersection)) {
@@ -147,7 +154,7 @@ export function useTresEventManager(
     propogateEvent('onPointerMove', event)
     propogateEvent('onPointerMove', event)
 
 
     // Update previous intersections
     // Update previous intersections
-    prevIntersections = hits as unknown as Intersection[]
+    prevIntersections = event.intersections as unknown as Intersection[]
   })
   })
 
 
   /**
   /**