From b844fe14543b39ad52339741ea757340a1190031 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Mon, 12 Aug 2024 18:36:23 -0400 Subject: [PATCH 1/6] Remove loose event listeners --- types/three/src/core/EventDispatcher.d.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/types/three/src/core/EventDispatcher.d.ts b/types/three/src/core/EventDispatcher.d.ts index fa8048a96..403dd1c2e 100644 --- a/types/three/src/core/EventDispatcher.d.ts +++ b/types/three/src/core/EventDispatcher.d.ts @@ -53,7 +53,6 @@ export class EventDispatcher { type: T, listener: EventListener, ): void; - addEventListener(type: T, listener: EventListener<{}, T, this>): void; /** * Checks if listener is added to an event type. @@ -64,7 +63,6 @@ export class EventDispatcher { type: T, listener: EventListener, ): boolean; - hasEventListener(type: T, listener: EventListener<{}, T, this>): boolean; /** * Removes a listener from an event type. @@ -75,7 +73,6 @@ export class EventDispatcher { type: T, listener: EventListener, ): void; - removeEventListener(type: T, listener: EventListener<{}, T, this>): void; /** * Fire an event type. From e52e18983bf0b9e19eee4b781a0e9fbb6b0d4f78 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Mon, 12 Aug 2024 18:46:51 -0400 Subject: [PATCH 2/6] Add missing PointerLockControls event map --- .../three/examples/jsm/controls/PointerLockControls.d.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/types/three/examples/jsm/controls/PointerLockControls.d.ts b/types/three/examples/jsm/controls/PointerLockControls.d.ts index 4df7f051a..79d46eb36 100644 --- a/types/three/examples/jsm/controls/PointerLockControls.d.ts +++ b/types/three/examples/jsm/controls/PointerLockControls.d.ts @@ -1,6 +1,12 @@ import { Camera, EventDispatcher, Vector3 } from "three"; -export class PointerLockControls extends EventDispatcher { +export interface PointerLockControlsEventMap { + change: {}; + lock: {}; + unlock: {}; +} + +export class PointerLockControls extends EventDispatcher { constructor(camera: Camera, domElement?: HTMLElement); camera: Camera; From 815017dd47912648a420c8b3049820283bf6a66c Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Mon, 12 Aug 2024 18:56:23 -0400 Subject: [PATCH 3/6] Fix webxr_vr_handinput_cubes --- .../webxr_vr_handinput_cubes.ts | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/types/three/test/integration/three-examples/webxr_vr_handinput_cubes.ts b/types/three/test/integration/three-examples/webxr_vr_handinput_cubes.ts index 114e52a18..56468d8a5 100644 --- a/types/three/test/integration/three-examples/webxr_vr_handinput_cubes.ts +++ b/types/three/test/integration/three-examples/webxr_vr_handinput_cubes.ts @@ -5,16 +5,12 @@ import { VRButton } from "three/addons/webxr/VRButton.js"; import { XRControllerModelFactory } from "three/addons/webxr/XRControllerModelFactory.js"; import { XRHandModelFactory } from "three/addons/webxr/XRHandModelFactory.js"; -interface Hand extends THREE.Group { - joints: { [key: string]: any }; -} - const container = document.createElement("div"); let camera: THREE.PerspectiveCamera; let scene: THREE.Scene; let renderer: THREE.WebGLRenderer; -let hand1: Hand; -let hand2: Hand; +let hand1: THREE.XRHandSpace; +let hand2: THREE.XRHandSpace; let controller1: THREE.Group; let controller2: THREE.Group; let controllerGrip1: THREE.Group; @@ -105,7 +101,7 @@ function init() { controllerGrip1.add(controllerModelFactory.createControllerModel(controllerGrip1)); scene.add(controllerGrip1); - hand1 = renderer.xr.getHand(0) as Hand; + hand1 = renderer.xr.getHand(0); hand1.addEventListener("pinchstart", onPinchStartLeft); hand1.addEventListener("pinchend", () => { scaling.active = false; @@ -119,7 +115,7 @@ function init() { controllerGrip2.add(controllerModelFactory.createControllerModel(controllerGrip2)); scene.add(controllerGrip2); - hand2 = renderer.xr.getHand(1) as Hand; + hand2 = renderer.xr.getHand(1); hand2.addEventListener("pinchstart", onPinchStartRight); hand2.addEventListener("pinchend", onPinchEndRight); hand2.add(handModelFactory.createHandModel(hand2)); @@ -152,11 +148,11 @@ function onWindowResize() { } const SphereRadius = 0.05; -function onPinchStartLeft(event: THREE.Event<"pinchstart", Hand>) { +function onPinchStartLeft(event: THREE.Event<"pinchstart", THREE.XRHandSpace>) { const controller = event.target; if (grabbing) { - const indexTip = controller.joints["index-finger-tip"]; + const indexTip = controller.joints["index-finger-tip"]!; const sphere = collideObject(indexTip); if (sphere) { @@ -166,7 +162,7 @@ function onPinchStartLeft(event: THREE.Event<"pinchstart", Hand>) { scaling.active = true; scaling.object = sphere; scaling.initialScale = sphere.scale.x; - scaling.initialDistance = indexTip.position.distanceTo(hand2.joints["index-finger-tip"].position); + scaling.initialDistance = indexTip.position.distanceTo(hand2.joints["index-finger-tip"]!.position); return; } } @@ -181,7 +177,7 @@ function onPinchStartLeft(event: THREE.Event<"pinchstart", Hand>) { const spawn = new THREE.Mesh(geometry, material); spawn.geometry.computeBoundingSphere(); - const indexTip = controller.joints["index-finger-tip"]; + const indexTip = controller.joints["index-finger-tip"]!; spawn.position.copy(indexTip.position); spawn.quaternion.copy(indexTip.quaternion); @@ -202,9 +198,9 @@ function collideObject(indexTip: THREE.Group) { return null; } -function onPinchStartRight(event: THREE.Event<"pinchstart", Hand>) { +function onPinchStartRight(event: THREE.Event<"pinchstart", THREE.XRHandSpace>) { const controller = event.target; - const indexTip = controller.joints["index-finger-tip"]; + const indexTip = controller.joints["index-finger-tip"]!; const object = collideObject(indexTip); if (object) { grabbing = true; @@ -214,7 +210,7 @@ function onPinchStartRight(event: THREE.Event<"pinchstart", Hand>) { } } -function onPinchEndRight(event: THREE.Event<"pinchend", Hand>) { +function onPinchEndRight(event: THREE.Event<"pinchend", THREE.XRHandSpace>) { const controller = event.target; if (controller.userData.selected !== undefined) { @@ -237,8 +233,8 @@ function animate() { function render() { if (scaling.active && scaling.object) { - const indexTip1Pos = hand1.joints["index-finger-tip"].position; - const indexTip2Pos = hand2.joints["index-finger-tip"].position; + const indexTip1Pos = hand1.joints["index-finger-tip"]!.position; + const indexTip2Pos = hand2.joints["index-finger-tip"]!.position; const distance = indexTip1Pos.distanceTo(indexTip2Pos); const newScale = scaling.initialScale + distance / scaling.initialDistance - 1; scaling.object.scale.setScalar(newScale); From e52adaa63b23e00555f0bc527a000bc33cd5f1aa Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Mon, 12 Aug 2024 18:57:17 -0400 Subject: [PATCH 4/6] Update unit tests --- types/three/test/unit/src/core/EventDispatcher.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/three/test/unit/src/core/EventDispatcher.ts b/types/three/test/unit/src/core/EventDispatcher.ts index 32cd43143..b2e4618b5 100644 --- a/types/three/test/unit/src/core/EventDispatcher.ts +++ b/types/three/test/unit/src/core/EventDispatcher.ts @@ -42,7 +42,7 @@ eveDisForTestEvent.addEventListener("bar", e => { e.foo; }); -// call addEventListener with an unknown event. The typing should allow you listen any unknown event. +// @ts-expect-error eveDisForTestEvent.addEventListener("baz", e => { e.type; // $ExpectType "baz" e.target; // $ExpectType EventDispatcher @@ -53,6 +53,7 @@ eveDisForTestEvent.addEventListener("baz", e => { // @ts-expect-error e.bar(); }); +// @ts-expect-error eveDisForTestEvent.addEventListener("NotRegistered", e => { e.type; // $ExpectType "NotRegistered" e.target; // $ExpectType EventDispatcher From 556404fa61db01442541c9207d4b433774475103 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Mon, 12 Aug 2024 19:01:11 -0400 Subject: [PATCH 5/6] Simplify --- .../test/unit/src/core/EventDispatcher.ts | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/types/three/test/unit/src/core/EventDispatcher.ts b/types/three/test/unit/src/core/EventDispatcher.ts index b2e4618b5..b124e7303 100644 --- a/types/three/test/unit/src/core/EventDispatcher.ts +++ b/types/three/test/unit/src/core/EventDispatcher.ts @@ -43,27 +43,7 @@ eveDisForTestEvent.addEventListener("bar", e => { }); // @ts-expect-error -eveDisForTestEvent.addEventListener("baz", e => { - e.type; // $ExpectType "baz" - e.target; // $ExpectType EventDispatcher - // @ts-expect-error - e.bar; - // @ts-expect-error - e.foo; - // @ts-expect-error - e.bar(); -}); -// @ts-expect-error -eveDisForTestEvent.addEventListener("NotRegistered", e => { - e.type; // $ExpectType "NotRegistered" - e.target; // $ExpectType EventDispatcher - // @ts-expect-error - e.bar; - // @ts-expect-error - e.foo; - // @ts-expect-error - e.bar(); -}); +eveDisForTestEvent.addEventListener("baz", e => {}); eveDisForTestEvent.dispatchEvent({ type: "foo", foo: 42 }); eveDisForTestEvent.dispatchEvent({ type: "bar", bar: "42" }); From 12e85949682cb6c62057d773afdea4a445e294b3 Mon Sep 17 00:00:00 2001 From: Nathan Bierema Date: Fri, 30 Aug 2024 08:23:43 -0400 Subject: [PATCH 6/6] Update three.js --- three.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/three.js b/three.js index 067f8a0cc..17abdb5e4 160000 --- a/three.js +++ b/three.js @@ -1 +1 @@ -Subproject commit 067f8a0ccc1d508a8819ba3fa0ea066be40e432c +Subproject commit 17abdb5e4b88368a6c1528743d014e641b32cf85