Parcourir la source

THREE.Color support for '#ff0000' and '#f00'.

Mr.doob il y a 12 ans
Parent
commit
62bb18f918
1 fichiers modifiés avec 25 ajouts et 5 suppressions
  1. 25 5
      src/core/Color.js

+ 25 - 5
src/core/Color.js

@@ -4,11 +4,7 @@
 
 THREE.Color = function ( value ) {
 
-	if ( value !== undefined ) {
-
-		this.set( value );
-
-	}
+	if ( value !== undefined ) this.set( value );
 
 	return this;
 
@@ -221,6 +217,30 @@ THREE.Color.prototype = {
 
 		}
 
+		// #ff0000
+
+		if ( /^\#([0-9a-f]{6})$/i.test( style ) ) {
+
+			var color = /^\#([0-9a-f]{6})$/i.exec( style );
+
+			this.setHex( parseInt( color[ 1 ], 16 ) );
+
+			return this;
+
+		}
+
+		// #f00
+
+		if ( /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.test( style ) ) {
+
+			var color = /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec( style );
+
+			this.setHex( parseInt( color[ 1 ] + color[ 1 ] + color[ 2 ] + color[ 2 ] + color[ 3 ] + color[ 3 ], 16 ) );
+
+			return this;
+
+		}
+
 		// red
 
 		if ( /^(\w+)$/i.test( style ) ) {