Skip to content
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

Document how to enter/exit VR #1473

Closed
cvan opened this issue May 18, 2016 · 29 comments
Closed

Document how to enter/exit VR #1473

cvan opened this issue May 18, 2016 · 29 comments

Comments

@cvan
Copy link
Contributor

cvan commented May 18, 2016

Description:

document.querySelector('a-scene').enterVR();
document.querySelector('a-scene').exitVR();

And also document how to when <iframe>-ing content.

  • A-Frame Version: any
  • Platform/Device: all
@ngokevin
Copy link
Member

@cvan
Copy link
Contributor Author

cvan commented May 18, 2016

Nice section here, but for some reason waiting for loaded doesn't work. you have to add a setTimeout. gotta figure out why:

<script>
   (function () {
       // switch to stereoscopic mode directly on page load, this needs to be after the a-scene loads.
       var scene = document.querySelector('a-scene');
       if (scene.hasLoaded) {
           scene.enterVR();
       } else {
           scene.addEventListener('loaded', function () {
               setTimeout(function () {
                   scene.enterVR();
               }, 1000);
           });
       };
   })();
</script>

Also, not exactly specific to this issue, but still think we should support #705.

@ngokevin
Copy link
Member

ngokevin commented May 18, 2016

Well, no one is against #705. Though I might also just recommend creating a scene component. They have the advantage that you don't have to worry about query selecting, waiting for events. Just write JS and attach:

AFRAME.registerComponent('auto-enter-vr', {
  init: function () {
    this.el.sceneEl.enterVR();
  }
});
<a-scene auto-enter-vr>

@cvan
Copy link
Contributor Author

cvan commented May 18, 2016

like it

@ngokevin
Copy link
Member

Though I guess you might still have to add the event listener...but at least you don't have to query selector or worry whether it's already loaded. And you get reusable code for free.

@manojkota
Copy link

This is not working with version >=0.3.0

@cvan
Copy link
Contributor Author

cvan commented Nov 22, 2016

This is not working with version >=0.3.0

Are you testing in Chromium or Firefox Nightly? Chromium currently has a temporary user-gesture requirement; Firefox Nightly does not.

@cvan cvan closed this as completed Nov 22, 2016
@cvan
Copy link
Contributor Author

cvan commented Nov 22, 2016

(Accidentally closed issue.)

@cvan cvan reopened this Nov 22, 2016
@manojkota
Copy link

I have tested in firefox & chrome in Android. It is not working. When I change the afrmae version to 0.2.0, it is directly going to vr mode.

@UXVirtual
Copy link

The following code seems to work with v0.4.0 in Firefox Nightly when auto-init-vr component is attached to the scene. Unfortunately Chromium still requires user interaction before it can auto-trigger VR mode:

AFRAME.registerComponent('auto-init-vr', {
    init: function () {

        var scene = this;

        scene.el.addEventListener('loaded', function () {
            setTimeout(function(){
                console.log('Automatically entering VR...');
                scene.el.sceneEl.enterVR();
            },1000);
        });
    }
});

Note that I changed the component name since the original name collides with an internal component in v0.4.0. The setTimeout isn't exactly very elegant - is there a better way of detecting when the entire scene is ready?

@machenmusik
Copy link
Contributor

auto-enter-vr in 0.4.0 does what you want, but is configured by default to only enter if VR display is Gear VR (for Carmel browser which has no other way to enter VR)

@Silver-Seagull
Copy link

Silver-Seagull commented Jan 20, 2017

Is there any way for auto-enter-vr to have the GearVR be over-ridden? We are trying to jump through multiple small scenes, but we have to enter VR manually each time, which is inconvenient on Cardboard!

None of the "old" methods of calling a script of setting a setTimeout or loaded work on 0.4.0, so this is extra-frustrating.

@cvan
Copy link
Contributor Author

cvan commented Jan 20, 2017

@Silver-Seagull yep, there is - I'm working on it right now. out of curiosity, are you working with only Cardboard? or are you using Chromium/Firefox w/ Vive/Rift? I'm just curious which platforms A-Frame devs are using.

@Silver-Seagull
Copy link

@cvan Do you have an ETA, or a hint? I'm sorta stuck and it's driving me bonkers.

Our main platform will be cardboard and cardboard-like devices. Vive and Rift aren't really on the map for now :)

@cvan
Copy link
Contributor Author

cvan commented Jan 20, 2017

@Silver-Seagull there are a couple bugs in that code. I'm fixing them right now. but if you're trying to do it right now, just set <a-scene auto-enter-vr="display: all">; that's a temporary workaround though.

@dmarcos
Copy link
Member

dmarcos commented Jan 20, 2017

Just for the record. auto-enter-vr will go away in next version in favor of the link component and system

@machenmusik
Copy link
Contributor

sorry about the bugs :-/

@machenmusik
Copy link
Contributor

