@pmndrs/pointer-events
Advanced tools
Comparing version 6.2.10 to 6.2.11
@@ -9,5 +9,6 @@ import { Object3D, Intersection as ThreeIntersection } from 'three'; | ||
abstract intersectPointerCapture(pointerCapture: PointerCapture, nativeEvent: unknown): Intersection | undefined; | ||
protected abstract prepareIntersection(nativeEvent: unknown): boolean; | ||
abstract isReady(): boolean; | ||
protected abstract prepareIntersection(nativeEvent: unknown): void; | ||
abstract executeIntersection(object: Object3D, objectPointerEventsOrder: number): void; | ||
abstract finalizeIntersection(): Intersection | undefined; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Matrix4, Vector3, Object3D } from 'three'; | ||
import { Vector3, Object3D } from 'three'; | ||
import type { PointerCapture } from '../pointer.js'; | ||
@@ -6,3 +6,3 @@ import { Intersector } from './intersector.js'; | ||
export declare class LinesIntersector extends Intersector { | ||
private readonly prepareTransformation; | ||
private readonly space; | ||
private readonly options; | ||
@@ -13,10 +13,15 @@ private raycasters; | ||
private intersectionDistanceOnLine; | ||
constructor(prepareTransformation: (nativeEvent: unknown, fromMatrixWorld: Matrix4) => boolean, options: IntersectionOptions & { | ||
private ready?; | ||
constructor(space: { | ||
current?: Object3D | null; | ||
}, options: IntersectionOptions & { | ||
linePoints?: Array<Vector3>; | ||
minDistance?: number; | ||
}); | ||
intersectPointerCapture({ intersection, object }: PointerCapture, nativeEvent: unknown): Intersection | undefined; | ||
protected prepareIntersection(nativeEvent: unknown): boolean; | ||
isReady(): boolean; | ||
private prepareTransformation; | ||
intersectPointerCapture({ intersection, object }: PointerCapture): Intersection | undefined; | ||
protected prepareIntersection(): void; | ||
executeIntersection(object: Object3D, objectPointerEventsOrder: number | undefined): void; | ||
finalizeIntersection(): Intersection | undefined; | ||
} |
import { Line3, Matrix4, Plane, Quaternion, Ray, Raycaster, Vector3, } from 'three'; | ||
import { computeIntersectionWorldPlane, getDominantIntersectionIndex } from './utils.js'; | ||
import { Intersector } from './intersector.js'; | ||
import { updateAndCheckWorldTransformation } from '../utils.js'; | ||
const invertedMatrixHelper = new Matrix4(); | ||
@@ -11,3 +12,3 @@ const intersectsHelper = []; | ||
export class LinesIntersector extends Intersector { | ||
prepareTransformation; | ||
space; | ||
options; | ||
@@ -18,8 +19,24 @@ raycasters = []; | ||
intersectionDistanceOnLine = 0; | ||
constructor(prepareTransformation, options) { | ||
ready; | ||
constructor(space, options) { | ||
super(); | ||
this.prepareTransformation = prepareTransformation; | ||
this.space = space; | ||
this.options = options; | ||
} | ||
intersectPointerCapture({ intersection, object }, nativeEvent) { | ||
isReady() { | ||
return this.ready ?? this.prepareTransformation(); | ||
} | ||
prepareTransformation() { | ||
const spaceObject = this.space.current; | ||
if (spaceObject == null) { | ||
return (this.ready = false); | ||
} | ||
this.ready = updateAndCheckWorldTransformation(spaceObject); | ||
if (!this.ready) { | ||
return false; | ||
} | ||
this.fromMatrixWorld.copy(spaceObject.matrixWorld); | ||
return true; | ||
} | ||
intersectPointerCapture({ intersection, object }) { | ||
const details = intersection.details; | ||
@@ -29,3 +46,3 @@ if (details.type != 'lines') { | ||
} | ||
if (!this.prepareTransformation(nativeEvent, this.fromMatrixWorld)) { | ||
if (!this.prepareTransformation()) { | ||
return undefined; | ||
@@ -46,5 +63,5 @@ } | ||
} | ||
prepareIntersection(nativeEvent) { | ||
if (!this.prepareTransformation(nativeEvent, this.fromMatrixWorld)) { | ||
return false; | ||
prepareIntersection() { | ||
if (!this.prepareTransformation()) { | ||
return; | ||
} | ||
@@ -67,5 +84,8 @@ const linePoints = this.options.linePoints ?? defaultLinePoints; | ||
this.raycasters.length = length; | ||
return true; | ||
return; | ||
} | ||
executeIntersection(object, objectPointerEventsOrder) { | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
let lineLengthSum = 0; | ||
@@ -72,0 +92,0 @@ const length = this.raycasters.length; |
@@ -1,2 +0,2 @@ | ||
import { Matrix4, Vector3, Object3D, Camera, Vector2 } from 'three'; | ||
import { Vector3, Object3D, Camera, Vector2 } from 'three'; | ||
import { Intersection, IntersectionOptions } from './index.js'; | ||
@@ -6,3 +6,3 @@ import { type PointerCapture } from '../pointer.js'; | ||
export declare class RayIntersector extends Intersector { | ||
private readonly prepareTransformation; | ||
private readonly space; | ||
private readonly options; | ||
@@ -12,8 +12,13 @@ private readonly raycaster; | ||
private worldScale; | ||
constructor(prepareTransformation: (nativeEvent: unknown, matrixWorld: Matrix4) => boolean, options: IntersectionOptions & { | ||
private ready?; | ||
constructor(space: { | ||
current?: Object3D | null; | ||
}, options: IntersectionOptions & { | ||
minDistance?: number; | ||
direction?: Vector3; | ||
}); | ||
intersectPointerCapture({ intersection, object }: PointerCapture, nativeEvent: unknown): Intersection | undefined; | ||
protected prepareIntersection(nativeEvent: unknown): boolean; | ||
isReady(): boolean; | ||
private prepareTransformation; | ||
intersectPointerCapture({ intersection, object }: PointerCapture): Intersection | undefined; | ||
protected prepareIntersection(): void; | ||
executeIntersection(object: Object3D, objectPointerEventsOrder: number | undefined): void; | ||
@@ -31,2 +36,3 @@ finalizeIntersection(): Intersection | undefined; | ||
constructor(prepareTransformation: (nativeEvent: unknown, coords: Vector2) => Camera | undefined, options: IntersectionOptions); | ||
isReady(): boolean; | ||
intersectPointerCapture({ intersection, object }: PointerCapture, nativeEvent: unknown): Intersection | undefined; | ||
@@ -33,0 +39,0 @@ protected prepareIntersection(nativeEvent: unknown): boolean; |
import { Matrix4, Plane, Quaternion, Raycaster, Vector3, Vector2, } from 'three'; | ||
import { computeIntersectionWorldPlane, getDominantIntersectionIndex } from './utils.js'; | ||
import { Intersector } from './intersector.js'; | ||
import { updateAndCheckWorldTransformation } from '../utils.js'; | ||
const invertedMatrixHelper = new Matrix4(); | ||
const intersectsHelper = []; | ||
const matrixHelper = new Matrix4(); | ||
const scaleHelper = new Vector3(); | ||
@@ -12,3 +12,3 @@ const NegZAxis = new Vector3(0, 0, -1); | ||
export class RayIntersector extends Intersector { | ||
prepareTransformation; | ||
space; | ||
options; | ||
@@ -18,12 +18,30 @@ raycaster = new Raycaster(); | ||
worldScale = 0; | ||
constructor(prepareTransformation, options) { | ||
ready; | ||
constructor(space, options) { | ||
super(); | ||
this.prepareTransformation = prepareTransformation; | ||
this.space = space; | ||
this.options = options; | ||
} | ||
intersectPointerCapture({ intersection, object }, nativeEvent) { | ||
isReady() { | ||
return this.ready ?? this.prepareTransformation(); | ||
} | ||
prepareTransformation() { | ||
const spaceObject = this.space.current; | ||
if (spaceObject == null) { | ||
return (this.ready = false); | ||
} | ||
this.ready = updateAndCheckWorldTransformation(spaceObject); | ||
if (!this.ready) { | ||
return false; | ||
} | ||
spaceObject.matrixWorld.decompose(this.raycaster.ray.origin, this.raycasterQuaternion, scaleHelper); | ||
this.worldScale = scaleHelper.x; | ||
this.raycaster.ray.direction.copy(this.options?.direction ?? NegZAxis).applyQuaternion(this.raycasterQuaternion); | ||
return true; | ||
} | ||
intersectPointerCapture({ intersection, object }) { | ||
if (intersection.details.type != 'ray') { | ||
return undefined; | ||
} | ||
if (!this.prepareIntersection(nativeEvent)) { | ||
if (!this.prepareTransformation()) { | ||
return undefined; | ||
@@ -43,12 +61,9 @@ } | ||
} | ||
prepareIntersection(nativeEvent) { | ||
if (!this.prepareTransformation(nativeEvent, matrixHelper)) { | ||
return false; | ||
} | ||
matrixHelper.decompose(this.raycaster.ray.origin, this.raycasterQuaternion, scaleHelper); | ||
this.worldScale = scaleHelper.x; | ||
this.raycaster.ray.direction.copy(this.options?.direction ?? NegZAxis).applyQuaternion(this.raycasterQuaternion); | ||
return true; | ||
prepareIntersection() { | ||
this.prepareTransformation(); | ||
} | ||
executeIntersection(object, objectPointerEventsOrder) { | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
object.raycast(this.raycaster, intersectsHelper); | ||
@@ -95,2 +110,5 @@ const index = getDominantIntersectionIndex(this.intersection, this.pointerEventsOrder, intersectsHelper, objectPointerEventsOrder, this.options); | ||
} | ||
isReady() { | ||
return true; | ||
} | ||
intersectPointerCapture({ intersection, object }, nativeEvent) { | ||
@@ -97,0 +115,0 @@ const details = intersection.details; |
@@ -1,2 +0,2 @@ | ||
import { Object3D, Vector3, Quaternion } from 'three'; | ||
import { Object3D } from 'three'; | ||
import type { PointerCapture } from '../pointer.js'; | ||
@@ -6,18 +6,17 @@ import { Intersector } from './intersector.js'; | ||
export declare class SphereIntersector extends Intersector { | ||
/** | ||
* @returns the sphere radius | ||
*/ | ||
private readonly prepareTransformation; | ||
private readonly space; | ||
private readonly getSphereRadius; | ||
private readonly options; | ||
private readonly fromPosition; | ||
private readonly fromQuaternion; | ||
constructor( | ||
/** | ||
* @returns the sphere radius | ||
*/ | ||
prepareTransformation: (nativeEvent: unknown, fromPosition: Vector3, fromQuaternion: Quaternion) => number | undefined, options: IntersectionOptions); | ||
intersectPointerCapture({ intersection, object }: PointerCapture, nativeEvent: unknown): Intersection | undefined; | ||
protected prepareIntersection(nativeEvent: unknown): boolean; | ||
private ready?; | ||
constructor(space: { | ||
current?: Object3D | null; | ||
}, getSphereRadius: () => number, options: IntersectionOptions); | ||
isReady(): boolean; | ||
private prepareTransformation; | ||
intersectPointerCapture({ intersection, object }: PointerCapture): Intersection | undefined; | ||
protected prepareIntersection(): void; | ||
executeIntersection(object: Object3D, objectPointerEventsOrder: number | undefined): void; | ||
finalizeIntersection(): Intersection | undefined; | ||
} |
import { InstancedMesh, Matrix4, Mesh, Vector3, Sphere, Quaternion, Plane, } from 'three'; | ||
import { computeIntersectionWorldPlane, getDominantIntersectionIndex } from './utils.js'; | ||
import { Intersector } from './intersector.js'; | ||
import { updateAndCheckWorldTransformation } from '../utils.js'; | ||
const collisionSphere = new Sphere(); | ||
const intersectsHelper = []; | ||
export class SphereIntersector extends Intersector { | ||
prepareTransformation; | ||
space; | ||
getSphereRadius; | ||
options; | ||
fromPosition = new Vector3(); | ||
fromQuaternion = new Quaternion(); | ||
constructor( | ||
/** | ||
* @returns the sphere radius | ||
*/ | ||
prepareTransformation, options) { | ||
ready; | ||
constructor(space, getSphereRadius, options) { | ||
super(); | ||
this.prepareTransformation = prepareTransformation; | ||
this.space = space; | ||
this.getSphereRadius = getSphereRadius; | ||
this.options = options; | ||
} | ||
intersectPointerCapture({ intersection, object }, nativeEvent) { | ||
isReady() { | ||
return this.ready ?? this.prepareTransformation(); | ||
} | ||
prepareTransformation() { | ||
const spaceObject = this.space.current; | ||
if (spaceObject == null) { | ||
return (this.ready = false); | ||
} | ||
this.ready = updateAndCheckWorldTransformation(spaceObject); | ||
if (!this.ready) { | ||
return false; | ||
} | ||
this.fromPosition.setFromMatrixPosition(spaceObject.matrixWorld); | ||
this.fromQuaternion.setFromRotationMatrix(spaceObject.matrixWorld); | ||
return true; | ||
} | ||
intersectPointerCapture({ intersection, object }) { | ||
if (intersection.details.type != 'sphere') { | ||
return undefined; | ||
} | ||
if (this.prepareTransformation(nativeEvent, this.fromPosition, this.fromQuaternion) == null) { | ||
if (!this.prepareTransformation()) { | ||
return undefined; | ||
@@ -49,12 +65,13 @@ } | ||
} | ||
prepareIntersection(nativeEvent) { | ||
const radius = this.prepareTransformation(nativeEvent, this.fromPosition, this.fromQuaternion); | ||
if (radius == null) { | ||
return false; | ||
prepareIntersection() { | ||
if (!this.prepareTransformation()) { | ||
return; | ||
} | ||
collisionSphere.center.copy(this.fromPosition); | ||
collisionSphere.radius = radius; | ||
return true; | ||
collisionSphere.radius = this.getSphereRadius(); | ||
} | ||
executeIntersection(object, objectPointerEventsOrder) { | ||
if (!this.isReady()) { | ||
return; | ||
} | ||
intersectSphereWithObject(collisionSphere, object, intersectsHelper); | ||
@@ -61,0 +78,0 @@ const index = getDominantIntersectionIndex(this.intersection, this.pointerEventsOrder, intersectsHelper, objectPointerEventsOrder, this.options); |
@@ -101,3 +101,3 @@ import { Object3D } from 'three'; | ||
* allows to separately compute and afterwards commit a move | ||
* => do not forget to call commitMove after computeMove | ||
* => do not forget to call commit after computeMove | ||
* can be used to compute the current intersection and disable or enable the pointer before commiting the move | ||
@@ -104,0 +104,0 @@ */ |
@@ -114,3 +114,3 @@ import { Object3D } from 'three'; | ||
* allows to separately compute and afterwards commit a move | ||
* => do not forget to call commitMove after computeMove | ||
* => do not forget to call commit after computeMove | ||
* can be used to compute the current intersection and disable or enable the pointer before commiting the move | ||
@@ -154,3 +154,3 @@ */ | ||
this.prevEnabled = this.enabled; | ||
if (!this.wasMoved) { | ||
if (!this.wasMoved && this.intersector.isReady()) { | ||
this.wasMoved = true; | ||
@@ -157,0 +157,0 @@ const length = this.onFirstMove.length; |
@@ -5,12 +5,3 @@ import { Pointer } from '../pointer.js'; | ||
export function createGrabPointer(space, pointerState, options = {}, pointerType = 'grab') { | ||
return new Pointer(generateUniquePointerId(), pointerType, pointerState, new SphereIntersector((_nativeEvent, fromPosition, fromQuaternion) => { | ||
const spaceObject = space.current; | ||
if (spaceObject == null) { | ||
return undefined; | ||
} | ||
spaceObject.updateWorldMatrix(true, false); | ||
fromPosition.setFromMatrixPosition(spaceObject.matrixWorld); | ||
fromQuaternion.setFromRotationMatrix(spaceObject.matrixWorld); | ||
return options.radius ?? 0.07; | ||
}, options), undefined, undefined, undefined, options); | ||
return new Pointer(generateUniquePointerId(), pointerType, pointerState, new SphereIntersector(space, () => options.radius ?? 0.07, options), undefined, undefined, undefined, options); | ||
} |
@@ -5,10 +5,3 @@ import { Pointer } from '../pointer.js'; | ||
export function createLinesPointer(space, pointerState, options = {}, pointerType = 'lines') { | ||
return new Pointer(generateUniquePointerId(), pointerType, pointerState, new LinesIntersector((_nativeEvent, fromMatrixWorld) => { | ||
const spaceObject = space.current; | ||
if (spaceObject == null) { | ||
return false; | ||
} | ||
fromMatrixWorld.copy(spaceObject.matrixWorld); | ||
return true; | ||
}, options), undefined, undefined, undefined, options); | ||
return new Pointer(generateUniquePointerId(), pointerType, pointerState, new LinesIntersector(space, options), undefined, undefined, undefined, options); | ||
} |
@@ -5,9 +5,3 @@ import { Pointer } from '../pointer.js'; | ||
export function createRayPointer(space, pointerState, options = {}, pointerType = 'ray') { | ||
return new Pointer(generateUniquePointerId(), pointerType, pointerState, new RayIntersector((_nativeEvent, matrixWorld) => { | ||
if (space.current == null) { | ||
return false; | ||
} | ||
matrixWorld.copy(space.current.matrixWorld); | ||
return true; | ||
}, options), undefined, undefined, undefined, options); | ||
return new Pointer(generateUniquePointerId(), pointerType, pointerState, new RayIntersector(space, options), undefined, undefined, undefined, options); | ||
} |
@@ -5,12 +5,3 @@ import { Pointer } from '../pointer.js'; | ||
export function createTouchPointer(space, pointerState, options = {}, pointerType = 'touch') { | ||
return new Pointer(generateUniquePointerId(), pointerType, pointerState, new SphereIntersector((_nativeEvent, fromPosition, fromQuaternion) => { | ||
const spaceObject = space.current; | ||
if (spaceObject == null) { | ||
return undefined; | ||
} | ||
spaceObject.updateWorldMatrix(true, false); | ||
fromPosition.setFromMatrixPosition(spaceObject.matrixWorld); | ||
fromQuaternion.setFromRotationMatrix(spaceObject.matrixWorld); | ||
return options.hoverRadius ?? 0.1; | ||
}, options), createUpdateTouchPointer(options), undefined, undefined, options); | ||
return new Pointer(generateUniquePointerId(), pointerType, pointerState, new SphereIntersector(space, () => options.hoverRadius ?? 0.1, options), createUpdateTouchPointer(options), undefined, undefined, options); | ||
} | ||
@@ -17,0 +8,0 @@ function createUpdateTouchPointer(options) { |
@@ -9,6 +9,12 @@ import { Mesh, Object3D, Vector2, Vector3 } from 'three'; | ||
}; | ||
/** | ||
* undefined and true means the transformation is ready | ||
* false means transformation is not ready | ||
*/ | ||
transformReady?: boolean; | ||
} | ||
} | ||
export declare function updateAndCheckWorldTransformation({ transformReady, parent, matrix, matrixWorld }: Object3D): boolean; | ||
export declare function hasObjectListeners({ _listeners, __r3f }: Object3D): boolean; | ||
export declare function getObjectListeners<E>({ _listeners, __r3f }: Object3D, forEvent: keyof PointerEventsMap): Array<(event: E) => void> | undefined; | ||
export declare function getClosestUV(target: Vector2, point: Vector3, mesh: Mesh): void; |
import { BufferAttribute, Matrix4, Triangle, Vector2, Vector3 } from 'three'; | ||
export function updateAndCheckWorldTransformation({ transformReady, parent, matrix, matrixWorld }) { | ||
if (transformReady === false) { | ||
return false; | ||
} | ||
if (parent == null) { | ||
return true; | ||
} | ||
if (!updateAndCheckWorldTransformation(parent)) { | ||
return false; | ||
} | ||
matrixWorld.multiplyMatrices(parent.matrixWorld, matrix); | ||
return true; | ||
} | ||
export function hasObjectListeners({ _listeners, __r3f }) { | ||
@@ -3,0 +16,0 @@ if (__r3f != null && __r3f?.eventCount > 0) { |
@@ -5,3 +5,3 @@ { | ||
"license": "SEE LICENSE IN LICENSE", | ||
"version": "6.2.10", | ||
"version": "6.2.11", | ||
"homepage": "https://github.com/pmndrs/xr", | ||
@@ -8,0 +8,0 @@ "author": "Bela Bohlender", |
84965
1997