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.

76 lines
1.7KB

  1. // IE9
  2. if (typeof console === "undefined") {
  3. var console = {
  4. log: function(logMsg) {}
  5. };
  6. }
  7. var controls, renderer, raycaster, scene, selection, camera;
  8. // Run on startup
  9. window.onload = init;
  10. // Clear the whole scene
  11. function makeScene() {
  12. var myScene = new THREE.Scene();
  13. var grid = makeGrid(10, 10, "lightgray");
  14. myScene.add(grid);
  15. return myScene;
  16. }
  17. // Render the current frame to the screen
  18. function render() {
  19. requestAnimationFrame(function () {
  20. renderer.render(scene, camera);
  21. });
  22. }
  23. // This just organises kickoff
  24. function startMainLoop() {
  25. scene = makeScene();
  26. controls.addEventListener("change", render);
  27. poll();
  28. }
  29. // Someone resized the window
  30. function onWindowResize(evt){
  31. camera.aspect = window.innerWidth / window.innerHeight;
  32. camera.updateProjectionMatrix();
  33. renderer.setSize(window.innerWidth, window.innerHeight);
  34. render();
  35. }
  36. // Called on startup
  37. function init() {
  38. // Measure things, get references
  39. var width = window.innerWidth;
  40. var height = window.innerHeight;
  41. // Renderer
  42. renderer = new THREE.WebGLRenderer({"antialias":true});
  43. renderer.setSize(width, height);
  44. renderer.setClearColor(0xffffff, 1);
  45. document.querySelector("body").appendChild(renderer.domElement);
  46. window.addEventListener("resize", onWindowResize, false);
  47. // Time to load the materials
  48. loadMaterials();
  49. // Camera, controls, raycaster
  50. camera = new THREE.PerspectiveCamera(45, width / height, 0.3, 100);
  51. controls = new THREE.OrbitControls(camera);
  52. // Center the camera
  53. controls.center.set(0, 0, 0);
  54. controls.rotateSpeed = 0.2;
  55. camera.position.set(0, 0, 20);
  56. // Start polling
  57. setInterval(poll, 1000);
  58. // Run
  59. startMainLoop();
  60. }