Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
bb640b1c
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
bb640b1c
编写于
10月 01, 2019
作者:
M
Michael Herzog
提交者:
GitHub
10月 01, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14784 from pauloddr/patch-color-improvements
Color: add .setColorName() and Color.NAMES
上级
9b36c7a5
0cc77571
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
62 addition
and
20 deletion
+62
-20
docs/api/en/math/Color.html
docs/api/en/math/Color.html
+10
-1
src/math/Color.d.ts
src/math/Color.d.ts
+12
-0
src/math/Color.js
src/math/Color.js
+18
-9
test/unit/src/math/Color.tests.js
test/unit/src/math/Color.tests.js
+22
-10
未找到文件。
docs/api/en/math/Color.html
浏览文件 @
bb640b1c
...
...
@@ -126,7 +126,7 @@ var color = new THREE.Color( 1, 0, 0 );
[page:Float gammaFactor] - (optional). Default is *2.0*.
<br
/><br
/>
Converts this color from gamma space to linear space by taking [page:.r r], [page:.g g] and [page:.b b] to the power of [page:Float gammaFactor].
</p>
<h3>
[method:Color convertLinearToGamma]( [param:Float gammaFactor] )
</h3>
<p>
[page:Float gammaFactor] - (optional). Default is *2.0*.
<br
/><br
/>
...
...
@@ -302,6 +302,15 @@ var color = new THREE.Color( 1, 0, 0 );
Note that for X11 color names, multiple words such as Dark Orange become the string 'darkorange' (all lowercase).
</p>
<h3>
[method:Color setColorName]( [param:String style] )
</h3>
<p>
[page:String style] — color name ( from [link:https://en.wikipedia.org/wiki/X11_color_names#Color_name_chart X11 color names] ).
<br
/><br
/>
Sets this color from a color name. Faster than [page:.setStyle] method if you don't need the other CSS-style formats.
<br/><br/>
For convenience, the list of names is exposed in Color.NAMES as a hash:
<code>
Color.NAMES.aliceblue // returns 0xF0F8FF
</code>
</p>
<h3>
[method:Color sub]( [param:Color color] )
</h3>
<p>
Subtracts the RGB components of the given color from the RGB components of this color.
...
...
src/math/Color.d.ts
浏览文件 @
bb640b1c
...
...
@@ -68,6 +68,13 @@ export class Color {
*/
setStyle
(
style
:
string
):
Color
;
/**
* Sets this color from a color name.
* Faster than {@link Color#setStyle .setStyle()} method if you don't need the other CSS-style formats.
* @param style Color name in X11 format.
*/
setColorName
(
style
:
string
):
Color
;
/**
* Clones this color.
*/
...
...
@@ -183,4 +190,9 @@ export class Color {
*/
toArray
(
xyz
:
ArrayLike
<
number
>
,
offset
?:
number
):
ArrayLike
<
number
>
;
/**
* List of X11 color names.
*/
static
NAMES
:
Record
<
string
,
number
>
;
}
src/math/Color.js
浏览文件 @
bb640b1c
...
...
@@ -261,20 +261,28 @@ Object.assign( Color.prototype, {
if
(
style
&&
style
.
length
>
0
)
{
// color keywords
var
hex
=
_colorKeywords
[
style
];
return
this
.
setColorName
(
style
);
if
(
hex
!==
undefined
)
{
}
// red
this
.
setHex
(
hex
);
return
this
;
}
else
{
},
// unknown color
console
.
warn
(
'
THREE.Color: Unknown color
'
+
style
);
setColorName
:
function
(
style
)
{
}
// color keywords
var
hex
=
_colorKeywords
[
style
];
if
(
hex
!==
undefined
)
{
// red
this
.
setHex
(
hex
);
}
else
{
// unknown color
console
.
warn
(
'
THREE.Color: Unknown color
'
+
style
);
}
...
...
@@ -580,5 +588,6 @@ Object.assign( Color.prototype, {
}
);
Color
.
NAMES
=
_colorKeywords
;
export
{
Color
};
test/unit/src/math/Color.tests.js
浏览文件 @
bb640b1c
...
...
@@ -28,6 +28,13 @@ export default QUnit.module( 'Maths', () => {
}
);
// EXPOSED CONSTANTS
QUnit
.
test
(
"
Color.NAMES
"
,
(
assert
)
=>
{
assert
.
ok
(
Color
.
NAMES
.
aliceblue
==
0xF0F8FF
,
"
Exposed Color.NAMES
"
);
}
);
// PUBLIC STUFF
QUnit
.
test
(
"
isColor
"
,
(
assert
)
=>
{
...
...
@@ -137,6 +144,21 @@ export default QUnit.module( 'Maths', () => {
assert
.
ok
(
a
.
g
==
0xAB
/
255
,
"
Green:
"
+
a
.
g
);
assert
.
ok
(
a
.
b
==
0xC1
/
255
,
"
Blue:
"
+
a
.
b
);
a
.
setStyle
(
"
aliceblue
"
);
assert
.
ok
(
a
.
r
==
0xF0
/
255
,
"
Red:
"
+
a
.
r
);
assert
.
ok
(
a
.
g
==
0xF8
/
255
,
"
Green:
"
+
a
.
g
);
assert
.
ok
(
a
.
b
==
0xFF
/
255
,
"
Blue:
"
+
a
.
b
);
}
);
QUnit
.
test
(
"
setColorName
"
,
(
assert
)
=>
{
var
c
=
new
Color
();
var
res
=
c
.
setColorName
(
"
aliceblue
"
);
assert
.
ok
(
c
.
getHex
()
==
0xF0F8FF
,
"
Hex:
"
+
c
.
getHex
()
);
assert
.
ok
(
c
==
res
,
"
Returns Self
"
);
}
);
QUnit
.
test
(
"
clone
"
,
(
assert
)
=>
{
...
...
@@ -343,16 +365,6 @@ export default QUnit.module( 'Maths', () => {
}
);
QUnit
.
test
(
"
setRGB
"
,
(
assert
)
=>
{
var
c
=
new
Color
();
c
.
setRGB
(
1
,
0.2
,
0.1
);
assert
.
ok
(
c
.
r
==
1
,
"
Red:
"
+
c
.
r
);
assert
.
ok
(
c
.
g
==
0.2
,
"
Green:
"
+
c
.
g
);
assert
.
ok
(
c
.
b
==
0.1
,
"
Blue:
"
+
c
.
b
);
}
);
QUnit
.
test
(
"
lerp
"
,
(
assert
)
=>
{
var
c
=
new
Color
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录