如何从A帧上的GLB 3D对象获取动画剪辑的名称?

时间:2020-03-06 23:37:57

标签: javascript aframe

我已经在A-FRAME上创建了一个简单的场景,并导入了包含3个动画的3D GLB对象。

现在,我想使用纯Javascript获取这些动画的名称,以便以后可以使用,但我不知道该如何获取它们。

使用浏览器控制台,我能够找到动画的名称,但是无法使用JS收集它们。

GLB 3D Object Component

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

动画参考保存在gltf-model组件属性:model.animationssource)中。就像KostasX在他的评论中写道的那样,您可以简单地获取该属性:

// better to check the glft-model, as it is responsible for loading the model
document.getElementById("GLB3D614").components['gltf-model'].model.animations 

为确保属性不是undefined,应等到发出model-loaded事件后:

// custom component of the entity with the gltf-model
this.el.addEventListener('model-loaded', e => {
    console.log(this.el.components['gltf-model'].model.animations
})