Browse Source

coding style corrections

aardgoose 8 years ago
parent
commit
3bbb8eee07
1 changed files with 32 additions and 18 deletions
  1. 32 18
      examples/webgl_nearestneighbour.html

+ 32 - 18
examples/webgl_nearestneighbour.html

@@ -63,8 +63,8 @@
 
 			void main() {
 
-				gl_FragColor = texture2D(tex1, gl_PointCoord);
-				gl_FragColor.r = (1.0 - gl_FragColor.r) * vAlpha + gl_FragColor.r;
+				gl_FragColor = texture2D( tex1, gl_PointCoord );
+				gl_FragColor.r = ( 1.0 - gl_FragColor.r ) * vAlpha + gl_FragColor.r;
 
 			}
 
@@ -77,7 +77,7 @@
 
 			var objects = [];
 
-			var amountOfParticles = 500000, maxDistance = Math.pow(120, 2);
+			var amountOfParticles = 500000, maxDistance = Math.pow( 120, 2 );
 			var positions, alphas, particles, _particleGeom;
 
 			var clock = new THREE.Clock();
@@ -88,7 +88,7 @@
 
 			function init() {
 
-				camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 1000000);
+				camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1000000 );
 
 				scene = new THREE.Scene();
 
@@ -96,6 +96,8 @@
 				controls.movementSpeed = 100;
 				controls.lookSpeed = 0.1;
 
+
+				// add a skybox background
 				var cubeTextureLoader = new THREE.CubeTextureLoader();
 
 				cubeTextureLoader.setPath( 'textures/cube/skybox/' );
@@ -132,12 +134,14 @@
 					vertexShader:   document.getElementById( 'vertexshader' ).textContent,
 					fragmentShader: document.getElementById( 'fragmentshader' ).textContent,
 					transparent: true
-				});
+				} );
 
 
 				//create particles with buffer geometry
-				var distanceFunction = function(a, b){
-					return Math.pow(a[0] - b[0], 2) +  Math.pow(a[1] - b[1], 2) +  Math.pow(a[2] - b[2], 2);
+				var distanceFunction = function( a, b ) {
+
+					return Math.pow( a[ 0 ] - b [0 ], 2 ) +  Math.pow( a[ 1 ] - b[ 1 ], 2 ) +  Math.pow( a[ 2 ] - b[ 2 ], 2 );
+
 				};
 
 				positions = new Float32Array( amountOfParticles * 3 );
@@ -149,11 +153,14 @@
 
 				particles = new THREE.Points( _particleGeom, pointShaderMaterial );
 
-				for (var x = 0; x < amountOfParticles; x++) {
+				for ( var x = 0; x < amountOfParticles; x ++ ) {
+
 					positions[ x * 3 + 0 ] = Math.random() * 1000;
 					positions[ x * 3 + 1 ] = Math.random() * 1000;
 					positions[ x * 3 + 2 ] = Math.random() * 1000;
-					alphas[x] = 1.0;
+
+					alphas[ x ] = 1.0;
+
 				}
 
 
@@ -162,10 +169,10 @@
 				// creating the kdtree takes a lot of time to execute, in turn the nearest neighbour search will be much faster
 				kdtree = new THREE.TypedArrayUtils.Kdtree( positions, distanceFunction, 3 );
 
-				console.log('TIME building kdtree', new Date().getTime() - measureStart);
+				console.log( 'TIME building kdtree', new Date().getTime() - measureStart );
 
 				// display particles after the kd-tree was generated and the sorting of the positions-array is done
-				scene.add(particles);
+				scene.add( particles );
 
 				window.addEventListener( 'resize', onWindowResize, false );
 
@@ -186,7 +193,7 @@
 				requestAnimationFrame( animate );
 
 				//
-				displayNearest(camera.position);
+				displayNearest( camera.position );
 
 				controls.update( clock.getDelta() );
 
@@ -194,38 +201,45 @@
 
 			}
 
-			function displayNearest(position) {
+			function displayNearest( position ) {
 
 				// take the nearest 200 around him. distance^2 'cause we use the manhattan distance and no square is applied in the distance function
-				var imagePositionsInRange = kdtree.nearest([position.x, position.y, position.z], 100, maxDistance);
+				var imagePositionsInRange = kdtree.nearest( [ position.x, position.y, position.z ], 100, maxDistance );
 
 				// We combine the nearest neighbour with a view frustum. Doesn't make sense if we change the sprites not in our view... well maybe it does. Whatever you want.
 				var _frustum = new THREE.Frustum();
 				var _projScreenMatrix = new THREE.Matrix4();
+
 				camera.matrixWorldInverse.getInverse( camera.matrixWorld );
 
 				_projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
 				_frustum.setFromMatrix( _projScreenMatrix );
 
 				for ( var i = 0, il = imagePositionsInRange.length; i < il; i ++ ) {
-					var object = imagePositionsInRange[i];
+
+					var object = imagePositionsInRange[ i ];
 					var objectPoint = new THREE.Vector3().fromArray( object[ 0 ].obj );
 
-					if (_frustum.containsPoint(objectPoint)){
+					if ( _frustum.containsPoint( objectPoint ) ) {
 
-						var objectIndex = object[0].pos;
+						var objectIndex = object[ 0 ].pos;
 
 						// set the alpha according to distance
-						alphas[ objectIndex ] = 1.0 / maxDistance * object[1];
+						alphas[ objectIndex ] = 1.0 / maxDistance * object[ 1 ];
+
 						// update the attribute
 						_particleGeom.attributes.alpha.needsUpdate = true;
+
 					}
+
 				}
+
 			}
 
 
 			init();
 			animate();
+
 		</script>
 	</body>
 </html>