시계의 시침, 분침, 초침에 회전 적용하는 방법
function Rotate() {
scene.getObjectByName("sec").rotation.z = -(Math.PI/180)*90;
scene.getObjectByName("min").rotation.z = -(Math.PI/180)*180;
scene.getObjectByName("hour").rotation.z = -(Math.PI/180)*265;
scene.getObjectByName("orbit").rotation.y = (Math.PI/180)*45;
}
실제시간 정보 가져와서 애니메이션 적용하기
function setTime(){
const hour = scene.getObjectByName("hour");
const sec = scene.getObjectByName("sec");
const min = scene.getObjectByName("min");
const orbit = scene.getObjectByName("orbit");
const date = new Date();
const hourRate = date.getHours()/24;
const minRate = date.getMinutes()/60;
const secRate = date.getSeconds()/60;
hour.rotation.z = -(Math.PI*2)*2*hourRate;
min.rotation.z = -(Math.PI*2) * minRate;
sec.rotation.z = -(Math.PI*2) * secRate;
orbit.rotation.y = -(Math.PI*2)*hourRate;
console.log(date, hourRate, minRate, secRate)
}
실시간으로 시계에 시간 적용하기
function render() {
setTime();
requestAnimationFrame(render);
controls.update();
renderer.render(scene, camera);
}
init();
낮과 밤에 따라서 3가지의 색상 적용하기
//colors 변수 설정
const colors = {
day:{
sky: "hsl(45,100%,60%)",
ground: "hsl(10,100%,50%)",
background: "hsl(20,80%,10%)",
},
night:{
sky: "#ffffff",
ground: "hsl(180,80%,25%)",
background: "hsl(200,80%,15%)",
}
}
let currentSky, currentGround, currentBackground;
if(date.getHours() > 6 && date.getHours() < 18){
//day
currentSky = colors.day.sky;
currentGround = colors.day.ground;
currentBackground = colors.day.background;
}else{
// night
currentSky = colors.night.sky;
currentGround = colors.night.ground;
currentBackground = colors.night.background;
}
scene.background = new THREE.Color(currentBackground);
hemiLight.color = new THREE.Color(currentSky);
hemiLight.groundColor = new THREE.Color(currentGround)
3D 시계 모델링 결과
'3D Project > 3D 인터랙티브 웹' 카테고리의 다른 글
[3D 인터랙티브 웹] 파티클 시스템/애니메이션 만들기 by Three.js (1) | 2024.01.14 |
---|---|
[3D 인터랙티브 웹] 스크롤 인터랙션/애니메이션 적용하기 (1) | 2024.01.14 |
[3D 인터랙티브 웹] 3D 공간 떠다니기 (1) | 2024.01.13 |
[3D 인터랙티브 웹] glTF, glb 모델 불러오기, 애니메이션 불러오기 (0) | 2024.01.13 |
[3D 인터랙티브 웹] Three.js 기초 - 실시간 조명 세팅하기, 3D Scene에 이미지 적용하기 (0) | 2024.01.13 |