提交 87f7378c 编写于 作者: B Ben Houston

Merge branch 'dev' of git@github.com:mrdoob/three.js.git into math-line

......@@ -319,60 +319,38 @@ THREE.extend( THREE.Color.prototype, {
setHSV: function ( h, s, v ) {
// based on MochiKit implementation by Bob Ippolito
// h,s,v ranges are < 0.0 - 1.0 >
console.log( 'DEPRECATED: Color\'s .setHSV() will be removed. Use .setHSL( h, s, l ) instead.' );
return this.setHSL(h,s*v/((h=(2-s)*v)<1?h:2-h),h/2); // https://gist.github.com/xpansive/1337890
var i, f, p, q, t;
if ( v === 0 ) {
this.r = this.g = this.b = 0;
} else {
i = Math.floor( h * 6 );
f = ( h * 6 ) - i;
p = v * ( 1 - s );
q = v * ( 1 - ( s * f ) );
t = v * ( 1 - ( s * ( 1 - f ) ) );
if ( i === 0 ) {
this.r = v;
this.g = t;
this.b = p;
},
} else if ( i === 1 ) {
setHSL: function ( h, s, l ) {
this.r = q;
this.g = v;
this.b = p;
// h,s,l ranges are in 0.0 - 1.0
} else if ( i === 2 ) {
if ( s === 0 ) {
this.r = p;
this.g = v;
this.b = t;
this.r = this.g = this.b = l;
} else if ( i === 3 ) {
} else {
this.r = p;
this.g = q;
this.b = v;
var hue2rgb = function ( p, q, t ) {
} else if ( i === 4 ) {
if ( t < 0 ) t += 1;
if ( t > 1 ) t -= 1;
if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
if ( t < 1 / 2 ) return q;
if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
return p;
this.r = t;
this.g = p;
this.b = v;
};
} else if ( i === 5 ) {
var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
var q = ( 2 * l ) - p;
this.r = v;
this.g = p;
this.b = q;
}
this.r = hue2rgb( q, p, h + 1 / 3 );
this.g = hue2rgb( q, p, h );
this.b = hue2rgb( q, p, h - 1 / 3 );
}
......@@ -511,78 +489,70 @@ THREE.extend( THREE.Color.prototype, {
},
getStyle: function () {
getHSL: function () {
return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
var hsl = { h: 0, s: 0, l: 0 };
},
getHSV: function ( hsv ) {
return function () {
// based on MochiKit implementation by Bob Ippolito
// h,s,v ranges are < 0.0 - 1.0 >
// h,s,l ranges are in 0.0 - 1.0
var r = this.r;
var g = this.g;
var b = this.b;
var r = this.r, g = this.g, b = this.b;
var max = Math.max( Math.max( r, g ), b );
var min = Math.min( Math.min( r, g ), b );
var max = Math.max( r, g, b );
var min = Math.min( r, g, b );
var hue;
var saturation;
var value = max;
var hue, saturation;
var lightness = ( min + max ) / 2.0;
if ( min === max ) {
if ( min === max ) {
hue = 0;
saturation = 0;
hue = 0;
saturation = 0;
} else {
} else {
var delta = ( max - min );
saturation = delta / max;
var delta = max - min;
if ( r === max ) {
saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
hue = ( g - b ) / delta;
switch ( max ) {
} else if ( g === max ) {
case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
case g: hue = ( b - r ) / delta + 2; break;
case b: hue = ( r - g ) / delta + 4; break;
hue = 2 + ( ( b - r ) / delta );
}
} else {
hue /= 6;
hue = 4 + ( ( r - g ) / delta );
}
hue /= 6;
hsl.h = hue;
hsl.s = saturation;
hsl.l = lightness;
if ( hue < 0 ) {
return hsl;
hue += 1;
}
};
if ( hue > 1 ) {
}(),
hue -= 1;
getStyle: function () {
}
return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
}
},
if ( hsv === undefined ) {
offsetHSL: function ( h, s, l ) {
hsv = { h: 0, s: 0, v: 0 };
var hsl = this.getHSL();
}
hsl.h += h; hsl.s += s; hsl.l += l;
hsv.h = hue;
hsv.s = saturation;
hsv.v = value;
this.setHSL( hsl.h, hsl.s, hsl.l );
return hsv;
return this;
},
......@@ -25515,28 +25485,6 @@ THREE.RenderableLine = function () {
};
/**
* @author alteredq / http://alteredqualia.com/
*/
THREE.ColorUtils = {
adjustHSV : function ( color, h, s, v ) {
var hsv = THREE.ColorUtils.__hsv;
color.getHSV( hsv );
hsv.h = THREE.Math.clamp( hsv.h + h, 0, 1 );
hsv.s = THREE.Math.clamp( hsv.s + s, 0, 1 );
hsv.v = THREE.Math.clamp( hsv.v + v, 0, 1 );
color.setHSV( hsv.h, hsv.s, hsv.v );
}
};
THREE.ColorUtils.__hsv = { h: 0, s: 0, v: 0 };/**
* @author mrdoob / http://mrdoob.com/
* @author alteredq / http://alteredqualia.com/
*/
......
此差异已折叠。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="../../list.js"></script>
<script src="../../page.js"></script>
<link type="text/css" rel="stylesheet" href="../../page.css" />
</head>
<body>
<h1>[name]</h1>
<div class="desc">This is a utility class to handle values in <a href="https://en.wikipedia.org/wiki/RGB_color_model">RGB</a> and <a href="https://en.wikipedia.org/wiki/HSL_and_HSV">HSV</a> color spaces.</div>
<h2>Methods</h2>
<h3>.adjustHSV( [page:Color color], [page:Number h], [page:Number s], [page:Number v] )</h3>
<div class="desc">Taking a color as input, converts it to HSV, and applies the h, s, v parameters in place, i.e. no new color is returned but the original object is modified.</div>
<div>
[page:Color color] — source color to be adjusted<br />
[page:Number h] — hue change amount<br />
[page:Number s] — saturation change amount<br />
[page:Number v] — value change amount
</div>
<h3>.rgbToHsv( [page:Color color], [page:Object hsv] )</h3>
<div class="desc">Converts an RGB color into an HSV triplet and returns the converted color.</div>
<div>
[page:Color color] — source color to be converted<br />
[page:Object hsv] — object in which the return value will be stored, if not null
</div>
<h2>Source</h2>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</body>
</html>
......@@ -9,29 +9,24 @@
<body>
<h1>[name]</h1>
<div class="desc">This is a utility class to handle values in <a href="https://en.wikipedia.org/wiki/RGB_color_model">RGB</a> and <a href="https://en.wikipedia.org/wiki/HSL_and_HSV">HSV</a> color spaces.</div>
<div class="desc">todo</div>
<h2>Constructor</h2>
<h3>[name]()</h3>
<h2>Properties</h2>
<h3>.[page:Vector3 todo]</h3>
<h2>Methods</h2>
<h3>.adjustHSV( [page:Color color], [page:Number h], [page:Number s], [page:Number v] )</h3>
<div class="desc">Taking a color as input, converts it to HSV, and applies the h, s, v parameters in place, i.e. no new color is returned but the original object is modified.</div>
<div>
[page:Color color] — source color to be adjusted<br />
[page:Number h] — hue change amount<br />
[page:Number s] — saturation change amount<br />
[page:Number v] — value change amount
</div>
<h3>.rgbToHsv( [page:Color color], [page:Object hsv] )</h3>
<div class="desc">Converts an RGB color into an HSV triplet and returns the converted color.</div>
<h3>.todo( [page:Vector3 todo] )</h3>
<div>
[page:Color color] — source color to be converted<br />
[page:Object hsv] — object in which the return value will be stored, if not null
todo — todo<br />
</div>
......
......@@ -128,7 +128,6 @@ var list = {
],
"Extras": [
[ "ColorUtils", "api/extras/ColorUtils" ],
[ "FontUtils", "api/extras/FontUtils" ],
[ "GeometryUtils", "api/extras/GeometryUtils" ],
[ "ImageUtils", "api/extras/ImageUtils" ],
......
......@@ -173,7 +173,7 @@
//hearts circleLines
var material = new THREE.ParticleCanvasMaterial( { program: hearts, blending:THREE.AdditiveBlending } );
material.color.setHSV(hue, 0.5, 1);
material.color.setHSL(hue, 1, 0.75);
hue += 0.001;
if (hue>1) hue-=1;
......
......@@ -4,7 +4,11 @@
*
* Description: A THREE loader for STL ASCII files, as created by Solidworks and other CAD programs.
*
* Limitations: Currently supports ASCII format only
* Supports both binary and ASCII encoded files, with automatic detection of type.
*
* Limitations: Binary decoding ignores header. There doesn't seem to be much of a use for it.
* There is perhaps some question as to how valid it is to always assume little-endian-ness.
* ASCII decoding assumes file is UTF-8. Seems to work for the examples...
*
* Usage:
* var loader = new THREE.STLLoader();
......@@ -35,7 +39,8 @@ THREE.STLLoader.prototype = {
request.addEventListener( 'load', function ( event ) {
var geometry = scope.parse( event.target.responseText );
var geometry;
geometry = scope.parse( event.target.response );
scope.dispatchEvent( { type: 'load', content: geometry } );
......@@ -56,11 +61,48 @@ THREE.STLLoader.prototype = {
}, false );
request.open( 'GET', url, true );
request.responseType = "arraybuffer";
request.send( null );
},
parse: function ( data ) {
bin2str: function (buf) {
var array_buffer = new Uint8Array(buf);
var str = '';
for(var i = 0; i < buf.byteLength; i++) {
str += String.fromCharCode(array_buffer[i]); // implicitly assumes little-endian
}
return str
},
isASCII: function(buf){
var dv = new DataView(buf);
var str = '';
for(var i = 0; i < 5; i++) {
str += String.fromCharCode(dv.getUint8(i, true)); // assume little-endian
}
return (str.toLowerCase() === 'solid'); // All ASCII stl files begin with 'solid'
},
parse: function (buf) {
if( this.isASCII(buf) )
{
var str = this.bin2str(buf);
return this.parseASCII(str);
}
else
{
return this.parseBinary(buf);
}
},
parseASCII: function ( data ) {
var geometry = new THREE.Geometry();
......@@ -99,6 +141,55 @@ THREE.STLLoader.prototype = {
return geometry;
},
parseBinary: function (buf) {
// STL binary format specification, as per http://en.wikipedia.org/wiki/STL_(file_format)
//
// UINT8[80] – Header
// UINT32 – Number of triangles
//
// foreach triangle
// REAL32[3] – Normal vector
// REAL32[3] – Vertex 1
// REAL32[3] – Vertex 2
// REAL32[3] – Vertex 3
// UINT16 – Attribute byte count
// end
//
var geometry = new THREE.Geometry();
var headerLength = 80;
var dataOffset = 84;
var faceLength = 12*4 + 2;
var le = true; // is little-endian // This might be processor dependent...
// var header = new Uint8Array(buf, 0, headerLength); // not presently used
var dvTriangleCount = new DataView(buf, headerLength, 4);
var numTriangles = dvTriangleCount.getUint32(0, le);
for (var i = 0; i < numTriangles; i++) {
var dv = new DataView(buf, dataOffset + i*faceLength, faceLength);
var normal = new THREE.Vector3( dv.getFloat32(0, le), dv.getFloat32(4, le), dv.getFloat32(8, le) );
for(var v = 3; v < 12; v+=3) {
geometry.vertices.push( new THREE.Vector3( dv.getFloat32(v*4, le), dv.getFloat32((v+1)*4, le), dv.getFloat32( (v+2)*4, le ) ) );
}
var len = geometry.vertices.length;
geometry.faces.push( new THREE.Face3( len - 3, len - 2, len - 1, normal ) );
}
geometry.computeCentroids();
geometry.computeBoundingSphere();
return geometry;
}
};
......@@ -212,10 +212,10 @@
for ( var i = 0, l = geometry.faces.length; i < l; i ++ ) {
var face = geometry.faces[ i ];
face.vertexColors[ 0 ] = new THREE.Color().setHSV( Math.random() * 0.2 + 0.5, Math.random() * 0.5, 1 );
face.vertexColors[ 1 ] = new THREE.Color().setHSV( Math.random() * 0.2 + 0.5, Math.random() * 0.5, 1 );
face.vertexColors[ 2 ] = new THREE.Color().setHSV( Math.random() * 0.2 + 0.5, Math.random() * 0.5, 1 );
face.vertexColors[ 3 ] = new THREE.Color().setHSV( Math.random() * 0.2 + 0.5, Math.random() * 0.5, 1 );
face.vertexColors[ 0 ] = new THREE.Color().setHSL( Math.random() * 0.2 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
face.vertexColors[ 1 ] = new THREE.Color().setHSL( Math.random() * 0.2 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
face.vertexColors[ 2 ] = new THREE.Color().setHSL( Math.random() * 0.2 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
face.vertexColors[ 3 ] = new THREE.Color().setHSL( Math.random() * 0.2 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
}
......@@ -231,10 +231,10 @@
for ( var i = 0, l = geometry.faces.length; i < l; i ++ ) {
var face = geometry.faces[ i ];
face.vertexColors[ 0 ] = new THREE.Color().setHSV( Math.random() * 0.2 + 0.5, Math.random() * 0.5, 1 );
face.vertexColors[ 1 ] = new THREE.Color().setHSV( Math.random() * 0.2 + 0.5, Math.random() * 0.5, 1 );
face.vertexColors[ 2 ] = new THREE.Color().setHSV( Math.random() * 0.2 + 0.5, Math.random() * 0.5, 1 );
face.vertexColors[ 3 ] = new THREE.Color().setHSV( Math.random() * 0.2 + 0.5, Math.random() * 0.5, 1 );
face.vertexColors[ 0 ] = new THREE.Color().setHSL( Math.random() * 0.2 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
face.vertexColors[ 1 ] = new THREE.Color().setHSL( Math.random() * 0.2 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
face.vertexColors[ 2 ] = new THREE.Color().setHSL( Math.random() * 0.2 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
face.vertexColors[ 3 ] = new THREE.Color().setHSL( Math.random() * 0.2 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
}
......@@ -248,7 +248,7 @@
mesh.position.z = Math.floor( Math.random() * 20 - 10 ) * 20;
scene.add( mesh );
material.color.setHSV( Math.random() * 0.2 + 0.5, Math.random() * 0.5, 1 );
material.color.setHSL( Math.random() * 0.2 + 0.5, 0.75, Math.random() * 0.25 + 0.75 );
objects.push( mesh );
......
......@@ -131,10 +131,6 @@
material_sphere1 = new THREE.MeshLambertMaterial( { color: 0xffaa00, shading: THREE.FlatShading } );
material_sphere2 = new THREE.MeshLambertMaterial( { color: 0xff2200, shading: THREE.FlatShading } );
var cube = new THREE.CubeGeometry( 5, 40, 5 );
var material_cube = new THREE.MeshLambertMaterial( { color: 0xffff00, shading: THREE.FlatShading } );
material_cube.color.setHSV( 0.1, 0.7, 1 );
// sound spheres
var s = 1;
......@@ -162,10 +158,9 @@
// ground
var material_wireframe = new THREE.MeshLambertMaterial( { color: 0xffaa00, wireframe: true, wireframeLinewidth: 1 } );
material_wireframe.color.setHSV( 0.1, 0.2, 0.5 );
var material = new THREE.MeshLambertMaterial( { color: 0x7f7566, wireframe: true, wireframeLinewidth: 1 } );
mesh = new THREE.Mesh( new THREE.PlaneGeometry( 1000, 1000, 100, 100 ), material_wireframe );
mesh = new THREE.Mesh( new THREE.PlaneGeometry( 1000, 1000, 100, 100 ), material );
mesh.position.y = 0.1;
mesh.rotation.x = - Math.PI / 2;
scene.add( mesh );
......@@ -210,8 +205,8 @@
controls.update( delta );
material_sphere1.color.setHSV( 0.0, 0.3 + 0.7 * ( 1 + Math.cos( time ) ) / 2, 1 );
material_sphere2.color.setHSV( 0.1, 0.3 + 0.7 * ( 1 + Math.sin( time ) ) / 2, 1 );
material_sphere1.color.setHSL( 0.0, 0.3 + 0.7 * ( 1 + Math.cos( time ) ) / 2, 0.5 );
material_sphere2.color.setHSL( 0.1, 0.3 + 0.7 * ( 1 + Math.sin( time ) ) / 2, 0.5 );
renderer.render( scene, camera );
......
此差异已折叠。
此差异已折叠。
......@@ -144,8 +144,7 @@
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0x000000, 500, 10000 );
scene.fog.color.setHSV( 0.6, 0.2, 1 );
scene.fog = new THREE.Fog( 0xcce0ff, 500, 10000 );
// camera
......@@ -160,8 +159,7 @@
scene.add( new THREE.AmbientLight( 0x666666 ) );
light = new THREE.DirectionalLight( 0xffffff, 1.75 );
light.color.setHSV( 0.6, 0.125, 1 );
light = new THREE.DirectionalLight( 0xdfebff, 1.75 );
light.position.set( 50, 200, 100 );
light.position.multiplyScalar( 1.3 );
......@@ -183,8 +181,7 @@
scene.add( light );
light = new THREE.DirectionalLight( 0xffffff, 0.35 );
light.color.setHSV( 0.3, 0.95, 1 );
light = new THREE.DirectionalLight( 0x3dff0c, 0.35 );
light.position.set( 0, -1, 0 );
scene.add( light );
......@@ -234,8 +231,7 @@
// ground
var initColor = new THREE.Color( 0x00ff00 );
initColor.setHSV( 0.25, 0.85, 0.5 );
var initColor = new THREE.Color( 0x497f13 );
var initTexture = THREE.ImageUtils.generateDataTexture( 1, 1, initColor );
var groundMaterial = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, map: initTexture } );
......
......@@ -77,8 +77,7 @@
camera.position.set( 0, 185, 2500 );
scene = new THREE.Scene();
scene.fog = new THREE.FogExp2( 0xffffff, 0.0003 );
scene.fog.color.setHSV( 0.1, 0.10, 1 );
scene.fog = new THREE.FogExp2( 0xfff4e5, 0.0003 );
light = new THREE.DirectionalLight( 0xffffff, 1.5 );
light.position.set( 0, 1, 1 ).normalize();
......@@ -86,9 +85,8 @@
var planeSimple = new THREE.PlaneGeometry( 200, 300 );
var planeTesselated = new THREE.PlaneGeometry( 100, 300, 25, 40 );
var matWire = new THREE.MeshBasicMaterial( { color :0x110000, wireframe: true, wireframeLinewidth: 2 } );
var matSolid = new THREE.MeshBasicMaterial( { color :0x330000 } );
matSolid.color.setHSV( 0.1, 0.75, 1 );
var matWire = new THREE.MeshBasicMaterial( { color: 0x110000, wireframe: true, wireframeLinewidth: 2 } );
var matSolid = new THREE.MeshBasicMaterial( { color: 0xffb23f } );
floor = new THREE.Mesh( planeSimple, matSolid );
floor.position.y = -10;
......
......@@ -82,20 +82,12 @@
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0xffffff, 2000, 10000 );
scene.fog.color.setHSV( 0.6, 0, 1 );
scene.add( camera );
// GROUND
/*
var groundTexture = THREE.ImageUtils.loadTexture( "textures/terrain/grasslight-big.jpg" );
groundTexture.wrapS = groundTexture.wrapT = THREE.RepeatWrapping;
groundTexture.repeat.set( 16, 16 );
groundTexture.anisotropy = 4;
*/
var groundMaterial = new THREE.MeshPhongMaterial( { /*map: groundTexture,*/ emissive: 0xbbbbbb } );
var groundMaterial = new THREE.MeshPhongMaterial( { emissive: 0xbbbbbb } );
var planeGeometry = new THREE.PlaneGeometry( 16000, 16000 );
var ground = new THREE.Mesh( planeGeometry, groundMaterial );
......@@ -112,10 +104,8 @@
scene.add( ambient );
var light = new THREE.DirectionalLight( 0xffffff, 1.6 );
light.position.set( 0, 140, 500 );
light.position.multiplyScalar( 1.1 );
light.color.setHSV( 0.6, 0.075, 1 );
var light = new THREE.DirectionalLight( 0xebf3ff, 1.6 );
light.position.set( 0, 140, 500 ).multiplyScalar( 1.1 );
scene.add( light );
light.castShadow = true;
......@@ -135,9 +125,8 @@
//
var light = new THREE.DirectionalLight( 0xffffff, 1 );
var light = new THREE.DirectionalLight( 0x497f13, 1 );
light.position.set( 0, -1, 0 );
light.color.setHSV( 0.25, 0.85, 0.5 );
scene.add( light );
// RENDERER
......@@ -233,9 +222,9 @@
m.skinning = true;
m.morphTargets = true;
m.specular.setHSV( 0, 0, 0.1 );
m.specular.setHSL( 0, 0, 0.1 );
m.color.setHSV( 0.6, 0, 0.6 );
m.color.setHSL( 0.6, 0, 0.6 );
m.ambient.copy( m.color );
//m.map = map;
......
......@@ -110,7 +110,6 @@
var vy = ( y / n ) + 0.5;
var vz = ( z / n ) + 0.5;
//color.setHSV( 0.5 + 0.5 * vx, 0.25 + 0.75 * vy, 0.25 + 0.75 * vz );
color.setRGB( vx, vy, vz );
colors[ i ] = color.r;
......
......@@ -140,7 +140,7 @@
var vertices = sphere.geometry.vertices;
var values = attributes.displacement.value;
for( var v = 0; v < vertices.length; v++ ) {
for ( var v = 0; v < vertices.length; v++ ) {
values[ v ] = 0;
noise[ v ] = Math.random() * 5;
......@@ -191,9 +191,9 @@
sphere.rotation.y = sphere.rotation.z = 0.01 * time;
uniforms.amplitude.value = 2.5 * Math.sin( sphere.rotation.y * 0.125 );
THREE.ColorUtils.adjustHSV( uniforms.color.value, 0.0005, 0, 0 );
uniforms.color.value.offsetHSL( 0.0005, 0, 0 );
for( var i = 0; i < attributes.displacement.value.length; i ++ ) {
for ( var i = 0; i < attributes.displacement.value.length; i ++ ) {
attributes.displacement.value[ i ] = Math.sin( 0.1 * i + time );
......
......@@ -174,10 +174,10 @@
for( var v = 0; v < vertices.length; v ++ ) {
displacement[ v ] = new THREE.Vector3( 0, 0, 0 );
displacement[ v ] = new THREE.Vector3();
color[ v ] = new THREE.Color( 0xffffff );
color[ v ].setHSV( v / vertices.length, 0.9, 0.9 );
color[ v ].setHSL( v / vertices.length, 0.5, 0.5 );
}
......@@ -227,7 +227,7 @@
object.rotation.y = 0.25 * time;
uniforms.amplitude.value = 0.5 * Math.sin( 0.5 * time );
THREE.ColorUtils.adjustHSV( uniforms.color.value, 0.0005, 0, 0 );
uniforms.color.value.offsetHSL( 0.0005, 0, 0 );
var nx, ny, nz, value;
......
......@@ -142,14 +142,12 @@
function addLight( h, s, v, x, y, z ) {
var light = new THREE.PointLight( 0xffffff, 1.5, 4500 );
light.color.setHSV( h, s, v );
light.position.set( x, y, z );
scene.add( light );
light.color.setHSV( h, s, v );
var flareColor = new THREE.Color( 0xffffff );
flareColor.copy( light.color );
THREE.ColorUtils.adjustHSV( flareColor, 0, -0.5, 0.5 );
flareColor.setHSV( h, s - 0.5, v + 0.5 );
var lensFlare = new THREE.LensFlare( textureFlare0, 700, 0.0, THREE.AdditiveBlending, flareColor );
......
......@@ -258,7 +258,6 @@
for ( var i = 0; i < colorMap.colors.length; i ++ ) {
geometry.faces[ i ].color = colorMap.colors[ i ];
THREE.ColorUtils.adjustHSV( geometry.faces[ i ].color, 0, -0.1, 0 );
}
......
......@@ -137,15 +137,11 @@
light.position.multiplyScalar( 30 );
scene.add( light );
THREE.ColorUtils.adjustHSV( light.color, 0, -0.75, 0 );
var light = new THREE.PointLight( 0xffffff, 0.75 );
light.position.set( -12, 4.6, 2.4 );
light.position.multiplyScalar( 30 );
scene.add( light );
THREE.ColorUtils.adjustHSV( light.color, 0, -0.5, 0 );
scene.add( new THREE.AmbientLight( 0x050505 ) );
// RENDERER
......
......@@ -24,12 +24,22 @@
}
a { color: skyblue }
.button { background:#999; color:#eee; padding:0.2em 0.5em; cursor:pointer }
.highlight { background:orange; color:#fff; }
span {
display: inline-block;
width: 60px;
float: left;
text-align: center;
}
</style>
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> -
STL loader test by <a href="https://github.com/aleeper">aleeper</a>
STL loader test by <a href="https://github.com/aleeper">aleeper</a>. PR2 head from <a href="http://www.ros.org/wiki/pr2_description">www.ros.org</a>
</div>
<script src="../build/three.min.js"></script>
......@@ -45,7 +55,7 @@
var container, stats;
var camera, scene, renderer, objects;
var camera, cameraTarget, scene, renderer;
init();
animate();
......@@ -56,33 +66,15 @@
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 15 );
camera.position.set( 3, 0.5, 3 );
camera.position.set( 3, 0.15, 3 );
cameraTarget = new THREE.Vector3( 0, -0.25, 0 );
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0xffffff, 2, 15 );
scene.fog.color.setHSV( 0.06, 0.2, 0.45 );
// Grid
var size = 20, step = 0.25;
var geometry = new THREE.Geometry();
var material = new THREE.LineBasicMaterial( { color: 0x000000 } );
for ( var i = - size; i <= size; i += step ) {
geometry.vertices.push( new THREE.Vector3( - size, - 0.04, i ) );
geometry.vertices.push( new THREE.Vector3( size, - 0.04, i ) );
geometry.vertices.push( new THREE.Vector3( i, - 0.04, - size ) );
geometry.vertices.push( new THREE.Vector3( i, - 0.04, size ) );
}
var line = new THREE.Line( geometry, material, THREE.LinePieces );
line.position.y = -0.46;
scene.add( line );
// Ground
......@@ -93,7 +85,8 @@
plane.receiveShadow = true;
// Object
// ASCII file
var loader = new THREE.STLLoader();
loader.addEventListener( 'load', function ( event ) {
......@@ -102,13 +95,59 @@
var material = new THREE.MeshPhongMaterial( { ambient: 0xff5533, color: 0xff5533, specular: 0x111111, shininess: 200 } );
var mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 0, - 0.25, 0.6 );
mesh.rotation.set( 0, - Math.PI / 2, 0 );
mesh.scale.set( 0.5, 0.5, 0.5 );
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add( mesh );
} );
loader.load( './models/stl/slotted_disk.stl' );
loader.load( './models/stl/ascii/slotted_disk.stl' );
// Binary files
var material = new THREE.MeshPhongMaterial( { ambient: 0x555555, color: 0xAAAAAA, specular: 0x111111, shininess: 200 } );
var loader = new THREE.STLLoader();
loader.addEventListener( 'load', function ( event ) {
var geometry = event.content;
var mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 0, - 0.37, - 0.6 );
mesh.rotation.set( - Math.PI / 2, 0, 0 );
mesh.scale.set( 2, 2, 2 );
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add( mesh );
} );
loader.load( './models/stl/binary/pr2_head_pan.stl' );
var loader = new THREE.STLLoader();
loader.addEventListener( 'load', function ( event ) {
var geometry = event.content;
var mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 0.136, - 0.37, - 0.6 );
mesh.rotation.set( - Math.PI / 2, 0.3, 0 );
mesh.scale.set( 2, 2, 2 );
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add( mesh );
} );
loader.load( './models/stl/binary/pr2_head_tilt.stl' );
// Lights
......@@ -119,7 +158,7 @@
// renderer
renderer = new THREE.WebGLRenderer( { antialias: true, clearColor: 0x111111, clearAlpha: 1, alpha: false } );
renderer = new THREE.WebGLRenderer( { antialias: true, alpha: false } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( scene.fog.color, 1 );
......@@ -153,7 +192,7 @@
scene.add( directionalLight );
directionalLight.castShadow = true;
//directionalLight.shadowCameraVisible = true;
// directionalLight.shadowCameraVisible = true;
var d = 1;
directionalLight.shadowCameraLeft = -d;
......@@ -164,8 +203,8 @@
directionalLight.shadowCameraNear = 1;
directionalLight.shadowCameraFar = 4;
directionalLight.shadowMapWidth = 2048;
directionalLight.shadowMapHeight = 2048;
directionalLight.shadowMapWidth = 1024;
directionalLight.shadowMapHeight = 1024;
directionalLight.shadowBias = -0.005;
directionalLight.shadowDarkness = 0.15;
......@@ -181,8 +220,6 @@
}
//
function animate() {
requestAnimationFrame( animate );
......@@ -196,10 +233,10 @@
var timer = Date.now() * 0.0005;
camera.position.x = Math.cos( timer ) * 5;
camera.position.z = Math.sin( timer ) * 5;
camera.position.x = Math.cos( timer ) * 3;
camera.position.z = Math.sin( timer ) * 3;
camera.lookAt( scene.position );
camera.lookAt( cameraTarget );
renderer.render( scene, camera );
......
......@@ -178,11 +178,9 @@
// POSTPROCESSING
var renderModelUV = new THREE.RenderPass( scene, camera, materialUV, new THREE.Color( 0xca9c8d ) );
var renderModelUV = new THREE.RenderPass( scene, camera, materialUV, new THREE.Color( 0x575757 ) );
var renderModel = new THREE.RenderPass( scene, camera );
THREE.ColorUtils.adjustHSV( renderModelUV.clearColor, 0, -0.5, -0.45 );
var effectCopy = new THREE.ShaderPass( THREE.CopyShader );
var effectBloom1 = new THREE.BloomPass( 1, 15, 2, 512 );
......
......@@ -157,7 +157,7 @@
for ( var i = 0; i < colorMap.colors.length; i ++ ) {
geometry.faces[ i ].color = colorMap.colors[ i ];
THREE.ColorUtils.adjustHSV( geometry.faces[ i ].color, 0, 0.125, 0 );
geometry.faces[ i ].color.offsetHSL( 0, 0.3, 0 );
}
......
......@@ -86,11 +86,11 @@
}
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 ],
parameters = [ [ [1.0, 0.2, 0.5], sprite2, 20 ],
[ [0.95, 0.1, 0.5], sprite3, 15 ],
[ [0.90, 0.05, 0.5], sprite1, 10 ],
[ [0.85, 0, 0.5], sprite5, 8 ],
[ [0.80, 0, 0.5], sprite4, 5 ],
];
for ( i = 0; i < parameters.length; i ++ ) {
......@@ -100,7 +100,7 @@
size = parameters[i][2];
materials[i] = new THREE.ParticleBasicMaterial( { size: size, map: sprite, blending: THREE.AdditiveBlending, depthTest: false, transparent : true } );
materials[i].color.setHSV( color[0], color[1], color[2] );
materials[i].color.setHSL( color[0], color[1], color[2] );
particles = new THREE.ParticleSystem( geometry, materials[i] );
......@@ -213,7 +213,7 @@
color = parameters[i][0];
h = ( 360 * ( color[0] + time ) % 360 ) / 360;
materials[i].color.setHSV( h, color[1], color[2] );
materials[i].color.setHSL( h, color[1], color[2] );
}
......
......@@ -292,7 +292,7 @@
for( i = 0; i < nobjects; i ++ ) {
h = ( 360 * ( i / nobjects + time ) % 360 ) / 360;
materials[ i ].color.setHSV( h, 1, 1 );
materials[ i ].color.setHSL( h, 1, 0.5 );
}
......
......@@ -93,10 +93,6 @@
//
// todo - try with fog
// scene.fog = new THREE.Fog( 0xffaa55, 1000, FAR );
// THREE.ColorUtils.adjustHSV( scene.fog.color, 0.02, -0.15, -0.65 );
materialDepth = new THREE.MeshDepthMaterial();
var materialScene = new THREE.MeshBasicMaterial( { color: 0x000000, shading: THREE.FlatShading } );
......
......@@ -56,7 +56,7 @@
if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
var container, stats;
var camera, scene, renderer, ribbon, geometry, geometry2, materials = [], ribbons = [],
var camera, scene, renderer, ribbon, geometry, geometry2, ribbons = [],
parameters, i, i2, h, color, x, y, z, z2, s, n, n2, nribbons, grid;
var mouseX = 0, mouseY = 0;
......@@ -108,7 +108,7 @@
if( i2 % 4 <= 2 ) h -= 0.15;
color = new THREE.Color( 0xffffff );
color.setHSV( 0.1 , 0, h );
color.setHSL( 0.1, 0, h );
geometry.colors.push( color );
geometry2.colors.push( color );
......@@ -125,9 +125,9 @@
for ( i = 0; i < xgrid; i ++ )
for ( j = 0; j < ygrid; j ++ ) {
materials[ c ] = new THREE.MeshBasicMaterial( { color: 0xffffff, vertexColors: true, side: THREE.DoubleSide } );
var material = new THREE.MeshBasicMaterial( { color: 0xffffff, vertexColors: true, side: THREE.DoubleSide } );
ribbon = new THREE.Ribbon( i % 2 ? geometry : geometry2, materials[ c ] );
ribbon = new THREE.Ribbon( i % 2 ? geometry : geometry2, material );
ribbon.rotation.x = 0;
ribbon.rotation.y = Math.PI / 2;
ribbon.rotation.z = Math.PI;
......@@ -135,9 +135,8 @@
x = 40 * ( i - xgrid/2 );
y = 40 * ( j - ygrid/2 );
z = 0;
ribbon.position.set( x, y, z );
materials[c].color.setHSV( i / xgrid, 0.3 + 0.7 * j / ygrid, 1 );
ribbon.position.set( x, y, z );
ribbon.matrixAutoUpdate = false;
......@@ -295,10 +294,10 @@
geometry.verticesNeedUpdate = true;
geometry2.verticesNeedUpdate = true;
for( i = 0; i < nribbons; i++ ) {
for ( i = 0; i < nribbons; i++ ) {
h = ( 360 * ( i / nribbons + time ) % 360 ) / 360;
materials[ i ].color.setHSV( h, 0.5 + 0.5 * ( i % 20 / 20 ), 1 );
ribbons[ i ].material.color.setHSL( h, ( i % 20 / 20 ) * 0.3 + 0.7, 0.6 );
}
......
......@@ -125,11 +125,6 @@
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0x00aaff, 1000, FAR );
if ( DAY )
scene.fog.color.setHSV( 0.13, 0.25, 0.99 );
else
scene.fog.color.setHSV( 0.13, 0.25, 0.1 );
// CUBE CAMERA
cubeCamera = new THREE.CubeCamera( 1, FAR, 128 );
......@@ -187,7 +182,6 @@
// GROUND
var groundMaterial = new THREE.MeshPhongMaterial( { shininess: 80, ambient: 0x444444, color: 0xffffff, specular: 0xffffff, map: textureSquares } );
//groundMaterial.color.setHSV( 0.1, 0.1, 0.99 );
var planeGeometry = new THREE.PlaneGeometry( 100, 100 );
......@@ -231,8 +225,6 @@
function addObjectColor( geometry, color, x, y, z, ry ) {
var material = new THREE.MeshPhongMaterial( { color: 0xffffff, ambient: 0x444444 } );
//var material = new THREE.MeshPhongMaterial( { color: color, ambient: color } );
//THREE.ColorUtils.adjustHSV( material.ambient, 0, 0, -0.5 );
return addObject( geometry, material, x, y, z, ry );
......@@ -242,7 +234,7 @@
var tmpMesh = new THREE.Mesh( geometry, material );
THREE.ColorUtils.adjustHSV( tmpMesh.material.color, 0.1, -0.1, 0 );
tmpMesh.material.color.offsetHSL( 0.1, -0.1, 0 );
tmpMesh.position.set( x, y, z );
......@@ -317,8 +309,7 @@
}
ambientLight = new THREE.AmbientLight( 0xffffff );
ambientLight.color.setHSV( 0.1, 0.9, 0.25 );
ambientLight = new THREE.AmbientLight( 0x3f2806 );
scene.add( ambientLight );
pointLight = new THREE.PointLight( 0xffaa00, pointIntensity, 5000 );
......@@ -345,8 +336,6 @@
renderer = new THREE.WebGLRenderer( { clearColor: 0x00aaff, clearAlpha: 1, antialias: false } );
renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT );
if ( scene.fog )
renderer.setClearColor( scene.fog.color, 1 );
renderer.domElement.style.position = "absolute";
......@@ -442,7 +431,7 @@
tweenDirection = -1;
tweenDay = new TWEEN.Tween( parameters ).to( { control: 100 }, 1000 ).easing( TWEEN.Easing.Exponential.Out );
tweenDay = new TWEEN.Tween( parameters ).to( { control: 1 }, 1000 ).easing( TWEEN.Easing.Exponential.Out );
tweenNight = new TWEEN.Tween( parameters ).to( { control: 0 }, 1000 ).easing( TWEEN.Easing.Exponential.Out );
// GUI
......@@ -565,13 +554,13 @@
if ( morph ) morph.updateAnimation( delta );
scene.fog.color.setHSV( 0.13, 0.25, THREE.Math.mapLinear( parameters.control, 0, 100, 0.1, 0.99 ) );
scene.fog.color.setHSL( 0.63, 0.05, parameters.control );
renderer.setClearColor( scene.fog.color, 1 );
sunLight.intensity = THREE.Math.mapLinear( parameters.control, 0, 100, 0.3, 1 );
pointLight.intensity = THREE.Math.mapLinear( parameters.control, 0, 100, 1, 0.5 );
sunLight.intensity = parameters.control * 0.7 + 0.3;
pointLight.intensity = - parameters.control * 0.5 + 1;
pointLight.color.setHSV( 0.1, THREE.Math.mapLinear( parameters.control, 0, 100, 0.99, 0 ), 0.9 );
pointLight.color.setHSL( 0.1, 0.75, parameters.control * 0.5 + 0.5 );
sunLight.shadowDarkness = shadowConfig.shadowDarkness * sunLight.intensity;
......
......@@ -96,8 +96,7 @@
// SCENE
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0xffaa55, 1000, FAR );
THREE.ColorUtils.adjustHSV( scene.fog.color, 0.02, -0.15, -0.65 );
scene.fog = new THREE.Fog( 0x59472b, 1000, FAR );
// LIGHTS
......@@ -200,7 +199,6 @@
var geometry = new THREE.PlaneGeometry( 100, 100 );
var planeMaterial = new THREE.MeshPhongMaterial( { color: 0xffdd99 } );
THREE.ColorUtils.adjustHSV( planeMaterial.color, 0, 0, 0.9 );
planeMaterial.ambient = planeMaterial.color;
var ground = new THREE.Mesh( geometry, planeMaterial );
......@@ -276,7 +274,7 @@
if ( fudgeColor ) {
THREE.ColorUtils.adjustHSV( material.color, 0, 0.5 - Math.random(), 0.5 - Math.random() );
material.color.offsetHSL( 0, Math.random() * 0.5 - 0.25, Math.random() * 0.5 - 0.25 );
material.ambient = material.color;
}
......
......@@ -96,8 +96,7 @@
// SCENE
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0xffaa55, 1000, FAR );
THREE.ColorUtils.adjustHSV( scene.fog.color, 0.02, -0.15, -0.65 );
scene.fog = new THREE.Fog( 0x59472b, 1000, FAR );
// LIGHTS
......@@ -200,7 +199,6 @@
var geometry = new THREE.PlaneGeometry( 100, 100 );
var planeMaterial = new THREE.MeshPhongMaterial( { color: 0xffdd99 } );
THREE.ColorUtils.adjustHSV( planeMaterial.color, 0, 0, 0.9 );
planeMaterial.ambient = planeMaterial.color;
var ground = new THREE.Mesh( geometry, planeMaterial );
......@@ -276,7 +274,7 @@
if ( fudgeColor ) {
THREE.ColorUtils.adjustHSV( material.color, 0, 0.5 - Math.random(), 0.5 - Math.random() );
material.color.offsetHSL( 0, Math.random() * 0.5 - 0.25, Math.random() * 0.5 - 0.25 );
material.ambient = material.color;
}
......
......@@ -78,7 +78,7 @@
} else {
material = materialC.clone();
material.color.setHSV( 0.5 * Math.random(), 0.8, 0.9 );
material.color.setHSL( 0.5 * Math.random(), 0.75, 0.5 );
material.uvScale.set( 2, 2 );
material.uvOffset.set( -0.5, -0.5 );
......
/**
* @author alteredq / http://alteredqualia.com/
*/
THREE.ColorUtils = {
adjustHSV : function ( color, h, s, v ) {
var hsv = THREE.ColorUtils.__hsv;
color.getHSV( hsv );
hsv.h = THREE.Math.clamp( hsv.h + h, 0, 1 );
hsv.s = THREE.Math.clamp( hsv.s + s, 0, 1 );
hsv.v = THREE.Math.clamp( hsv.v + v, 0, 1 );
color.setHSV( hsv.h, hsv.s, hsv.v );
}
};
THREE.ColorUtils.__hsv = { h: 0, s: 0, v: 0 };
\ No newline at end of file
......@@ -54,60 +54,38 @@ THREE.extend( THREE.Color.prototype, {
setHSV: function ( h, s, v ) {
// based on MochiKit implementation by Bob Ippolito
// h,s,v ranges are < 0.0 - 1.0 >
console.log( 'DEPRECATED: Color\'s .setHSV() will be removed. Use .setHSL( h, s, l ) instead.' );
return this.setHSL(h,s*v/((h=(2-s)*v)<1?h:2-h),h/2); // https://gist.github.com/xpansive/1337890
var i, f, p, q, t;
if ( v === 0 ) {
this.r = this.g = this.b = 0;
} else {
i = Math.floor( h * 6 );
f = ( h * 6 ) - i;
p = v * ( 1 - s );
q = v * ( 1 - ( s * f ) );
t = v * ( 1 - ( s * ( 1 - f ) ) );
if ( i === 0 ) {
this.r = v;
this.g = t;
this.b = p;
} else if ( i === 1 ) {
},
this.r = q;
this.g = v;
this.b = p;
setHSL: function ( h, s, l ) {
} else if ( i === 2 ) {
// h,s,l ranges are in 0.0 - 1.0
this.r = p;
this.g = v;
this.b = t;
if ( s === 0 ) {
} else if ( i === 3 ) {
this.r = this.g = this.b = l;
this.r = p;
this.g = q;
this.b = v;
} else {
} else if ( i === 4 ) {
var hue2rgb = function ( p, q, t ) {
this.r = t;
this.g = p;
this.b = v;
if ( t < 0 ) t += 1;
if ( t > 1 ) t -= 1;
if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
if ( t < 1 / 2 ) return q;
if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
return p;
} else if ( i === 5 ) {
};
this.r = v;
this.g = p;
this.b = q;
var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
var q = ( 2 * l ) - p;
}
this.r = hue2rgb( q, p, h + 1 / 3 );
this.g = hue2rgb( q, p, h );
this.b = hue2rgb( q, p, h - 1 / 3 );
}
......@@ -246,78 +224,70 @@ THREE.extend( THREE.Color.prototype, {
},
getStyle: function () {
getHSL: function () {
return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
var hsl = { h: 0, s: 0, l: 0 };
},
getHSV: function ( hsv ) {
return function () {
// based on MochiKit implementation by Bob Ippolito
// h,s,v ranges are < 0.0 - 1.0 >
// h,s,l ranges are in 0.0 - 1.0
var r = this.r;
var g = this.g;
var b = this.b;
var r = this.r, g = this.g, b = this.b;
var max = Math.max( Math.max( r, g ), b );
var min = Math.min( Math.min( r, g ), b );
var max = Math.max( r, g, b );
var min = Math.min( r, g, b );
var hue;
var saturation;
var value = max;
var hue, saturation;
var lightness = ( min + max ) / 2.0;
if ( min === max ) {
if ( min === max ) {
hue = 0;
saturation = 0;
hue = 0;
saturation = 0;
} else {
} else {
var delta = ( max - min );
saturation = delta / max;
var delta = max - min;
if ( r === max ) {
saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
hue = ( g - b ) / delta;
switch ( max ) {
} else if ( g === max ) {
case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
case g: hue = ( b - r ) / delta + 2; break;
case b: hue = ( r - g ) / delta + 4; break;
hue = 2 + ( ( b - r ) / delta );
}
} else {
hue /= 6;
hue = 4 + ( ( r - g ) / delta );
}
hue /= 6;
hsl.h = hue;
hsl.s = saturation;
hsl.l = lightness;
if ( hue < 0 ) {
return hsl;
hue += 1;
};
}
}(),
if ( hue > 1 ) {
getStyle: function () {
hue -= 1;
return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
}
},
}
offsetHSL: function ( h, s, l ) {
if ( hsv === undefined ) {
var hsl = this.getHSL();
hsv = { h: 0, s: 0, v: 0 };
hsl.h += h; hsl.s += s; hsl.l += l;
}
this.setHSL( hsl.h, hsl.s, hsl.l );
hsv.h = hue;
hsv.s = saturation;
hsv.v = value;
return hsv;
return this;
},
......
......@@ -157,29 +157,26 @@ test( "getHexString", function(){
});
test( "getStyle", function(){
var c = new THREE.Color('plum');
var c = new THREE.Color('plum');
var res = c.getStyle();
ok( res == 'rgb(221,160,221)', "style: " + res );
});
test( "getHSV", function(){
var c = new THREE.Color('maroon');
var hsv = c.getHSV();
test( "getHSL", function () {
var c = new THREE.Color( 0x80ffff );
var hsl = c.getHSL();
ok( hsv.h == 0, "hue: " + hsv.h );
ok( hsv.s == 1, "saturation: " + hsv.s );
ok( (Math.round(parseFloat(hsv.v)*100)/100) == 0.5,
"value: " + hsv.v );
ok( hsl.h == 0.5, "hue: " + hsl.h );
ok( hsl.s == 1.0, "saturation: " + hsl.s );
ok( (Math.round(parseFloat(hsl.l)*100)/100) == 0.75, "lightness: " + hsl.l );
});
test( "setHSV", function(){
var c = new THREE.Color();
c.setHSV(0, 1, 1);
var hsv = c.getHSV();
ok( hsv.h == 0, "hue: " + hsv.h );
ok( hsv.s == 1, "saturation: " + hsv.s );
ok( hsv.v == 1, "value: " + hsv.v );
});
// xxx todo more hsv tests
test( "setHSL", function () {
var c = new THREE.Color();
c.setHSL(0.75, 1.0, 0.25);
var hsl = c.getHSL();
ok( hsl.h == 0.75, "hue: " + hsl.h );
ok( hsl.s == 1.00, "saturation: " + hsl.s );
ok( hsl.l == 0.25, "lightness: " + hsl.l );
});
[
"src/extras/ColorUtils.js",
"src/extras/GeometryUtils.js",
"src/extras/ImageUtils.js",
"src/extras/SceneUtils.js",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册