我在A-FRAME上创建了一个简单的场景,并导入了一个3D GLB对象,其中包含3个动画。
现在,我想使用纯Javascript获取这些动画的名称,以便以后可以使用,但我不知道该如何获取它们。
使用浏览器控制台,我能够找到动画的名称,但无法使用JS收集它们。
感谢您的任何帮助
动画参考保存在gltf-model
组件属性中:model.animations
(source)。就像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
})