Lut.js 12.6 KB
Newer Older
D
daron1337 已提交
1 2 3 4 5 6
/**
 * @author daron1337 / http://daron1337.github.io/
 */

THREE.Lut = function ( colormap, numberofcolors ) {

7
	this.lut = [];
M
Mr.doob 已提交
8 9 10 11 12 13
	this.map = THREE.ColorMapKeywords[ colormap ];
	this.n = numberofcolors;
	this.mapname = colormap;

	var step = 1.0 / this.n;

M
Mr.doob 已提交
14
	for ( var i = 0; i <= 1; i += step ) {
M
Mr.doob 已提交
15

M
Mr.doob 已提交
16
		for ( var j = 0; j < this.map.length - 1; j ++ ) {
M
Mr.doob 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30

			if ( i >= this.map[ j ][ 0 ] && i < this.map[ j + 1 ][ 0 ] ) {

				var min = this.map[ j ][ 0 ];
				var max = this.map[ j + 1 ][ 0 ];

				var color = new THREE.Color( 0xffffff );
				var minColor = new THREE.Color( 0xffffff ).setHex( this.map[ j ][ 1 ] );
				var maxColor = new THREE.Color( 0xffffff ).setHex( this.map[ j + 1 ][ 1 ] );

				color = minColor.lerp( maxColor, ( i - min ) / ( max - min ) );

				this.lut.push(color);

M
Mr.doob 已提交
31
			}
M
Mr.doob 已提交
32

M
Mr.doob 已提交
33
		}
M
Mr.doob 已提交
34 35 36 37 38

	}

	return this.set( this );

D
daron1337 已提交
39 40 41 42 43
};

