-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.html
268 lines (218 loc) · 9.3 KB
/
socket.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
<html>
<head>
<title>Vizlab 1</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.1.0/papaparse.js"></script>
<!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>-->
<script src="http://code.jquery.com/ui/1.11.3/jquery-ui.js"></script>
<script src="js/stats.js"></script>
<script src="js/tsv.js"></script>
<script src="js/marker.js"></script>
<script src="js/connection.js"></script>
<script src="js/controls/OrbitalControls.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
</head>
<body>
<!--
<div id="loader">
<img src="images/loading.gif" />
</div>
-->
<div class="container">
<div id="draw-controls">
<button id="add-connection" type="button" class="btn btn-default">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-default">
<span id="delete-connection" class="glyphicon glyphicon-trash" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-default">
<span id="delete-connections" class="glyphicon glyphicon-refresh" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-default">
<span id="delete-connections" class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>
</button>
</div>
</div>
<div id="controls">
<div class="container">
<div id="buttons-holder">
<div class="btn-group btn-group-md" role="group" aria-label="...">
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-fast-backward" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-backward" aria-hidden="true"></span>
</button>
<button id="play-button" type="button" class="btn btn-default">
<span id="play-icon" class="glyphicon glyphicon-pause" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-forward" aria-hidden="true"></span>
</button>
<button type="button" class="btn btn-default">
<span class="glyphicon glyphicon-fast-forward" aria-hidden="true"></span>
</button>
</div>
</div>
<div id="slider-holder">
<div id="slider"></div>
</div>
</div>
</div>
<script>
var SCREEN_WIDTH = window.innerWidth;
var SCREEN_HEIGHT = window.innerHeight;
var camera, scene, raycaster, canvasRenderer, webglRenderer;
var container, mesh, geometry, light, plane;
var colors=["green","green","orange","orange","red","blue","blue","blue","blue","black","black","black","black","black","black","black","black","black","black","black","black"];
var markers = [];
var connections = [];
var selected = [];
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var mouse = new THREE.Vector2(), intersected;
var iteration = 0;
var paused = false;
var coordinate_strings = [];
var marker_coordinates = [];
var initiated = false;
function init(){
console.log(marker_coordinates);
$( "#play-button" ).click(function() {
if(paused != true){
paused = true;
document.getElementById("play-icon").className = "glyphicon glyphicon-play";
}else{
paused = false
document.getElementById("play-icon").className = "glyphicon glyphicon-pause";
}
});
// Create a connection, to do so, pass selected points
$( "#add-connection" ).click(function() {
var connection = new connection(selected[0].index, selected[1].index);
connection.draw(markers,scene);
connections.push(connection);
console.log(connections);
});
container = document.createElement('div');
$('body').prepend(container);
// Setup camera
camera = new THREE.PerspectiveCamera(30, window.innerWidth / window.innerHeight, 1, 100000);
camera.position.x = 1200;
camera.position.y = 1000;
camera.position.z = 300;
camera.up = new THREE.Vector3( 0, 0, 1 );
// Create a new scene
scene = new THREE.Scene();
// Create grey floor
var groundMaterial = new THREE.MeshPhongMaterial({
color: 0x444444
});
plane = new THREE.Mesh(new THREE.PlaneGeometry(1500, 1500), groundMaterial);
plane.receiveShadow = true;
scene.add(plane);
// Setup lights and add to scene
light = new THREE.DirectionalLight(0xdfebff, 1.75);
light.position.set(0, 0, 250);
light.position.multiplyScalar(1.3);
scene.add(light);
// Draw markers for the first line in coordinates[]
for(var i=0;i<marker_coordinates[0].length;i++){
console.log(i);
marker = new Marker(i,colors[i],marker_coordinates[0][0],marker_coordinates[0][0],marker_coordinates[0][0],5);
markers[i] = marker.draw();
scene.add(markers[i]);
console.log(markers);
}
// RENDERER
webglRenderer = new THREE.WebGLRenderer();
webglRenderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
webglRenderer.setClearColor( 0xffffff, 1);
webglRenderer.domElement.style.position = "relative";
webglRenderer.shadowMapEnabled = true;
webglRenderer.shadowMapSoft = true;
// Define the controls
controls = new THREE.OrbitControls( camera );
controls.damping = 0.2;
// Add raycaster
raycaster = new THREE.Raycaster();
container.appendChild(webglRenderer.domElement);
window.addEventListener('resize', onWindowResize, false);
window.addEventListener('keydown', onKeyDown, false);
document.addEventListener( 'mousedown', onDocumentMouseDown, false );
}
function onKeyDown(e) {
if (e.keyCode == 0 || e.keyCode == 32) {
if(paused != true){
paused = true;
document.getElementById("play-icon").className = "glyphicon glyphicon-play";
}else{
paused = false
document.getElementById("play-icon").className = "glyphicon glyphicon-pause";
}
}
}
function onWindowResize() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
webglRenderer.setSize(window.innerWidth, window.innerHeight);
}
function onDocumentMouseDown( event ) {
event.preventDefault();
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
// find intersections
raycaster.setFromCamera( mouse, camera );
var intersects = raycaster.intersectObjects( scene.children );
if ( intersects.length > 0 ) {
if ( intersected != intersects[ 0 ].object ) {
if ( intersected ) intersected.material.emissive.setHex( intersected.currentHex );
intersected = intersects[ 0 ].object;
// If there are to selected, shift second to first place, add new one
if(selected.length == 2){
selected[0].selected = false;
selected[0] = selected[1];
selected[1] = intersected;
}else{
selected.push(intersected);
}
intersected.selected = true;
intersected.currentHex = intersected.material.emissive.getHex();
intersected.material.emissive.setHex( 0xff0000 );
}
} else {
if ( intersected ) intersected.material.emissive.setHex( intersected.currentHex );
intersected = null;
}
}
function animate(){
// $('#slider').slider('value', iteration);
// Updates markers
for(var i = 0; i < markers.length; i++){
markers[i].position.set(marker_coordinates[0][i][0], marker_coordinates[0][i][1], marker_coordinates[0][i][2]);
if(markers[i].selected == true){
markers[i].material.color.setHex( 0xffffff );
}else{
markers[i].material.color.set( colors[i] );
}
}
for(var i = 0; i < connections.length; i++){
connections[i].update;
console.log(connections[i]);
}
requestAnimationFrame(animate);
render();
}
function render() {
webglRenderer.render(scene, camera);
// find intersections
camera.updateMatrixWorld();
}
</script>
</body>
</html>