Forráskód Böngészése

Adding additional color constructor: Color( r, g, b )

Essentially a shorthand for new THREE.Color().setRGB( r, g, b );
Andrew Ray 11 éve
szülő
commit
98be2a8fe4
3 módosított fájl, 16 hozzáadás és 4 törlés
  1. 2 1
      docs/api/math/Color.html
  2. 7 3
      src/math/Color.js
  3. 7 0
      test/unit/math/Color.js

+ 2 - 1
docs/api/math/Color.html

@@ -18,6 +18,7 @@
 		<code>var color = new THREE.Color();</code>
 		<code>var color = new THREE.Color( 0xff0000 );</code>
 		<code>var color = new THREE.Color("rgb(255,0,0)");</code>
+		<code>var color = new THREE.Color( 1, 0, 0 );</code>
 
 
 		<h2>Constructor</h2>
@@ -25,7 +26,7 @@
 
 		<h3>[name]( value )</h3>
 		<div>
-		value — optional argument that sets initial color.  Can be a hexadecimal or a CSS-style string, for example, "rgb(250, 0,0)", "rgb(100%,0%,0%)", "#ff0000", "#f00", or "red"
+		value — optional argument that sets initial color.  Can be a hexadecimal or a CSS-style string, for example, "rgb(250, 0,0)", "rgb(100%,0%,0%)", "#ff0000", "#f00", or "red", or three arguments that represent color channels.
 		</div>
 
 		<h2>Properties</h2>

+ 7 - 3
src/math/Color.js

@@ -2,9 +2,9 @@
  * @author mrdoob / http://mrdoob.com/
  */
 
-THREE.Color = function ( value ) {
+THREE.Color = function () {
 
-	if ( value !== undefined ) this.set( value );
+	if ( arguments.length ) this.set( arguments.length === 1 ? arguments[0] : arguments );
 
 	return this;
 
@@ -30,7 +30,11 @@ THREE.Color.prototype = {
 
 			this.setStyle( value );
 
-		}
+		} else if ( value.length ) {
+
+            this.setRGB.apply( this, value );
+
+        }
 
 		return this;
 

+ 7 - 0
test/unit/math/Color.js

@@ -7,6 +7,13 @@ test( "constructor", function(){
     ok( c.b, "Blue: " + c.g );
 });
 
+test( "rgb constructor", function(){
+    var c = new THREE.Color( 1, 1, 1 );
+    ok( c.r == 1, "Passed" );
+    ok( c.g == 1, "Passed" );
+    ok( c.b == 1, "Passed" );
+});
+
 test( "copyHex", function(){
     var c = new THREE.Color();
     var c2 = new THREE.Color(0xF5FFFA);