@pmndrs/pointer-events
Advanced tools
Comparing version 6.4.11 to 6.4.12-alpha.30
@@ -32,3 +32,3 @@ import { BaseEvent, Face, Object3D, Quaternion, Ray, Vector2, Vector3 } from 'three'; | ||
protected internalPointer: Pointer; | ||
protected readonly intersection: ThreeIntersection; | ||
readonly intersection: ThreeIntersection; | ||
readonly camera: Camera; | ||
@@ -35,0 +35,0 @@ readonly currentObject: Object3D; |
@@ -101,8 +101,13 @@ import { Ray, Vector2, Vector3 } from 'three'; | ||
get ray() { | ||
if (this._ray == null) { | ||
this._ray = new Ray(); | ||
this._ray.origin.setFromMatrixPosition(this.camera.matrixWorld); | ||
this._ray.lookAt(this.point); | ||
if (this._ray != null) { | ||
return this._ray; | ||
} | ||
return this._ray; | ||
switch (this.intersection.details.type) { | ||
case 'screen-ray': | ||
case 'ray': | ||
case 'sphere': | ||
return (this._ray = new Ray(this.intersection.pointerPosition, new Vector3(0, 0, -1).applyQuaternion(this.intersection.pointerQuaternion))); | ||
case 'lines': | ||
return (this._ray = new Ray(this.intersection.details.line.start, this.intersection.details.line.end.clone().sub(this.intersection.details.line.start).normalize())); | ||
} | ||
} | ||
@@ -109,0 +114,0 @@ _intersections = []; |
@@ -1,2 +0,2 @@ | ||
import { Intersection as ThreeIntersection, Quaternion, Vector3, Vector2 } from 'three'; | ||
import { Intersection as ThreeIntersection, Quaternion, Vector3, Line3, Vector2 } from 'three'; | ||
export type Intersection = ThreeIntersection & { | ||
@@ -15,2 +15,3 @@ pointerPosition: Vector3; | ||
lineIndex: number; | ||
line: Line3; | ||
} | { | ||
@@ -22,2 +23,3 @@ type: 'screen-ray'; | ||
distanceViewPlane: number; | ||
direction: Vector3; | ||
/** | ||
@@ -24,0 +26,0 @@ * point on the screen for x and y from -1 to 1 |
@@ -6,2 +6,3 @@ import { Line3, Matrix4, Plane, Quaternion, Ray, Raycaster, Vector3, Mesh, Vector2, } from 'three'; | ||
const lineHelper = new Line3(); | ||
const scaleHelper = new Vector3(); | ||
const planeHelper = new Plane(); | ||
@@ -53,2 +54,5 @@ const rayHelper = new Ray(); | ||
const pointOnFace = rayHelper.intersectPlane(planeHelper, new Vector3()) ?? point; | ||
const pointerPosition = new Vector3(); | ||
const pointerQuaternion = new Quaternion(); | ||
this.fromMatrixWorld.decompose(pointerPosition, pointerQuaternion, scaleHelper); | ||
let uv = intersection.uv; | ||
@@ -64,4 +68,4 @@ if (intersection.object instanceof Mesh && getClosestUV(point2Helper, point, intersection.object)) { | ||
point, | ||
pointerPosition: new Vector3().setFromMatrixPosition(this.fromMatrixWorld), | ||
pointerQuaternion: new Quaternion().setFromRotationMatrix(this.fromMatrixWorld), | ||
pointerPosition, | ||
pointerQuaternion, | ||
}; | ||
@@ -118,3 +122,4 @@ } | ||
const lastRaycaster = this.raycasters[lastRaycasterIndex]; | ||
return voidObjectIntersectionFromRay(scene, lastRaycaster.ray, (distanceOnLine) => ({ | ||
return voidObjectIntersectionFromRay(scene, lastRaycaster.ray, (point, distanceOnLine) => ({ | ||
line: new Line3(lastRaycaster.ray.origin.clone(), point), | ||
lineIndex: this.raycasters.length - 1, | ||
@@ -131,2 +136,3 @@ distanceOnLine, | ||
//TODO: consider maxLength | ||
const raycaster = this.raycasters[raycasterIndex]; | ||
return Object.assign(intersection, { | ||
@@ -137,2 +143,3 @@ details: { | ||
type: 'lines', | ||
line: new Line3(raycaster.ray.origin.clone(), raycaster.ray.direction.clone().multiplyScalar(raycaster.far).add(raycaster.ray.origin)), | ||
}, | ||
@@ -139,0 +146,0 @@ distance, |
@@ -31,6 +31,7 @@ import { Vector3, Object3D, Camera, Vector2 } from 'three'; | ||
private readonly raycaster; | ||
private readonly cameraQuaternion; | ||
private readonly fromPosition; | ||
private readonly fromQuaternion; | ||
private readonly coords; | ||
private viewPlane; | ||
private readonly viewPlane; | ||
private readonly intersects; | ||
@@ -37,0 +38,0 @@ private readonly pointerEventsOrders; |
@@ -7,3 +7,2 @@ import { Matrix4, Plane, Quaternion, Raycaster, Vector3, Vector2, Mesh, } from 'three'; | ||
const NegZAxis = new Vector3(0, 0, -1); | ||
const directionHelper = new Vector3(); | ||
const planeHelper = new Plane(); | ||
@@ -107,2 +106,3 @@ const point2Helper = new Vector2(); | ||
} | ||
const directionHelper = new Vector3(); | ||
export class ScreenRayIntersector { | ||
@@ -112,2 +112,3 @@ prepareTransformation; | ||
raycaster = new Raycaster(); | ||
cameraQuaternion = new Quaternion(); | ||
fromPosition = new Vector3(); | ||
@@ -148,2 +149,7 @@ fromQuaternion = new Quaternion(); | ||
...intersection, | ||
details: { | ||
...details, | ||
direction: this.raycaster.ray.direction.clone(), | ||
screenPoint: this.coords.clone(), | ||
}, | ||
uv, | ||
@@ -153,4 +159,4 @@ object, | ||
pointOnFace: point, | ||
pointerPosition: this.fromPosition.clone(), | ||
pointerQuaternion: this.fromQuaternion.clone(), | ||
pointerPosition: this.raycaster.ray.origin.clone(), | ||
pointerQuaternion: this.cameraQuaternion.clone(), | ||
}; | ||
@@ -176,3 +182,4 @@ } | ||
const pointerPosition = this.fromPosition.clone(); | ||
const pointerQuaternion = this.fromQuaternion.clone(); | ||
const pointerQuaternion = this.cameraQuaternion.clone(); | ||
const pointerDirection = this.raycaster.ray.direction.clone(); | ||
const index = getDominantIntersectionIndex(this.intersects, this.pointerEventsOrders, this.options); | ||
@@ -183,3 +190,8 @@ const intersection = index == null ? undefined : this.intersects[index]; | ||
if (intersection == null) { | ||
return voidObjectIntersectionFromRay(scene, this.raycaster.ray, (distance) => ({ type: 'screen-ray', distanceViewPlane: distance, screenPoint: this.coords.clone() }), pointerPosition, pointerQuaternion); | ||
return voidObjectIntersectionFromRay(scene, this.raycaster.ray, (_point, distance) => ({ | ||
type: 'screen-ray', | ||
distanceViewPlane: distance, | ||
screenPoint: this.coords.clone(), | ||
direction: pointerDirection, | ||
}), pointerPosition, pointerQuaternion); | ||
} | ||
@@ -193,2 +205,3 @@ intersection.object.updateWorldMatrix(true, false); | ||
screenPoint: this.coords.clone(), | ||
direction: pointerDirection, | ||
}, | ||
@@ -195,0 +208,0 @@ pointOnFace: intersection.point, |
@@ -11,3 +11,3 @@ import { Plane, Intersection as ThreeIntersection, Object3D, Vector3, Ray, Quaternion, Matrix4 } from 'three'; | ||
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 voidObjectIntersectionFromRay(scene: Object3D, ray: Ray, getDetails: (distanceOnRay: number) => Intersection['details'], pointerPosition: Vector3, pointerQuaternion: Quaternion, addToDistance?: number): Intersection; | ||
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; |
@@ -151,3 +151,3 @@ import { getVoidObject } from './intersector.js'; | ||
normal: ray.origin.clone().sub(point).normalize(), | ||
details: getDetails(distanceOnRay), | ||
details: getDetails(point, distanceOnRay), | ||
pointerPosition, | ||
@@ -154,0 +154,0 @@ pointerQuaternion, |
@@ -5,3 +5,3 @@ { | ||
"license": "SEE LICENSE IN LICENSE", | ||
"version": "6.4.11", | ||
"version": "6.4.12-alpha.30", | ||
"homepage": "https://github.com/pmndrs/xr", | ||
@@ -8,0 +8,0 @@ "author": "Bela Bohlender", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
105305
2517
1