Simulate graph states in the browser
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

81 строка
2.3KB

  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);
  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 = true;
  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);
  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. };