materials_video.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - geometry - cube</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
  7. <style type="text/css">
  8. body {
  9. font-family: Monospace;
  10. background-color: #f0f0f0;
  11. margin: 0px;
  12. overflow: hidden;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <script type="text/javascript" src="../build/three.js"></script>
  18. <script type="text/javascript" src="primitives/Plane.js"></script>
  19. <script type="text/javascript" src="http://github.com/mrdoob/stats.js/raw/master/build/stats.js"></script>
  20. <script type="text/javascript">
  21. var SCREEN_WIDTH = window.innerWidth;
  22. var SCREEN_HEIGHT = window.innerHeight;
  23. var AMOUNT = 100;
  24. var container, stats;
  25. var camera, scene, renderer;
  26. var video, texture, textureContext,
  27. textureReflection, textureReflectionContext, textureReflectionGradient;
  28. var mesh;
  29. var mouseX = 0;
  30. var mouseY = 0;
  31. var windowHalfX = window.innerWidth >> 1;
  32. var windowHalfY = window.innerHeight >> 1;
  33. document.addEventListener('mousemove', onDocumentMouseMove, false);
  34. init();
  35. setInterval(loop, 1000/60);
  36. function init() {
  37. container = document.createElement('div');
  38. document.body.appendChild(container);
  39. camera = new THREE.Camera(0, 0, 500);
  40. camera.focus = 300;
  41. scene = new THREE.Scene();
  42. video = document.createElement( 'video' );
  43. video.src = 'textures/sintel.mp4';
  44. video.loop = 'loop';
  45. video.play();
  46. //
  47. texture = document.createElement( 'canvas' );
  48. texture.width = 480;
  49. texture.height = 204;
  50. textureContext = texture.getContext( '2d' );
  51. textureContext.fillStyle = '#000000';
  52. textureContext.fillRect( 0, 0, 480, 204 );
  53. var material = new THREE.BitmapUVMappingMaterial( texture );
  54. textureReflection = document.createElement( 'canvas' );
  55. textureReflection.width = 480;
  56. textureReflection.height = 204;
  57. textureReflectionContext = textureReflection.getContext( '2d' );
  58. textureReflectionContext.fillStyle = '#000000';
  59. textureReflectionContext.fillRect( 0, 0, 480, 204 );
  60. textureReflectionGradient = textureReflectionContext.createLinearGradient( 0, 0, 0, 204 );
  61. textureReflectionGradient.addColorStop( 0.2, 'rgba(240, 240, 240, 1)' );
  62. textureReflectionGradient.addColorStop( 1, 'rgba(240, 240, 240, 0.8)' );
  63. var materialReflection = new THREE.BitmapUVMappingMaterial( textureReflection );
  64. //
  65. var plane = new Plane( 480, 204, 4, 4 );
  66. mesh = new THREE.Mesh( plane, material );
  67. mesh.scale.x = mesh.scale.y = mesh.scale.z = 1.5;
  68. scene.add(mesh);
  69. mesh = new THREE.Mesh( plane, materialReflection );
  70. mesh.position.y = -306;
  71. mesh.scale.x = mesh.scale.y = mesh.scale.z = 1.5;
  72. mesh.rotation.x = 180 * Math.PI / 180;
  73. mesh.doubleSided = true;
  74. scene.add(mesh);
  75. //
  76. var separation = 150;
  77. var amountx = 10;
  78. var amounty = 10;
  79. var material = new THREE.ColorFillMaterial(0x808080);
  80. for (var ix = 0; ix < amountx; ix++) {
  81. for(var iy = 0; iy < amounty; iy++) {
  82. particle = new THREE.Particle( material );
  83. particle.position.x = ix * separation - ((amountx * separation) / 2);
  84. particle.position.y = -153
  85. particle.position.z = iy * separation - ((amounty * separation) / 2);
  86. scene.add( particle );
  87. }
  88. }
  89. renderer = new THREE.CanvasRenderer();
  90. renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  91. container.appendChild(renderer.domElement);
  92. stats = new Stats();
  93. stats.domElement.style.position = 'absolute';
  94. stats.domElement.style.top = '0px';
  95. container.appendChild(stats.domElement);
  96. }
  97. function onDocumentMouseMove(event) {
  98. mouseX = (event.clientX - windowHalfX);
  99. mouseY = (event.clientY - windowHalfY) * .2;
  100. }
  101. function loop() {
  102. camera.position.x += (mouseX - camera.position.x) * .05;
  103. camera.position.y += (-mouseY - camera.position.y) * .05;
  104. textureContext.drawImage( video, 0, 0 );
  105. textureReflectionContext.drawImage( texture, 0, 0 );
  106. textureReflectionContext.fillStyle = textureReflectionGradient;
  107. textureReflectionContext.fillRect(0, 0, 480, 204);
  108. renderer.render(scene, camera);
  109. stats.update();
  110. }
  111. </script>
  112. </body>
  113. </html>
粤ICP备19079148号