I’m trying to cobble together a workable Three boilerplate in TypeScript with a vr view and control for Oculus Go. I’m trying to build a project not in vanilla JS… and everything besides the VR view works.
I seem to have come across several different versions of WebVRManager, and no adequate typings. The current DefinitelyTyped interface references something called VRDisplay which no longer exists anywhere I can find it. Meanwhile, WebVRManager.js has a ton of dependencies that should probably be referencing the global THREE… I’ve attempted to rewrite it into a Typescript class, it goes to VR mode in Chrome but I’m still stuck with the spinning wheel in Oculus browser and I can only assume this has something to do with either scoping issues in WebGLAnimation when brought into Typescript, or maybe the bad assumptions being made in the DefinitelyTyped interface as it stands.
Is there, by any chance, a definitive Typescript build or set of definitions that corroborate with the current master?
All I’m trying to do is set up a scene, a renderer, and a VR button that works, and do it all in TS without any untyped classes or webpack-style “requires” (I’m using require.js for the initial bootstrap). The only thing I’m apparently missing is a WebVRManager that plays nicely with the existing three.d.ts and three.js standalones.
Thanks, that’s helpful… so I got the .d.ts to resolve that at least…
Another thing is, I’m using StereoEffect.js but it seems as if the (new?) version of WebVRManager has its own L/R stereo layers. Is StereoEffect redundant when using WebVRManager?
Also, WebVRManager has “bounds” as a property of PerspectiveCamera (cameraL/R) which is not defined in the TS spec of Object3D. So … that’s hackish… is there any sane way to do this without rolling everything out in plain JS?
Yes, removing it makes it mono until it goes to VR mode in Chrome, then it’s stereo. But OrbitControls stops working without this file (when I don’t run the render through the effect) Why would that be?
Unfortunately, still spinning wheel of death in Oculus Browser… even though no errors and running smoothly in “VR” in Chrome…
It does work in a browser, so fiddle isn’t much use… but here is a link to the sample. In Chrome, this goes stereoscopic when you click the VR button. In Oculus browser it just goes to VR with a spinning wheel. This is clearly some scope issue in Typescript. If I put similar code in a tag in the main HTML it works fine.
The entire problem was calling requestAnimationFrame(renderer) instead of the (new? better? totally freakin undocumented?) renderer.setAnimationLoop().
For whatever reason, setAnimationLoop lets the VR transition proceed, while requestAnimationFrame leaves it hanging.
Oh wait, here it is buried in the Typescript on line 5672:
/**
* A build in function that can be used instead of requestAnimationFrame. **For WebVR projects this function must be used.**
* @param callback The function will be called every available frame. If `null` is passed it will stop any already ongoing animation.
*/
setAnimationLoop
Hey thanks for making that crystal clear.
** I’m just mad that I spent 10 hours of my life on this, but I still (sort of ) like this code (I miss Away3D, Starling and, ya know data typing in general).
Heh. Thanks for the help.
The problem is the majority of Three.js examples don’t even use this call… so it’s very easy to miss it if you’re trying to do a WebVR project.
All WebVR examples actually use this method. If you are doing a WebVR project, it’s best to study the code of these files. You normally do just this to enable VR in three.js:
// tell renderer to perform vr-rendering
renderer.vr.enabled = true;
// add button so users can enter VR
document.body.appendChild( WEBVR.createButton( renderer ) );
// adjust animate() so it looks like this
function animate() {
renderer.setAnimationLoop( render );
}