Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5KB

  1. var body;
  2. function poll() {
  3. var xhr = new XMLHttpRequest();
  4. xhr.onload = function() {
  5. var state = JSON.parse(xhr.responseText);
  6. updateScene(state);
  7. };
  8. xhr.onerror = function(e){
  9. //soft_console.innerHTML = "\n" + "Lost connection to server";
  10. };
  11. xhr.open("GET", "/state", true);
  12. xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
  13. xhr.send();
  14. }
  15. function updateScene(state) {
  16. var oldState = scene.getObjectByName("graphstate");
  17. scene.remove(oldState);
  18. oldState = null;
  19. var geometry = new THREE.Geometry();
  20. //nodeGeometry.labels = [];
  21. //nodeGeometry.colors = [];
  22. for (var i in state.vops) {
  23. var vop = state.vops[i];
  24. var pos = state.meta[i].pos;
  25. var vertex = new THREE.Vector3(pos.x, pos.y, pos.z);
  26. geometry.vertices.push(vertex);
  27. //geometry.colors[i] = new THREE.Color(n.color);
  28. //geometry.labels[i] = n.label;
  29. }
  30. var edges = new THREE.Object3D();
  31. for (i=0; i < state.edge.length; ++i) {
  32. var edge = state.edge[i];
  33. var start = state.meta[edge[0]].pos;
  34. var end = state.meta[edge[1]].pos;
  35. var newEdge = makeEdge(start, end);
  36. edges.add(newEdge);
  37. }
  38. var particles = new THREE.Points(geometry, materials.qubit);
  39. var newState = new THREE.Object3D();
  40. newState.name = "graphstate";
  41. newState.add(particles);
  42. newState.add(edges);
  43. scene.add(newState);
  44. render();
  45. }