Anders and Briegel in Python
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

79 строки
2.2KB

  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. };
  20. // Someone resized the window
  21. gui.onWindowResize = function(evt) {
  22. gui.camera.aspect = window.innerWidth / window.innerHeight;
  23. gui.camera.updateProjectionMatrix();
  24. gui.renderer.setSize(window.innerWidth, window.innerHeight);
  25. gui.render();
  26. };
  27. // Render the current frame to the screen
  28. gui.render = function() {
  29. requestAnimationFrame(function() {
  30. gui.renderer.render(gui.scene, gui.camera);
  31. });
  32. };
  33. // Make the extra bits of gui
  34. gui.makeScene = function() {
  35. gui.scene = new THREE.Scene();
  36. };
  37. // Put an HTML message to the screen
  38. // TODO: write a generic messaging class?
  39. gui.serverMessage = function(msgtext, persist) {
  40. if (persist === undefined) {persist = false;}
  41. server_info.innerHTML = msgtext;
  42. server_info.className = "visible";
  43. clearInterval(gui.ki);
  44. if (!persist){
  45. gui.ki = setInterval(function(){server_info.className="hidden";}, 3000);
  46. }
  47. };
  48. gui.nodeMessage = function(msgtext) {
  49. node_info.innerHTML = msgtext;
  50. node_info.className = "visible";
  51. };
  52. gui.hideNodeMessage = function(){
  53. node_info.className = "hidden";
  54. };
  55. // Set the position of the info popup
  56. gui.setInfoPosition = function(position){
  57. w = node_info.offsetWidth;
  58. h = node_info.offsetHeight;
  59. node_info.style.left = position.x - w/2 + "px";
  60. node_info.style.top = position.y - h -10 + "px";
  61. };
  62. // The main loop
  63. gui.loop = function() {
  64. gui.controls.update();
  65. editor.update();
  66. requestAnimationFrame(gui.loop);
  67. };