materials_video.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>three.js - materials - video</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. var info = document.createElement('div');
  40. info.style.position = 'absolute';
  41. info.style.top = '10px';
  42. info.style.width = '100%';
  43. info.style.textAlign = 'center';
  44. info.innerHTML = '<a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - video demo. playing <a href="http://durian.blender.org/" target="_blank">sintel</a> trailer';
  45. container.appendChild(info);
  46. camera = new THREE.Camera(0, 0, 500);
  47. camera.focus = 300;
  48. scene = new THREE.Scene();
  49. video = document.createElement( 'video' );
  50. video.src = 'textures/sintel.mp4';
  51. video.play();
  52. //
  53. texture = document.createElement( 'canvas' );
  54. texture.width = 480;
  55. texture.height = 204;
  56. textureContext = texture.getContext( '2d' );
  57. textureContext.fillStyle = '#000000';
  58. textureContext.fillRect( 0, 0, 480, 204 );
  59. var material = new THREE.BitmapUVMappingMaterial( texture );
  60. textureReflection = document.createElement( 'canvas' );
  61. textureReflection.width = 480;
  62. textureReflection.height = 204;
  63. textureReflectionContext = textureReflection.getContext( '2d' );
  64. textureReflectionContext.fillStyle = '#000000';
  65. textureReflectionContext.fillRect( 0, 0, 480, 204 );
  66. textureReflectionGradient = textureReflectionContext.createLinearGradient( 0, 0, 0, 204 );
  67. textureReflectionGradient.addColorStop( 0.2, 'rgba(240, 240, 240, 1)' );
  68. textureReflectionGradient.addColorStop( 1, 'rgba(240, 240, 240, 0.8)' );
  69. var materialReflection = new THREE.BitmapUVMappingMaterial( textureReflection );
  70. //
  71. var plane = new Plane( 480, 204, 4, 4 );
  72. mesh = new THREE.Mesh( plane, material );
  73. mesh.scale.x = mesh.scale.y = mesh.scale.z = 1.5;
  74. scene.add(mesh);
  75. mesh = new THREE.Mesh( plane, materialReflection );
  76. mesh.position.y = -306;
  77. mesh.scale.x = mesh.scale.y = mesh.scale.z = 1.5;
  78. mesh.rotation.x = 180 * Math.PI / 180;
  79. mesh.doubleSided = true;
  80. scene.add(mesh);
  81. //
  82. var separation = 150;
  83. var amountx = 10;
  84. var amounty = 10;
  85. var material = new THREE.ColorFillMaterial(0x808080);
  86. for (var ix = 0; ix < amountx; ix++) {
  87. for(var iy = 0; iy < amounty; iy++) {
  88. particle = new THREE.Particle( material );
  89. particle.position.x = ix * separation - ((amountx * separation) / 2);
  90. particle.position.y = -153
  91. particle.position.z = iy * separation - ((amounty * separation) / 2);
  92. scene.add( particle );
  93. }
  94. }
  95. renderer = new THREE.CanvasRenderer();
  96. renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
  97. container.appendChild(renderer.domElement);
  98. stats = new Stats();
  99. stats.domElement.style.position = 'absolute';
  100. stats.domElement.style.top = '0px';
  101. container.appendChild(stats.domElement);
  102. }
  103. function onDocumentMouseMove(event) {
  104. mouseX = (event.clientX - windowHalfX);
  105. mouseY = (event.clientY - windowHalfY) * .2;
  106. }
  107. function loop() {
  108. camera.position.x += (mouseX - camera.position.x) * .05;
  109. camera.position.y += (-mouseY - camera.position.y) * .05;
  110. textureContext.drawImage( video, 0, 0 );
  111. textureReflectionContext.drawImage( texture, 0, 0 );
  112. textureReflectionContext.fillStyle = textureReflectionGradient;
  113. textureReflectionContext.fillRect(0, 0, 480, 204);
  114. renderer.render(scene, camera);
  115. stats.update();
  116. }
  117. </script>
  118. </body>
  119. </html>
粤ICP备19079148号