-
Notifications
You must be signed in to change notification settings - Fork 0
/
globe.html
82 lines (62 loc) · 2.09 KB
/
globe.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
82
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Globe and Texture</title>
<style>
div {
border : 1px solid;
}
</style>
</head>
<body>
<div id="webgl_view"></div>
<script type="text/javascript" src="three.js" charset="utf-8"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script>
var height = 640;
var width = 640;
var container = $('#webgl_view');
container.css({
height : height + "px",
width : width + "px"});
// (1) 球体
var geometry = new THREE.SphereGeometry(1, 32, 32);
var material = new THREE.MeshPhongMaterial({
map: THREE.ImageUtils.loadTexture('land_shallow_topo_2048.jpg') });
var sphere = new THREE.Mesh(geometry, material);
// (2) ライト(平行光)
var light = new THREE.DirectionalLight(0xffffff);
light.position.x = Math.sin(Math.PI * 23.4 / 180.0);
light.position.y = Math.cos(Math.PI * 23.4 / 180.0);
light.position.z = 0;
// (3) 環境光
var alight = new THREE.AmbientLight(0x444444);
// (4) Scene
var scene = new THREE.Scene();
scene.add(sphere);
scene.add(light);
scene.add(alight);
// (5) Camera (視野角, アスペクト比(縦横比), 描画対象(最小距離), 描画対象(最大距離)
var camera = new THREE.PerspectiveCamera(90, (height / width), 0.1, 10);
// (6) WebGL Renderer
var renderer = new THREE.WebGLRenderer();
renderer.setSize(height, width);
renderer.setClearColor(0x101010);
renderer.clear(true);
container.append(renderer.domElement);
// (7) Animation (Rotate)
function animation() {
var time = (new Date()).getTime();
sphere.rotation.y = time / 3000;
camera.position.x = 1.5 * Math.sin(-1.0 * time / 10000);
camera.position.y = 1.0 * Math.sin(time / 10000);
camera.position.z = 1.5 * Math.cos(-1.0 * time / 10000);
camera.lookAt(new THREE.Vector3(-1.0 * camera.position.x,-1.0 * camera.position.y,-1.0 * camera.position.z));
renderer.render(scene, camera);
requestAnimationFrame(animation);
}
animation();
</script>
</body>
</html>