123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <!DOCTYPE HTML>
- <html lang="en">
- <head>
- <title>three.js - particles - billboards - webgl</title>
- <meta charset="utf-8">
- <style type="text/css">
- body {
- background-color: #000000;
- margin: 0px;
- overflow: hidden;
- font-family:Monospace;
- font-size:13px;
- text-align:center;
- font-weight: bold;
- text-align:center;
- }
- a {
- color:#0078ff;
- }
-
- #info {
- color:#fff;
- position: absolute;
- top: 0px; width: 100%;
- padding: 5px;
- z-index:100;
-
- }
-
- </style>
- </head>
- <body>
-
- <div id="info">
- <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl particle billboards example
- </div>
- <script type="text/javascript" src="../build/ThreeExtras.js"></script>
- <script type="text/javascript" src="js/Stats.js"></script>
- <script type="text/javascript">
-
- if ( ! THREE.Detector.webgl ) THREE.Detector.addGetWebGLMessage();
- var container, stats;
- var camera, scene, renderer, particles, geometry, material, i, h, color, sprite, size, x, y, z;
- var mouseX = 0, mouseY = 0;
- var windowHalfX = window.innerWidth / 2;
- var windowHalfY = window.innerHeight / 2;
- init();
- setInterval( loop, 1000 / 60 );
- //loop();
- function init() {
- container = document.createElement( 'div' );
- document.body.appendChild( container );
- camera = new THREE.Camera( 55, window.innerWidth / window.innerHeight, 1, 3000 );
- camera.position.z = 1000;
- scene = new THREE.Scene();
- scene.fog = new THREE.FogExp2( 0x000000, 0.001 );
-
- geometry = new THREE.Geometry();
-
- sprite = ImageUtils.loadTexture( "textures/sprites/circle.png" );
-
- for ( i = 0; i < 5000; i++ ) {
- x = 2000 * Math.random() - 1000;
- y = 2000 * Math.random() - 1000;
- z = 2000 * Math.random() - 1000;
- vector = new THREE.Vector3( x, y, z );
- geometry.vertices.push( new THREE.Vertex( vector ) );
-
- }
- material = new THREE.ParticleBasicMaterial( { size: 35, map: sprite, blending: THREE.BillboardBlending } );
- material.color.setHSV( 1.0, 0.2, 0.8 );
- particles = new THREE.ParticleSystem( geometry, material );
- particles.sortParticles = true;
- particles.updateMatrix();
- scene.addObject( particles );
-
- var light = new THREE.DirectionalLight( 0xffffff );
- light.position.x = 0;
- light.position.y = 0;
- light.position.z = 1;
- scene.addLight( light );
- renderer = new THREE.WebGLRenderer( { clearAlpha: 1 });
- 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 );
- document.addEventListener( 'touchstart', onDocumentTouchStart, false );
- document.addEventListener( 'touchmove', onDocumentTouchMove, false );
-
- }
- function onDocumentMouseMove( event ) {
- mouseX = event.clientX - windowHalfX;
- mouseY = event.clientY - windowHalfY;
-
- }
- function onDocumentTouchStart( event ) {
- if ( event.touches.length == 1 ) {
- event.preventDefault();
- mouseX = event.touches[ 0 ].pageX - windowHalfX;
- mouseY = event.touches[ 0 ].pageY - windowHalfY;
-
- }
- }
- function onDocumentTouchMove( event ) {
- if ( event.touches.length == 1 ) {
- event.preventDefault();
- mouseX = event.touches[ 0 ].pageX - windowHalfX;
- mouseY = event.touches[ 0 ].pageY - windowHalfY;
-
- }
-
- }
- function loop() {
- var time = new Date().getTime() * 0.00005;
-
- camera.position.x += ( mouseX - camera.position.x ) * 0.05;
- camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
- /*
- for( i = 0; i < scene.objects.length; i++ ) {
-
- scene.objects[i].rotation.y = 5*time * ( i < 4 ? i+1 : - (i+1) );
-
- }
- */
- h = ( 360 * ( 1.0 + time ) % 360 ) / 360;
- material.color.setHSV( h, 0.75, 0.8 );
-
-
- renderer.render( scene, camera );
- stats.update();
- }
- </script>
- </body>
- </html>
|