Skip to content

Commit

Permalink
fix: voidObjectIntersectionFromRay reading distanceTo of null
Browse files Browse the repository at this point in the history
  • Loading branch information
bbohlender committed Nov 4, 2024
1 parent 1a43d0d commit 19aaf82
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
6 changes: 3 additions & 3 deletions examples/uikit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"dependencies": {
"@pmndrs/pointer-events": "workspace:^",
"@react-three/drei": "^9.108.3",
"@react-three/uikit": "^0.7.0",
"@react-three/uikit-default": "^0.7.0",
"@react-three/uikit-lucide": "^0.7.0",
"@react-three/uikit": "^0.7.1",
"@react-three/uikit-default": "^0.7.1",
"@react-three/uikit-lucide": "^0.7.1",
"@react-three/xr": "workspace:^",
"leva": "^0.9.35"
},
Expand Down
5 changes: 2 additions & 3 deletions packages/pointer-events/src/intersections/intersector.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Mesh, Object3D, Sphere, SphereGeometry, Intersection as ThreeIntersection } from 'three'
import { Mesh, Object3D, Sphere, SphereGeometry } from 'three'
import { Intersection } from '../index.js'
import { PointerCapture } from '../pointer.js'

const VoidObjectRadius = 1000000
export const VoidObjectCollider = new Sphere(undefined, VoidObjectRadius)
const VoidObjectRadius = 10000000000
const VoidObjectGeometry = new SphereGeometry(VoidObjectRadius)

const sceneVoidObjectMap = new Map<Object3D, Object3D>()
Expand Down
8 changes: 5 additions & 3 deletions packages/pointer-events/src/intersections/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Plane, Intersection as ThreeIntersection, Object3D, Vector3, Ray, Quaternion, Matrix4 } from 'three'
import { Intersection, IntersectionOptions } from './index.js'
import { AllowedPointerEventsType, Pointer, type AllowedPointerEvents } from '../pointer.js'
import { getVoidObject, VoidObjectCollider } from './intersector.js'
import { getVoidObject } from './intersector.js'
import { listenerNames } from '../event.js'

export function computeIntersectionWorldPlane(
Expand Down Expand Up @@ -186,6 +186,8 @@ function defaultSort(
return i1.distance - i2.distance
}

const VoidObjectDistance = 10000000

export function voidObjectIntersectionFromRay(
scene: Object3D,
ray: Ray,
Expand All @@ -194,8 +196,8 @@ export function voidObjectIntersectionFromRay(
pointerQuaternion: Quaternion,
addToDistance: number = 0,
): Intersection {
const point = ray.intersectSphere(VoidObjectCollider, new Vector3())!
const distanceOnRay = point.distanceTo(ray.origin)
const point = ray.direction.clone().multiplyScalar(VoidObjectDistance)
const distanceOnRay = VoidObjectDistance
return {
distance: distanceOnRay + addToDistance,
object: getVoidObject(scene),
Expand Down
42 changes: 21 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19aaf82

Please sign in to comment.