Skip to content

Conversation

@danrossi
Copy link
Contributor

@danrossi danrossi commented Nov 25, 2025

Related issue: #32350

Description

Adds a grip update event to the WebXRController to individually handle gamepad and input source for each controller. The event can be enabled / disabled easily so it's not being called all the time.

I found trying to handle gamepad inputs externally for each controller connected is clunky and should be handled in an event. I was forced to make a patched XRController to do this.

A gamepad helper can then use this event to handle gamepad inputs and dispatch specific events like in my patched XRController. Perhaps this can be added to the examples also.

https://github.com/danrossi/three-xr-controller/blob/main/src/XRController.js#L79

Usage

const controllerGrip = renderer.xr.getControllerGrip( 0 );
controllerGrip.enableUpdate = true;
controllerGrip.addEventListener('update', (event) => {
    console.log("on grip update ", event);
});

@github-actions
Copy link

github-actions bot commented Nov 25, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 350.9
83.23
350.9
83.23
+0 B
+0 B
WebGPU 616.03
171
616.03
171
+0 B
+0 B
WebGPU Nodes 614.64
170.74
614.64
170.74
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 482.96
118.03
483.11
118.07
+143 B
+41 B
WebGPU 686.7
186.56
686.84
186.6
+143 B
+41 B
WebGPU Nodes 636.54
173.77
636.68
173.81
+143 B
+41 B

@danrossi
Copy link
Contributor Author

I've added the XRGamePad helper and example to complement the new event.

@danrossi
Copy link
Contributor Author

I hope that design is acceptable. It seems the other method was an update event into just after this. Obtaining the inputSource from the motioncontroller.

https://github.com/mrdoob/three.js/blob/dev/examples/jsm/webxr/XRControllerModelFactory.js#L95

@danrossi danrossi changed the title add grip update event to WebXRController if enabled WebXRController: add grip update event to WebXRController if enabled Dec 2, 2025
@danrossi
Copy link
Contributor Author

danrossi commented Dec 2, 2025

I have some other controller features to submit for review including GripPointer util like the HandPointerModel which adds a line and cursor which seems to have to be duplicated everywhere. An intersection util to handle the different pointer models now it uses a common api like the HandPointerModel. A controller manager to handle all the different controllers and events. So it's universal.

It's taking parts of my internal controller work including handling transient-pointer for Apple vision.

I found it clunky to manage externally for both controllers.

Add universal XRControllerManager
Add universal XRI{ntersections feature
Add GripPointerModel
Add GazePointerModel
Add example for XRControllerManager

//

function onSelectStart() {

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused function onSelectStart.

}

function onSelectEnd() {

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused function onSelectEnd.
@danrossi
Copy link
Contributor Author

danrossi commented Dec 3, 2025

I thought I would add these extra addons with the gamepad feature. A universal controller and intersections manager. The grip cursor and line is added into a pointer model so they can be handled the same way as the hand pointer model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant