-
Notifications
You must be signed in to change notification settings - Fork 2
/
app1.js
98 lines (63 loc) · 2.34 KB
/
app1.js
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
let scene;
let camera;
let renderer;
function main()
{
const canvas = document.querySelector('#c');
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 2;
scene.add(camera);
renderer = new THREE.WebGLRenderer({canvas: canvas, antialias: true,});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.autoClear = false;
renderer.setClearColor(0x00000, 0.0);
// create earthgeometry
const earthgeometry = new THREE.SphereGeometry(0.6,32,32);
const eatrhmaterial = new THREE.MeshPhongMaterial({
roughness : 1,
metalness:0,
map: THREE.ImageUtils.loadTexture('texture/earthmap1k.jpg'),
bumpMap: THREE.ImageUtils.loadTexture('texture/earthbump.jpg'),
bumpScale: 0.3,
});
const earthmesh = new THREE.Mesh(earthgeometry,eatrhmaterial);
scene.add(earthmesh);
// set ambientlight
const ambientlight = new THREE.AmbientLight(0xffffff, 0.2);
scene.add(ambientlight);
// set point light
const pointerlight = new THREE.PointLight(0xffffff,0.9);
// set light position
pointerlight.position.set(5,3,5);
scene.add(pointerlight);
// cloud
const cloudgeometry = new THREE.SphereGeometry(0.63,32,32);
const cloudmaterial = new THREE.MeshPhongMaterial({
map: THREE.ImageUtils.loadTexture('texture/earthCloud.png'),
transparent: true
});
const cloudmesh = new THREE.Mesh(cloudgeometry,cloudmaterial);
scene.add(cloudmesh);
// star
const stargeometry = new THREE.SphereGeometry(80,64,64);
const starmaterial = new THREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture('texture/galaxy.png'),
side: THREE.BackSide
});
const starmesh = new THREE.Mesh(stargeometry,starmaterial);
scene.add(starmesh);
const animate = () =>{
requestAnimationFrame(animate);
earthmesh.rotation.y -= 0.0015;
cloudmesh.rotation.y += 0.0015;
starmesh.rotation.y += 0.0005;
render();
}
const render = () => {
renderer.render(scene,camera);
}
animate();
}
window.onload = main;