首页 > 解决方案 > 是否可以附加到threejs/aframe 中的动画glb 对象?

问题描述

我有一个在场景中移动的对象,我将其导出为 .glb(模型 A)。

在 Aframe 中,我正在使用animation-mixer标签在模型 A 上播放动画,并且可以看到对象四处移动。现在我要做的是附加另一个模型(模型 B),以便模型 B 也在场景中移动。但是,模型 B 只是停留在原地 - 在指定的模型 A 位置。

有没有办法在 Threejs/Aframe 中实现这一点?

到目前为止,我已经重新审视了这项技术并拥有以下代码,但是模型的位置在它的静态位置和它在刻度中设置的位置之间闪烁。

<a-entity id="mantaray-path" gltf-model="#mantaray-path-glb" animation-mixer="timeScale: 1; loop: true;" pathanim></a-entity>
<a-entity id="mantaray" gltf-model="#mantaray-glb" animation-mixer="timeScale: 1;"></a-entity>        

AFRAME.registerComponent("pathanim", {
    init: function() {
        this.el.addEventListener('model-loaded', this.update.bind(this));            
    },
    tick: function() {
        this.el.object3D.traverse(function(child) {
            if (child.name == "mantaraypath") {
                mantaray.object3D.position = child.position;
            }
        });
    }
});

标签: animationthree.jsaframegltf

解决方案


推荐阅读