[SOLVED] VR debug errors and hyper sensitive

Hi. Why, when I start the application in debug mode, I get these errors?
Errors

Also, the default sensitivity is very high. How can I reduce it?

Link to the project: https://playcanvas.com/editor/scene/768841

The web polyfill is really out of date on PlayCanvas. They are working on a more generic solution to make it easier to add external libraries.

Right now, their fork of the polyfill doesn’t account for the change in Chrome when they changed from degrees to radians for the device orientation IIRC.

TLDR; WebVR polyfill support is broken on PlayCanvas. If you enable WebVR in the browser Chrome flags or use a native device like the GearVR, you should be fine.

Is it possible to use latest version webvr-polyfill or cardboard-vr-display in Playcanvas? For example, if I do not include support for VR in the settings, but simply plug in any of these polyfills as a standalone script?

If we consider the work given polyfilov without PlayCanvas, then they work correctly: example.

I honestly don’t know. There may be some logic flow paths in PlayCanvas that look at if the flag and enable logic paths. It might be possible to disable the flag in the editor and enable it at runtime?

Yeah, the latest polyfill works fine. It’s just that PlayCanvas has forked it and hasn’t updated it.

Do you mean, that in order for PlayCanvas not to connect its version of the polyfill, but at the same time to have support for working with VR, I need to disable support for VR in the editor and activate it at runtime?

If the Enable VR flag is ticked in the project settings, PlayCanvas bundles their version of the polyfill into the build.

I honestly, have no idea not to do that and still have WebVR work in the project off the top of my head.

I found this topic and checked it. If you enable support for VR via code, then the polyfill does not connect and pc.VrManager is available. Tomorrow, I will try to use the latest version of the polyphil instead of the old one that provides PlayCanvas.

Hi, @yaustar . I managed to connect the latest version of the polyfill to PlayCanvas. It works fine and I can also in the future add settings for my helmet from Google Cardboard. :slightly_smiling_face:

If interested, here is a link to the project: https://playcanvas.com/editor/scene/768841

2 Likes

Awesome, nice work. What did you have to do in the end to get it working?

For starters, I got rid of the polyfile, which provides PlayCanvas. For this, I did not include support for VR in the settings.
11

Then I took the latest version of the polyfil from here and set the priority for loading the scripts.
12

Then I wrote a simple script to activate VR support when initializing PlayCanvas.

Webvr.prototype.initialize = function() {
  
    var self = this;
    var VrDisplay = null;
    
    this.app.vr = new pc.VrManager(this.app);
    
    var polyfill = new WebVRPolyfill();
    
    navigator.getVRDisplays().then(function(displays) {
        
        VrDisplay = new pc.VrDisplay(self.app, displays[0]);
        
    });
    
};

The script does the following…

  1. Creates a new object VrManager;
  2. Creates a new object WebVRPolyfill() for to activate the API webvr-polyfill;
  3. Next, using the getVRDisplays() method of the polyfile navigator interface, I was able to access the available displays;
  4. Finally, using the VrDisplay constructor built into the PlayCanvas, I created a display for the PlayCanvas;

After all the actions, I got a working VR and the correct output to the console this.app.vr. :slightly_smiling_face:

However, if you run the code on your smartphone in debug mode, you will receive errors. There are no errors with the published version. Example.

2 Likes

The release version still has the errors (they should show in dev tools) but don’t show it to the user.

Yes, you are right. :slightly_smiling_face:

As an added aside, you may have to check if WebVR is natively supported before creating the polyfill. Gear VR and Daydream for example should have native WebVR support.

That is, when initializing the project, I need check to have built-in support for WebVR, and if it is, then disable the script with polyphile?

I think so? I’m just looking at how the PlayCanvas do this here: https://github.com/playcanvas/engine/blob/fab9d05a711d0a075e719dd603e57278c212dfaa/src/vr/vr-manager.js

Can you give an example? :slightly_smiling_face: