diff --git a/static/index.html b/static/index.html index d114288..d3c047f 100644 --- a/static/index.html +++ b/static/index.html @@ -15,6 +15,7 @@ + diff --git a/static/main.js b/static/main.js index f2589bb..c92b53c 100644 --- a/static/main.js +++ b/static/main.js @@ -52,8 +52,8 @@ function init() { controls = new THREE.OrbitControls(camera); controls.center.set(0, 0, 0); controls.rotateSpeed = 0.2; - controls.addEventListener("change", render); camera.position.set(0, 0, 20); + controls.addEventListener("change", render); // Run scene = makeScene(); diff --git a/static/websocket_interface.js b/static/websocket_interface.js new file mode 100644 index 0000000..843a09c --- /dev/null +++ b/static/websocket_interface.js @@ -0,0 +1,34 @@ +var ws; + +function connect_to_server() { + ws = new WebSocket("ws://localhost:5000"); + ws.onopen = function() + { + message.innerHTML = "Connected to server."; + message.className = "visible"; + }; + + ws.onerror = function(err) + { + message.innerHTML = "Could not connect to server."; + message.className = "visible"; + }; + + ws.onmessage = function (evt) + { + console.log("Received update"); + var new_state = JSON.parse(evt.data); + vops = new_state.vops; + ngbh = new_state.ngbh; + meta = new_state.meta; + updateScene(); + }; + + ws.onclose = function() + { + message.innerHTML = "Connection to server lost. Reconnect."; + message.className = "visible"; + }; +} + +