diff --git a/docs/api/en/math/Color.html b/docs/api/en/math/Color.html index b04a760f5856459677261a4e29b433536af4bd0a..57ec28c70b895eaac1a2d0ebc4116478666fafd8 100644 --- a/docs/api/en/math/Color.html +++ b/docs/api/en/math/Color.html @@ -302,7 +302,7 @@ var color = new THREE.Color( 1, 0, 0 ); Note that for X11 color names, multiple words such as Dark Orange become the string 'darkorange' (all lowercase).

-

[method:Color setStyleName]( [param:String style] )

+

[method:Color setColorName]( [param:String style] )

[page:String style] — color name ( from [link:https://en.wikipedia.org/wiki/X11_color_names#Color_name_chart X11 color names] ).

diff --git a/src/math/Color.d.ts b/src/math/Color.d.ts index 94b3a712ac7e174cae6f7f19abda5ecc45107fef..17fb3c895d521d084b07d32b927651f11aca0437 100644 --- a/src/math/Color.d.ts +++ b/src/math/Color.d.ts @@ -68,6 +68,13 @@ export class Color { */ setStyle( style: string ): Color; + /** + * Sets this color from a color name. + * Faster than {@link Color#setStyle .setStyle()} method if you don't need the other CSS-style formats. + * @param style Color name in X11 format. + */ + setColorName( style: string ): Color; + /** * Clones this color. */ @@ -183,4 +190,9 @@ export class Color { */ toArray( xyz: ArrayLike, offset?: number ): ArrayLike; + /** + * List of X11 color names. + */ + static NAMES: Record; + } diff --git a/src/math/Color.js b/src/math/Color.js index a7f9f2c3e5ecd2956cc5086a4c246736ad233a89..fe5eafb9828a3d06409dd7c0a1ba5976c9636646 100644 --- a/src/math/Color.js +++ b/src/math/Color.js @@ -261,7 +261,7 @@ Object.assign( Color.prototype, { if ( style && style.length > 0 ) { - return this.setStyleName( style ); + return this.setColorName( style ); } @@ -269,7 +269,7 @@ Object.assign( Color.prototype, { }, - setStyleName: function ( style ) { + setColorName: function ( style ) { // color keywords var hex = _colorKeywords[ style ]; diff --git a/test/unit/src/math/Color.tests.js b/test/unit/src/math/Color.tests.js index f54dd6638247633a8305298553ed7e9ef15f065a..5e0593895eb851e3837364cf4444e84b185364b7 100644 --- a/test/unit/src/math/Color.tests.js +++ b/test/unit/src/math/Color.tests.js @@ -144,12 +144,17 @@ export default QUnit.module( 'Maths', () => { assert.ok( a.g == 0xAB / 255, "Green: " + a.g ); assert.ok( a.b == 0xC1 / 255, "Blue: " + a.b ); + a.setStyle( "aliceblue" ); + assert.ok( a.r == 0xF0 / 255, "Red: " + a.r ); + assert.ok( a.g == 0xF8 / 255, "Green: " + a.g ); + assert.ok( a.b == 0xFF / 255, "Blue: " + a.b ); + } ); - QUnit.test( "setStyleName", ( assert ) => { + QUnit.test( "setColorName", ( assert ) => { var c = new Color(); - var res = c.setStyleName( "aliceblue" ); + var res = c.setColorName( "aliceblue" ); assert.ok( c.getHex() == 0xF0F8FF, "Hex: " + c.getHex() ); assert.ok( c == res, "Returns Self" );