【问题标题】:How can I get camera world direction with webxr?如何使用 webxr 获取相机世界方向?
【发布时间】:2023-03-06 21:52:01
【问题描述】:

我想使用camera.getWorldDirection() 并访问头戴式显示器方向。我可以使用之前的 webVR API 做到这一点。当我使用来自 THREE 的新 HelioWebXRPolyfill.js 时,我无法接收当前职位。

【问题讨论】:

  • 新 webXR 实现上的摄像头似乎没有链接到实际的耳机视图,它位于旁边。如果我得到 camera.rotation 并且我使用耳机环顾四周,则没有任何变化。我也在寻找这个问题的答案?!
  • 我也面临同样的问题?你解决了吗?

标签: three.js webvr webxr


【解决方案1】:

全局变量

var cameraVector = new THREE.Vector3();  //define once and reuse it!

在你的渲染循环中

let xrCamera = renderer.xr.getCamera(camera);
xrCamera.getWorldDirection(cameraVector);
//heading vector for webXR camera now within cameraVector

【讨论】:

    【解决方案2】:

    根据 WebXR 设备 API,这应该使用 XRViewerPose object 来完成。

    此功能仅在使用 HTTPS 时有效。

    【讨论】:

      【解决方案3】:

      我想出了一个简单的解决方法。只需将一个盒子作为相机的父级,并使用相机盒子代替相机。

      camera.add( camerabox );
      

      这不起作用:

      var direction = new THREE.Vector3();
      camera.getWorldDirection( direction );
      

      这确实有效:

      var direction = new THREE.Vector3();
      camerabox.getWorldDirection( direction );
      

      【讨论】:

      • 实际上它不适用于 FireFox WebXR 开发工具。相机盒是指使用 BoxGeometry 附加网格?
      【解决方案4】:

      似乎调用renderer.xr.getCamera() 并没有完全复制camera.getWorldDirection() 期望找到的各种相机成员属性。我不确定这个问题的根源(也许是 polyfill?),但你可以通过自己计算方向来解决它:

              let xrCamera = this.renderer.xr.getCamera(sceneCamera)
              let e = xrCamera.matrixWorld.elements
              let direction = new THREE.Vector3(-e[8], -e[9], -e[10]).normalize()
      

      【讨论】:

        猜你喜欢
        • 2019-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-15
        • 2013-03-21
        • 1970-01-01
        相关资源
        最近更新 更多