如何通过three.js在A框架中控制.GLB模型动画
我正在尝试用三架A-js播放GLB动画, 现在它只是一秒钟的工作,然后停止,有人可以帮我吗? 这是我的代码:
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<script>
AFRAME.registerComponent('move', {
init: function () {
setTimeout( () => {
let position = this.el.getAttribute("position")
console.log(this.el.components['gltf-model'].model )
// Create an AnimationMixer, and get the list of AnimationClip instances
const mixer = new THREE.AnimationMixer( this.el.components['gltf-model'].model);
const clips = this.el.components['gltf-model'].model.animations[0];
var clock = new THREE.Clock();
// Play all animations
mixer.clipAction( clips ).play();
//In the animation block of your scene:
var delta = 0.25 * clock.getDelta();
mixer.update( delta );
}, 2000)
}
})
</script>
<a-scene>
<a-entity gltf-model="https://rawcdn.githack.com/BabylonJS/MeshesLibrary/55f475726670be2e7e4017b5f88c5762a90508c2/shark.glb" move position=".5 0.5 -5" scale="0.5 0.5 0.5"></a-entity>
</a-scene>
I'm trying to play a glb animation in A-FRAME with Three.js,
now it works just for a second and then it stop, could someone help me please?
this is my code:
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<script>
AFRAME.registerComponent('move', {
init: function () {
setTimeout( () => {
let position = this.el.getAttribute("position")
console.log(this.el.components['gltf-model'].model )
// Create an AnimationMixer, and get the list of AnimationClip instances
const mixer = new THREE.AnimationMixer( this.el.components['gltf-model'].model);
const clips = this.el.components['gltf-model'].model.animations[0];
var clock = new THREE.Clock();
// Play all animations
mixer.clipAction( clips ).play();
//In the animation block of your scene:
var delta = 0.25 * clock.getDelta();
mixer.update( delta );
}, 2000)
}
})
</script>
<a-scene>
<a-entity gltf-model="https://rawcdn.githack.com/BabylonJS/MeshesLibrary/55f475726670be2e7e4017b5f88c5762a90508c2/shark.glb" move position=".5 0.5 -5" scale="0.5 0.5 0.5"></a-entity>
</a-scene>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在A框架中控制动画是使用Aframe Extra的使用预定义的动画混合组件。
您可以将所需的动画设置为剪辑属性并根据程序逻辑播放任何动画。将其用于参考。在我的代码游泳动画中,首先播放了咬合动画。
To control animation in a-frame is to use predefined animation-mixer component by aframe extra's.
where you can set the required animation to clip attribute and play any animation based on your program logic. Use this for reference if any. Here in my code swimming animation plays first and after 2 seconds bite animation plays.
等到型号加载:
更新renderloop中的动画 - 在每个
tick
。您可以使用间隔或其他内容,但是Aframe已经为此目的具有内置功能:Wait until the model is loaded with:
update the animation in the renderloop - on each
tick
. You could use an interval or something else, but aframe has already a built-in function for this purpose: