materials_cubemap_escher.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - materials - cube reflection [Escher] - webgl</title>
  5. <meta charset="utf-8">
  6. <style type="text/css">
  7. body {
  8. background:#fff;
  9. color:#fff;
  10. padding:0;
  11. margin:0;
  12. overflow:hidden;
  13. font-family:georgia;
  14. text-align:center;
  15. }
  16. a { color: #ff0080; text-decoration: none; }
  17. a:hover { color: #0080ff; }
  18. #log { position:absolute; top:50px; text-align:left; display:block; z-index:100; pointer-events:none; }
  19. #d { text-align:center; margin:1em auto -9.0em; z-index:1000; position:relative; display:block;
  20. background:rgba(0,0,0,0.75); padding:0.25em; width:300px; border-radius:10px; -webkit-box-shadow: 0px 0px 10px rgba(0,0,0,0.5) }
  21. #oldie { margin-top:15em !important }
  22. </style>
  23. </head>
  24. <body>
  25. <div id="d">
  26. <p><a href="http://github.com/mrdoob/three.js">Three.js</a> cube mapping demo
  27. <p>Original artwork by <a href="http://en.wikipedia.org/wiki/Hand_with_Reflecting_Sphere" target="_blank">M. C. Escher</a>
  28. <p>Texture by <a href="http://brainwagon.org/2002/12/05/fun-with-environment-maps/" target="_blank">Mark VandeWettering</a>
  29. </div>
  30. <pre id="log"></pre>
  31. <script type="text/javascript" src="../build/ThreeExtras.js"></script>
  32. <script type="text/javascript" src="js/Stats.js"></script>
  33. <script type="text/javascript">
  34. if ( ! THREE.Detector.webgl ) THREE.Detector.addGetWebGLMessage();
  35. var statsEnabled = false;
  36. var container, stats;
  37. var camera, scene, webglRenderer;
  38. var mesh, zmesh, lightMesh, geometry;
  39. var directionalLight, pointLight;
  40. var mouseX = 0;
  41. var mouseY = 0;
  42. var windowHalfX = window.innerWidth / 2;
  43. var windowHalfY = window.innerHeight / 2;
  44. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  45. init();
  46. setInterval( loop, 1000 / 60 );
  47. function init() {
  48. container = document.createElement('div');
  49. document.body.appendChild(container);
  50. camera = new THREE.Camera( 75, window.innerWidth / window.innerHeight, 1, 100000 );
  51. camera.position.z = 3200;
  52. scene = new THREE.Scene();
  53. var r = "textures/cube/Escher/";
  54. var urls = [ r + "px.jpg", r + "nx.jpg",
  55. r + "py.jpg", r + "ny.jpg",
  56. r + "pz.jpg", r + "nz.jpg" ];
  57. var images = ImageUtils.loadArray( urls );
  58. var textureCube = new THREE.Texture( images );
  59. var material = new THREE.MeshBasicMaterial( { color: 0xffffff, env_map: textureCube } )
  60. var geometry = new Sphere( 100, 96, 64 );
  61. var mesh = new THREE.Mesh( geometry, material );
  62. mesh.scale.x = mesh.scale.y = mesh.scale.z = 16;
  63. scene.addObject( mesh );
  64. //SceneUtils.addPanoramaCubePlanes( scene, 6000, images );
  65. //SceneUtils.addPanoramaCube( scene, 6000, images );
  66. SceneUtils.addPanoramaCubeWebGL( scene, 6000, textureCube );
  67. webglRenderer = new THREE.WebGLRenderer();
  68. webglRenderer.setSize( window.innerWidth, window.innerHeight );
  69. container.appendChild( webglRenderer.domElement );
  70. if ( statsEnabled ) {
  71. stats = new Stats();
  72. stats.domElement.style.position = 'absolute';
  73. stats.domElement.style.top = '0px';
  74. stats.domElement.style.zIndex = 100;
  75. container.appendChild( stats.domElement );
  76. }
  77. }
  78. function onDocumentMouseMove(event) {
  79. mouseX = ( event.clientX - windowHalfX );
  80. mouseY = ( event.clientY - windowHalfY );
  81. }
  82. function loop() {
  83. camera.position.x += ( mouseX - camera.position.x ) * .05;
  84. camera.position.y += ( - mouseY - camera.position.y ) * .05;
  85. webglRenderer.render( scene, camera );
  86. if ( statsEnabled ) stats.update();
  87. }
  88. function log(text) {
  89. var e = document.getElementById("log");
  90. e.innerHTML = text + "<br/>" + e.innerHTML;
  91. }
  92. </script>
  93. </body>
  94. </html>