lights_pointlights_gl.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - point light WebGL</title>
  5. <meta charset="utf-8">
  6. <style type="text/css">
  7. body {
  8. background-color: #000;
  9. margin: 0px;
  10. overflow: hidden;
  11. }
  12. #info {
  13. position: absolute;
  14. top: 0px; width: 100%;
  15. color: #ffffff;
  16. padding: 5px;
  17. font-family: Monospace;
  18. font-size: 13px;
  19. text-align: center;
  20. }
  21. a {
  22. color: #ff0080;
  23. text-decoration: none;
  24. }
  25. a:hover {
  26. color: #0080ff;
  27. }
  28. </style>
  29. </head>
  30. <body>
  31. <div id="container"></div>
  32. <div id="info">
  33. <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - point lights WebGL demo.<br />
  34. Walt Disney head by <a href="http://www.davidoreilly.com/2009/01/walt-disneys-head-on-a-plate" target="_blank">David OReilly</a>
  35. </div>
  36. <script type="text/javascript" src="../build/Three.js"></script>
  37. <script type="text/javascript" src="../src/extras/io/Loader.js"></script>
  38. <script type="text/javascript" src="../src/extras/primitives/Sphere.js"></script>
  39. <script type="text/javascript" src="js/Stats.js"></script>
  40. <script type="text/javascript">
  41. var camera, scene, renderer,
  42. particle1, particle2, particle2,
  43. light1, light2, light3,
  44. object;
  45. init();
  46. setInterval( loop, 1000 / 60 );
  47. function init() {
  48. var container = document.getElementById( 'container' );
  49. camera = new THREE.Camera( 65, window.innerWidth / window.innerHeight, 1, 1000 );
  50. camera.position.z = 100;
  51. scene = new THREE.Scene();
  52. var loader = new THREE.Loader();
  53. loader.loadAscii( "obj/walt/WaltHead_slim.js", function( geometry ) {
  54. object = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0xffffff, shininess: 50 } ) );
  55. object.scale.x = object.scale.y = object.scale.z = 0.80;
  56. object.overdraw = true;
  57. scene.addObject( object );
  58. });
  59. /*
  60. loader.loadBinary( "obj/walt/WaltHead_bin.js", function( geometry ) {
  61. object = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( 0x555555, 0x555555, 0xffffff, 50, 1.0 ) );
  62. object.scale.x = object.scale.y = object.scale.z = 0.80;
  63. object.overdraw = true;
  64. scene.addObject( object );
  65. }, "obj/walt");
  66. */
  67. /*
  68. var directionalLight = new THREE.DirectionalLight( 0x111111, 0.9 );
  69. directionalLight.position.x = 1;
  70. directionalLight.position.y = 1;
  71. directionalLight.position.z = 2;
  72. directionalLight.position.normalize();
  73. scene.addLight( directionalLight );
  74. */
  75. scene.addLight( new THREE.AmbientLight( 0x00020 ) );
  76. scene.addLight( new THREE.AmbientLight( 0x00000 ) );
  77. light1 = new THREE.PointLight( 0xff0040 );
  78. scene.addLight( light1 );
  79. light2 = new THREE.PointLight( 0x0040ff );
  80. scene.addLight( light2 );
  81. light3 = new THREE.PointLight( 0x80ff80 );
  82. scene.addLight( light3 );
  83. var sphere = new Sphere( 0.5, 16, 8, 1 );
  84. var l1 = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xff0040 } ) );
  85. l1.position = light1.position;
  86. scene.addObject( l1 );
  87. var l2 = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x0040ff } ) );
  88. l2.position = light2.position;
  89. scene.addObject( l2 );
  90. var l3 = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x80ff80 } ) );
  91. l3.position = light3.position;
  92. scene.addObject( l3 );
  93. //renderer = new THREE.CanvasRenderer();
  94. renderer = new THREE.WebGLRenderer( );
  95. renderer.setSize( window.innerWidth, window.innerHeight );
  96. container.appendChild( renderer.domElement );
  97. /*
  98. stats = new Stats();
  99. stats.domElement.style.position = 'absolute';
  100. stats.domElement.style.top = '0px';
  101. stats.domElement.style.zIndex = 100;
  102. container.appendChild( stats.domElement );
  103. */
  104. }
  105. function loop() {
  106. var time = new Date().getTime() * 0.0005;
  107. if( object ) object.rotation.y -= 0.01;
  108. light1.position.x = Math.sin( time * 0.7 ) * 30;
  109. light1.position.y = Math.cos( time * 0.5 ) * 40;
  110. light1.position.z = Math.cos( time * 0.3 ) * 30;
  111. light2.position.x = Math.cos( time * 0.3 ) * 30;
  112. light2.position.y = Math.sin( time * 0.5 ) * 40;
  113. light2.position.z = Math.sin( time * 0.7 ) * 30;
  114. light3.position.x = Math.sin( time * 0.7 ) * 30;
  115. light3.position.y = Math.cos( time * 0.3 ) * 40;
  116. light3.position.z = Math.sin( time * 0.5 ) * 30;
  117. renderer.render(scene, camera);
  118. //stats.update();
  119. }
  120. function log() {
  121. }
  122. </script>
  123. </body>
  124. </html>