app.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. */
  4. var APP = {};
  5. APP.Player = function () {
  6. var loader = new THREE.ObjectLoader();
  7. var camera, scene, renderer;
  8. var scripts;
  9. this.dom = undefined;
  10. this.load = function ( json ) {
  11. renderer = new THREE.WebGLRenderer( { antialias: true } );
  12. scene = loader.parse( json );
  13. /*
  14. scripts = [];
  15. scene.traverse( function ( child ) {
  16. if ( child.script !== undefined ) {
  17. var script = new Function( 'scene', 'time', child.script.source ).bind( child );
  18. scripts.push( script );
  19. }
  20. } );
  21. */
  22. this.dom = renderer.domElement;
  23. };
  24. this.setCamera = function ( master ) {
  25. camera = master.clone();
  26. };
  27. this.setSize = function ( width, height ) {
  28. renderer.setSize( width, height );
  29. };
  30. var request;
  31. var animate = function ( time ) {
  32. request = requestAnimationFrame( animate );
  33. /*
  34. for ( var i = 0; i < scripts.length; i ++ ) {
  35. scripts[ i ]( scene, time );
  36. }
  37. */
  38. renderer.render( scene, camera );
  39. };
  40. this.play = function () {
  41. request = requestAnimationFrame( animate );
  42. };
  43. this.stop = function () {
  44. cancelAnimationFrame( request );
  45. };
  46. };
  47. APP.Script = function ( source ) {
  48. this.uuid = THREE.Math.generateUUID();
  49. this.source = source;
  50. };