app.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. (function(){
  2. var Data = require("./setup");
  3. var camera = Data.Camera;
  4. var renderer = Data.Renderer;
  5. var scene = Data.Scene;
  6. var mouse = Data.Mouse;
  7. var onRender = Data.onRender;
  8. var ambientLight= new THREE.AmbientLight( 0x020202 )
  9. scene.add( ambientLight)
  10. var frontLight = new THREE.DirectionalLight('white', 1)
  11. frontLight.position.set(0.5, 0.5, 2)
  12. scene.add( frontLight )
  13. var backLight = new THREE.DirectionalLight('white', 0.75)
  14. backLight.position.set(-0.5, -0.5, -2)
  15. scene.add( backLight )
  16. onRender.push(function(delta, now){
  17. camera.position.x += (mouse.x*5 - camera.position.x) * (delta*3)
  18. camera.position.y += (mouse.y*5 - camera.position.y) * (delta*3)
  19. camera.lookAt( scene.position )
  20. })
  21. var geometry = new THREE.CubeGeometry( 1, 1, 1);
  22. var material = new THREE.MeshPhongMaterial();
  23. var mesh = new THREE.Mesh( geometry, material );
  24. scene.add( mesh );
  25. onRender.push(function(delta, now){
  26. mesh.rotateX(0.5 * delta);
  27. mesh.rotateY(2.0 * delta);
  28. })
  29. onRender.push(function(){
  30. renderer.render( scene, camera );
  31. })
  32. })();