【问题标题】:How to use inner camera in gltf in aframe?如何在 aframe 中的 gltf 中使用内部摄像头?
【发布时间】:2021-08-10 06:59:14
【问题描述】:

我有一个 gltf 模型,其中包含相机、模型和相机动画。加载后,它们成为一个 gltf 实体。我不能使用secondcamera el. SetAttribute ('camera ','active', true ')" 来更换相机。我如何使用里面的相机。

这可以修改为三个。 JS

this.content.traverse((node) => {

if (node.isCamera && node.name === name) {

this.activeCamera = node;

}

});

this.renderer.render( this.scene, this.activeCamera )

但是,如何在 aframe 中使用 gltf 中的内部摄像头?

【问题讨论】:

    标签: camera aframe gltf


    【解决方案1】:

    您可以保留对相机的引用:

    var model_camera = null;
    // wait until the model is loaded
    entity.addEventListener("model-loaded", e => {
      const mesh = entity.getObject3D("mesh");
      mesh.traverse(node => {
        // assuming there is one camera
        if (node.isCamera) model_camera = node;
      })
    })
    

    当您需要使用它时,只需将活动摄像头替换为scene.camera property

    entity.sceneEl.camera = model_camera;
    

    this example 中查看包含两个不同摄像头的模型。


    Afaik 不涉及清理,look-controlswasd-controls 仍然可以工作,只要您在切换相机时不手动禁用它们。

    camera system 具有交换活动摄像头的功能,但您需要为摄像头引用添加 <a-entity> 包装器(因为系统尝试在提供的实体上执行 getObject3D('camera'))。

    【讨论】:

      猜你喜欢
      • 2023-04-08
      • 2018-11-16
      • 2022-01-15
      • 2013-04-22
      • 2016-10-19
      • 2018-08-27
      • 2015-10-15
      • 2012-12-27
      • 1970-01-01
      相关资源
      最近更新 更多