stewdio / THREE.VRController

Support hand controllers for Oculus, Vive, Windows Mixed Reality, Daydream, GearVR, and more by adding VRController to your existing Three.js-based WebVR project.
https://stewdio.github.io/THREE.VRController/
MIT License
230 stars 32 forks source link

GearVR / Daydream Gamepad not updated when exiting and entering presentation mode #15

Open danrossi opened 6 years ago

danrossi commented 6 years ago

I am not sure what the story is with Occulus. But the Gamepad instance changes when exiting then re-entering presentation mode. The timestamp is different which can be detected.

A new gamepad instance is required to be updated. I have tried to modify myself but it's not detecting button changes when updating to it yet. I haven't uploaded my tests with a working example yet.

Something like this could detect the change and either update the gamepad or disconnect the controller.

if (this.controllers[ i ].gamepad.timestamp !== gamepad.timestamp) {

In GearVR / Daydream taking off the headset does not dispatch a deactivate event to possible manage gamepad disconnection that way. Only exit presentation events would work.

I guess it has to be disconnected and reconnected ?

danrossi commented 6 years ago

I made a heap of changes to be able to module the gamepad update process. Sadly that wouldnt work. This seems to work

if( this.controllers[ i ] === undefined ) {
                    THREE.VRController.onGamepadConnect( gamepad );
                }
                else if (this.controllers[ i ].gamepad.timestamp !== gamepad.timestamp) {
                    console.log("gamepad change");

                    //this.controllers[ i ].gamepad = gamepad;
                    //this.controllers[ i ].updateGamepad(gamepad);
                    THREE.VRController.onGamepadDisconnect( this.controllers[ i ].gamepad );
                    THREE.VRController.onGamepadConnect( gamepad );
                }
danrossi commented 6 years ago

I put the fix here now and added a method to disconnect all controllers.

I am working on an Es6 version as this code is hard to maintain and needs some efficiency improvements I think.

https://github.com/danrossi/THREE.VRController/blob/master/VRController.js#L831

danrossi commented 6 years ago

example of all fixes in that branch and current three.js is here

http://dev.electroteque.org/vrcontroller/raycast.html