webgl_lights_pointlights.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - lights - point lights</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <style>
  8. body {
  9. background-color: #000;
  10. margin: 0px;
  11. overflow: hidden;
  12. }
  13. #info {
  14. position: absolute;
  15. top: 0px; width: 100%;
  16. color: #ffffff;
  17. padding: 5px;
  18. font-family: Monospace;
  19. font-size: 13px;
  20. text-align: center;
  21. }
  22. a {
  23. color: #ff0080;
  24. text-decoration: none;
  25. }
  26. a:hover {
  27. color: #0080ff;
  28. }
  29. </style>
  30. </head>
  31. <body>
  32. <div id="container"></div>
  33. <div id="info">
  34. <a href="http://threejs.org" target="_blank">three.js</a> - point lights WebGL demo.<br />
  35. Walt Disney head by <a href="http://davidoreilly.com/post/18087489343/disneyhead" target="_blank">David OReilly</a>
  36. </div>
  37. <script src="../build/three.min.js"></script>
  38. <script src="js/loaders/BinaryLoader.js"></script>
  39. <script src="js/Detector.js"></script>
  40. <script>
  41. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  42. var camera, scene, renderer,
  43. particle1, particle2, particle2,
  44. light1, light2, light3, light4,
  45. object, loader;
  46. var clock = new THREE.Clock();
  47. init();
  48. animate();
  49. function init() {
  50. var container = document.getElementById( 'container' );
  51. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
  52. camera.position.z = 100;
  53. scene = new THREE.Scene();
  54. loader = new THREE.BinaryLoader( true );
  55. document.body.appendChild( loader.statusDomElement );
  56. var callback = function( geometry ) {
  57. object = new THREE.Mesh( geometry, new THREE.MeshPhongMaterial( { color: 0x555555, specular: 0xffffff, shininess: 50 } ) );
  58. object.scale.x = object.scale.y = object.scale.z = 0.80;
  59. scene.add( object );
  60. loader.statusDomElement.style.display = "none";
  61. };
  62. loader.load( "obj/walt/WaltHead_bin.js", callback );
  63. scene.add( new THREE.AmbientLight( 0x000000 ) );
  64. var sphere = new THREE.SphereGeometry( 0.5, 16, 8 );
  65. light1 = new THREE.PointLight( 0xff0040, 2, 50 );
  66. light1.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xff0040 } ) ) );
  67. scene.add( light1 );
  68. light2 = new THREE.PointLight( 0x0040ff, 2, 50 );
  69. light2.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x0040ff } ) ) );
  70. scene.add( light2 );
  71. light3 = new THREE.PointLight( 0x80ff80, 2, 50 );
  72. light3.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0x80ff80 } ) ) );
  73. scene.add( light3 );
  74. light4 = new THREE.PointLight( 0xffaa00, 2, 50 );
  75. light4.add( new THREE.Mesh( sphere, new THREE.MeshBasicMaterial( { color: 0xffaa00 } ) ) );
  76. scene.add( light4 );
  77. renderer = new THREE.WebGLRenderer();
  78. renderer.setPixelRatio( window.devicePixelRatio );
  79. renderer.setSize( window.innerWidth, window.innerHeight );
  80. container.appendChild( renderer.domElement );
  81. //
  82. window.addEventListener( 'resize', onWindowResize, false );
  83. }
  84. function onWindowResize() {
  85. camera.aspect = window.innerWidth / window.innerHeight;
  86. camera.updateProjectionMatrix();
  87. renderer.setSize( window.innerWidth, window.innerHeight );
  88. }
  89. //
  90. function animate() {
  91. requestAnimationFrame( animate );
  92. render();
  93. }
  94. function render() {
  95. var time = Date.now() * 0.0005;
  96. var delta = clock.getDelta();
  97. if( object ) object.rotation.y -= 0.5 * delta;
  98. light1.position.x = Math.sin( time * 0.7 ) * 30;
  99. light1.position.y = Math.cos( time * 0.5 ) * 40;
  100. light1.position.z = Math.cos( time * 0.3 ) * 30;
  101. light2.position.x = Math.cos( time * 0.3 ) * 30;
  102. light2.position.y = Math.sin( time * 0.5 ) * 40;
  103. light2.position.z = Math.sin( time * 0.7 ) * 30;
  104. light3.position.x = Math.sin( time * 0.7 ) * 30;
  105. light3.position.y = Math.cos( time * 0.3 ) * 40;
  106. light3.position.z = Math.sin( time * 0.5 ) * 30;
  107. light4.position.x = Math.sin( time * 0.3 ) * 30;
  108. light4.position.y = Math.cos( time * 0.7 ) * 40;
  109. light4.position.z = Math.sin( time * 0.5 ) * 30;
  110. renderer.render( scene, camera );
  111. }
  112. </script>
  113. </body>
  114. </html>