|
@@ -0,0 +1,228 @@
|
|
|
+<!DOCTYPE HTML>
|
|
|
+<html lang="en">
|
|
|
+ <head>
|
|
|
+ <title>three.js - particles - sprites - 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;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ #oldie {
|
|
|
+ font-family:monospace;
|
|
|
+ font-size:13px;
|
|
|
+
|
|
|
+ text-align:center;
|
|
|
+ background:#eee;
|
|
|
+ color:#000;
|
|
|
+ padding:1em;
|
|
|
+
|
|
|
+ width:475px;
|
|
|
+ margin:5em auto 0;
|
|
|
+
|
|
|
+ display:none;
|
|
|
+ }
|
|
|
+
|
|
|
+ </style>
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+
|
|
|
+ <div id="info">
|
|
|
+ <a href="http://github.com/mrdoob/three.js" target="_blank">three.js</a> - webgl particle sprites example -
|
|
|
+ snowflakes by <a href="http://en.wikipedia.org/wiki/File:Sketch_of_snow_crystal_by_Ren%C3%A9_Descartes.jpg">René Descartes</a>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <center>
|
|
|
+ <div id="oldie">
|
|
|
+ Sorry, your browser doesn't support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation">WebGL</a>
|
|
|
+ and <a href="http://www.whatwg.org/specs/web-workers/current-work/">Web Workers</a>.<br/>
|
|
|
+ <br/>
|
|
|
+ Please try in
|
|
|
+ <a href="http://www.chromium.org/getting-involved/dev-channel">Chrome 9+</a> /
|
|
|
+ <a href="http://www.mozilla.com/en-US/firefox/all-beta.html">Firefox 4+</a> /
|
|
|
+ <a href="http://nightly.webkit.org/">Safari OSX 10.6+</a>
|
|
|
+ </div>
|
|
|
+ </center>
|
|
|
+
|
|
|
+ <script type="text/javascript" src="../build/ThreeExtras.js"></script>
|
|
|
+ <script type="text/javascript" src="js/Stats.js"></script>
|
|
|
+
|
|
|
+ <script type="text/javascript">
|
|
|
+
|
|
|
+ if ( !is_browser_compatible() ) {
|
|
|
+
|
|
|
+ document.getElementById( "oldie" ).style.display = "block";
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ var container, stats;
|
|
|
+ var camera, scene, renderer, particles, geometry, materials = [], parameters, i, h, color, sprite, size;
|
|
|
+ var mouseX = 0, mouseY = 0;
|
|
|
+
|
|
|
+ var windowHalfX = window.innerWidth / 2;
|
|
|
+ var windowHalfY = window.innerHeight / 2;
|
|
|
+
|
|
|
+ init();
|
|
|
+ setInterval( loop, 1000 / 60 );
|
|
|
+
|
|
|
+ function init() {
|
|
|
+
|
|
|
+ container = document.createElement( 'div' );
|
|
|
+ document.body.appendChild( container );
|
|
|
+
|
|
|
+ camera = new THREE.Camera( 75, window.innerWidth / window.innerHeight, 1, 3000 );
|
|
|
+ camera.position.z = 1000;
|
|
|
+
|
|
|
+ scene = new THREE.Scene();
|
|
|
+ scene.fog = new THREE.FogExp2( 0x000000, 0.0008 );
|
|
|
+
|
|
|
+ geometry = new THREE.Geometry();
|
|
|
+
|
|
|
+ sprite1 = ImageUtils.loadTexture( "textures/sprites/snowflake1.png" );
|
|
|
+ sprite2 = ImageUtils.loadTexture( "textures/sprites/snowflake2.png" );
|
|
|
+ sprite3 = ImageUtils.loadTexture( "textures/sprites/snowflake3.png" );
|
|
|
+ sprite4 = ImageUtils.loadTexture( "textures/sprites/snowflake4.png" );
|
|
|
+ sprite5 = ImageUtils.loadTexture( "textures/sprites/snowflake5.png" );
|
|
|
+
|
|
|
+ for ( i = 0; i < 2000; i++ ) {
|
|
|
+
|
|
|
+ vector = new THREE.Vector3( Math.random() * 2000 - 1000, Math.random() * 2000 - 1000, Math.random() * 2000 - 1000 );
|
|
|
+ geometry.vertices.push( new THREE.Vertex( vector ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ parameters = [ [ [1.0, 0.2, 1.0], sprite2, 20 ], [ [0.95, 0.1, 1], sprite3, 15 ], [ [0.90, 0.05, 1], sprite1, 10 ], [ [0.85, 0, 0.8], sprite5, 8 ], [ [0.80, 0, 0.7], sprite4, 5 ],
|
|
|
+ ];
|
|
|
+
|
|
|
+ for ( i = 0; i < parameters.length; i++ ) {
|
|
|
+
|
|
|
+ color = parameters[i][0];
|
|
|
+ sprite = parameters[i][1];
|
|
|
+ size = parameters[i][2];
|
|
|
+
|
|
|
+ materials[i] = new THREE.ParticleBasicMaterial( { size: size, map: sprite, blending: THREE.AdditiveBlending } );
|
|
|
+ materials[i].color.setHSV( color[0], color[1], color[2] );
|
|
|
+
|
|
|
+ particles = new THREE.ParticleSystem( geometry, materials[i] );
|
|
|
+ particles.rotation.x = Math.random() * 6;
|
|
|
+ particles.rotation.y = Math.random() * 6;
|
|
|
+ particles.rotation.z = Math.random() * 6;
|
|
|
+ particles.updateMatrix();
|
|
|
+ scene.addObject( particles );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ scene.addObject( particles );
|
|
|
+
|
|
|
+ renderer = new THREE.WebGLRenderer( { clearAlpha: 1 });
|
|
|
+ renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
+ container.appendChild( renderer.domElement );
|
|
|
+
|
|
|
+ renderer.context.disable( renderer.context.DEPTH_TEST );
|
|
|
+
|
|
|
+ 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 = time * ( i < 4 ? i+1 : - (i+1) );
|
|
|
+ scene.objects[i].updateMatrix();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for( i = 0; i < materials.length; i++ ) {
|
|
|
+
|
|
|
+ color = parameters[i][0];
|
|
|
+
|
|
|
+ h = ( 360 * ( color[0] + time ) % 360 ) / 360;
|
|
|
+ materials[i].color.setHSV( h, color[1], color[2] );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ renderer.render( scene, camera );
|
|
|
+
|
|
|
+ stats.update();
|
|
|
+ }
|
|
|
+
|
|
|
+ function is_browser_compatible() {
|
|
|
+
|
|
|
+ // WebGL support
|
|
|
+
|
|
|
+ try { var test = new Float32Array(1); } catch(e) { return false; }
|
|
|
+
|
|
|
+ // Web workers
|
|
|
+
|
|
|
+ return !!window.Worker;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ </script>
|
|
|
+ </body>
|
|
|
+</html>
|