如何在桌面上的摄像头和虚拟现实之间切换?我想使用鼠标光标在桌面上,当我进入虚拟现实,它应该切换到另一个相机与光标融合。
这是我的代码:
<a-entity id="cam-desktop" camera="userHeight: 1.6; zoom:1 " look-controls mouse-cursor>
</a-entity>
<a-entity id="cam-vr" camera="userHeight: 1.6; zoom:1 " look-controls>
<a-animation begin="cursor-fusing" delay=" 3000" attribute="camera.zoom" from="1" to="4" dur="1000"></a-animation>
<a-animation begin="click" delay="500" attribute="camera.zoom" from="4" to="1" dur="1000"></a-animation>
<a-entity cursor="fuse: true; fuseTimeout:4000" geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03; thetaLength: 360; thetaStart: 0" rotation="0 0 90" position="0 0 -1" material="color: black; side: double; shader: flat">
<a-animation begin="cursor-fusing" attribute="geometry.thetaLength" from="360" to="0" easing="linear" dur="3000"></a-animation>
<a-animation begin="mouseleave" attribute="geometry.thetaLength" from="360" to="360" dur="0"></a-animation>
</entity>
</a-entity>非常感谢!
发布于 2017-07-05 10:53:50
您可以创建一个组件,该组件侦听“enter-vr”和“exit-vr”事件,并相应地设置活动摄像机:
AFRAME.registerComponent('scenelistener',{
init:function(){
let vrcam = document.querySelector("#cam-vr");
let dcam = document.querySelector("#cam-desktop");
let vrmode = false;
this.el.sceneEl.addEventListener('enter-vr',function(){
if(!vrmode){
dcam.setAttribute('active',false);
vrcam.setAttribute('active',true);
vrmode!=vrmode;
}
}
this.el.sceneEl.addEventListener('exit-vr',function(){
if(vrmode){
dcam.setAttribute('active',true);
vrcam.setAttribute('active',false);
vrmode!=vrmode;
}
}
}
});实际上,你可以把听众粘贴到任何地方,而且你可以听任何事件,并对接收到的事件做相应的事情,我只是想给你们展示这个概念。
我不知道如果2+相机是活动的会发生什么,所以我在改变的时候让它们变假了。
更新
我没有看到相机是实体,而不是原语,所以您必须设置如下属性:setAttribute('camera','active',true)
我有一些问题,光标,所以我使它可见和无形,取决于虚拟现实的状态。
工作小提琴(至少相机开关) 这里。
https://stackoverflow.com/questions/44922024
复制相似问题