-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorbit-test.html
57 lines (52 loc) · 2.18 KB
/
orbit-test.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Three.js Sphere with Texture</title>
<style>
body { margin: 0; }
canvas { display: block; }
</style>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script src="/libs/three-orbit-controls.js"></script>
<script>
// 씬, 카메라, 렌더러 생성
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 0.1; // 카메라 위치 설정
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// 텍스처 로드 및 구체 생성
const textureLoader = new THREE.TextureLoader();
textureLoader.load('/assets/screenshots/landscape.jpg', function(texture) { // 이미지 경로를 넣으세요
const geometry = new THREE.SphereGeometry(12, 32, 32); // 구체 크기 및 분할 수 설정
const material = new THREE.MeshBasicMaterial({ map: texture, side: THREE.BackSide }); // 텍스처 적용
const sphere = new THREE.Mesh(geometry, material);
scene.add(sphere);
// OrbitControls 추가
const controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true; // 감속 효과 활성화
controls.dampingFactor = 0.05; // 감속 계수 설정
controls.enableZoom = true; // 줌 활성화 (필요시 비활성화 가능)
controls.reverseOrbit = true;
// 애니메이션 루프
function animate() {
requestAnimationFrame(animate);
controls.update(); // 컨트롤러 업데이트
renderer.render(scene, camera);
}
animate();
});
// 창 크기 변경 시 카메라와 렌더러 업데이트
window.addEventListener('resize', () => {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
});
</script>
</body>
</html>