@cvan not sure display: all works correctly at the moment, https://github.com/aframevr/aframe/blob/master/src/components/scene/auto-enter-vr.js#L50 ...
the original intent was to leave blank for all, but unfortunately the parsing just fills in the default... which is unfortunately still GearVR. if you've got fixes forthcoming, they haven't appeared in master yet

@machenmusik
Copy link
Contributor

auto-enter-vr will go away in next version in favor of the link component and system

we will presumably still want the vrdisplayactivate and vrdisplaydeactivate enter/exit behaviors (assuming that browsers fire the events)

@Silver-Seagull
Copy link

Silver-Seagull commented Jan 20, 2017

@cvan & @machenmusik Thank you for the help and tips - however the app isn't entering the split-view as it should.

I feel a little out of my depth (to say the least) and I may have posted out of turn. Looking at our code, I think the view is not Cardboard, but an a-frame page in a Cordova app using the Crosswalk browser. I assume the WebKit-based browser is why this is not working?

:edit:
Running the code now, definitely a Crosswalk-based project in Cordova. On desktop, the VR/cardboard button disappears, which looks like it fired.

@cvan
Copy link
Contributor Author

cvan commented Jan 20, 2017

I got this patch working to auto-enter VR, but I still have to fix up the tests (and write new ones).

As Diego mentions above, the code in A-Frame (and three.js) is going to have to be reimplemented soon anyway (to support all the variations in Oculus Carmel, Google Daydream, Google Cardboard, Firefox Nightly, and Chromium Desktop), as the WebVR API's navigation flow (for auto-entering VR) is in flux right now (see issues immersive-web/webxr#30 and immersive-web/webxr#152).

@Silver-Seagull: I'd recommend dropping this JS snippet into your scene for now:

window.addEventListener('load', function () {
  var scene = document.querySelector('a-scene');
  if (scene.hasLoaded) {
    scene.enterVR();
  } else {
    el.addEventListener('loaded', function () {
      scene.enterVR();
    });
  }
});

Hope that gets you where you need to be.

@Silver-Seagull
Copy link

@cvan It looks like it's a WebVR block, as browsers (save Carmel?) won't allow that sort of action unless it comes from a human.

Thank you for the help and suggestions - hopefully link comes along in the January roadmap as planned ^_^

phonofidelic added a commit to phonofidelic/onto3d that referenced this issue Sep 23, 2017
Added hud ui prototype. Renders a curved panel 180˚ around the user.
The panel could hold UI elements, info or other content. Toggle
functionality is triggered by the select button on the game pad.

handleGamepadButtonDown in CanvasContainer handles gamepad button
event determines game pad button type based on passed event parameter
e.detail.index

Bug: trying to add toggle VR-mode functionality triggered by the
gamepad start button event, but getting error from a-frame:
scene.enterVR() can only be invoked by a user-gesture.
aframevr/aframe#1473
@0atman
Copy link

0atman commented Jan 28, 2019

Hi all. Has this been fixed? I see that in the link docs we have the requirements:

The browser is up-to-date with the WebVR specification and implements the vrdisplayactivate event.
The destination web page listens to the window [vrdisplayactivate] event and enters VR.

How would one listen to vrdisplayactivate and kick off a scene.enterVR();? I've tried this, and it doesn't seem to fire:

window.addEventListener('vrdisplayactivate', function () {
  var scene = document.querySelector('a-scene');
  scene.enterVR();
  console.log(scene);
}

@ngokevin
Copy link
Member

ngokevin commented Feb 1, 2019

aframe has vrdisplayactivate automatic. entervr/exitvr methods documented

@ngokevin ngokevin closed this as completed Feb 1, 2019
0atman added a commit to 0atman/aframe that referenced this issue Feb 4, 2019
We should make it clear that the VR experience is only seamless on Vive et al. We are not managing our user's expectations correctly, see aframevr#1473
@0atman
Copy link

0atman commented Feb 4, 2019

Unsatisfactory.

Aframe makes very bold claims, on the frontpage of the site, that it

Works on Vive, Rift, Daydream, GearVR, desktop

When in fact vrdisplayactivate works only on Vive and Rift.

We should manage our users expectations correctly. Here is an example of the update I would like to see:

#3994

@0atman
Copy link

0atman commented Feb 5, 2019

This is now documented thank you, guys! 8f94626

@fmagrosoto
Copy link

Hello every one...
I tried to load my scene in VR mode using enterVR() within a component:

AFRAME.registerComponent('do-something', {
  init: function () {
    var sceneEl = this.el;
   sceneEl.enterVR()
  }
});

In Chrome for iOS (77.0.8685.103) works fine, but in Android, same Chrome version, do not works... anybody has a solution?, or maybe an explanation?

Thanks in advance

@0atman
Copy link

0atman commented Nov 2, 2019

Halloween was last week, I'm not into zombie threads this week 😆

@fmagrosoto I don't think this is the right place to ask this question. Try the aframe discord, or if you think it's a bug, open your own issue. Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants