我已经在A-FRAME上创建了一个简单的场景,并导入了包含3个动画的3D GLB对象。
现在,我想使用纯Javascript获取这些动画的名称,以便以后可以使用,但我不知道该如何获取它们。
使用浏览器控制台,我能够找到动画的名称,但是无法使用JS收集它们。
感谢您的帮助
答案 0 :(得分:1)
动画参考保存在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
})