123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <!DOCTYPE HTML>
- <html lang="en">
- <head>
- <title>three.js canvas - materials - video</title>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
- <style type="text/css">
- body {
- font-family: Monospace;
- background-color: #f0f0f0;
- margin: 0px;
- overflow: hidden;
- }
- </style>
- </head>
- <body>
- <script type="text/javascript" src="../build/Three.js"></script>
- <script type="text/javascript" src="../src/extras/primitives/Plane.js"></script>
- <script type="text/javascript" src="js/RequestAnimationFrame.js"></script>
- <script type="text/javascript" src="js/Stats.js"></script>
- <video id="video" autoplay style="display:none">
- <source src="textures/sintel.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
- <source src="textures/sintel.ogv" type='video/ogg; codecs="theora, vorbis"'>
- </video>
- <script type="text/javascript">
- var AMOUNT = 100;
- var container, stats;
- var camera, scene, renderer;
- var video, texture, textureContext,
- textureReflection, textureReflectionContext, textureReflectionGradient;
- var mesh;
- var mouseX = 0;
- var mouseY = 0;
- var windowHalfX = window.innerWidth / 2;
- var windowHalfY = window.innerHeight / 2;
- init();
- animate();
- function init() {
- container = document.createElement('div');
- document.body.appendChild( container );
- var info = document.createElement('div');
- info.style.position = 'absolute';
- info.style.top = '10px';
- info.style.width = '100%';
- info.style.textAlign = 'center';
- 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';
- container.appendChild(info);
- camera = new THREE.Camera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
- camera.position.z = 1000;
- scene = new THREE.Scene();
- video = document.getElementById( 'video' );
- //
- texture = document.createElement( 'canvas' );
- texture.loaded = true;
- texture.width = 480;
- texture.height = 204;
- textureContext = texture.getContext( '2d' );
- textureContext.fillStyle = '#000000';
- textureContext.fillRect( 0, 0, 480, 204 );
- var map = new THREE.Texture( texture );
- var material = new THREE.MeshBasicMaterial( { map: map } );
- textureReflection = document.createElement( 'canvas' );
- textureReflection.loaded = true;
- textureReflection.width = 480;
- textureReflection.height = 204;
- textureReflectionContext = textureReflection.getContext( '2d' );
- textureReflectionContext.fillStyle = '#000000';
- textureReflectionContext.fillRect( 0, 0, 480, 204 );
- textureReflectionGradient = textureReflectionContext.createLinearGradient( 0, 0, 0, 204 );
- textureReflectionGradient.addColorStop( 0.2, 'rgba(240, 240, 240, 1)' );
- textureReflectionGradient.addColorStop( 1, 'rgba(240, 240, 240, 0.8)' );
- var materialReflection = new THREE.MeshBasicMaterial( { map: new THREE.Texture( textureReflection ) } );
- //
- var plane = new Plane( 480, 204, 4, 4 );
- mesh = new THREE.Mesh( plane, material );
- mesh.scale.x = mesh.scale.y = mesh.scale.z = 1.5;
- mesh.overdraw = true;
- scene.addObject(mesh);
- mesh = new THREE.Mesh( plane, materialReflection );
- mesh.position.y = -306;
- mesh.scale.x = mesh.scale.y = mesh.scale.z = 1.5;
- mesh.rotation.x = 180 * Math.PI / 180;
- mesh.doubleSided = true;
- mesh.overdraw = true;
- scene.addObject( mesh );
- //
- var separation = 150;
- var amountx = 10;
- var amounty = 10;
- var material = new THREE.ParticleCircleMaterial( { color: 0x808080 } );
- for ( var ix = 0; ix < amountx; ix++ ) {
- for ( var iy = 0; iy < amounty; iy++ ) {
- particle = new THREE.Particle( material );
- particle.position.x = ix * separation - ( ( amountx * separation ) / 2 );
- particle.position.y = -153
- particle.position.z = iy * separation - ( ( amounty * separation ) / 2 );
- scene.addObject( particle );
- }
- }
- renderer = new THREE.CanvasRenderer();
- renderer.setSize( window.innerWidth, window.innerHeight );
- container.appendChild( renderer.domElement );
- stats = new Stats();
- stats.domElement.style.position = 'absolute';
- stats.domElement.style.top = '0px';
- container.appendChild( stats.domElement );
- document.addEventListener( 'mousemove', onDocumentMouseMove, false );
- }
- function onDocumentMouseMove(event) {
- mouseX = ( event.clientX - windowHalfX );
- mouseY = ( event.clientY - windowHalfY ) * 0.2;
- }
- //
- function animate() {
- requestAnimationFrame( animate );
- render();
- stats.update();
- }
- function render() {
- camera.position.x += ( mouseX - camera.position.x ) * 0.05;
- camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
- if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
- textureContext.drawImage( video, 0, 0 );
- }
- textureReflectionContext.drawImage( texture, 0, 0 );
- textureReflectionContext.fillStyle = textureReflectionGradient;
- textureReflectionContext.fillRect( 0, 0, 480, 204 );
- renderer.render( scene, camera );
- }
- </script>
- </body>
- </html>
|