语音识别事件A帧上的动画



当说出语音命令时,我正试图在3D模型(gltf模型(上播放动画,但动画只播放一次,接下来的几次我说出语音命令都不会发生。

我尝试的是以下代码:

var ent = document.querySelector('#model3D');
if(voiceCommand.includes("hello")) {
ent.setAttribute("animation",'property: rotation; to: 0 360 0; loop: false; dur: 5000');
}

你能给我一些解决这个问题的想法吗?

动画播放一次,因为添加了一个带有loop: false的动画组件,所以它只附加一次,并播放一个循环。

您应该使用startEvents属性,并随时重新启动动画:

// when the window is clicked
window.addEventListener('click', e => {
// emit the event
document.querySelector('a-box').emit('foo');
});
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<a-scene>
<!-- The animation is here from the beginning -->
<a-box position="0 1 -3" color="#4CC3D9" 
animation="property: rotation; from: 0 0 0; to: 0 360 0; 
loop: false; dur: 400; startEvents: foo"></a-box>
</a-scene>

最新更新