【问题标题】:aframe camera switch between exit vr and enter vraframe 相机在退出 vr 和进入 vr 之间切换
【发布时间】:2017-12-08 20:58:50
【问题描述】:

如何在桌面相机和 VR 相机之间切换? 我想在桌面上使用鼠标光标,当我进入 VR 时,它应该切换到另一个带有光标融合的相机。

这是我的代码:

<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>

非常感谢!

【问题讨论】:

    标签: three.js camera virtual-reality aframe webvr


    【解决方案1】:

    您可以创建一个组件,它会监听“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)
    我的光标有一些问题,所以我让它可见和不可见,具体取决于 vr 状态。
    工作小提琴(至少相机开关)here

    【讨论】:

    • 我不明白,它不起作用 :-/ 为什么 vr-cam 和 desktop-cam 同时是假的和真的? #cam-vr 应该在 vr 中有效,在非 vr 中无效。和#cam-desktop 在非虚拟现实中有效,在虚拟现实中无效。相机不能同时处于活动状态。 :-(
    • 我这样做是为了让它们不会同时处于活动状态,在下一行中,我将正确的设置为活动状态,我可以将其换成简单的检查
    • 感谢您的帮助,但光标移动到了摄像机下方的地面。并切换不起作用或我为此愚蠢。在这里查看:davidklapheck.de/webvr/navbar.html 我想我必须尝试另一种解决方案。
    • 非常感谢。有用! :-D 你是最棒的。如果之前在这里问过这个问题,但是您知道为什么 vr 模式下的缩放动画不起作用吗?
    • @Stephan 很高兴我能帮上忙,我设法通过缩放重现了这个问题,但我不知道为什么它不能按预期工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-10
    • 2018-08-28
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多