-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic VR controller. #10991
Generic VR controller. #10991
Conversation
examples/js/vr/VRController.js
Outdated
controller.dispatchEvent({ type: 'disconnected', controller: controller }) | ||
delete controller | ||
} | ||
window.addEventListener( 'gamepaddisconnected', function( event ){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... This is sneaky...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if someone includes VRController.js
twice (by mistake)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 😉—it would indeed make those callbacks as many times as 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I’ve removed the 'ongamepadconnected' and 'ongamepaddisconnected' event listeners.
examples/webvr_controllers.html
Outdated
torus.rotation.y += 0.002; | ||
if (torus.rotation.y > Math.PI) torus.rotation.y = torus.rotation.y - (Math.PI * 2); | ||
|
||
controls.update(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
examples/js/vr/VRController.js
Outdated
// Adapted from Boris’ code in a hurry -- many thanks! | ||
|
||
const | ||
HEAD_ELBOW_OFFSET = new THREE.Vector3( 0.155, -0.465, -0.15 ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're defining these in global space. I think you should wrap all this code in a closure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are so correct here—I am embarrassed! It was a quick inclusion job. Will enclose those variables for sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 😉 |
@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? 😄 |
@mrdoob Any updates? |
Now supports r86: https://github.com/stewdio/THREE.VRController |
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. |
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!) |
To be fair it really needs some documentation on how to use it. |
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. |
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! |
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... |
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. |
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... |
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.