Browse Source

Merge branch 'dev' of https://github.com/mrdoob/three.js into dev

Mr.doob 10 years ago
parent
commit
da96f43de5
4 changed files with 103 additions and 46 deletions
  1. 7 5
      docs/api/math/Color.html
  2. 5 7
      docs/api/renderers/WebGLRenderer.html
  3. 84 27
      src/math/Color.js
  4. 7 7
      utils/codestyle/config.json

+ 7 - 5
docs/api/math/Color.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html lang="en">
 	<head>
-		<meta charset="utf-8" />
+		<meta charset="utf-8" />
 		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
@@ -18,7 +18,9 @@
 		<h2>Example</h2>
 		<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("rgb(255, 0, 0)");</code>
+		<code>var color = new THREE.Color("rgb(100%, 0%, 0%)");</code>
+		<code>var color = new THREE.Color("hsl(0, 100%, 50%)");</code>
 		<code>var color = new THREE.Color( 1, 0, 0 );</code>
 
 
@@ -27,7 +29,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", or three arguments that represent color channels.
+		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%)", "hsl(0, 100%, 50%)", "#ff0000", "#f00", or "red", or three arguments that represent color channels.
 		</div>
 
 		<h2>Properties</h2>
@@ -113,10 +115,10 @@
 
 		<h3>[method:Color setStyle]( [page:String style] ) [page:Color this]</h3>
 		<div>
-		style — color as a CSS-style string, for example, "rgb(250, 0,0)", "rgb(100%,0%,0%)", "#ff0000", "#f00", or "red"
+		style — color as a CSS-style string.
 		</div>
 		<div>
-		Sets this color	from a CSS-style string.
+		Sets this color from a CSS-style string. For example, "rgb(250, 0,0)", "rgb(100%, 0%, 0%)", "hsl(0, 100%, 50%)", "#ff0000", "#f00", or "red". Transluent colors such as "rgba(255, 0, 0, 0.5)" and "hsla(0, 100%, 50%, 0.5)" are also accepted, but the alpha-channel coordinate will be discarded.
 		</div>
 
 		<h3>[method:String getStyle]()</h3>

+ 5 - 7
docs/api/renderers/WebGLRenderer.html

@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html lang="en">
 	<head>
-		<meta charset="utf-8" />
+		<meta charset="utf-8" />
 		<base href="../../" />
 		<script src="list.js"></script>
 		<script src="page.js"></script>
@@ -23,13 +23,15 @@
 
 		<div>
 		canvas — A [page:Canvas] where the renderer draws its output.<br />
-		precision — shader precision. Can be *"highp"*, *"mediump"* or *"lowp"*.<br />
+		context — The [page:RenderingContext] context to use.<br />
+		precision — Shader precision. Can be *"highp"*, *"mediump"* or *"lowp"*. Defaults to *"highp"* if supported by the device.<br />
 		alpha — [page:Boolean], default is *false*.<br />
 		premultipliedAlpha — [page:Boolean], default is *true*.<br />
 		antialias — [page:Boolean], default is *false*.<br />
 		stencil — [page:Boolean], default is *true*.<br />
 		preserveDrawingBuffer — [page:Boolean], default is *false*.<br />
-		maxLights — [page:Integer], default is *4*.<br />
+		depth — [page:Boolean], default is *true*.<br />
+		logarithmicDepthBuffer — [page:Boolean], default is *false*.<br />
 		</div>
 
 		<h2>Properties</h2>
@@ -70,10 +72,6 @@
 		<div>Note: Sorting is used to attempt to properly render objects that have some degree of transparency.  By definition, sorting objects may not work in all cases.  Depending on the needs of application, it may be neccessary to turn off sorting and use other methods to deal with transparency rendering e.g. manually determining the object rendering order.</div>
 
 
-		<h3>[property:Boolean autoUpdateObjects]</h3>
-
-		<div>Defines whether the renderer should auto update objects. Default is true.</div>
-
 		<h3>[property:Boolean gammaInput]</h3>
 
 		<div>Default is false. If set, then it expects that all textures and colors are premultiplied gamma.</div>

+ 84 - 27
src/math/Color.js

