-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_health.html
312 lines (262 loc) · 7.43 KB
/
demo_health.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>DEMO 3D</title>
<style>
html, body {
height: 100%;
margin: 0px;
padding: 0px;
overflow: hidden;
}
#stats { position: absolute; top:0; left: 0 }
#stats #fps { background: transparent !important }
#stats #fps #fpsText { color: #aaa !important }
#stats #fps #fpsGraph { color: #0040ff }
</style>
<link rel="stylesheet" type="text/css" href="scripts2/css/pagemenu.css"/>
</head>
<body>
<div id="state"></div>
<div id="playground"></div>
<div id="submenu"></div>
<div id="voltage_tooltip">10V</div>
<script src="./libs/three.min.js"></script>
<script src="./libs/d3.js"></script>
<script src="./libs/jquery-1.11.1.min.js"></script>
<script src="./libs/tiny-pubsub.js"></script>
<script src="./libs/EasePack.min.js"></script>
<script src="./libs/TweenMax.min.js"></script>
<script src="./js/controls/OrbitControls.js"></script>
<script src="./js/libs/stats.min.js"></script>
<script src="./scripts2/view/HealthView.js"></script>
<script src="./scripts2/global/Utils.js"></script>
<script id="vertexShader" type="x-shader/x-vertex">
precision mediump float;
precision mediump int;
uniform mat4 modelViewMatrix; // optional
uniform mat4 projectionMatrix; // optional
attribute vec3 position;
attribute vec4 color;
varying vec3 vPosition;
varying vec4 vColor;
void main() {
vPosition = position;
vColor = color;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
precision mediump float;
precision mediump int;
uniform float time;
varying vec3 vPosition;
varying vec4 vColor;
void main() {
vec4 color = vec4( vColor );
color.a = time;
gl_FragColor = color;
}
</script>
<script>
const SITE_URL = "http://chain-api.media.mit.edu/devices/?site_id=7";
var devices;
var container, scene, renderer, camera, controls, sw, sh, stats;
var ground, groundWid, groundHei, groundZero;
var menuHealth, viewHealth;
var mouse = new THREE.Vector2();
$(document).ready(function() {
$.getJSON(SITE_URL, function(dat) {
// TODO: That's use a little trick way to get all sensors from on request, maybe change the way in future...
var url = SITE_URL + '&limit=' + dat.totalCount + '&offset=0';
$.getJSON(url, function(dat2) {
devices = dat2["_links"]["items"];
init3d();
// create health graph
viewHealth = new HealthView();
viewHealth.create("./res/data_2014/2014_all.csv", devices);
});
});
});
// 不让网页文字选中
document.onselectstart = function() {
return false;
}
function init3d()
{
container = $("#playground");
sw = window.innerWidth;
sh = window.innerHeight;
// Setup the renderer
renderer = new THREE.WebGLRenderer({ antialias:true });
renderer.setSize(sw, sh);
renderer.setClearColor( 0x202428, 1 );
renderer.sortObjects = true;
//renderer.autoClear = false;
container.append(renderer.domElement);
// Setup the camera
camera = new THREE.PerspectiveCamera(45, sw / sh, 0.1, 10000);
camera.position.y = 1000;
camera.position.z = 1000;
// Setup the scene
scene = new THREE.Scene();
//scene.fog = new THREE.Fog(0xffffff, 4000, 4000);
//scene.add(camera);
// STATS
stats = new Stats();
$("#state").append(stats.domElement);
// CONTROLS
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.autoRotate = false;
//controls.noZoom = true;
//controls.noRotate = true;
//controls.noPan = true;
// Handling window resize
window.addEventListener("resize", function() {
sw = window.innerWidth;
sh = window.innerHeight;
renderer.setSize(sw, sh);
camera.aspect = sw / sh;
camera.updateProjectionMatrix();
});
document.addEventListener( 'mousemove', function(event) {
event.preventDefault();
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
}, false );
createWorld();
animate();
}
function createWorld()
{
// var box = new THREE.Mesh(
// new THREE.BoxGeometry(100, 100, 100),
// new THREE.MeshBasicMaterial({color: 0xff0000})
// );
// scene.add(box);
createBaseGround();
}
function createBaseGround()
{
groundWid = 1000;
groundHei = 1000;
var texture = THREE.ImageUtils.loadTexture("./res/textures/map_area.jpg");
texture.wrapS = THREE.ClampToEdgeWrapping;
texture.wrapT = THREE.ClampToEdgeWrapping;
texture.minFilter = THREE.NearestFilter;
ground = new THREE.Mesh(
new THREE.PlaneBufferGeometry(groundWid, groundHei, 200, 200),
new THREE.MeshPhongMaterial({map: texture, shading: THREE.SmoothShading, side: THREE.DoubleSide})
);
ground.position.y = -200;
ground.rotation.x = -Math.PI / 2;
groundZero = ground.position.y - 3;
scene.add(ground);
camera.lookAt(ground.position);
}
function animate()
{
requestAnimationFrame(animate);
render();
stats.update();
}
function render()
{
renderer.render(scene, camera);
controls.update();
}
/////////////////////////////////////////////
// JUST FOR TEST
/////////////////////////////////////////////
function onKeyboardDown()
{
// 返回键退出
console.log(d3.event.keyCode);
if(d3.event.keyCode == 68) // D:
{
var obj = scene.getObjectByName("axis_container");
console.log("= Camera Info =================================");
console.log(camera.position);
console.log(camera.rotation);
console.log("Polar Angle = " + controls.getPolarAngle());
console.log("Azimuthal Angle = " + controls.getAzimuthalAngle());
console.log(obj.position);
console.log(obj.rotation);
console.log("===============================================");
} else if(d3.event.keyCode == 69) // e
{
var obj = scene.getObjectByName("axis_container");
console.log(obj.position);
}
else if(d3.event.keyCode == 70) // f
{
camera.lookAt(new THREE.Vector3(0, 0, 0));
}
else if(d3.event.keyCode == 49) // 1
{
var obj = scene.getObjectByName("axis_container");
obj.position.x += 10;
}
else if(d3.event.keyCode == 50) // 2
{
var obj = scene.getObjectByName("axis_container");
obj.position.x -= 10;
}
else if(d3.event.keyCode == 51) // 3
{
var obj = scene.getObjectByName("axis_container");
obj.position.y += 10;
}
else if(d3.event.keyCode == 52) // 4
{
var obj = scene.getObjectByName("axis_container");
obj.position.y -= 10;
}
else if(d3.event.keyCode == 53) // 5
{
var obj = scene.getObjectByName("axis_container");
obj.position.z += 10;
//obj.rotation.y += 0.1;
}
else if(d3.event.keyCode == 54) // 6
{
var obj = scene.getObjectByName("axis_container");
obj.position.z -= 10;
//obj.rotation.y -= 0.1;
}
else if(d3.event.keyCode == 55) // 7
{
var obj = scene3.getObjectByName("charging_container");
obj.rotation.z += 0.1;
}
else if(d3.event.keyCode == 56) // 8
{
var obj = scene3.getObjectByName("charging_container");
obj.rotation.z -= 0.1;
}
else if(d3.event.keyCode == 57) // 9
{
var obj = scene3.getObjectByName("charging_container");
obj.rotation.y += 0.1;
}
else if(d3.event.keyCode == 48) // 0
{
var obj = scene3.getObjectByName("charging_container");
obj.rotation.y -= 0.1;
}
else if(d3.event.keyCode == 74) // j
{
camera.fov = 1;
camera.updateProjectionMatrix();
}
else if(d3.event.keyCode == 75) // k
{
//camera.fov = 45;
///camera.updateProjectionMatrix();
}
}
d3.select("body").on("keydown", onKeyboardDown);
</script>
</body>
</html>