|
@@ -28,19 +28,6 @@ const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua'
|
|
|
const _hslA = { h: 0, s: 0, l: 0 };
|
|
|
const _hslB = { h: 0, s: 0, l: 0 };
|
|
|
|
|
|
-function Color( r, g, b ) {
|
|
|
-
|
|
|
- if ( g === undefined && b === undefined ) {
|
|
|
-
|
|
|
- // r is THREE.Color, hex or string
|
|
|
- return this.set( r );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return this.setRGB( r, g, b );
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
function hue2rgb( p, q, t ) {
|
|
|
|
|
|
if ( t < 0 ) t += 1;
|
|
@@ -64,13 +51,22 @@ function LinearToSRGB( c ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
-Object.assign( Color.prototype, {
|
|
|
+class Color {
|
|
|
+
|
|
|
+ constructor( r, g, b ) {
|
|
|
+
|
|
|
+ if ( g === undefined && b === undefined ) {
|
|
|
|
|
|
- isColor: true,
|
|
|
+ // r is THREE.Color, hex or string
|
|
|
+ return this.set( r );
|
|
|
|
|
|
- r: 1, g: 1, b: 1,
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.setRGB( r, g, b );
|
|
|
|
|
|
- set: function ( value ) {
|
|
|
+ }
|
|
|
+
|
|
|
+ set( value ) {
|
|
|
|
|
|
if ( value && value.isColor ) {
|
|
|
|
|
@@ -88,9 +84,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setScalar: function ( scalar ) {
|
|
|
+ setScalar( scalar ) {
|
|
|
|
|
|
this.r = scalar;
|
|
|
this.g = scalar;
|
|
@@ -98,9 +94,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setHex: function ( hex ) {
|
|
|
+ setHex( hex ) {
|
|
|
|
|
|
hex = Math.floor( hex );
|
|
|
|
|
@@ -110,9 +106,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setRGB: function ( r, g, b ) {
|
|
|
+ setRGB( r, g, b ) {
|
|
|
|
|
|
this.r = r;
|
|
|
this.g = g;
|
|
@@ -120,9 +116,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setHSL: function ( h, s, l ) {
|
|
|
+ setHSL( h, s, l ) {
|
|
|
|
|
|
// h,s,l ranges are in 0.0 - 1.0
|
|
|
h = MathUtils.euclideanModulo( h, 1 );
|
|
@@ -146,9 +142,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setStyle: function ( style ) {
|
|
|
+ setStyle( style ) {
|
|
|
|
|
|
function handleAlpha( string ) {
|
|
|
|
|
@@ -263,9 +259,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setColorName: function ( style ) {
|
|
|
+ setColorName( style ) {
|
|
|
|
|
|
// color keywords
|
|
|
const hex = _colorKeywords[ style ];
|
|
@@ -284,15 +280,15 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- clone: function () {
|
|
|
+ clone() {
|
|
|
|
|
|
return new this.constructor( this.r, this.g, this.b );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- copy: function ( color ) {
|
|
|
+ copy( color ) {
|
|
|
|
|
|
this.r = color.r;
|
|
|
this.g = color.g;
|
|
@@ -300,9 +296,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- copyGammaToLinear: function ( color, gammaFactor ) {
|
|
|
+ copyGammaToLinear( color, gammaFactor ) {
|
|
|
|
|
|
if ( gammaFactor === undefined ) gammaFactor = 2.0;
|
|
|
|
|
@@ -312,9 +308,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- copyLinearToGamma: function ( color, gammaFactor ) {
|
|
|
+ copyLinearToGamma( color, gammaFactor ) {
|
|
|
|
|
|
if ( gammaFactor === undefined ) gammaFactor = 2.0;
|
|
|
|
|
@@ -326,25 +322,25 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- convertGammaToLinear: function ( gammaFactor ) {
|
|
|
+ convertGammaToLinear( gammaFactor ) {
|
|
|
|
|
|
this.copyGammaToLinear( this, gammaFactor );
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- convertLinearToGamma: function ( gammaFactor ) {
|
|
|
+ convertLinearToGamma( gammaFactor ) {
|
|
|
|
|
|
this.copyLinearToGamma( this, gammaFactor );
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- copySRGBToLinear: function ( color ) {
|
|
|
+ copySRGBToLinear( color ) {
|
|
|
|
|
|
this.r = SRGBToLinear( color.r );
|
|
|
this.g = SRGBToLinear( color.g );
|
|
@@ -352,9 +348,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- copyLinearToSRGB: function ( color ) {
|
|
|
+ copyLinearToSRGB( color ) {
|
|
|
|
|
|
this.r = LinearToSRGB( color.r );
|
|
|
this.g = LinearToSRGB( color.g );
|
|
@@ -362,37 +358,37 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- convertSRGBToLinear: function () {
|
|
|
+ convertSRGBToLinear() {
|
|
|
|
|
|
this.copySRGBToLinear( this );
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- convertLinearToSRGB: function () {
|
|
|
+ convertLinearToSRGB() {
|
|
|
|
|
|
this.copyLinearToSRGB( this );
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getHex: function () {
|
|
|
+ getHex() {
|
|
|
|
|
|
return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getHexString: function () {
|
|
|
+ getHexString() {
|
|
|
|
|
|
return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getHSL: function ( target ) {
|
|
|
+ getHSL( target ) {
|
|
|
|
|
|
// h,s,l ranges are in 0.0 - 1.0
|
|
|
|
|
@@ -440,15 +436,15 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return target;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getStyle: function () {
|
|
|
+ getStyle() {
|
|
|
|
|
|
return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- offsetHSL: function ( h, s, l ) {
|
|
|
+ offsetHSL( h, s, l ) {
|
|
|
|
|
|
this.getHSL( _hslA );
|
|
|
|
|
@@ -458,9 +454,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- add: function ( color ) {
|
|
|
+ add( color ) {
|
|
|
|
|
|
this.r += color.r;
|
|
|
this.g += color.g;
|
|
@@ -468,9 +464,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- addColors: function ( color1, color2 ) {
|
|
|
+ addColors( color1, color2 ) {
|
|
|
|
|
|
this.r = color1.r + color2.r;
|
|
|
this.g = color1.g + color2.g;
|
|
@@ -478,9 +474,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- addScalar: function ( s ) {
|
|
|
+ addScalar( s ) {
|
|
|
|
|
|
this.r += s;
|
|
|
this.g += s;
|
|
@@ -488,9 +484,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- sub: function ( color ) {
|
|
|
+ sub( color ) {
|
|
|
|
|
|
this.r = Math.max( 0, this.r - color.r );
|
|
|
this.g = Math.max( 0, this.g - color.g );
|
|
@@ -498,9 +494,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- multiply: function ( color ) {
|
|
|
+ multiply( color ) {
|
|
|
|
|
|
this.r *= color.r;
|
|
|
this.g *= color.g;
|
|
@@ -508,9 +504,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- multiplyScalar: function ( s ) {
|
|
|
+ multiplyScalar( s ) {
|
|
|
|
|
|
this.r *= s;
|
|
|
this.g *= s;
|
|
@@ -518,9 +514,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- lerp: function ( color, alpha ) {
|
|
|
+ lerp( color, alpha ) {
|
|
|
|
|
|
this.r += ( color.r - this.r ) * alpha;
|
|
|
this.g += ( color.g - this.g ) * alpha;
|
|
@@ -528,9 +524,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- lerpHSL: function ( color, alpha ) {
|
|
|
+ lerpHSL( color, alpha ) {
|
|
|
|
|
|
this.getHSL( _hslA );
|
|
|
color.getHSL( _hslB );
|
|
@@ -543,15 +539,15 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- equals: function ( c ) {
|
|
|
+ equals( c ) {
|
|
|
|
|
|
return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- fromArray: function ( array, offset ) {
|
|
|
+ fromArray( array, offset ) {
|
|
|
|
|
|
if ( offset === undefined ) offset = 0;
|
|
|
|
|
@@ -561,9 +557,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- toArray: function ( array, offset ) {
|
|
|
+ toArray( array, offset ) {
|
|
|
|
|
|
if ( array === undefined ) array = [];
|
|
|
if ( offset === undefined ) offset = 0;
|
|
@@ -574,9 +570,9 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return array;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- fromBufferAttribute: function ( attribute, index ) {
|
|
|
+ fromBufferAttribute( attribute, index ) {
|
|
|
|
|
|
this.r = attribute.getX( index );
|
|
|
this.g = attribute.getY( index );
|
|
@@ -594,16 +590,20 @@ Object.assign( Color.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- toJSON: function () {
|
|
|
+ toJSON() {
|
|
|
|
|
|
return this.getHex();
|
|
|
|
|
|
}
|
|
|
|
|
|
-} );
|
|
|
+}
|
|
|
|
|
|
Color.NAMES = _colorKeywords;
|
|
|
+Color.prototype.isColor = true;
|
|
|
+Color.prototype.r = 1;
|
|
|
+Color.prototype.g = 1;
|
|
|
+Color.prototype.b = 1;
|
|
|
|
|
|
export { Color };
|