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 );
