如何在A帧中检测台式机,移动设备,GearVR,Oculus Rift和Vive? [英] How to detect Desktop vs. Mobile vs. GearVR vs. Oculus Rift vs. Vive in A-Frame?
问题描述
在A-Frame中,我想检测用户是否连接了VR耳机并告诉他们正在使用哪个设备。我该怎么办?
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?
- 台式机(无VR显示)
- 移动设备(例如webvr) -polyfilled Google Cardboard,iPhone,Android)
- Samsung GearVR
- Oculus Rift
- HTC Vive
- Desktop (no VR display)
- Mobile (e.g., webvr-polyfilled Google Cardboard, iPhone, Android)
- Samsung GearVR
- Oculus Rift
- HTC Vive
推荐答案
A-Frame中有几个实用程序功能可用于检测兼容性: https://aframe.io/docs/master/core/utils.html
There are several utility functions in A-Frame we can use to detect compatibility: https://aframe.io/docs/master/core/utils.html
与移动设备相关的实用程序位于 navigator.userAgent
。与VR相关的使用者检查从头戴式耳机/聚合物填充器返回的姿势数据是否不是0,0,0。
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.
给出当前的API:
- 桌面:
!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()
- 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()
要区分Rift与Vive,请尝试使用WebVR API阶段参数 https://w3c.github.io/webvr/#interface-vrstageparameters
To differentiate Rift vs. Vive, try using WebVR API Stage Parameters https://w3c.github.io/webvr/#interface-vrstageparameters
这篇关于如何在A帧中检测台式机,移动设备,GearVR,Oculus Rift和Vive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!