Spaces:
Running
Running
gini1
commited on
Commit
โข
6ff4d9b
1
Parent(s):
726fff4
Update index.html
Browse files- index.html +22 -135
index.html
CHANGED
@@ -1,162 +1,49 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
-
<title>
|
5 |
<style>
|
6 |
body { margin: 0; }
|
7 |
-
canvas { display: block; }
|
8 |
-
#gameInfo {
|
9 |
-
position: absolute;
|
10 |
-
top: 10px;
|
11 |
-
left: 10px;
|
12 |
-
background: rgba(0,0,0,0.7);
|
13 |
-
color: white;
|
14 |
-
padding: 10px;
|
15 |
-
border-radius: 5px;
|
16 |
-
z-index: 100;
|
17 |
-
}
|
18 |
</style>
|
19 |
</head>
|
20 |
<body>
|
21 |
-
<div id="gameInfo">
|
22 |
-
Click to start<br>
|
23 |
-
WASD - Move<br>
|
24 |
-
Mouse - Look Around
|
25 |
-
</div>
|
26 |
-
|
27 |
<script type="module">
|
28 |
-
import * as THREE from 'https://unpkg.com/three@0.
|
29 |
-
import { PointerLockControls } from 'https://unpkg.com/three@0.149.0/examples/jsm/controls/PointerLockControls.js';
|
30 |
-
|
31 |
-
// ๋ฉ์ธ ๋ณ์
|
32 |
-
let scene, camera, renderer, controls;
|
33 |
-
|
34 |
-
// ์ด๊ธฐํ ํจ์
|
35 |
-
function init() {
|
36 |
-
// Scene ์์ฑ
|
37 |
-
scene = new THREE.Scene();
|
38 |
-
scene.background = new THREE.Color(0x87ceeb); // ํ๋์ ๋ฐฐ๊ฒฝ
|
39 |
-
|
40 |
-
// Camera ์ค์
|
41 |
-
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
42 |
-
camera.position.set(0, 5, 10);
|
43 |
-
|
44 |
-
// Renderer ์ค์
|
45 |
-
renderer = new THREE.WebGLRenderer({ antialias: true });
|
46 |
-
renderer.setSize(window.innerWidth, window.innerHeight);
|
47 |
-
renderer.shadowMap.enabled = true;
|
48 |
-
document.body.appendChild(renderer.domElement);
|
49 |
-
|
50 |
-
// Controls ์ค์
|
51 |
-
controls = new PointerLockControls(camera, document.body);
|
52 |
-
|
53 |
-
// ํด๋ฆญ ์ด๋ฒคํธ
|
54 |
-
document.addEventListener('click', function() {
|
55 |
-
controls.lock();
|
56 |
-
});
|
57 |
-
|
58 |
-
// ๊ธฐ๋ณธ ์งํ ์์ฑ
|
59 |
-
createGround();
|
60 |
-
|
61 |
-
// ๊ธฐ๋ณธ ์กฐ๋ช
์ถ๊ฐ
|
62 |
-
addLights();
|
63 |
-
|
64 |
-
// ํ
์คํธ์ฉ ๋ฐ์ค ์ถ๊ฐ
|
65 |
-
addTestBox();
|
66 |
-
}
|
67 |
-
|
68 |
-
// ์งํ ์์ฑ ํจ์
|
69 |
-
function createGround() {
|
70 |
-
const groundGeometry = new THREE.PlaneGeometry(100, 100);
|
71 |
-
const groundMaterial = new THREE.MeshStandardMaterial({
|
72 |
-
color: 0x3a8c3a,
|
73 |
-
roughness: 0.8,
|
74 |
-
metalness: 0.2
|
75 |
-
});
|
76 |
-
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
77 |
-
ground.rotation.x = -Math.PI / 2;
|
78 |
-
ground.receiveShadow = true;
|
79 |
-
scene.add(ground);
|
80 |
-
}
|
81 |
-
|
82 |
-
// ์กฐ๋ช
์ถ๊ฐ ํจ์
|
83 |
-
function addLights() {
|
84 |
-
// ์ฃผ๋ณ๊ด
|
85 |
-
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
|
86 |
-
scene.add(ambientLight);
|
87 |
-
|
88 |
-
// ์ง์ฌ๊ด
|
89 |
-
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
|
90 |
-
directionalLight.position.set(20, 30, 20);
|
91 |
-
directionalLight.castShadow = true;
|
92 |
-
scene.add(directionalLight);
|
93 |
-
}
|
94 |
|
95 |
-
//
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
box.receiveShadow = true;
|
103 |
-
scene.add(box);
|
104 |
-
}
|
105 |
-
|
106 |
-
// ์์ง์ ๊ด๋ จ ๋ณ์๋ค
|
107 |
-
const moveState = {
|
108 |
-
forward: false,
|
109 |
-
backward: false,
|
110 |
-
left: false,
|
111 |
-
right: false
|
112 |
-
};
|
113 |
|
114 |
-
//
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
case 'KeyA': moveState.left = true; break;
|
120 |
-
case 'KeyD': moveState.right = true; break;
|
121 |
-
}
|
122 |
-
});
|
123 |
|
124 |
-
|
125 |
-
switch (event.code) {
|
126 |
-
case 'KeyW': moveState.forward = false; break;
|
127 |
-
case 'KeyS': moveState.backward = false; break;
|
128 |
-
case 'KeyA': moveState.left = false; break;
|
129 |
-
case 'KeyD': moveState.right = false; break;
|
130 |
-
}
|
131 |
-
});
|
132 |
|
133 |
-
// ์ ๋๋ฉ์ด์
|
134 |
function animate() {
|
135 |
requestAnimationFrame(animate);
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
if (moveState.forward) controls.moveForward(speed);
|
140 |
-
if (moveState.backward) controls.moveForward(-speed);
|
141 |
-
if (moveState.left) controls.moveRight(-speed);
|
142 |
-
if (moveState.right) controls.moveRight(speed);
|
143 |
-
}
|
144 |
|
145 |
renderer.render(scene, camera);
|
146 |
}
|
147 |
|
148 |
// ํ๋ฉด ํฌ๊ธฐ ์กฐ์ ์ฒ๋ฆฌ
|
149 |
-
window.addEventListener('resize',
|
150 |
-
|
151 |
-
function onWindowResize() {
|
152 |
camera.aspect = window.innerWidth / window.innerHeight;
|
153 |
camera.updateProjectionMatrix();
|
154 |
-
|
155 |
-
}
|
156 |
|
157 |
-
// ์ด๊ธฐํ ๋ฐ ์ ๋๋ฉ์ด์
์์
|
158 |
-
init();
|
159 |
animate();
|
160 |
</script>
|
161 |
</body>
|
162 |
-
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
+
<title>Basic Three.js Test</title>
|
5 |
<style>
|
6 |
body { margin: 0; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
</style>
|
8 |
</head>
|
9 |
<body>
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
<script type="module">
|
11 |
+
import * as THREE from 'https://unpkg.com/three@0.157.0/build/three.module.js';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
// ๊ธฐ๋ณธ ์ค์
|
14 |
+
const scene = new THREE.Scene();
|
15 |
+
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
16 |
+
const renderer = new THREE.WebGLRenderer();
|
17 |
+
|
18 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
19 |
+
document.body.appendChild(renderer.domElement);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
// ํ
์คํธ์ฉ ํ๋ธ ์์ฑ
|
22 |
+
const geometry = new THREE.BoxGeometry();
|
23 |
+
const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
|
24 |
+
const cube = new THREE.Mesh(geometry, material);
|
25 |
+
scene.add(cube);
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
camera.position.z = 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
// ์ ๋๋ฉ์ด์
|
30 |
function animate() {
|
31 |
requestAnimationFrame(animate);
|
32 |
|
33 |
+
cube.rotation.x += 0.01;
|
34 |
+
cube.rotation.y += 0.01;
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
renderer.render(scene, camera);
|
37 |
}
|
38 |
|
39 |
// ํ๋ฉด ํฌ๊ธฐ ์กฐ์ ์ฒ๋ฆฌ
|
40 |
+
window.addEventListener('resize', () => {
|
41 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
|
42 |
camera.aspect = window.innerWidth / window.innerHeight;
|
43 |
camera.updateProjectionMatrix();
|
44 |
+
});
|
|
|
45 |
|
|
|
|
|
46 |
animate();
|
47 |
</script>
|
48 |
</body>
|
49 |
+
</html>
|