r/oculusdev • u/irascible • Aug 04 '14
Oculus DK2-WebGL WebSocket Bridge
https://mega.co.nz/#!gBZVDI7L!QxBESxUaDuFMUcr6F0ERwC70EGk8whjIGXfWhJWxVXE Here's a build of an Oculus DK2 WebSocket broadcaster I am working on, that opens a websocket on localhost port 38950 and streams the HMD's rotation quaternion and position vector as a json packet. This is a VERY rough implementation but is enough to get a flakey connection between the dk2 hmd and a webgl app. Please wrap your JSON parse in an exception handler because of a bug in the packet stream that sometimes loses the last character of the json being sent... Let me know if you find this useful and I can give you the source or help with integration..
EDIT: A reminder from r/pyalot: There are existing browser VR extensions in the developer builds of Chrome/FireFox. These should be used in place of any workarounds like mine for more performant and full featured browser support. My bridge is just a hack to quickly snoop the computed eye position/orientation from the SDK to a websocket and use that to update a gl view matrix in any websocket supporting browser.
Mozilla Firefox Rift integration: http://blog.bitops.com/blog/2014/07/31/css-and-vr-integration/ Google Chrome Rift integration: http://blog.tojicode.com/2014/07/bringing-vr-to-chrome.html
Caveat: This is currently only streaming the position of one eye, forcing the client to implement the ipd/eye matrix transforms in addition to the streamed data. The SDK actually reports pos/rot for each eye, so I will start streaming both in the next rev I make.
3
u/48K Aug 04 '14
Open sourcing this would make it more compelling and someone might be able to fix your lost character issue for you.
1
u/irascible Aug 04 '14 edited Aug 04 '14
Yep. It's on my list. I just wanted to put a build out there because it works well enough to make webgl walkthroughs demos as is. When I throw it on github, I'll update this thread.
The whole webgl integration is this:
var eyeLocal = mat4.create(); var url = "ws://127.0.0.1:38950" var ws= new WebSocket(url); ws.onmessage=function(evt){ if (typeof evt !== "undefined" && typeof evt.data == "string") { var str = evt.data.toString(); try{ var packet = JSON.parse(str); var lq=packet.L.O; var lo=packet.L.P; quat4.toMat4(lq,eyeLocal); mat4.translate(eyeLocal,[lo[0]*-1,lo[1]*-1,lo[2]*-1]); { catch(syntaxError){ console.log("Bad Packet!"); console.log(str); } } }and then in the rendering code after computing the regular left/right eye view matrix in your app, catenate the HMD view matrix to offset it by the transform of the HMDs position/orientation.
mat4.multiply(eyeLocal,wglrenderer.vMatrix,wglrenderer.vMatrix);Caveat: This is currently only streaming the position of one eye, forcing the client to implement the ipd/eye matrix transforms in addition to the streamed data. The SDK actually reports pos/rot for each eye, so I will start streaming both in the next rev I make.
3
u/48K Aug 04 '14
You may need to defer registering the onmessage handler until the connection is open. Typically this is done in an onopen handler. You might also want to register onerror and redirect it to the console at least. I doubt this is causing problems, but it's one possible cause of non-determinism you can eliminate in the hunt for your missing character.
1
3
u/pyalot Aug 04 '14
I'll just leave these here:
Mozilla Firefox Rift integration: http://blog.bitops.com/blog/2014/07/31/css-and-vr-integration/
Google Chrome Rift integration: http://blog.tojicode.com/2014/07/bringing-vr-to-chrome.html