How to detect Desktop vs. Mobile vs. GearVR vs. Oculus Rift vs. Vive in A-Frame?

荒凉一梦 提交于 2019-11-29 12:51:11

问题


In A-Frame, I want to detect if the user has a VR headset connected and to tell which device they are using. How can I do this?

  • Desktop (no VR display)
  • Mobile (e.g., webvr-polyfilled Google Cardboard, iPhone, Android)
  • Samsung GearVR
  • Oculus Rift
  • HTC Vive

回答1:


There are several utility functions in A-Frame we can use to detect compatibility: https://aframe.io/docs/master/core/utils.html

The mobile-related utils look at navigator.userAgent. The VR-related utils check to see if the pose data returned from the headset/polyfill is not 0,0,0.

Given the current API:

  • Desktop: !AFRAME.utils.checkHeadsetConnected()
  • Mobile: AFRAME.utils.isMobile()
  • GearVR: AFRAME.utils.isGearVR()
  • Oculus Rift: !AFRAME.utils.isMobile() && AFRAME.utils.checkHeadsetConnected()
  • HTC Vive: !AFRAME.utils.isMobile() && AFRAME.utils.checkHeadsetConnected()

To differentiate Rift vs. Vive, try using WebVR API Stage Parameters https://w3c.github.io/webvr/#interface-vrstageparameters



来源:https://stackoverflow.com/questions/38984951/how-to-detect-desktop-vs-mobile-vs-gearvr-vs-oculus-rift-vs-vive-in-a-frame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!