three.js帧动画 + 自动适配尺寸
直接上代码,有疑惑请加群讨论:854184700
var mixer,
var posTrack = new THREE.KeyframeTrack( "Build.position", [0, 20], [0, 0, 0, -100, 0, 0]//前三个为起始位置,后三个为移动后的位置 ); var scaleTrack = new THREE.KeyframeTrack( "Floor.scale", [0, 1], [2, 2, 2, 5, 5, 5] //前三个值为起始值大小,后面为放大后的值 ); var clip = new THREE.AnimationClip("default", 1, [ posTrack,scaleTrack ]); mixer = new THREE.AnimationMixer(mesh);//里面的值为需要做动画的对象 var AnimationAction = mixer.clipAction(clip); AnimationAction.timeScale = 5; //默认1,可以调节播放速度
AnimationAction.loop = THREE.LoopOnce; AnimationAction.clampWhenFinished = true; AnimationAction.time = 0; clip.duration = 1; AnimationAction5.play();
function render(){
var time = clock.getDelta();
if (mixer) {
mixer.update(time);
}
}
自动适配屏幕尺寸 + 自动适配尺寸
function onWindowResize() {
var w = container.clientWidth;
var h = container.clientHeight;
camera.aspect = w / h;
camera.updateProjectionMatrix();
renderer.setSize( w, h );
resolution.set( w, h );
}
window.addEventListener( 'resize', onWindowResize );