Skip to content

Instantly share code, notes, and snippets.

@mikeyhu
Created April 25, 2013 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeyhu/5460397 to your computer and use it in GitHub Desktop.
Save mikeyhu/5460397 to your computer and use it in GitHub Desktop.
Trying out Three.js with CoffeeScript
$scope.drawGraph = ()->
scene = new THREE.Scene()
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 )
camera.position.z = 300
scene.add camera
renderer = new THREE.WebGLRenderer()
renderer.setSize(400,400)
document.getElementById("canvasDiv").appendChild(renderer.domElement)
directionalLight = new THREE.DirectionalLight(0xffffff, 1.0)
directionalLight.position = camera.position
scene.add(directionalLight)
geometry = new THREE.CubeGeometry(1,1,1)
material = new THREE.MeshLambertMaterial( { color: 0x00ff00 } )
cube = new THREE.Mesh( geometry, material )
scene.add cube
geometry = new THREE.Geometry()
geometry.vertices.push( new THREE.Vector3( -1, -1, 0 ) )
geometry.vertices.push( new THREE.Vector3( 1, -1, 0 ) )
geometry.vertices.push( new THREE.Vector3( 1, 0, 0 ) )
geometry.vertices.push( new THREE.Vector3( 0, 0, 2 ) )
geometry.faces.push( new THREE.Face3( 0, 1, 2 ) )
geometry.faces.push( new THREE.Face3( 1, 2, 3 ) )
geometry.faces.push( new THREE.Face3( 0, 1, 3 ) )
geometry.faces.push( new THREE.Face3( 2, 1, 3 ) )
#geometry.computeBoundingSphere()
material = new THREE.MeshLambertMaterial( { color: 0x00ff00 } )
mesh = new THREE.Mesh(geometry,material)
scene.add( mesh )
camera.position.z = 5
render =()->
requestAnimationFrame(render)
cube.rotation.x += 0.01
cube.rotation.y += 0.01
mesh.rotation.x += 0.01
mesh.rotation.y += 0.01
renderer.render(scene, camera)
render()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment