-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
205 lines (162 loc) · 6.61 KB
/
index.html
File metadata and controls
205 lines (162 loc) · 6.61 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Solar System</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.js"></script>
<script type="module">
import { OrbitControls } from 'https://threejs.org/examples/jsm/controls/OrbitControls.js'
const renderer = new THREE.WebGLRenderer({alpha: true});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const fov = 40;
const aspect = 2;
const near = 0.1;
const far = 1000;
const camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
camera.position.set(0, 50, 0);
camera.up.set(0, 0, 1);
camera.lookAt(0, 0, 0);
const scene = new THREE.Scene();
const color = 0xFFFFFF;
const intensity = 3;
const light = new THREE.PointLight(color, intensity);
scene.add(light);
const radius = 1;
const widthSegments = 128;
const heightSegments = 64;
const sphereGeometry = new THREE.SphereGeometry(radius, widthSegments, heightSegments);
const loader = new THREE.TextureLoader();
// Sun
const solarSystem = new THREE.Object3D();
scene.add(solarSystem);
const sunMaterial = new THREE.MeshBasicMaterial({
map: loader.load('./textures/sun3.jpg'),
});
const sun = new THREE.Mesh(sphereGeometry, sunMaterial);
sun.scale.set(5, 5, 5);
solarSystem.add(sun);
//Mercury
const mercuryOrbit = new THREE.Object3D();
solarSystem.add(mercuryOrbit);
const mercuryMaterial = new THREE.MeshBasicMaterial({
map: loader.load('./textures/mercury.jpg')
});
const mercury = new THREE.Mesh(sphereGeometry, mercuryMaterial);
mercury.position.x = 7;
mercury.scale.set(.3, .3, .3);
mercuryOrbit.add(mercury);
//Venus
const venusOrbit = new THREE.Object3D();
solarSystem.add(venusOrbit);
const venusMaterial = new THREE.MeshBasicMaterial({
map: loader.load('./textures/venus.jpg')
});
const venus = new THREE.Mesh(sphereGeometry, venusMaterial);
venus.position.x = 10;
venus.scale.set(.9, .9, .9);
venusOrbit.add(venus);
// Earth
const earthOrbit = new THREE.Object3D();
earthOrbit.position.x = 15;
solarSystem.add(earthOrbit);
const earthMaterial = new THREE.MeshPhongMaterial({
map: loader.load('./textures/earth.jpg'), emissive: 0x222222
});
const earth = new THREE.Mesh(sphereGeometry, earthMaterial);
earth.scale.set(1, 1, 1);
earthOrbit.add(earth);
// Moon
const moonOrbit = new THREE.Object3D();
moonOrbit.position.x = 2;
earthOrbit.add(moonOrbit);
const moonMaterial = new THREE.MeshBasicMaterial({
map: loader.load('./textures/moon.jpg')
} );
const moon = new THREE.Mesh(sphereGeometry, moonMaterial);
moon.scale.set(.2, .2, .2);
moonOrbit.add(moon);
//Mars
const marsOrbit = new THREE.Object3D();
solarSystem.add(marsOrbit);
const marsMaterial = new THREE.MeshBasicMaterial({
map: loader.load('./textures/mars.jpg')
} );
const mars = new THREE.Mesh(sphereGeometry, marsMaterial);
mars.position.x = 19;
mars.scale.set(.7, .7, .7);
marsOrbit.add(mars);
//Jupiter
const jupiterOrbit = new THREE.Object3D();
solarSystem.add(jupiterOrbit);
const jupiterMaterial = new THREE.MeshBasicMaterial({
map: loader.load('./textures/jupiter.jpg')
} );
const jupiter = new THREE.Mesh(sphereGeometry, jupiterMaterial);
jupiter.position.x = 26;
jupiter.scale.set(3, 3, 3);
jupiterOrbit.add(jupiter);
//Saturn
const saturnOrbit = new THREE.Object3D();
solarSystem.add(saturnOrbit);
const saturnMaterial = new THREE.MeshBasicMaterial({
map: loader.load('./textures/saturn.jpg')
});
const saturn = new THREE.Mesh(sphereGeometry, saturnMaterial);
saturn.position.x = 37;
saturn.scale.set(2.7, 2.7, 2.7);
saturnOrbit.add(saturn);
//Uranus
const uranusOrbit = new THREE.Object3D();
solarSystem.add(uranusOrbit);
const uranusMaterial = new THREE.MeshBasicMaterial({
map: loader.load('./textures/uranus.jpg')
});
const uranus = new THREE.Mesh(sphereGeometry, uranusMaterial);
uranus.position.x = 46;
uranus.scale.set(1.5, 1.5, 1.5);
uranusOrbit.add(uranus);
// Neptune
const neptuneOrbit = new THREE.Object3D();
solarSystem.add(neptuneOrbit);
const neptuneMaterial = new THREE.MeshBasicMaterial({
map: loader.load('./textures/neptune.jpg')
});
const neptune = new THREE.Mesh(sphereGeometry, neptuneMaterial);
neptune.position.x = 54;
neptune.scale.set(1.5, 1.5, 1.5);
neptuneOrbit.add(neptune);
// Orbit Controls
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.minDistance = 1;
controls.maxDistance = 500;
controls.update();
function animate() {
requestAnimationFrame(animate);
solarSystem.rotation.y += 0.005;
mercuryOrbit.rotation.y += 0.002;
venusOrbit.rotation.y += 0.003;
earthOrbit.rotation.y += 0.06;
marsOrbit.rotation.y += 0.007;
jupiterOrbit.rotation.y += 0.008;
saturnOrbit.rotation.y += 0.009;
uranusOrbit.rotation.y += 0.01;
neptuneOrbit.rotation.y += 0.011;
controls.update();
renderer.render(scene, camera);
}
animate();
//Resize
window.addEventListener('resize', onWindowResize, false);
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight)
}
</script>
</body>
</html>