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.

77 lines
1.8KB

  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. render();
  29. }
  30. // Someone resized the window
  31. function onWindowResize(evt){
  32. camera.aspect = window.innerWidth / window.innerHeight;
  33. camera.updateProjectionMatrix();
  34. renderer.setSize(window.innerWidth, window.innerHeight);
  35. render();
  36. }
  37. // Called on startup
  38. function init() {
  39. // Measure things, get references
  40. var width = window.innerWidth;
  41. var height = window.innerHeight;
  42. // Renderer
  43. renderer = new THREE.WebGLRenderer({"antialias":true});
  44. renderer.setSize(width, height);
  45. renderer.setClearColor(0xffffff, 1);
  46. document.querySelector("body").appendChild(renderer.domElement);
  47. window.addEventListener("resize", onWindowResize, false);
  48. // Time to load the materials
  49. loadMaterials();
  50. // Camera, controls, raycaster
  51. camera = new THREE.PerspectiveCamera(45, width / height, 0.3, 100);
  52. controls = new THREE.OrbitControls(camera);
  53. // Center the camera
  54. // TODO: frustrum
  55. controls.center.set(0, 0, 0);
  56. controls.rotateSpeed = 0.2;
  57. camera.position.set(0, 0, 40);
  58. // Start polling
  59. // Run
  60. startMainLoop();
  61. }