-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspinny-sphere.html
81 lines (70 loc) · 2.97 KB
/
spinny-sphere.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html>
<body id="spinny-sphere-body">
<script src="js/three.min.js"></script>
<script>
// from: http://learningthreejs.com/blog/2013/09/16/how-to-make-the-earth-in-webgl/
// renderer
var renderer = new THREE.WebGLRenderer({ alpha: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
renderer.setClearColor( 0x000000, 0 ); // the default
// camera
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.z = 250;
// scene
var scene = new THREE.Scene();
// light
var light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 0, 0, 500 ).normalize();
scene.add(light);
// material
var material = new THREE.MeshPhongMaterial( { ambient: 0x050505, color: "orange",
specular: 0x555555, shininess: 12 } );
// material.bumpMap = THREE.ImageUtils.loadTexture('textures/earthbump1k.jpg');
material.bumpMap = THREE.ImageUtils.loadTexture('textures/sigmoid.png');
material.bumpScale = 500;
// geometry
// the first argument of THREE.SphereGeometry is the radius, the second argument is
// the segmentsWidth, and the third argument is the segmentsHeight. Increasing the
// segmentsWidth and segmentsHeight will yield a more perfect circle, but will degrade
// rendering performance
var geometry = new THREE.SphereGeometry(75, 75, 50);
// sphere
var sphere = new THREE.Mesh(geometry, material);
sphere.overdraw = true;
scene.add(sphere);
document.getElementById("spinny-sphere-body").onclick = function() {
scene.remove(light);
light.intensity = 1;
light.position.set(100, 20, 100);
scene.add(light);
scene.remove(sphere);
var world_material = new THREE.MeshPhongMaterial();
world_material.map = THREE.ImageUtils.loadTexture('textures/world/earth_unshaded_hs__hschmidt.jpg');
world_material.bumpMap = THREE.ImageUtils.loadTexture('textures/world/elev_bump_8k.jpg');
world_material.bumpScale = 3;
world_material.specularMap = THREE.ImageUtils.loadTexture('textures/world/earth_unshaded_hs__hschmidt.jpg');
world_material.specular = new THREE.Color('grey');
sphere.material = world_material;
scene.add(sphere);
var cloud_geometry = new THREE.SphereGeometry(75.1, 75, 50);
var cloud_material = new THREE.MeshPhongMaterial({
map : THREE.ImageUtils.loadTexture('textures/world/earth_clouds_hs__h_schmidt.jpg'),
side : THREE.DoubleSide,
opacity : 0.4,
transparent : true,
depthWrite : false,
})
var cloudMesh = new THREE.Mesh(cloud_geometry, cloud_material);
sphere.add(cloudMesh);
}
function render() {
requestAnimationFrame(render);
sphere.rotation.y -= 0.01;
renderer.render(scene, camera);
}
render();
</script>
</body>
</html>