You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取Three.js中被OrbitControls操控后的相机位置?

在Three.js中获取OrbitControls操控后的相机位置

当然可行,OrbitControls是直接对相机对象进行操控的,相机的位置参数始终保存在相机实例本身,而非OrbitControls对象里,所以你之前查看controls对象找不到变化是正常的。

获取位置的方法很简单:

  • 直接访问相机的position属性,它包含x、y、z三个坐标值,比如:
    • this.camera.position.x
    • this.camera.position.y
    • this.camera.position.z
  • 如果你想在控制台快速查看当前位置,可以直接打印:
    console.log(this.camera.position);
    
  • 要是想在调整完视角后手动触发获取,比如加个按钮:
    // 假设页面有个id为get-camera-pos的按钮
    document.getElementById('get-camera-pos').addEventListener('click', () => {
      const { x, y, z } = this.camera.position;
      console.log(`当前相机位置:x=${x.toFixed(2)}, y=${y.toFixed(2)}, z=${z.toFixed(2)}`);
    });
    

除了位置,相机的旋转、朝向等视角参数也都直接存在this.camera上,比如this.camera.rotation或this.camera.quaternion,这些都是OrbitControls操控后实时更新的。

内容的提问来源于stack exchange,提问作者Andrew Rusinas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 07:45:55