提交 da96f43d 编写于 作者: M Mr.doob

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

...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
<h2>Example</h2> <h2>Example</h2>
<code>var color = new THREE.Color();</code> <code>var color = new THREE.Color();</code>
<code>var color = new THREE.Color( 0xff0000 );</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> <code>var color = new THREE.Color( 1, 0, 0 );</code>
...@@ -27,7 +29,7 @@ ...@@ -27,7 +29,7 @@
<h3>[name]( value )</h3> <h3>[name]( value )</h3>
<div> <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> </div>
<h2>Properties</h2> <h2>Properties</h2>
...@@ -113,10 +115,10 @@ ...@@ -113,10 +115,10 @@
<h3>[method:Color setStyle]( [page:String style] ) [page:Color this]</h3> <h3>[method:Color setStyle]( [page:String style] ) [page:Color this]</h3>
<div> <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>
<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> </div>
<h3>[method:String getStyle]()</h3> <h3>[method:String getStyle]()</h3>
......
...@@ -23,13 +23,15 @@ ...@@ -23,13 +23,15 @@
<div> <div>
canvas — A [page:Canvas] where the renderer draws its output.<br /> 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 /> alpha — [page:Boolean], default is *false*.<br />
premultipliedAlpha — [page:Boolean], default is *true*.<br /> premultipliedAlpha — [page:Boolean], default is *true*.<br />
antialias — [page:Boolean], default is *false*.<br /> antialias — [page:Boolean], default is *false*.<br />
stencil — [page:Boolean], default is *true*.<br /> stencil — [page:Boolean], default is *true*.<br />
preserveDrawingBuffer — [page:Boolean], default is *false*.<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> </div>
<h2>Properties</h2> <h2>Properties</h2>
...@@ -70,10 +72,6 @@ ...@@ -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> <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> <h3>[property:Boolean gammaInput]</h3>
<div>Default is false. If set, then it expects that all textures and colors are premultiplied gamma.</div> <div>Default is false. If set, then it expects that all textures and colors are premultiplied gamma.</div>
......
...@@ -105,11 +105,27 @@ THREE.Color.prototype = { ...@@ -105,11 +105,27 @@ THREE.Color.prototype = {
setStyle: function ( style ) { 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; var m;
// rgb / hsl
if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) { if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
// rgb / hsl
var color; var color;
var name = m[ 1 ]; var name = m[ 1 ];
var components = m[ 2 ]; var components = m[ 2 ];
...@@ -117,9 +133,8 @@ THREE.Color.prototype = { ...@@ -117,9 +133,8 @@ THREE.Color.prototype = {
switch ( name ) { switch ( name ) {
case 'rgb': 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) // rgb(255,0,0)
this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255; this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
...@@ -130,7 +145,7 @@ THREE.Color.prototype = { ...@@ -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%) // rgb(100%,0%,0%)
this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100; this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
...@@ -143,13 +158,40 @@ THREE.Color.prototype = { ...@@ -143,13 +158,40 @@ THREE.Color.prototype = {
break; 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 '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%) // hsl(120,50%,50%)
var h = parseFloat( color[ 1 ], 10 ); var h = parseFloat( color[ 1 ] );
var s = parseInt( color[ 2 ], 10 ) / 100; var s = parseInt( color[ 2 ], 10 ) / 100;
var l = parseInt( color[ 3 ], 10 ) / 100; var l = parseInt( color[ 3 ], 10 ) / 100;
...@@ -159,33 +201,43 @@ THREE.Color.prototype = { ...@@ -159,33 +201,43 @@ THREE.Color.prototype = {
break; break;
case 'hsla':
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 );
} }
// unknown color break;
return this;
} }
// hex } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
// hex color
var hex = m[ 1 ]; var hex = m[ 1 ];
var size = hex.length; var size = hex.length;
if ( size === 3 ) { if ( size === 3 ) {
// # ff0 // #ff0
this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255; this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255; this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255; this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
return this; return this;
} } else if ( size === 6 ) {
if ( size === 6 ) {
// #fa11ac // #ff0000
this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255; this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255; this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255; this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
...@@ -194,22 +246,27 @@ THREE.Color.prototype = { ...@@ -194,22 +246,27 @@ THREE.Color.prototype = {
} }
// unknown color
return this;
} }
if ( style && style.length > 0 ) {
// color keywords // color keywords
if ( /^\w+$/i.test( style ) ) { var hex = THREE.ColorKeywords[ style ];
if ( hex !== undefined ) {
// red // red
this.setHex( THREE.ColorKeywords[ style ] ); this.setHex( hex );
return this; } else {
// unknown color
console.warn( 'THREE.Color: Unknown color ' + style );
}
} }
// unknown color
return this; return this;
}, },
......
{ {
"preset": "mdcs", "preset": "mdcs",
"disallowSpaceAfterPrefixUnaryOperators": ["+", "-"],
"disallowNewlineBeforeBlockStatements": true, "disallowNewlineBeforeBlockStatements": true,
"requireSpaceAfterBinaryOperators": [","], "requireSpaceAfterBinaryOperators": [","],
"disallowKeywordsOnNewLine": ["else"], "disallowKeywordsOnNewLine": ["else"],
...@@ -28,5 +29,4 @@ ...@@ -28,5 +29,4 @@
"../../examples/js/SimplexNoise.js", "../../examples/js/SimplexNoise.js",
"../../examples/js/loaders/UTF8Loader.js" "../../examples/js/loaders/UTF8Loader.js"
] ]
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册