@@ -105,18 +105,16 @@ THREE.Color.prototype = {
105
105
106
106
setStyle : function ( style ) {
107
107
108
- function parseAlpha ( strAlpha ) {
108
+ function handleAlpha ( string ) {
109
109
110
- var alpha = parseFloat ( strAlpha ) ;
110
+ if ( string === undefined ) return ;
111
111
112
- if ( alpha < 1 ) {
112
+ if ( parseFloat ( string ) < 1 ) {
113
113
114
- console . warn ( 'THREE.Color: Alpha component of color ' + style + ' will be ignored.' ) ;
114
+ console . warn ( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' ) ;
115
115
116
116
}
117
117
118
- return alpha ;
119
-
120
118
}
121
119
122
120
@@ -133,52 +131,29 @@ THREE.Color.prototype = {
133
131
switch ( name ) {
134
132
135
133
case 'rgb' :
136
-
137
- if ( color = / ^ ( \d + ) \s * , \s * ( \d + ) \s * , \s * ( \d + ) \s * $ / . exec ( components ) ) {
138
-
139
- // rgb(255,0,0)
140
- this . r = Math . min ( 255 , parseInt ( color [ 1 ] , 10 ) ) / 255 ;
141
- this . g = Math . min ( 255 , parseInt ( color [ 2 ] , 10 ) ) / 255 ;
142
- this . b = Math . min ( 255 , parseInt ( color [ 3 ] , 10 ) ) / 255 ;
143
-
144
- return this ;
145
-
146
- }
147
-
148
- if ( color = / ^ ( \d + ) \% \s * , \s * ( \d + ) \% \s * , \s * ( \d + ) \% \s * $ / . exec ( components ) ) {
149
-
150
- // rgb(100%,0%,0%)
151
- this . r = Math . min ( 100 , parseInt ( color [ 1 ] , 10 ) ) / 100 ;
152
- this . g = Math . min ( 100 , parseInt ( color [ 2 ] , 10 ) ) / 100 ;
153
- this . b = Math . min ( 100 , parseInt ( color [ 3 ] , 10 ) ) / 100 ;
154
-
155
- return this ;
156
-
157
- }
158
-
159
- break ;
160
-
161
134
case 'rgba' :
162
135
163
- if ( color = / ^ ( \d + ) \s * , \s * ( \d + ) \s * , \s * ( \d + ) \s * , \s * ( [ 0 - 9 ] * \. ? [ 0 - 9 ] + ) \s * $ / . exec ( components ) ) {
136
+ if ( color = / ^ ( \d + ) \s * , \s * ( \d + ) \s * , \s * ( \d + ) \s * ( , \s * ( [ 0 - 9 ] * \. ? [ 0 - 9 ] + ) \s * ) ? $ / . exec ( components ) ) {
164
137
165
- // rgba(255,0,0,0.5)
138
+ // rgb(255,0,0) rgba(255,0,0,0.5)
166
139
this . r = Math . min ( 255 , parseInt ( color [ 1 ] , 10 ) ) / 255 ;
167
140
this . g = Math . min ( 255 , parseInt ( color [ 2 ] , 10 ) ) / 255 ;
168
141
this . b = Math . min ( 255 , parseInt ( color [ 3 ] , 10 ) ) / 255 ;
169
- parseAlpha ( color [ 4 ] ) ;
142
+
143
+ handleAlpha ( color [ 5 ] ) ;
170
144
171
145
return this ;
172
146
173
147
}
174
148
175
- if ( color = / ^ ( \d + ) \% \s * , \s * ( \d + ) \% \s * , \s * ( \d + ) \% \s * , \s * ( [ 0 - 9 ] * \. ? [ 0 - 9 ] + ) \s * $ / . exec ( components ) ) {
149
+ if ( color = / ^ ( \d + ) \% \s * , \s * ( \d + ) \% \s * , \s * ( \d + ) \% \s * ( , \s * ( [ 0 - 9 ] * \. ? [ 0 - 9 ] + ) \s * ) ? $ / . exec ( components ) ) {
176
150
177
- // rgba(100%,0%,0%,0.5)
151
+ // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
178
152
this . r = Math . min ( 100 , parseInt ( color [ 1 ] , 10 ) ) / 100 ;
179
153
this . g = Math . min ( 100 , parseInt ( color [ 2 ] , 10 ) ) / 100 ;
180
154
this . b = Math . min ( 100 , parseInt ( color [ 3 ] , 10 ) ) / 100 ;
181
- parseAlpha ( color [ 4 ] ) ;
155
+
156
+ handleAlpha ( color [ 5 ] ) ;
182
157
183
158
return this ;
184
159
@@ -187,29 +162,16 @@ THREE.Color.prototype = {
187
162
break ;
188
163
189
164
case 'hsl' :
190
-
191
- if ( color = / ^ ( [ 0 - 9 ] * \. ? [ 0 - 9 ] + ) \s * , \s * ( \d + ) \% \s * , \s * ( \d + ) \% \s * $ / . exec ( components ) ) {
192
-
193
- // hsl(120,50%,50%)
194
- var h = parseFloat ( color [ 1 ] ) / 360 ;
195
- var s = parseInt ( color [ 2 ] , 10 ) / 100 ;
196
- var l = parseInt ( color [ 3 ] , 10 ) / 100 ;
197
-
198
- return this . setHSL ( h , s , l ) ;
199
-
200
- }
201
-
202
- break ;
203
-
204
165
case 'hsla' :
205
166
206
- if ( color = / ^ ( [ 0 - 9 ] * \. ? [ 0 - 9 ] + ) \s * , \s * ( \d + ) \% \s * , \s * ( \d + ) \% \s * , \s * ( [ 0 - 9 ] * \. ? [ 0 - 9 ] + ) \s * $ / . exec ( components ) ) {
167
+ if ( color = / ^ ( [ 0 - 9 ] * \. ? [ 0 - 9 ] + ) \s * , \s * ( \d + ) \% \s * , \s * ( \d + ) \% \s * ( , \s * ( [ 0 - 9 ] * \. ? [ 0 - 9 ] + ) \s * ) ? $ / . exec ( components ) ) {
207
168
208
- // hsla(120,50%,50%,0.5)
169
+ // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
209
170
var h = parseFloat ( color [ 1 ] ) / 360 ;
210
171
var s = parseInt ( color [ 2 ] , 10 ) / 100 ;
211
172
var l = parseInt ( color [ 3 ] , 10 ) / 100 ;
212
- parseAlpha ( color [ 4 ] ) ;
173
+
174
+ handleAlpha ( color [ 5 ] ) ;
213
175
214
176
return this . setHSL ( h , s , l ) ;
215
177
0 commit comments