【问题标题】:Multiple Distinct Cameras in A-FrameA帧中的多个不同的相机
【发布时间】:2021-10-20 16:53:02
【问题描述】:

我正在处理一个场景,其中多个摄像机设置在不同的预定义位置和旋转位置。我注意到当我使用鼠标(或在 VR 模式下)环顾四周时,相机旋转是在相机之间链接的。所以我认为这可以通过使用属性active: false 来避免,但两个相机仍然一起旋转。下面是一个示例场景,其中两个摄像机位于同一位置并在其视野中具有<a-box>,请注意,当您环顾场景时,立方体(两个独立摄像机的子对象)会同步移动。有没有办法阻止非活动相机跟随活动相机的旋转,从而使蓝色立方体(带有非活动相机)保持静止?

此外,此脚本中没有与 A-Frame 相关的控制台错误。非常感谢您的帮助,非常感谢您抽出宝贵的时间。

<!DOCTYPE html>
<html>

<head>
    <script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
</head>

<body>
    <a-scene>
        <a-camera active="true" look-controls>
            <a-box color="red" position="-2 0 -10"></a-box>
        </a-camera>
        <a-camera active="false" look-controls>
            <a-box color="blue" position="2 0 -10"></a-box>
        </a-camera>
        <a-plane color="gray" rotation="-90 0 0" width="20" height="20"></a-plane>
    </a-scene>
</body>

</html>

【问题讨论】:

    标签: aframe


    【解决方案1】:

    一个可行的解决方案是在摄像头之间切换时启用和禁用摄像头上的look-controls。这可以在 JavaScript 中使用:
    newCameraElement.setAttribute('look-controls', 'enabled', true);
    oldCameraElement.setAttribute('look-controls', 'enabled', false);
    这是问题示例的修订版本,最初禁用另一个摄像头的 look-controls 以提供具有不同摄像头的所需行为:

    <!DOCTYPE html>
    <html>
    
    <head>
        <script src="https://aframe.io/releases/1.0.4/aframe.min.js"></script>
    </head>
    
    <body>
        <a-scene>
            <a-camera active="true" look-controls>
                <a-box color="red" position="-2 0 -10"></a-box>
            </a-camera>
            <a-camera active="false" look-controls="enabled: false">
                <a-box color="blue" position="2 0 -10"></a-box>
            </a-camera>
            <a-plane color="gray" rotation="-90 0 0" width="20" height="20"></a-plane>
        </a-scene>
    </body>
    
    </html>
    

    【讨论】:

      猜你喜欢
      • 2021-09-09
      • 1970-01-01
      • 2021-07-20
      • 2019-12-21
      • 2021-11-24
      • 2021-08-06
      • 1970-01-01
      • 2021-09-07
      • 2014-03-27
      相关资源
      最近更新 更多