Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGeneric VR controller. #10991
Generic VR controller. #10991
Conversation
| controller.dispatchEvent({ type: 'disconnected', controller: controller }) | ||
| delete controller | ||
| } | ||
| window.addEventListener( 'gamepaddisconnected', function( event ){ |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
stewdio
Mar 13, 2017
Author
Contributor
For that particular bit I was aiming to follow Mozilla’s guidance here: https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API
But instead of removing only the reference to the gamepad I deleted the whole controller. But what makes you say sneaky?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
stewdio
Mar 30, 2017
Author
Contributor
Oh—are you talking about the window gamepaddisconnected event? I thought you were pointing out delete controller for some reason. As far as those events go I was (again) trying to follow the convention as seen here: https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API
But I see what you mean—despite that feeling like a pretty obscure thing to troubleshoot VRController.js was included in the document. Fortunately I’m not relying on those events (they’re not supported at all in Chrome right now) so I can strip them out without much fuss.
This comment has been minimized.
This comment has been minimized.
stewdio
Mar 31, 2017
Author
Contributor
Ok. I’ve removed the 'ongamepadconnected' and 'ongamepaddisconnected' event listeners.
| torus.rotation.y += 0.002; | ||
| if (torus.rotation.y > Math.PI) torus.rotation.y = torus.rotation.y - (Math.PI * 2); | ||
|
|
||
| controls.update(); |
This comment has been minimized.
This comment has been minimized.
mrdoob
Mar 17, 2017
Owner
Can we add a requestAnimationFrame inside the controls so we don't have to call update from outside? We'll probably have to pass the vrdisplay to the VRController constructor so we can use the correct requestAnimationFrame.
This comment has been minimized.
This comment has been minimized.
stewdio
Mar 21, 2017
Author
Contributor
Is your comment about THREE.VRControls? Or about this proposed THREE.VRController? (Both follow the convention of requiring the developer to include a call to .update() in their animation loop.) I chose to follow the existing THREE.VRControls convention because I think this is the cleanest way to do it—rather than having independent rAF loops; makes the sequence of updates more predictable.
|
Are |
| // Adapted from Boris’ code in a hurry -- many thanks! | ||
|
|
||
| const | ||
| HEAD_ELBOW_OFFSET = new THREE.Vector3( 0.155, -0.465, -0.15 ), |
This comment has been minimized.
This comment has been minimized.
mrdoob
Mar 17, 2017
Owner
You're defining these in global space. I think you should wrap all this code in a closure.
This comment has been minimized.
This comment has been minimized.
stewdio
Mar 21, 2017
Author
Contributor
You are so correct here—I am embarrassed! It was a quick inclusion job. Will enclose those variables for sure.
This comment has been minimized.
This comment has been minimized.
stewdio
Mar 30, 2017
Author
Contributor
Although it’s a bit verbose instead of wrapping it all in a closure, I made these formerly-global variables into properties of OrientationArmModel() because I felt it better expressed their purpose. But what do you think? (That change is in the latest commit around line 581.)
|
I think using Can I use ES6 is at least partially here and I think embracing it as it comes is not a terrible thing ;) |
|
My argument is that... If the user doesn't have |
|
I see your point. I’ve removed |
|
I think my latest commits have addressed your above concerns—aside from your comment about calling Once you’re happy with the structure I imagine you’d like me to add semicolons and conform to your whitespace standards? |
|
Looking good!
Yes, at least semicolons... Never trust the parser |
|
As much as it pained me to do it, I added semicolons just for you |
|
Howdy @mrdoob. Just checking if you had more thoughts on this VRController code |
mflux
commented
Apr 18, 2017
|
@mrdoob ricardo ;) bump |
|
For the time being I’ve posted the code here, including a README: But of course I’d love to see this become an official part of r86 |
|
@mrdoob any updates with this PR? |
alexozer
commented
Aug 6, 2017
|
@mrdoob Any updates? |
|
Now supports r86: https://github.com/stewdio/THREE.VRController |
danrossi
commented
Sep 9, 2017
|
How is this one going ? This seems to work well for me with the Oculus and game controllers. I was only able to get the trigger buttons working not the top buttons or joystick controls. However is there an object model that might reflect the game controllers ? I'd like to support the vive controller as well as the GearVR remote. I was unable to get a laser pointer raycaster working on the object just the menu The model available in the demo is for the vive controller but the textures are huge. |
|
It’s going really well, but I’m maintaining it here instead: The visual models for the various controllers is outside the scope of VRController. |
mflux
commented
Sep 9, 2017
|
I'm surprised @stewdio you didn't mention @djambo's https://github.com/djambo/VRControllerView |
|
(And that’s part of why I said it was “out of scope” cause I knew VRControllerView was going to handle it!) |
mflux
commented
Sep 9, 2017
|
To be fair it really needs some documentation on how to use it. |
danrossi
commented
Sep 10, 2017
|
I tried to look for models. aframe include them all but not public. I'm going to fork the project then if required to get Gear VR remote support working. |
danrossi
commented
Sep 10, 2017
|
That project is not live sadly. |
|
Just FYI for whoever ends up in this pull-request thread after Googling... The latest version of VRController now also supports Windows Mixed Reality motion controllers and is available here: |
|
Alright. So... how about updating this PR so it sits on top of the WebXR Controllers API? |
|
Yes yes yes! |
danrossi
commented
Jan 4, 2018
|
Is this api available yet ? I see it requires a new api to launch and handle vr devices also. |
|
For the record we've had our immediate plans for WebXR input derailed by some compatibility concerns with OpenXR. We're working on a solution to that, but in the meantime the Gamepad API will continue to be the way that these devices are accessed. |
|
Things have changed quite a bit in the last two years... |
danrossi
commented
Nov 30, 2019
|
What are the latest updates ? I implemented my own repository with a working updated gamepad controller to include support for Gear. I'm still waiting for details about WebXR to update to that. Mine works as a laser pointer for virtual video controls. |
danrossi
commented
Dec 9, 2019
|
This has been integrated into the VR and XR manager itself. Ive updated a controls project here to handle those controller events and setup a connect and disconnect event. |
|
It’s true that things have changed quite a bit over the past ... three years?! (That’s crazy in itself—that it’s been 3 years since I started kicking the tires on this generic VR controller idea in late 2016 / early 2017!) Looking back, I regret we couldn’t find a way to incorporate these generic VR hand controls in to Three when I offered it here initially. I think it would have benefited the community—and the code itself would have benefited from the community’s constructive input. And that could have driven the official API. I’ll miss the simplicity and legibility of constructions like this: But mostly I worry we’ve lost little gems like “Multi-channel haptic feedback”: Constructions like this made haptics so easy, you’d wonder why anyone was even making a fuss over it in the first place:
Lastly, I feel like I should apologize a bit. I didn’t keep up with Anyway, as we roll in to the new decade... |

stewdio commentedMar 12, 2017
Handles gamepad discovery, emits event with controller (Object3D) instance. Handles controller updates for position, orientation (including 3DOF rigs). Watches for updates on axes and button states, emits corresponding events on the controller instance. Good for Vive, Rift, Daydream, and beyond. And all you need to do is include THREE.VRController.update() in your animation loop.