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

问题描述 投票:0回答:1

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

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

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

GLB 3D Object Component

感谢您的任何帮助

javascript aframe
1个回答
0
投票

动画参考保存在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
})
© www.soinside.com 2019 - 2024. All rights reserved.