@@ -105,11 +105,27 @@ THREE.Color.prototype = {
 
 	setStyle: function ( style ) {
 
+		var parseAlpha = function ( strAlpha ) {
+
+			var alpha = parseFloat( strAlpha );
+
+			if ( alpha < 1 ) {
+
+				console.warn( 'THREE.Color: Alpha component of color ' + style + ' will be ignored.' );
+
+			}
+
+			return alpha;
+
+		}
+
+
 		var m;
 
-		// rgb / hsl
 		if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
 
+			// rgb / hsl
+
 			var color;
 			var name = m[ 1 ];
 			var components = m[ 2 ];
@@ -117,9 +133,8 @@ THREE.Color.prototype = {
 			switch ( name ) {
 
 				case 'rgb':
-				case 'rgba':
 
-					if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec( components ) ) {
+					if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*$/.exec( components ) ) {
 
 						// rgb(255,0,0)
 						this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
@@ -130,7 +145,7 @@ THREE.Color.prototype = {
 
 					}
 
-					if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%/.exec( components ) ) {
+					if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
 
 						// rgb(100%,0%,0%)
 						this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
@@ -143,13 +158,40 @@ THREE.Color.prototype = {
 
 					break;
 
+				case 'rgba':
+
+					if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
+
+						// rgba(255,0,0,0.5)
+						this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
+						this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
+						this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
+						parseAlpha( color[ 4 ] );
+
+						return this;
+
+					}
+
+					if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
+
+						// rgba(100%,0%,0%,0.5)
+						this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
+						this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
+						this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
+						parseAlpha( color[ 4 ] );
+
+						return this;
+
+					}
+
+					break;
+
 				case 'hsl':
-				case 'hsla':
 
-					if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%/.exec( components ) ) {
+					if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
 
 						// hsl(120,50%,50%)
-						var h = parseFloat( color[ 1 ], 10 );
+						var h = parseFloat( color[ 1 ] );
 						var s = parseInt( color[ 2 ], 10 ) / 100;
 						var l = parseInt( color[ 3 ], 10 ) / 100;
 
@@ -159,33 +201,43 @@ THREE.Color.prototype = {
 
 					break;
 
-			}
+				case 'hsla':
 
-			// unknown color
-			return this;
+					if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
 
-		}
+						// hsla(120,50%,50%,0.5)
+						var h = parseFloat( color[ 1 ] );
+						var s = parseInt( color[ 2 ], 10 ) / 100;
+						var l = parseInt( color[ 3 ], 10 ) / 100;
+						parseAlpha( color[ 4 ] );
+
+						return this.setHSL( h, s, l );
+
+					}
+
+					break;
+
+			}
+
+		} else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
 
-		// hex
-		if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
+			// hex color
 
 			var hex = m[ 1 ];
 			var size = hex.length;
 
 			if ( size === 3 ) {
 
-				// # ff0
+				// #ff0
 				this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
 				this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
 				this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
 
 				return this;
 
-			}
-
-			if ( size === 6 ) {
+			} else if ( size === 6 ) {
 
-				// #fa11ac
+				// #ff0000
 				this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
 				this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
 				this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
@@ -194,22 +246,27 @@ THREE.Color.prototype = {
 
 			}
 
-			// unknown color
-			return this;
-
 		}
 
-		// color keywords
-		if ( /^\w+$/i.test( style ) ) {
+		if ( style && style.length > 0 ) {
 
-			// red
-			this.setHex( THREE.ColorKeywords[ style ] );
+			// color keywords
+			var hex = THREE.ColorKeywords[ style ];
 
-			return this;
+			if ( hex !== undefined ) {
+
+				// red
+				this.setHex( hex );
+
+			} else {
+
+				// unknown color
+				console.warn( 'THREE.Color: Unknown color ' + style );
+
+			}
 
 		}
 
-		// unknown color
 		return this;
 
 	},

+ 7 - 7
utils/codestyle/config.json

@@ -1,13 +1,14 @@
 {
     "preset": "mdcs",
+    "disallowSpaceAfterPrefixUnaryOperators": ["+", "-"],
     "disallowNewlineBeforeBlockStatements": true,
     "requireSpaceAfterBinaryOperators": [","],
     "disallowKeywordsOnNewLine": ["else"],
-    "excludeFiles": [ 
-        "../../.c9/", 
-        "../../.c9version/", 
-        "../../.git/", 
-        "../../build/", 
+    "excludeFiles": [
+        "../../.c9/",
+        "../../.c9version/",
+        "../../.git/",
+        "../../build/",
         "../../docs/",
         "../../editor/",
         "../../node_modules/",
@@ -28,5 +29,4 @@
         "../../examples/js/SimplexNoise.js",
         "../../examples/js/loaders/UTF8Loader.js"
         ]
-    
-}
+}