THREE.Lut.prototype = {

	constructor: THREE.Lut,
M
Mr.doob 已提交
44

G
gero3 已提交
45
	lut: [], map: [], mapname: 'rainbow', n: 256, minV: 0, maxV: 1, legend: null,
M
Mr.doob 已提交
46

D
daron1337 已提交
47 48 49 50 51 52
	set: function ( value ) {

		if ( value instanceof THREE.Lut ) {

			this.copy( value );

M
Mr.doob 已提交
53
		}
D
daron1337 已提交
54 55 56 57 58 59 60 61

		return this;

	},

	setMin: function ( min ) {

		this.minV = min;
M
Mr.doob 已提交
62

D
daron1337 已提交
63 64 65 66 67 68 69
		return this;

	},

	setMax: function ( max ) {

		this.maxV = max;
M
Mr.doob 已提交
70

D
daron1337 已提交
71 72 73
		return this;

	},
M
Mr.doob 已提交
74

D
daron1337 已提交
75 76 77
	changeNumberOfColors: function ( numberofcolors ) {

		this.n = numberofcolors;
M
Mr.doob 已提交
78

D
daron1337 已提交
79 80 81
		return new THREE.Lut( this.mapname, this.n );

	},
M
Mr.doob 已提交
82

D
daron1337 已提交
83
	changeColorMap: function ( colormap ) {
M
Mr.doob 已提交
84 85 86

		this.mapname = colormap;

D
daron1337 已提交
87 88 89
		return new THREE.Lut( this.mapname, this.n );

	},
M
Mr.doob 已提交
90

M
Mr.doob 已提交
91
	copy: function ( lut ) {
D
daron1337 已提交
92 93 94 95 96

		this.lut = lut.lut;
		this.mapname = lut.mapname;
		this.map = lut.map;
		this.n = lut.n;
M
Mr.doob 已提交
97 98
		this.minV = lut.minV;
		this.maxV = lut.maxV;
D
daron1337 已提交
99 100 101 102 103

		return this;

	},

M
Mr.doob 已提交
104
	getColor: function ( alpha ) {
M
Mr.doob 已提交
105

M
Mr.doob 已提交
106
		if ( alpha <= this.minV ) {
M
Mr.doob 已提交
107

M
Mr.doob 已提交
108
			alpha = this.minV;
M
Mr.doob 已提交
109

M
Mr.doob 已提交
110
		} else if ( alpha >= this.maxV ) {
M
Mr.doob 已提交
111

M
Mr.doob 已提交
112
			alpha = this.maxV;
M
Mr.doob 已提交
113

M
Mr.doob 已提交
114
		}
M
Mr.doob 已提交
115

M
Mr.doob 已提交
116
		alpha = ( alpha - this.minV ) / ( this.maxV - this.minV );
M
Mr.doob 已提交
117

M
Mr.doob 已提交
118 119
		var colorPosition = Math.round ( alpha * this.n );
		colorPosition == this.n ? colorPosition -= 1 : colorPosition;
M
Mr.doob 已提交
120

M
Mr.doob 已提交
121
		return this.lut[ colorPosition ];
M
Mr.doob 已提交
122

M
Mr.doob 已提交
123
	},
M
Mr.doob 已提交
124

M
Mr.doob 已提交
125
	addColorMap: function ( colormapName, arrayOfColors ) {
M
Mr.doob 已提交
126

M
Mr.doob 已提交
127
		THREE.ColorMapKeywords[ colormapName ] = arrayOfColors;
M
Mr.doob 已提交
128

M
Mr.doob 已提交
129
	},
M
Mr.doob 已提交
130

M
Mr.doob 已提交
131
	setLegendOn: function ( parameters ) {
M
Mr.doob 已提交
132

M
Mr.doob 已提交
133
		if ( parameters === undefined ) { parameters = {}; }
M
Mr.doob 已提交
134

M
Mr.doob 已提交
135
		this.legend = {};
M
Mr.doob 已提交
136

M
Mr.doob 已提交
137
		this.legend.layout = parameters.hasOwnProperty( 'layout' ) ? parameters[ 'layout' ] : 'vertical';
M
Mr.doob 已提交
138

M
Mr.doob 已提交
139
		this.legend.position = parameters.hasOwnProperty( 'position' ) ? parameters[ 'position' ] : { 'x': 21.5, 'y': 8, 'z': 5 };
M
Mr.doob 已提交
140

M
Mr.doob 已提交
141
		this.legend.dimensions = parameters.hasOwnProperty( 'dimensions' ) ? parameters[ 'dimensions' ] : { 'width': 0.5, 'height': 3 };
M
Mr.doob 已提交
142

M
Mr.doob 已提交
143
		this.legend.canvas = document.createElement( 'canvas' );
M
Mr.doob 已提交
144

M
Mr.doob 已提交
145 146
		this.legend.canvas.setAttribute( 'id', 'legend' );
		this.legend.canvas.setAttribute( 'hidden', true );
M
Mr.doob 已提交
147

M
Mr.doob 已提交
148
		document.body.appendChild( this.legend.canvas );
M
Mr.doob 已提交
149

M
Mr.doob 已提交
150
		this.legend.ctx = this.legend.canvas.getContext( '2d' );
M
Mr.doob 已提交
151

M
Mr.doob 已提交
152 153
		this.legend.canvas.setAttribute( 'width',  1 );
		this.legend.canvas.setAttribute( 'height', this.n );
M
Mr.doob 已提交
154

M
Mr.doob 已提交
155
		this.legend.texture = new THREE.Texture( this.legend.canvas );
M
Mr.doob 已提交
156

M
Mr.doob 已提交
157
		imageData = this.legend.ctx.getImageData( 0, 0, 1, this.n );
M
Mr.doob 已提交
158

M
Mr.doob 已提交
159 160
		data = imageData.data;
		len = data.length;
M
Mr.doob 已提交
161

M
Mr.doob 已提交
162
		this.map = THREE.ColorMapKeywords[ this.mapname ];
M
Mr.doob 已提交
163

M
Mr.doob 已提交
164
		var k = 0;
M
Mr.doob 已提交
165

M
Mr.doob 已提交
166
		var step = 1.0 / this.n;
M
Mr.doob 已提交
167

M
Mr.doob 已提交
168
		for ( var i = 1; i >= 0; i-=step ) {
M
Mr.doob 已提交
169

G
gero3 已提交
170
			for ( var j = this.map.length - 1; j >= 0; j -- ) {
M
Mr.doob 已提交
171

M
Mr.doob 已提交
172
				if ( i < this.map[ j ][ 0 ] && i >= this.map[ j - 1 ][ 0 ]  ) {
M
Mr.doob 已提交
173

M
Mr.doob 已提交
174 175 176 177 178 179
					var min = this.map[ j - 1 ][ 0 ];
					var max = this.map[ j ][ 0 ];
					var color = new THREE.Color( 0xffffff );
					var minColor = new THREE.Color( 0xffffff ).setHex( this.map[ j - 1][ 1 ] );
					var maxColor = new THREE.Color( 0xffffff ).setHex( this.map[ j ][ 1 ] );
					color = minColor.lerp( maxColor, ( i - min ) / ( max - min ) );
M
Mr.doob 已提交
180

M
Mr.doob 已提交
181 182 183 184
					data[ k * 4     ] = Math.round( color.r * 255 );
					data[ k * 4 + 1 ] = Math.round( color.g * 255 );
					data[ k * 4 + 2 ] = Math.round( color.b * 255 );
					data[ k * 4 + 3 ] = 255;
M
Mr.doob 已提交
185

M
Mr.doob 已提交
186
					k+=1;
M
Mr.doob 已提交
187

M
Mr.doob 已提交
188
				}
M
Mr.doob 已提交
189 190 191 192 193

			}

		}

M
Mr.doob 已提交
194 195
		this.legend.ctx.putImageData( imageData, 0, 0 );
		this.legend.texture.needsUpdate = true;
M
Mr.doob 已提交
196

G
gero3 已提交
197
		this.legend.legendGeometry = new THREE.PlaneBufferGeometry( this.legend.dimensions.width, this.legend.dimensions.height );
M
Mr.doob 已提交
198
		this.legend.legendMaterial = new THREE.MeshBasicMaterial( { map : this.legend.texture, side : THREE.DoubleSide } );
M
Mr.doob 已提交
199

M
Mr.doob 已提交
200
		this.legend.mesh = new THREE.Mesh( this.legend.legendGeometry, this.legend.legendMaterial );
M
Mr.doob 已提交
201

M
Mr.doob 已提交
202
		if ( this.legend.layout == 'horizontal') {
M
Mr.doob 已提交
203

M
Mr.doob 已提交
204
			this.legend.mesh.rotation.z = - 90 * ( Math.PI / 180 );
M
Mr.doob 已提交
205

M
Mr.doob 已提交
206
		}
M
Mr.doob 已提交
207

M
Mr.doob 已提交
208
		this.legend.mesh.position.copy( this.legend.position );
M
Mr.doob 已提交
209

M
Mr.doob 已提交
210
		return this.legend.mesh;
M
Mr.doob 已提交
211

M
Mr.doob 已提交
212
	},
M
Mr.doob 已提交
213

M
Mr.doob 已提交
214
	setLegendOff: function () {
M
Mr.doob 已提交
215

M
Mr.doob 已提交
216
		this.legend = null;
M
Mr.doob 已提交
217

M
Mr.doob 已提交
218
		return this.legend;
M
Mr.doob 已提交
219

M
Mr.doob 已提交
220
	},
M
Mr.doob 已提交
221

M
Mr.doob 已提交
222
	setLegendLayout: function ( layout ) {
M
Mr.doob 已提交
223

M
Mr.doob 已提交
224
		if ( ! this.legend ) { return false; }
M
Mr.doob 已提交
225

M
Mr.doob 已提交
226
		if ( this.legend.layout == layout ) { return false; }
M
Mr.doob 已提交
227

M
Mr.doob 已提交
228
		if ( layout != 'horizontal' && layout != 'vertical' ) { return false; }
M
Mr.doob 已提交
229

M
Mr.doob 已提交
230
		this.layout = layout;
M
Mr.doob 已提交
231

M
Mr.doob 已提交
232
		if ( layout == 'horizontal' ) {
M
Mr.doob 已提交
233

M
Mr.doob 已提交
234
			this.legend.mesh.rotation.z = 90 * ( Math.PI / 180 );
M
Mr.doob 已提交
235

M
Mr.doob 已提交
236
		}
M
Mr.doob 已提交
237

M
Mr.doob 已提交
238
		if ( layout == 'vertical' ) {
M
Mr.doob 已提交
239

M
Mr.doob 已提交
240
			this.legend.mesh.rotation.z = -90 * ( Math.PI / 180 );
M
Mr.doob 已提交
241

M
Mr.doob 已提交
242
		}
M
Mr.doob 已提交
243

M
Mr.doob 已提交
244
		return this.legend.mesh;
M
Mr.doob 已提交
245

M
Mr.doob 已提交
246
	},
M
Mr.doob 已提交
247

M
Mr.doob 已提交
248
	setLegendPosition: function ( position ) {
M
Mr.doob 已提交
249

M
Mr.doob 已提交
250
		this.legend.position = new THREE.Vector3( position.x, position.y, position.z );
M
Mr.doob 已提交
251

M
Mr.doob 已提交
252
		return this.legend;
M
Mr.doob 已提交
253

M
Mr.doob 已提交
254
	},
M
Mr.doob 已提交
255

M
Mr.doob 已提交
256
	setLegendLabels: function ( parameters, callback ) {
M
Mr.doob 已提交
257

M
Mr.doob 已提交
258
		if ( ! this.legend ) { return false; }
M
Mr.doob 已提交
259

M
Mr.doob 已提交
260
		if ( typeof parameters === 'function') { callback = parameters; }
M
Mr.doob 已提交
261

M
Mr.doob 已提交
262
		if ( parameters === undefined ) { parameters = {}; }
M
Mr.doob 已提交
263

M
Mr.doob 已提交
264
		this.legend.labels = {};
M
Mr.doob 已提交
265

M
Mr.doob 已提交
266
		this.legend.labels.fontsize = parameters.hasOwnProperty( 'fontsize' ) ? parameters[ 'fontsize' ] : 24;
M
Mr.doob 已提交
267

M
Mr.doob 已提交
268
		this.legend.labels.fontface = parameters.hasOwnProperty( 'fontface' ) ? parameters[ 'fontface' ] : 'Arial';
M
Mr.doob 已提交
269

M
Mr.doob 已提交
270
		this.legend.labels.title = parameters.hasOwnProperty( 'title' ) ? parameters[ 'title' ] : '';
M
Mr.doob 已提交
271

G
gero3 已提交
272
		this.legend.labels.um = parameters.hasOwnProperty( 'um' ) ? ' [ ' + parameters[ 'um' ] + ' ]' : '';
M
Mr.doob 已提交
273

M
Mr.doob 已提交
274
		this.legend.labels.ticks = parameters.hasOwnProperty( 'ticks' ) ? parameters[ 'ticks' ] : 0;
M
Mr.doob 已提交
275

M
Mr.doob 已提交
276
		this.legend.labels.decimal = parameters.hasOwnProperty( 'decimal' ) ? parameters[ 'decimal' ] : 2;
M
Mr.doob 已提交
277

M
Mr.doob 已提交
278
		this.legend.labels.notation = parameters.hasOwnProperty( 'notation' ) ? parameters[ 'notation' ] : 'standard';
M
Mr.doob 已提交
279

M
Mr.doob 已提交
280 281 282
		var backgroundColor = { r: 255, g: 100, b: 100, a: 0.8 };
		var borderColor =  { r: 255, g: 0, b: 0, a: 1.0 };
		var borderThickness = 4;
M
Mr.doob 已提交
283

M
Mr.doob 已提交
284 285
		var canvasTitle = document.createElement( 'canvas' );
		var contextTitle = canvasTitle.getContext( '2d' );
M
Mr.doob 已提交
286

M
Mr.doob 已提交
287
		contextTitle.font = 'Normal ' + this.legend.labels.fontsize * 1.2 + 'px ' + this.legend.labels.fontface;
M
Mr.doob 已提交
288

M
Mr.doob 已提交
289 290
		var metrics = contextTitle.measureText( this.legend.labels.title.toString() + this.legend.labels.um.toString() );
		var textWidth = metrics.width;
M
Mr.doob 已提交
291

M
Mr.doob 已提交
292
		contextTitle.fillStyle   = 'rgba(' + backgroundColor.r + ',' + backgroundColor.g + ',' + backgroundColor.b + ',' + backgroundColor.a + ')';
M
Mr.doob 已提交
293

M
Mr.doob 已提交
294
		contextTitle.strokeStyle = 'rgba(' + borderColor.r + ',' + borderColor.g + ',' + borderColor.b + ',' + borderColor.a + ')';
M
Mr.doob 已提交
295

M
Mr.doob 已提交
296
		contextTitle.lineWidth = borderThickness;
M
Mr.doob 已提交
297

M
Mr.doob 已提交
298
		contextTitle.fillStyle = 'rgba( 0, 0, 0, 1.0 )';
M
Mr.doob 已提交
299

M
Mr.doob 已提交
300
		contextTitle.fillText( this.legend.labels.title.toString() + this.legend.labels.um.toString(), borderThickness, this.legend.labels.fontsize + borderThickness );
M
Mr.doob 已提交
301

M
Mr.doob 已提交
302
		var txtTitle = new THREE.Texture( canvasTitle );
M
Mr.doob 已提交
303

M
Mr.doob 已提交
304
		txtTitle.needsUpdate = true;
M
Mr.doob 已提交
305

M
Mr.doob 已提交
306
		var spriteMaterialTitle = new THREE.SpriteMaterial( { map: txtTitle, useScreenCoordinates: false } );
M
Mr.doob 已提交
307

M
Mr.doob 已提交
308
		var spriteTitle = new THREE.Sprite( spriteMaterialTitle );
M
Mr.doob 已提交
309

M
Mr.doob 已提交
310
		spriteTitle.scale.set( 2, 1, 1.0 );
M
Mr.doob 已提交
311

M
Mr.doob 已提交
312
		if ( this.legend.layout == 'vertical' ) {
M
Mr.doob 已提交
313

M
Mr.doob 已提交
314
			spriteTitle.position.set( this.legend.position.x + this.legend.dimensions.width, this.legend.position.y + ( this.legend.dimensions.height * 0.45 ), this.legend.position.z );
M
Mr.doob 已提交
315

M
Mr.doob 已提交
316
		}
M
Mr.doob 已提交
317

M
Mr.doob 已提交
318
		if ( this.legend.layout == 'horizontal' ) {
M
Mr.doob 已提交
319

M
Mr.doob 已提交
320
			spriteTitle.position.set( this.legend.position.x * 1.015, this.legend.position.y + ( this.legend.dimensions.height * 0.03 ), this.legend.position.z );
M
Mr.doob 已提交
321

M
Mr.doob 已提交
322
		}
M
Mr.doob 已提交
323

M
Mr.doob 已提交
324
		if ( this.legend.labels.ticks > 0 ) {
M
Mr.doob 已提交
325

M
Mr.doob 已提交
326 327
			var ticks = {};
			var lines = {};
M
Mr.doob 已提交
328

M
Mr.doob 已提交
329
			if ( this.legend.layout == 'vertical' ) {
M
Mr.doob 已提交
330

M
Mr.doob 已提交
331 332
				var topPositionY = this.legend.position.y + ( this.legend.dimensions.height * 0.36 );
				var bottomPositionY = this.legend.position.y - ( this.legend.dimensions.height * 0.61 );
M
Mr.doob 已提交
333

M
Mr.doob 已提交
334
			}
M
Mr.doob 已提交
335

M
Mr.doob 已提交
336
			if ( this.legend.layout == 'horizontal' ) {
M
Mr.doob 已提交
337

M
Mr.doob 已提交
338 339
				var topPositionX = this.legend.position.x + ( this.legend.dimensions.height * 0.75 );
				var bottomPositionX = this.legend.position.x - ( this.legend.dimensions.width * 1.2  ) ;
M
Mr.doob 已提交
340

M
Mr.doob 已提交
341
			}
M
Mr.doob 已提交
342

G
gero3 已提交
343
			for ( var i = 0; i < this.legend.labels.ticks; i ++ ) {
M
Mr.doob 已提交
344

M
Mr.doob 已提交
345
				var value = ( this.maxV - this.minV ) / ( this.legend.labels.ticks - 1  ) * i ;
M
Mr.doob 已提交
346

M
Mr.doob 已提交
347
				if ( callback ) {
M
Mr.doob 已提交
348

M
Mr.doob 已提交
349
					value = callback ( value );
M
Mr.doob 已提交
350

M
Mr.doob 已提交
351
				}
M
Mr.doob 已提交
352

M
Mr.doob 已提交
353
				else {
M
Mr.doob 已提交
354

M
Mr.doob 已提交
355
					if ( this.legend.labels.notation == 'scientific' ) {
M
Mr.doob 已提交
356

M
Mr.doob 已提交
357
						value = value.toExponential( this.legend.labels.decimal );
M
Mr.doob 已提交
358

M
Mr.doob 已提交
359
					}
M
Mr.doob 已提交
360

M
Mr.doob 已提交
361
					else {
M
Mr.doob 已提交
362

M
Mr.doob 已提交
363
						value = value.toFixed( this.legend.labels.decimal );
M
Mr.doob 已提交
364

M
Mr.doob 已提交
365
					}
M
Mr.doob 已提交
366 367 368

				}

M
Mr.doob 已提交
369 370
				var canvasTick = document.createElement( 'canvas' );
				var contextTick = canvasTick.getContext( '2d' );
M
Mr.doob 已提交
371

M
Mr.doob 已提交
372
				contextTick.font = 'Normal ' + this.legend.labels.fontsize + 'px ' + this.legend.labels.fontface;
M
Mr.doob 已提交
373

M
Mr.doob 已提交
374 375
				var metrics = contextTick.measureText( value.toString() );
				var textWidth = metrics.width;
M
Mr.doob 已提交
376

M
Mr.doob 已提交
377
				contextTick.fillStyle   = 'rgba(' + backgroundColor.r + ',' + backgroundColor.g + ',' + backgroundColor.b + ',' + backgroundColor.a + ')';
M
Mr.doob 已提交
378

M
Mr.doob 已提交
379
				contextTick.strokeStyle = 'rgba(' + borderColor.r + ',' + borderColor.g + ',' + borderColor.b + ',' + borderColor.a + ')';
M
Mr.doob 已提交
380

M
Mr.doob 已提交
381
				contextTick.lineWidth = borderThickness;
M
Mr.doob 已提交
382

M
Mr.doob 已提交
383
				contextTick.fillStyle = 'rgba( 0, 0, 0, 1.0 )';
M
Mr.doob 已提交
384

M
Mr.doob 已提交
385
				contextTick.fillText( value.toString(), borderThickness, this.legend.labels.fontsize + borderThickness );
M
Mr.doob 已提交
386

M
Mr.doob 已提交
387
				var txtTick = new THREE.Texture( canvasTick );
M
Mr.doob 已提交
388

M
Mr.doob 已提交
389
				txtTick.needsUpdate = true;
M
Mr.doob 已提交
390

M
Mr.doob 已提交
391
				var spriteMaterialTick = new THREE.SpriteMaterial( { map: txtTick, useScreenCoordinates: false } );
M
Mr.doob 已提交
392

M
Mr.doob 已提交
393
				var spriteTick = new THREE.Sprite( spriteMaterialTick );
M
Mr.doob 已提交
394

M
Mr.doob 已提交
395
				spriteTick.scale.set( 2, 1, 1.0 );
M
Mr.doob 已提交
396

M
Mr.doob 已提交
397
				if ( this.legend.layout == 'vertical' ) {
M
Mr.doob 已提交
398

M
Mr.doob 已提交
399
					var position = bottomPositionY + ( topPositionY - bottomPositionY ) * ( value / ( this.maxV - this.minV ) );
M
Mr.doob 已提交
400

M
Mr.doob 已提交
401
					spriteTick.position.set( this.legend.position.x + ( this.legend.dimensions.width * 2.7 ), position, this.legend.position.z );
M
Mr.doob 已提交
402

M
Mr.doob 已提交
403
				}
M
Mr.doob 已提交
404

M
Mr.doob 已提交
405
				if ( this.legend.layout == 'horizontal' ) {
M
Mr.doob 已提交
406

M
Mr.doob 已提交
407
					var position = bottomPositionX + ( topPositionX - bottomPositionX ) * ( value / ( this.maxV - this.minV ) );
M
Mr.doob 已提交
408

M
Mr.doob 已提交
409
					if ( this.legend.labels.ticks > 5 ) {
M
Mr.doob 已提交
410

M
Mr.doob 已提交
411
						if ( i % 2 === 0 ) { var offset = 1.7; }
M
Mr.doob 已提交
412

M
Mr.doob 已提交
413
						else { var offset = 2.1; }
M
Mr.doob 已提交
414

M
Mr.doob 已提交
415
					}
M
Mr.doob 已提交
416

M
Mr.doob 已提交
417
					else { var offset = 1.7; }
M
Mr.doob 已提交
418

M
Mr.doob 已提交
419
					spriteTick.position.set( position, this.legend.position.y - this.legend.dimensions.width * offset, this.legend.position.z );
M
Mr.doob 已提交
420

M
Mr.doob 已提交
421
				}
M
Mr.doob 已提交
422

M
Mr.doob 已提交
423
				var material = new THREE.LineBasicMaterial( { color: 0x000000, linewidth: 2 } );
M
Mr.doob 已提交
424

M
Mr.doob 已提交
425
				var geometry = new THREE.Geometry();
M
Mr.doob 已提交
426 427


M
Mr.doob 已提交
428
				if ( this.legend.layout == 'vertical' ) {
M
Mr.doob 已提交
429

M
Mr.doob 已提交
430
					var linePosition = ( this.legend.position.y - ( this.legend.dimensions.height * 0.5 ) + 0.01 ) + ( this.legend.dimensions.height ) * ( value / ( this.maxV - this.minV ) * 0.99 );
M
Mr.doob 已提交
431

G
gero3 已提交
432
					geometry.vertices.push( new THREE.Vector3( this.legend.position.x + this.legend.dimensions.width * 0.55, linePosition, this.legend.position.z  ) );
M
Mr.doob 已提交
433

M
Mr.doob 已提交
434
					geometry.vertices.push( new THREE.Vector3( this.legend.position.x + this.legend.dimensions.width * 0.7, linePosition, this.legend.position.z  ) );
M
Mr.doob 已提交
435

M
Mr.doob 已提交
436
				}
M
Mr.doob 已提交
437

M
Mr.doob 已提交
438
				if ( this.legend.layout == 'horizontal' ) {
M
Mr.doob 已提交
439

M
Mr.doob 已提交
440
					var linePosition = ( this.legend.position.x - ( this.legend.dimensions.height * 0.5 ) + 0.01 ) + ( this.legend.dimensions.height ) * ( value / ( this.maxV - this.minV ) * 0.99 );
M
Mr.doob 已提交
441

M
Mr.doob 已提交
442
					geometry.vertices.push( new THREE.Vector3( linePosition, this.legend.position.y - this.legend.dimensions.width * 0.55, this.legend.position.z  ) );
M
Mr.doob 已提交
443

M
Mr.doob 已提交
444
					geometry.vertices.push( new THREE.Vector3( linePosition, this.legend.position.y - this.legend.dimensions.width * 0.7, this.legend.position.z  ) );
M
Mr.doob 已提交
445

M
Mr.doob 已提交
446
				}
M
Mr.doob 已提交
447

M
Mr.doob 已提交
448
				var line = new THREE.Line( geometry, material );
M
Mr.doob 已提交
449

M
Mr.doob 已提交
450 451
				lines[ i ] = line;
				ticks[ i ] = spriteTick;
M
Mr.doob 已提交
452

M
Mr.doob 已提交
453
			}
M
Mr.doob 已提交
454 455 456

		}

M
Mr.doob 已提交
457
		return { 'title': spriteTitle,  'ticks': ticks, 'lines': lines };
M
Mr.doob 已提交
458

M
Mr.doob 已提交
459
	}
D
daron1337 已提交
460 461 462

};

M
Mr.doob 已提交
463

D
daron1337 已提交
464 465
THREE.ColorMapKeywords = {

G
gero3 已提交
466 467 468 469
  "rainbow":    [ [ 0.0, '0x0000FF' ], [ 0.2, '0x00FFFF' ], [ 0.5, '0x00FF00' ], [ 0.8, '0xFFFF00' ],  [ 1.0, '0xFF0000' ] ],
  "cooltowarm": [ [ 0.0, '0x3C4EC2' ], [ 0.2, '0x9BBCFF' ], [ 0.5, '0xDCDCDC' ], [ 0.8, '0xF6A385' ],  [ 1.0, '0xB40426' ] ],
  "blackbody" : [ [ 0.0, '0x000000' ], [ 0.2, '0x780000' ], [ 0.5, '0xE63200' ], [ 0.8, '0xFFFF00' ],  [ 1.0, '0xFFFFFF' ] ],
  "grayscale" : [ [ 0.0, '0x000000' ], [ 0.2, '0x404040' ], [ 0.5, '0x7F7F80' ], [ 0.8, '0xBFBFBF' ],  [ 1.0, '0xFFFFFF' ] ]
D
daron1337 已提交
470

M
Mr.doob 已提交
471
};