首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >aframe相机在vr出口和进入vr之间切换

aframe相机在vr出口和进入vr之间切换
EN

Stack Overflow用户
提问于 2017-07-05 09:20:12
回答 1查看 851关注 0票数 0

如何在桌面上的摄像头和虚拟现实之间切换?我想使用鼠标光标在桌面上,当我进入虚拟现实,它应该切换到另一个相机与光标融合。

这是我的代码:

代码语言:javascript
复制
<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>

非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-05 10:53:50

您可以创建一个组件,该组件侦听“enter-vr”和“exit-vr”事件,并相应地设置活动摄像机:

代码语言:javascript
复制
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)

我有一些问题,光标,所以我使它可见和无形,取决于虚拟现实的状态。

工作小提琴(至少相机开关) 这里

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44922024

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档