天天看点

three.js中动作动画和blendshape混合播放,并且固定帧数

function animate() {
	render()
	stats.update();
}

function render(){
       //更新动作,动作的帧数无需控制,速度可以通过timeScale进行设置
	if ( mixers.length > 0 ) {
		mixers[0].update( clock.getDelta());
	}
	if(gui){
		if(gui.audio) playAudio()
	}
	renderer.render( scene, camera );
}
function playAudio(){
       //因为我使用的模型中,控制表情的blendshape系数是51个为一组,+102是因为降帧到30,+51则是60帧,但是60帧会抖动,所以需要降帧。
	process+=102;
	if(process>arr.length){
		audio_p.stop()
	}else {
		mesh_all[0].morphTargetInfluences=arr.slice(process,process+50)
	}
}
setInterval(animate,1000/30)
           

虽然动画播放建议用requestAnimationFrame(animate),但是帧数不可控,因为此处的blenshape需要严格控制到每秒30帧,所以采用定时器进行实现。

继续阅读