lights_pointlights_gl.html 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #log { color:#fff; position:absolute; top:50px; text-align:left; display:block; z-index:100; pointer-events:none; }
  29. </style>
  30. </head>
  31. <body>
  32. <pre id="log"></pre>
  33. <div id="container"></div>
  34. <div id="info">
  35. <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - point lights WebGL demo.<br />
  36. Walt Disney head by <a href="http://www.davidoreilly.com/2009/01/walt-disneys-head-on-a-plate" target="_blank">David OReilly</a>
  37. </div>
  38. <script type="text/javascript" src="../build/Three.js"></script>
  39. <script type="text/javascript" src="../src/extras/io/Loader.js"></script>
  40. <script type="text/javascript" src="../src/extras/primitives/Sphere.js"></script>
  41. <script type="text/javascript" src="js/Stats.js"></script>
  42. <script type="text/javascript">
  43. var camera, scene, renderer,
  44. particle1, particle2, particle2,
  45. light1, light2, light3,
  46. object,loader;
  47. init();
  48. setInterval( loop, 1000 / 60 );
  49. function init() {
  50. var container = document.getElementById( 'container' );
  51. camera = new THREE.Camera( 65, window.innerWidth / window.innerHeight, 1, 1000 );
  52. camera.position.z = 100;
  53. scene = new THREE.Scene();
  54. loader = new THREE.Loader( true );
  55. document.body.appendChild( loader.statusDomElement );
  56. /*
  57. loader.loadAscii( "obj/walt/WaltHead_slim.js", function( geometry ) {
  58. //object = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0xffffff, shininess: 50, shading: THREE.FlatShading } ) );
  59. object = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0xffffff, shininess: 50, shading: THREE.SmoothShading } ) );
  60. object.scale.x = object.scale.y = object.scale.z = 0.80;
  61. object.overdraw = true;
  62. scene.addObject( object );
  63. });
  64. */
  65. loader.loadBinary( "obj/walt/WaltHead_bin.js", function( geometry ) {
  66. object = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0x555555, specular: 0xffffff, shininess: 50, shading: THREE.SmoothShading } ) );
  67. object.scale.x = object.scale.y = object.scale.z = 0.80;
  68. object.overdraw = true;
  69. scene.addObject( object );
  70. loader.statusDomElement.style.display = "none";
  71. }, "obj/walt");
  72. /*
  73. var directionalLight = new THREE.DirectionalLight( 0x111111, 0.9 );
  74. directionalLight.position.x = 1;
  75. directionalLight.position.y = 1;
  76. directionalLight.position.z = 2;
  77. directionalLight.position.normalize();
  78. scene.addLight( directionalLight );
  79. */
  80. scene.addLight( new THREE.AmbientLight( 0x00020 ) );
  81. scene.addLight( new THREE.AmbientLight( 0x00000 ) );
  82. light1 = new THREE.PointLight( 0xff0040 );
  83. scene.addLight( light1 );
  84. light2 = new THREE.PointLight( 0x0040ff );
  85. scene.addLight( light2 );
  86. light3 = new THREE.PointLight( 0x80ff80 );
  87. scene.addLight( light3 );
  88. var sphere = new Sphere( 0.5, 16, 8, 1 );
  89. var l1 = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xff0040 } ) );
  90. l1.position = light1.position;
  91. scene.addObject( l1 );
  92. var l2 = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x0040ff } ) );
  93. l2.position = light2.position;
  94. scene.addObject( l2 );
  95. var l3 = new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x80ff80 } ) );
  96. l3.position = light3.position;
  97. scene.addObject( l3 );
  98. //renderer = new THREE.CanvasRenderer();
  99. renderer = new THREE.WebGLRenderer( scene );
  100. renderer.setSize( window.innerWidth, window.innerHeight );
  101. container.appendChild( renderer.domElement );
  102. /*
  103. stats = new Stats();
  104. stats.domElement.style.position = 'absolute';
  105. stats.domElement.style.top = '0px';
  106. stats.domElement.style.zIndex = 100;
  107. container.appendChild( stats.domElement );
  108. */
  109. }
  110. function loop() {
  111. var time = new Date().getTime() * 0.0005;
  112. if( object ) object.rotation.y -= 0.01;
  113. light1.position.x = Math.sin( time * 0.7 ) * 30;
  114. light1.position.y = Math.cos( time * 0.5 ) * 40;
  115. light1.position.z = Math.cos( time * 0.3 ) * 30;
  116. light2.position.x = Math.cos( time * 0.3 ) * 30;
  117. light2.position.y = Math.sin( time * 0.5 ) * 40;
  118. light2.position.z = Math.sin( time * 0.7 ) * 30;
  119. light3.position.x = Math.sin( time * 0.7 ) * 30;
  120. light3.position.y = Math.cos( time * 0.3 ) * 40;
  121. light3.position.z = Math.sin( time * 0.5 ) * 30;
  122. renderer.render(scene, camera);
  123. //stats.update();
  124. }
  125. function log( text ) {
  126. var e = document.getElementById("log");
  127. e.innerHTML = text + "<br/>" + e.innerHTML;
  128. }
  129. </script>
  130. </body>
  131. </html>