Simulate graph states in the browser
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.

пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
пре 7 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. var gui = {};
  2. gui.prepare = function() {
  3. gui.renderer = new THREE.WebGLRenderer({
  4. "antialias": true
  5. });
  6. gui.renderer.setSize(window.innerWidth, window.innerHeight-5);
  7. gui.renderer.setClearColor(0xffffff, 1);
  8. document.querySelector("body").appendChild(gui.renderer.domElement);
  9. window.addEventListener("resize", gui.onWindowResize, false);
  10. gui.makeScene();
  11. gui.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.3, 1000);
  12. gui.controls = new THREE.OrbitControls(gui.camera);
  13. gui.controls.addEventListener("change", gui.render);
  14. gui.controls.center.set(0, 0, 0);
  15. gui.controls.target.set(0, 0, 0);
  16. gui.controls.rotateSpeed = 0.2;
  17. gui.controls.userPanSpeed = 0.1;
  18. gui.camera.position.set(0, 0, 10);
  19. gui.controls.autoRotate = false;
  20. gui.controls.autoRotateSpeed = 0.1;
  21. };
  22. // Someone resized the window
  23. gui.onWindowResize = function(evt) {
  24. gui.camera.aspect = window.innerWidth / window.innerHeight;
  25. gui.camera.updateProjectionMatrix();
  26. gui.renderer.setSize(window.innerWidth, window.innerHeight-5);
  27. gui.render();
  28. };
  29. // Render the current frame to the screen
  30. gui.render = function() {
  31. requestAnimationFrame(function() {
  32. gui.renderer.render(gui.scene, gui.camera);
  33. });
  34. };
  35. // Make the extra bits of gui
  36. gui.makeScene = function() {
  37. gui.scene = new THREE.Scene();
  38. };
  39. // Put an HTML message to the screen
  40. // TODO: write a generic messaging class?
  41. gui.serverMessage = function(msgtext, persist) {
  42. if (persist === undefined) {persist = false;}
  43. server_info.innerHTML = msgtext;
  44. server_info.className = "visible";
  45. clearInterval(gui.ki);
  46. if (!persist){
  47. gui.ki = setInterval(function(){server_info.className="hidden";}, 3000);
  48. }
  49. };
  50. gui.nodeMessage = function(msgtext) {
  51. node_info.innerHTML = msgtext;
  52. node_info.className = "visible";
  53. };
  54. gui.hideNodeMessage = function(){
  55. node_info.className = "hidden";
  56. };
  57. // Set the position of the info popup
  58. gui.setInfoPosition = function(position){
  59. w = node_info.offsetWidth;
  60. h = node_info.offsetHeight;
  61. node_info.style.left = position.x - w/2 + "px";
  62. node_info.style.top = position.y - h -10 + "px";
  63. };
  64. // The main loop
  65. gui.loop = function() {
  66. gui.controls.update();
  67. editor.update();
  68. requestAnimationFrame(gui.loop);
  69. };