Browse Source

Update code style

Temdog007 6 years ago
parent
commit
e4e8ed68bc
2 changed files with 61 additions and 43 deletions
  1. 22 17
      examples/js/math/Lut.js
  2. 39 26
      examples/webgl_geometry_colors_lookuptable.html

+ 22 - 17
examples/js/math/Lut.js

@@ -5,7 +5,7 @@
 THREE.Lut = function ( colormap, numberofcolors ) {
 THREE.Lut = function ( colormap, numberofcolors ) {
 
 
 	this.lut = [];
 	this.lut = [];
-	this.setColorMap(colormap, numberofcolors);
+	this.setColorMap( colormap, numberofcolors );
 	return this;
 	return this;
 
 
 };
 };
@@ -64,37 +64,39 @@ THREE.Lut.prototype = {
 
 
 	},
 	},
 
 
-	setColorMap: function(colormap, numberofcolors){
+	setColorMap: function ( colormap, numberofcolors ) {
+
 		this.map = THREE.ColorMapKeywords[ colormap ] || THREE.ColorMapKeywords.rainbow;
 		this.map = THREE.ColorMapKeywords[ colormap ] || THREE.ColorMapKeywords.rainbow;
 		this.n = numberofcolors || 32;
 		this.n = numberofcolors || 32;
 		this.mapname = colormap;
 		this.mapname = colormap;
-	
+
 		var step = 1.0 / this.n;
 		var step = 1.0 / this.n;
-	
+
 		this.lut.length = 0;
 		this.lut.length = 0;
 		for ( var i = 0; i <= 1; i += step ) {
 		for ( var i = 0; i <= 1; i += step ) {
-	
+
 			for ( var j = 0; j < this.map.length - 1; j ++ ) {
 			for ( var j = 0; j < this.map.length - 1; j ++ ) {
-	
+
 				if ( i >= this.map[ j ][ 0 ] && i < this.map[ j + 1 ][ 0 ] ) {
 				if ( i >= this.map[ j ][ 0 ] && i < this.map[ j + 1 ][ 0 ] ) {
-	
+
 					var min = this.map[ j ][ 0 ];
 					var min = this.map[ j ][ 0 ];
 					var max = this.map[ j + 1 ][ 0 ];
 					var max = this.map[ j + 1 ][ 0 ];
-	
+
 					var minColor = new THREE.Color( this.map[ j ][ 1 ] );
 					var minColor = new THREE.Color( this.map[ j ][ 1 ] );
 					var maxColor = new THREE.Color( this.map[ j + 1 ][ 1 ] );
 					var maxColor = new THREE.Color( this.map[ j + 1 ][ 1 ] );
-	
+
 					var color = minColor.lerp( maxColor, ( i - min ) / ( max - min ) );
 					var color = minColor.lerp( maxColor, ( i - min ) / ( max - min ) );
-	
+
 					this.lut.push( color );
 					this.lut.push( color );
-	
+
 				}
 				}
-	
+
 			}
 			}
-	
+
 		}
 		}
 
 
 		return this;
 		return this;
+
 	},
 	},
 
 
 	copy: function ( lut ) {
 	copy: function ( lut ) {
@@ -137,23 +139,25 @@ THREE.Lut.prototype = {
 
 
 	},
 	},
 
 
-	createCanvas: function(){
+	createCanvas: function () {
+
 		var canvas = document.createElement( 'canvas' );
 		var canvas = document.createElement( 'canvas' );
 		canvas.setAttribute( 'width', 1 );
 		canvas.setAttribute( 'width', 1 );
 		canvas.setAttribute( 'height', this.n );
 		canvas.setAttribute( 'height', this.n );
 		canvas.setAttribute( 'id', 'legend' );
 		canvas.setAttribute( 'id', 'legend' );
 		canvas.setAttribute( 'hidden', true );
 		canvas.setAttribute( 'hidden', true );
 
 
-		this.updateCanvas(canvas);
+		this.updateCanvas( canvas );
 
 
 		return canvas;
 		return canvas;
+
 	},
 	},
 
 
-	updateCanvas: function(canvas){
+	updateCanvas: function ( canvas ) {
 
 
 		canvas = canvas || this.legend.canvas;
 		canvas = canvas || this.legend.canvas;
 
 
-		var ctx = canvas.getContext('2d', {alpha : false});
+		var ctx = canvas.getContext( '2d', { alpha: false } );
 
 
 		var imageData = ctx.getImageData( 0, 0, 1, this.n );
 		var imageData = ctx.getImageData( 0, 0, 1, this.n );
 
 
@@ -195,6 +199,7 @@ THREE.Lut.prototype = {
 		ctx.putImageData( imageData, 0, 0 );
 		ctx.putImageData( imageData, 0, 0 );
 
 
 		return canvas;
 		return canvas;
+
 	},
 	},
 
 
 	setLegendOn: function ( parameters ) {
 	setLegendOn: function ( parameters ) {

+ 39 - 26
examples/webgl_geometry_colors_lookuptable.html

@@ -72,7 +72,7 @@
 
 
 				uiScene = new THREE.Scene();
 				uiScene = new THREE.Scene();
 
 
-				updateColorEvent = {type : 'updateColor'};
+				updateColorEvent = { type: 'updateColor' };
 
 
 				var width = window.innerWidth;
 				var width = window.innerWidth;
 				var height = window.innerHeight;
 				var height = window.innerHeight;
@@ -124,14 +124,18 @@
 
 
 				var gui = new dat.GUI();
 				var gui = new dat.GUI();
 
 
-				gui.add( params, 'legendLayout', [ 'vertical', 'horizontal' ] ).onChange( function(){
+				gui.add( params, 'legendLayout', [ 'vertical', 'horizontal' ] ).onChange( function () {
+
 					updateLegend();
 					updateLegend();
 					render();
 					render();
+
 				} );
 				} );
 
 
-				gui.add( params, 'colorMap', [ 'rainbow', 'cooltowarm', 'blackbody', 'grayscale' ] ).onChange( function(){
+				gui.add( params, 'colorMap', [ 'rainbow', 'cooltowarm', 'blackbody', 'grayscale' ] ).onChange( function () {
+
 					updateColors();
 					updateColors();
 					render();
 					render();
+
 				} );
 				} );
 
 
 			}
 			}
@@ -167,10 +171,12 @@
 
 
 					// default color attribute
 					// default color attribute
 					var colors = [];
 					var colors = [];
-					for(var i = 0, n = geometry.attributes.position.count; i < n; ++i){
-						colors.push(1,1,1);
+					for ( var i = 0, n = geometry.attributes.position.count; i < n; ++ i ) {
+
+						colors.push( 1, 1, 1 );
+
 					}
 					}
-					geometry.addAttribute('color', new THREE.Float32BufferAttribute(colors,3 ));
+					geometry.addAttribute( 'color', new THREE.Float32BufferAttribute( colors, 3 ) );
 
 
 					mesh.geometry = geometry;
 					mesh.geometry = geometry;
 					updateColors();
 					updateColors();
@@ -179,7 +185,7 @@
 
 
 					// vertical legend
 					// vertical legend
 					var verticalLegend = lut.setLegendOn();
 					var verticalLegend = lut.setLegendOn();
-					verticalLegendGroup.add(verticalLegend);
+					verticalLegendGroup.add( verticalLegend );
 
 
 					var labels = lut.setLegendLabels( labelParams );
 					var labels = lut.setLegendLabels( labelParams );
 
 
@@ -193,10 +199,10 @@
 					}
 					}
 
 
 					// horizontal legend
 					// horizontal legend
