|
- // IE9
- if (typeof console === "undefined") {
- var console = {
- log: function(logMsg) {}
- };
- }
-
- var controls, renderer, raycaster, scene, selection, camera;
-
- // Run on startup
- window.onload = init;
-
- // Clear the whole scene
- function makeScene() {
- var myScene = new THREE.Scene();
- myScene.add(makeGrid(10, 10, "lightgray"));
- return myScene;
- }
-
-
- // Render the current frame to the screen
- function render() {
- renderer.render(scene, camera);
- }
-
- // This is the main control loop
- function loopForever() {
- controls.update();
- requestAnimationFrame(loopForever);
- }
-
-
- // This just organises kickoff
- function startMainLoop() {
- scene = makeScene();
- controls.addEventListener("change", render);
- loopForever();
- }
-
-
- // Called on startup
- function init() {
- // Measure things, get references
- var width = window.innerWidth;
- var height = window.innerHeight;
-
- // Renderer
- renderer = new THREE.WebGLRenderer();
- renderer.setSize(width, height);
- renderer.setClearColor(0xffffff, 1);
- document.querySelector("body").appendChild(renderer.domElement);
-
- // Time to load the materials
- loadMaterials();
-
- // Camera, controls, raycaster
- camera = new THREE.PerspectiveCamera(45, width / height, 0.3, 100);
- controls = new THREE.OrbitControls(camera);
-
- // Center the camera
- controls.center.set(0, 0, 0);
- controls.rotateSpeed = 0.2;
- camera.position.set(0, 0, 20);
-
- // Start polling
- setInterval(poll, 1000);
-
- // Run
- startMainLoop();
- }
|