-
Notifications
You must be signed in to change notification settings - Fork 3
/
surface.html
247 lines (201 loc) · 7.1 KB
/
surface.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="js/Three.js"></script>
<script src="js/ShaderTerrain.js"></script>
<!--<script src="js/Stats.js"></script>-->
<!--<script src="js/TrackballControls.js"></script>-->
<style>
#file-selector-container {
background: #FFF;
position: absolute;
left: 50px;
top: 10px;
height: 28px;
width: 400px;
border: 1px solid rgba(0, 0, 0, 0.4);
border-radius: 3px;
z-index: 999;
}
</style>
</head>
<body>
<div id="main_map">
</div>
<div id='file-selector-container'>
<div id='file-selector'>
Select a LIDAR image file
<select id="LIDAR-image">
<select>
</div>
</div>
<script type="text/javascript">
var CONS = {
// THREE.JS CONSTANTS
// set the scene size
WIDTH: 904,
HEIGHT: 604,
// set some camera attributes
VIEW_ANGLE: 45,
NEAR: 0.1,
FAR: 10000,
CAMERA_X: 1300,
CAMERA_Y: 600,
CAMERA_Z: 1300
}
var scene = {};
var renderer = {};
var camera = {};
var texture = {};
var detailTexture = {};
var terrainShader = {};
var uniformsTerrain = {};
var material = {};
var geometryTerrain = {};
var controls;
var LIDARfile = '';
var n = 0;
var IsInitialised = false;
$.ajax({ url: 'images', success: function(data) {
var elements = $(data);
var found = $('li', elements);
var options = '';
$.each(found, function(item){
filename = $(this).text()
if (filename != "bg.jpg" && filename != "bg-plain.jpg" ){
options += '<option value="'+ filename +'">' + filename + '</option>'
}
;})
$("#LIDAR-image").html(options);
}
});
$('#LIDAR-image').change(function() {
var val = $("#LIDAR-image option:selected").val();
LIDARfile = '';
if (!IsInitialised) {
n = 0;
LIDARfile = "images/" + val
initMap();
animate();
IsInitialised = true
} else {
terrain.visible = false;
LIDARfile = "images/" + val
texture = THREE.ImageUtils.loadTexture(LIDARfile, null, reloaded);
}
});
// If we
function reloaded(){
uniformsTerrain["tDisplacement"].texture = texture;
terrain.visible = true;
render();
animate();
}
// Wait until everything is loaded before continuing
function loaded() {
n++;
console.log("loaded: " + n);
if (n == 3) {
terrain.visible = true;
render();
}
}
function initMap() {
// setup default three.js stuff
renderer = new THREE.WebGLRenderer();
renderer.setSize(CONS.WIDTH, CONS.HEIGHT);
renderer.setClearColor(0x0000cc);
$("#main_map").append(renderer.domElement);
camera = new THREE.PerspectiveCamera(CONS.VIEW_ANGLE, CONS.WIDTH / CONS.HEIGHT, CONS.NEAR, CONS.FAR);
scene = new THREE.Scene();
scene.add(camera);
camera.position.z = CONS.CAMERA_Z;
camera.position.x = CONS.CAMERA_X;
camera.position.y = CONS.CAMERA_Y;
camera.lookAt(scene.position);
// Controls
controls = new THREE.TrackballControls(camera, renderer.domElement);
controls.rotateSpeed = 2.0;
controls.zoomSpeed = 2.0;
controls.panSpeed = 2.0;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
controls.keys = [65, 83, 68];
controls.addEventListener('change', render);
// add a light
pointLight = new THREE.PointLight(0xFFFFFF);
scene.add(pointLight);
pointLight.position.x = 1000;
pointLight.position.y = 3000;
pointLight.position.z = -1000;
pointLight.intensity = 8.6;
// load the heightmap we created as a texture
texture = THREE.ImageUtils.loadTexture(LIDARfile, null, loaded);
// load two other textures we'll use to make the map look more real
detailTexture = THREE.ImageUtils.loadTexture("images/bg-plain.jpg", null, loaded);
// the following configuration defines how the terrain is rendered
terrainShader = THREE.ShaderTerrain["terrain"];
uniformsTerrain = THREE.UniformsUtils.clone(terrainShader.uniforms);
// how to treat abd scale the normal texture
uniformsTerrain["tNormal"].texture = detailTexture;
uniformsTerrain["uNormalScale"].value = 1;
// the displacement determines the height of a vector, mapped to
// the heightmap
uniformsTerrain["tDisplacement"].texture = texture;
uniformsTerrain["uDisplacementScale"].value = 200;
// the following textures can be use to finetune how
// the map is shown. These are good defaults for simple
// rendering
uniformsTerrain["tDiffuse1"].texture = detailTexture;
uniformsTerrain["tDetail"].texture = detailTexture;
uniformsTerrain["enableDiffuse1"].value = true;
uniformsTerrain["enableDiffuse2"].value = true;
uniformsTerrain["enableSpecular"].value = true;
// diffuse is based on the light reflection
uniformsTerrain["uDiffuseColor"].value.setHex(0xcccccc);
uniformsTerrain["uSpecularColor"].value.setHex(0xff0000);
// is the base color of the terrain
uniformsTerrain["uAmbientColor"].value.setHex(0x0000cc);
// how shiny is the terrain
uniformsTerrain["uShininess"].value = 3;
// handles light reflection
uniformsTerrain["uRepeatOverlay"].value.set(6, 6);
// configure the material that reflects our terrain
material = new THREE.ShaderMaterial({
uniforms: uniformsTerrain,
vertexShader: terrainShader.vertexShader,
fragmentShader: terrainShader.fragmentShader,
lights: true,
fog: false
});
// we use a plain to render as terrain
geometryTerrain = new THREE.PlaneGeometry(1024, 1024, 512, 512);
geometryTerrain.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI / 2));
geometryTerrain.computeFaceNormals();
geometryTerrain.computeVertexNormals();
geometryTerrain.computeTangents();
// create a 3D object to add
terrain = new THREE.Mesh(geometryTerrain, material);
terrain.position.set(0, -125, 0);
terrain.rotation.x = -Math.PI / 2;
// add the terrain
scene.add(terrain);
// tell everything is ready
loaded();
}
function animate() {
requestAnimationFrame(animate);
controls.update();
}
function render() {
renderer.render(scene, camera);
//stats.update();
}
</script>
</body>
</html>