@pmndrs/pointer-events
Advanced tools
Comparing version 6.4.12-alpha.48 to 6.4.12-alpha.54
@@ -114,3 +114,3 @@ import { intersectPointerEventTargets } from './intersections/utils.js'; | ||
//intersect scene using the non captured pointers | ||
intersectPointerEventTargets(scene, this.nonCapturedPointers); | ||
intersectPointerEventTargets('pointer', scene, this.nonCapturedPointers); | ||
//finalize the intersection for the non captured pointers | ||
@@ -117,0 +117,0 @@ const nonCapturedPointerLength = this.nonCapturedPointers.length; |
@@ -56,3 +56,3 @@ import { Pointer } from './pointer.js'; | ||
//this allows enter, down, ... events to be forwarded to the scene even when they dont come with a move event | ||
innerPointer.setIntersection(innerPointer.computeIntersection(scene, event)); | ||
innerPointer.setIntersection(innerPointer.computeIntersection('pointer', scene, event)); | ||
innerPointer.commit(event, false); | ||
@@ -59,0 +59,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Object3D } from 'three'; | ||
import { Object3D, Sphere, Intersection as ThreeIntersection } from 'three'; | ||
import type { PointerCapture } from '../pointer.js'; | ||
@@ -14,3 +14,2 @@ import { Intersector } from './intersector.js'; | ||
private readonly intersects; | ||
private readonly pointerEventsOrders; | ||
constructor(space: { | ||
@@ -23,4 +22,9 @@ current?: Object3D | null; | ||
startIntersection(): void; | ||
executeIntersection(object: Object3D, objectPointerEventsOrder: number | undefined): void; | ||
executeIntersection(object: Object3D): void; | ||
finalizeIntersection(scene: Object3D): Intersection; | ||
} | ||
declare module 'three' { | ||
interface Object3D { | ||
spherecast?(sphere: Sphere, intersects: Array<ThreeIntersection>): void; | ||
} | ||
} |
import { InstancedMesh, Matrix4, Mesh, Vector3, Sphere, Quaternion, Plane, Vector2, } from 'three'; | ||
import { computeIntersectionWorldPlane, getDominantIntersectionIndex, pushTimes } from './utils.js'; | ||
import { computeIntersectionWorldPlane, getDominantIntersectionIndex } from './utils.js'; | ||
import { getVoidObject } from '../index.js'; | ||
@@ -16,3 +16,2 @@ import { getClosestUV, updateAndCheckWorldTransformation } from '../utils.js'; | ||
intersects = []; | ||
pointerEventsOrders = []; | ||
constructor(space, getSphereRadius, options) { | ||
@@ -63,3 +62,3 @@ this.space = space; | ||
uv, | ||
distance: intersection.distance, | ||
distance: point.distanceTo(pointOnFace), | ||
pointerPosition: this.fromPosition.clone(), | ||
@@ -81,9 +80,7 @@ pointerQuaternion: this.fromQuaternion.clone(), | ||
} | ||
executeIntersection(object, objectPointerEventsOrder) { | ||
executeIntersection(object) { | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
const start = this.intersects.length; | ||
intersectSphereWithObject(this.collisionSphere, object, this.intersects); | ||
pushTimes(this.pointerEventsOrders, objectPointerEventsOrder, this.intersects.length - start); | ||
} | ||
@@ -93,6 +90,5 @@ finalizeIntersection(scene) { | ||
const pointerQuaternion = this.fromQuaternion.clone(); | ||
const index = getDominantIntersectionIndex(this.intersects, this.pointerEventsOrders, this.options); | ||
const index = getDominantIntersectionIndex(this.intersects, undefined, this.options); | ||
const intersection = index == null ? undefined : this.intersects[index]; | ||
this.intersects.length = 0; | ||
this.pointerEventsOrders.length = 0; | ||
if (intersection == null) { | ||
@@ -127,8 +123,5 @@ return { | ||
const matrixHelper = new Matrix4(); | ||
function isSpherecastable(obj) { | ||
return 'spherecast' in obj; | ||
} | ||
function intersectSphereWithObject(pointerSphere, object, target) { | ||
object.updateWorldMatrix(true, false); | ||
if (isSpherecastable(object)) { | ||
if (object.spherecast != null) { | ||
object.spherecast(pointerSphere, target); | ||
@@ -206,2 +199,6 @@ return; | ||
const point = vectorHelper.clone(); | ||
let uv; | ||
if (getClosestUV(point2Helper, point, mesh)) { | ||
uv = point2Helper.clone(); | ||
} | ||
return { | ||
@@ -216,2 +213,3 @@ distance: Math.sqrt(distanceToSphereCenterSquared), | ||
}, | ||
uv, | ||
normal, | ||
@@ -218,0 +216,0 @@ point, |
@@ -5,3 +5,3 @@ import { Plane, Intersection as ThreeIntersection, Object3D, Vector3, Ray, Quaternion, Matrix4 } from 'three'; | ||
export declare function computeIntersectionWorldPlane(target: Plane, intersection: Intersection, objectMatrixWorld: Matrix4): boolean; | ||
export declare function intersectPointerEventTargets(object: Object3D, pointers: Array<Pointer>, parentHasListener?: boolean, parentPointerEvents?: AllowedPointerEvents, parentPointerEventsType?: AllowedPointerEventsType, parentPointerEventsOrder?: number): void; | ||
export declare function intersectPointerEventTargets(type: 'wheel' | 'pointer', object: Object3D, pointers: Array<Pointer>, parentHasListener?: boolean, parentPointerEvents?: AllowedPointerEvents, parentPointerEventsType?: AllowedPointerEventsType, parentPointerEventsOrder?: number): void; | ||
/** | ||
@@ -11,4 +11,4 @@ * @returns undefined if `i1` is the dominant intersection | ||
*/ | ||
export declare function getDominantIntersectionIndex<T extends ThreeIntersection>(intersections: Array<T>, pointerEventsOrders: Array<number | undefined>, { customSort: compare }?: IntersectionOptions, filter?: (intersection: ThreeIntersection) => boolean): number | undefined; | ||
export declare function getDominantIntersectionIndex<T extends ThreeIntersection>(intersections: Array<T>, pointerEventsOrders: Array<number | undefined> | undefined, { customSort: compare }?: IntersectionOptions, filter?: (intersection: ThreeIntersection) => boolean): number | undefined; | ||
export declare function voidObjectIntersectionFromRay(scene: Object3D, ray: Ray, getDetails: (pointer: Vector3, distanceOnRay: number) => Intersection['details'], pointerPosition: Vector3, pointerQuaternion: Quaternion, addToDistance?: number): Intersection; | ||
export declare function pushTimes<T>(target: Array<T>, value: T, times: number): void; |
@@ -43,4 +43,4 @@ import { getVoidObject } from './intersector.js'; | ||
} | ||
export function intersectPointerEventTargets(object, pointers, parentHasListener = false, parentPointerEvents, parentPointerEventsType, parentPointerEventsOrder) { | ||
const hasListener = parentHasListener || hasObjectListeners(object); | ||
export function intersectPointerEventTargets(type, object, pointers, parentHasListener = false, parentPointerEvents, parentPointerEventsType, parentPointerEventsOrder) { | ||
const hasListener = parentHasListener || hasObjectListeners(type, object); | ||
const pointerEvents = object.pointerEvents ?? parentPointerEvents; | ||
@@ -77,15 +77,30 @@ const pointerEventsOrDefault = pointerEvents ?? object.defaultPointerEvents ?? 'listener'; | ||
for (let i = 0; i < descendantsLength; i++) { | ||
intersectPointerEventTargets(descendants[i], pointers, hasListener, pointerEvents, pointerEventsType, pointerEventsOrder); | ||
intersectPointerEventTargets(type, descendants[i], pointers, hasListener, pointerEvents, pointerEventsType, pointerEventsOrder); | ||
} | ||
} | ||
function hasObjectListeners(object) { | ||
function hasObjectListeners(type, object) { | ||
if (object.ancestorsHaveListeners) { | ||
return true; | ||
} | ||
if (object.__r3f != null && object.__r3f?.eventCount > 0) { | ||
if (type === 'pointer' && object.ancestorsHavePointerListeners) { | ||
return true; | ||
} | ||
if (type === 'wheel' && object.ancestorsHaveWheelListeners) { | ||
return true; | ||
} | ||
if (object.__r3f != null && object.__r3f?.eventCount > 0) { | ||
if (type === 'wheel' && object.__r3f['handlers']['onWheel'] != null) { | ||
return true; | ||
} | ||
if (type === 'pointer' && Object.keys(object.__r3f['handlers']).some((key) => key != 'onWheel')) { | ||
return true; | ||
} | ||
} | ||
if (object._listeners == null) { | ||
return false; | ||
} | ||
if (type === 'wheel') { | ||
const wheelListeners = object._listeners.wheel; | ||
return wheelListeners != null && wheelListeners.length > 0; | ||
} | ||
const entries = Object.entries(object._listeners); | ||
@@ -95,2 +110,5 @@ const length = entries.length; | ||
const entry = entries[i]; | ||
if (entry[0] === 'wheel') { | ||
continue; | ||
} | ||
if (!listenerNames.includes(entry[0])) { | ||
@@ -125,3 +143,3 @@ continue; | ||
} | ||
const newPointerEventsOrder = pointerEventsOrders[i]; | ||
const newPointerEventsOrder = pointerEventsOrders?.[i]; | ||
if (intersection == null || compare(newIntersection, newPointerEventsOrder, intersection, pointerEventsOrder) < 0) { | ||
@@ -128,0 +146,0 @@ index = i; |
@@ -50,3 +50,8 @@ import { Object3D, OrthographicCamera, PerspectiveCamera } from 'three'; | ||
interactableDescendants?: Array<Object3D>; | ||
/** | ||
* @deprecated | ||
*/ | ||
ancestorsHaveListeners?: boolean; | ||
ancestorsHavePointerListeners?: boolean; | ||
ancestorsHaveWheelListeners?: boolean; | ||
} | ||
@@ -92,3 +97,3 @@ } | ||
setEnabled(enabled: boolean, nativeEvent: NativeEvent, commit?: boolean): void; | ||
computeIntersection(scene: Object3D, nativeEvent: NativeEvent): Intersection; | ||
computeIntersection(type: 'wheel' | 'pointer', scene: Object3D, nativeEvent: NativeEvent): Intersection; | ||
setIntersection(intersection: Intersection): void; | ||
@@ -95,0 +100,0 @@ commit(nativeEvent: NativeEvent, emitMove: boolean): void; |
@@ -107,3 +107,3 @@ import { Object3D } from 'three'; | ||
} | ||
computeIntersection(scene, nativeEvent) { | ||
computeIntersection(type, scene, nativeEvent) { | ||
if (this.pointerCapture != null) { | ||
@@ -113,3 +113,3 @@ return this.intersector.intersectPointerCapture(this.pointerCapture, nativeEvent); | ||
this.intersector.startIntersection(nativeEvent); | ||
intersectPointerEventTargets(scene, [this]); | ||
intersectPointerEventTargets(type, scene, [this]); | ||
return this.intersector.finalizeIntersection(scene); | ||
@@ -168,3 +168,3 @@ } | ||
move(scene, nativeEvent) { | ||
this.intersection = this.computeIntersection(scene, nativeEvent); | ||
this.intersection = this.computeIntersection('pointer', scene, nativeEvent); | ||
this.commit(nativeEvent, true); | ||
@@ -263,3 +263,3 @@ } | ||
if (!useMoveIntersection) { | ||
this.wheelIntersection = this.computeIntersection(scene, nativeEvent); | ||
this.wheelIntersection = this.computeIntersection('wheel', scene, nativeEvent); | ||
} | ||
@@ -266,0 +266,0 @@ const intersection = useMoveIntersection ? this.intersection : this.wheelIntersection; |
@@ -5,3 +5,3 @@ { | ||
"license": "SEE LICENSE IN LICENSE", | ||
"version": "6.4.12-alpha.48", | ||
"version": "6.4.12-alpha.54", | ||
"homepage": "https://github.com/pmndrs/xr", | ||
@@ -8,0 +8,0 @@ "author": "Bela Bohlender", |
106257
2544