Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- React
- bip39
- three.js
- 프로그래밍
- SASS
- 에러
- 지갑
- frontend
- Console
- Mnemonic
- C++
- 블록체인
- Storybook
- 리액트
- algorithm
- Blockchain
- 알고리즘
- baekjoon
- 백준
- scss
- SVG
- 우선순위 큐
- TypeScript
- 코딩
- 기본수학1단계
- 풀이
- 니모닉
- 스토리북
- 기본 수학 2단계
- priority queue
Archives
- Today
- Total
Moong
[Three.js] Animation 본문
animation
function draw() {
// 애니메이션 동작
mesh.rotation.y += THREE.MathUtils.degToRad(1);
renderer.render(scene, camera);
// 재귀를 통한 애니메이션
window.requestAnimationFrame(draw); // 1) window func 이용
renderer.setAnimationLoop(draw); // 2) three.js func 이용
}
성능 보정
기기 성능에 따라 animation frame 수가 다른 문제 해결
getElapsedTime()
💡 절대 시간을 변경 값에 이용하여 성능 보정
const clock = new THREE.Clock();
function draw() {
const time = clock.getElapsedTime();
mesh.rotation.y = time; // 변경 값에 절대 시간을 이용함
renderer.render(scene, camera);
renderer.setAnimationLoop(draw);
}
getDelta()
💡 함수 실행 간격 시간을 이용하여 성능 보정
const clock = new THREE.Clock();
function draw() {
const delta = clock.getDelta();
mesh.rotation.y += 1 * delta; // 변경 값에 draw 함수 실행 간격 시간을 이용함
mesh.position.y += 0.8 * delta;
renderer.render(scene, camera);
renderer.setAnimationLoop(draw);
}
GSAP
three.js 애니메이션을 보다 손쉽게 구현할 수 있는 라이브러리 사용
npm i gsap
gsap.to(
mesh.position,
{
duration: 1,
y: 2,
}
)
🔗 라이브러리 링크 : https://greensock.com/gsap/
'Three.js' 카테고리의 다른 글
[Three.js] 기본 구성요소 (0) | 2023.01.27 |
---|
Comments