Last active
August 29, 2015 14:02
-
-
Save rejjin/753cae7c05beda07672b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Application | |
| constructor: () -> | |
| init: -> | |
| if Detector.webgl | |
| @Renderer = new THREE.WebGLRenderer | |
| @Renderer.setClearColor 0xBBBBBB, 1 | |
| else | |
| do Detector.addGetWebGLMessage | |
| return false | |
| @Renderer.setSize window.innerWidth, window.innerHeight | |
| document.getElementById('container').appendChild(@Renderer.domElement) | |
| @Scene = new THREE.Scene(); | |
| @Camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 1, 10000 ); | |
| @Camera.position.set 0, 0, 5 | |
| @CameraControls = new THREEx.DragPanControls(@Camera) | |
| geometry = new THREE.TorusGeometry( 1, 0.42 ) | |
| material = new THREE.MeshNormalMaterial() | |
| mesh = new THREE.Mesh( geometry, material ) | |
| @Scene.add( mesh ); | |
| THREEx.WindowResize.bind @Renderer, @Camera | |
| if( THREEx.FullScreen.available() ) | |
| THREEx.FullScreen.bindKey() | |
| appendStats: -> | |
| @Stats = new Stats | |
| @Stats.domElement.style.position = 'absolute'; | |
| @Stats.domElement.style.bottom = '0px'; | |
| document.body.appendChild @Stats.domElement | |
| processRender: -> | |
| do @CameraControls.update | |
| @Renderer.render @Scene, @Camera | |
| animate: -> | |
| requestAnimationFrame @animate.bind @ # !!! | |
| do @processRender | |
| do @Stats.update | |
| Game = new Application() | |
| document.addEventListener "DOMContentLoaded", -> | |
| return if not Game.init() | |
| do Game.appendStats | |
| do Game.animate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment