-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_palette.html
135 lines (111 loc) · 4.42 KB
/
index_palette.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>land ahoy</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
color: #61443e;
font-family:Monospace;
font-size:13px;
text-align:center;
background-color: #000000;
margin: 0px;
overflow: hidden;
}
a {
color: #ffffff;
}
</style>
</head>
<body>
<div id="container"><br /><br /><br /><br /><br />Loading...</div>
<script src="js/three.min.js"></script>
<script src="js/FirstPersonControls.js"></script>
<script src="data.js"></script>
<script src="palette.js"></script>
<script src="depth_counts.js"></script>
<script>
var worldWidth = elevation[0].length, worldDepth = elevation.length;
var clock = new THREE.Clock();
var paletteLength = palette.length;
var pinValue = 127;
var seaPaletteStep = pinValue / sea_value_sum;
var landPaletteStep = (paletteLength - pinValue) / land_value_sum;
var camera, controls, scene, renderer, mesh;
var dataMin = -10911, dataMax = 8850;
function height_from_vertice_index(idx) {
var y = Math.floor(idx / worldWidth);
var x = idx - (y * worldWidth);
return elevation[y][x];
}
function colour_from_elevation(elevation) {
var discreteElevation = parseFloat(Math.round(elevation / 10.0));
var count = depth_counts[discreteElevation + ".0"];
if (count === undefined) {
count = depth_counts["-" + discreteElevation + ".0"];
}
var paletteStep = seaPaletteStep;
var paletteBase = 0;
if (discreteElevation >= -0.0) {
paletteStep = landPaletteStep;
paletteBase = pinValue;
}
var paletteIdx = parseInt(count * paletteStep) + paletteBase;
return new THREE.Color(
palette[paletteIdx][0] / paletteLength,
palette[paletteIdx][1] / paletteLength,
palette[paletteIdx][2] / paletteLength
);
}
function init() {
var geometry = new THREE.PlaneGeometry( worldWidth, worldDepth, worldWidth - 1, worldDepth - 1 );
geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
for (var y = 0; y < worldDepth; y++) {
for (var x = 0; x < worldWidth; x++) {
geometry.vertices[y * worldWidth + x].y = elevation[y][x] / 1500;
}
}
for (var faceIndex in geometry.faces )
{
var face = geometry.faces[ faceIndex ];
face.vertexColors[ 0 ] = colour_from_elevation(height_from_vertice_index(face.a));
face.vertexColors[ 1 ] = colour_from_elevation(height_from_vertice_index(face.b));
face.vertexColors[ 2 ] = colour_from_elevation(height_from_vertice_index(face.c));
}
material = new THREE.MeshLambertMaterial({ color: 0xFFFFFF, vertexColors: THREE.VertexColors});
mesh = new THREE.Mesh( geometry, material );
var pointLight = new THREE.PointLight(0xFFFFFF);
pointLight.position.x = -(worldWidth / 2);
pointLight.position.y = worldWidth;
pointLight.position.z = -(worldDepth/2);
scene = new THREE.Scene();
scene.add( mesh );
scene.add(pointLight);
renderer = new THREE.WebGLRenderer();
renderer.setClearColor( 0x000000 );
renderer.setSize( window.innerWidth, window.innerHeight );
container = document.getElementById( 'container' );
container.innerHTML = "";
container.appendChild( renderer.domElement );
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 20000 );
camera.position.x = 0
camera.position.y = 50;
camera.position.z = 150;
camera.up = new THREE.Vector3(0,1,0);
camera.lookAt(new THREE.Vector3(0,0,0));
controls = new THREE.FirstPersonControls( camera );
controls.movementSpeed = 30;
controls.lookSpeed = 0.1;
}
function animate() {
requestAnimationFrame( animate );
controls.update( clock.getDelta() );
renderer.render( scene, camera );
}
init();
animate();
</script>
</body>
</html>