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.

70 lines
1.6KB

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