THREE.Clock은 Three.js에서 시간 관리를 위한 유용한 도구로, 애니메이션과 프레임 간의 간격을 측정하는 데 주로 사용됩니다. Clock 객체를 이용하면 시간의 경과를 측정하거나 프레임별 델타 시간(delta time)을 계산하여 애니메이션 속도를 일정하게 유지할 수 있습니다.
const elapsedTime = clock.getElapsedTime();
const delta = clock.getDelta();
clock.start();
clock.stop();
const isRunning = clock.running;
활용예
// Clock 생성
const clock = new THREE.Clock();
// 렌더링 루프에서 애니메이션 처리
function animate() {
// 새로운 프레임을 요청 (requestAnimationFrame을 통한 반복적인 호출)
requestAnimationFrame(animate);
// 이전 프레임과의 시간 차이(델타 시간) 계산
const delta = clock.getDelta();
// 애니메이션에 delta 값을 반영하여 객체의 회전 속도를 일정하게 유지
mesh.rotation.x += delta * 0.5; // 0.5 radian per second
mesh.rotation.y += delta * 0.5;
// 씬을 렌더링
renderer.render(scene, camera);
}
// 애니메이션 시작
animate();
| dai-gui, lil-gui 차이점(2) (0) | 2024.09.23 |
|---|---|
| material.clone(), random colors (0) | 2024.09.21 |
| Object3D - three.js (0) | 2024.09.21 |
| MeshLambertMaterial (1) | 2024.09.20 |
| OrbitControls - import 오류 및 주요 기능 (1) | 2024.09.20 |