-					var horizontalLegend = lut.setLegendOn({layout : 'horizontal'});
-					horizontalLegendGroup.add(horizontalLegend);
+					var horizontalLegend = lut.setLegendOn( { layout: 'horizontal' } );
+					horizontalLegendGroup.add( horizontalLegend );
 
 
-					var labels = lut.setLegendLabels( labelParams);
+					var labels = lut.setLegendLabels( labelParams );
 
 
 					horizontalLegendGroup.add( labels[ 'title' ] );
 					horizontalLegendGroup.add( labels[ 'title' ] );
 
 
@@ -207,32 +213,37 @@
 
 
 					}
 					}
 
 
-					uiScene.addEventListener('updateColor', function(){
-						lut.updateCanvas(horizontalLegend.material.map.image);
-						lut.updateCanvas(verticalLegend.material.map.image);
+					uiScene.addEventListener( 'updateColor', function () {
+
+						lut.updateCanvas( horizontalLegend.material.map.image );
+						lut.updateCanvas( verticalLegend.material.map.image );
 
 
 						horizontalLegend.material.map.needsUpdate = true;
 						horizontalLegend.material.map.needsUpdate = true;
 						verticalLegend.material.map.needsUpdate = true;
 						verticalLegend.material.map.needsUpdate = true;
-					});
+
+					} );
 
 
 					// vertical layer = 0, horizontal layer = 1
 					// vertical layer = 0, horizontal layer = 1
-					horizontalLegendGroup.traverse(function(obj)
-					{
-						if(obj.layers)
-						{
-							obj.layers.set(1);
+					horizontalLegendGroup.traverse( function ( obj ) {
+
+						if ( obj.layers ) {
+
+							obj.layers.set( 1 );
+
 						}
 						}
-					})
+
+					} );
 
 
 					updateLegend();
 					updateLegend();
 					render();
 					render();
+
 				} );
 				} );
 
 
 			}
 			}
 
 
 			function updateColors() {
 			function updateColors() {
 
 
-				lut.setColorMap(params.colorMap);
+				lut.setColorMap( params.colorMap );
 
 
 				lut.setMax( 2000 );
 				lut.setMax( 2000 );
 				lut.setMin( 0 );
 				lut.setMin( 0 );
@@ -242,7 +253,7 @@
 				var colors = geometry.attributes.color;
 				var colors = geometry.attributes.color;
 				for ( var i = 0; i < pressures.array.length; i ++ ) {
 				for ( var i = 0; i < pressures.array.length; i ++ ) {
 
 
-					var colorValue = pressures.array[i];
+					var colorValue = pressures.array[ i ];
 
 
 					var color = lut.getColor( colorValue );
 					var color = lut.getColor( colorValue );
 
 
@@ -252,14 +263,15 @@
 
 
 					} else {
 					} else {
 
 
-						colors.setXYZ(i, color.r, color.g, color.b);
+						colors.setXYZ( i, color.r, color.g, color.b );
+
 					}
 					}
 
 
 				}
 				}
 
 
 				colors.needsUpdate = true;
 				colors.needsUpdate = true;
 
 
-				uiScene.dispatchEvent(updateColorEvent);
+				uiScene.dispatchEvent( updateColorEvent );
 
 
 			}
 			}
 
 
@@ -269,11 +281,11 @@
 
 
 					if ( params.legendLayout === 'horizontal' ) {
 					if ( params.legendLayout === 'horizontal' ) {
 
 
-						orthoCamera.layers.set(1);
+						orthoCamera.layers.set( 1 );
 
 
 					} else {
 					} else {
 
 
-						orthoCamera.layers.set(0);
+						orthoCamera.layers.set( 0 );
 
 
 					}
 					}
 
 
@@ -281,6 +293,7 @@
 
 
 			}
 			}
 
 
+
 		</script>
 		</script>
 
 
 	</body>
 	</body>