Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
b6070a0c
T
three.js
项目概览
Ablesons
/
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,发现更多精彩内容 >>
提交
b6070a0c
编写于
10月 14, 2015
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ImageUtils: Moved getNormalMap() and generateDataTexture() to examples.
上级
15da3dde
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
136 addition
and
127 deletion
+136
-127
examples/js/utils/ImageUtils.js
examples/js/utils/ImageUtils.js
+136
-0
src/extras/ImageUtils.js
src/extras/ImageUtils.js
+0
-127
未找到文件。
examples/js/utils/ImageUtils.js
0 → 100644
浏览文件 @
b6070a0c
/**
* @author alteredq / http://alteredqualia.com/
* @author mrdoob / http://mrdoob.com/
* @author Daosheng Mu / https://github.com/DaoshengMu/
*/
THREE
.
ImageUtils
=
{
getNormalMap
:
function
(
image
,
depth
)
{
// Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
function
cross
(
a
,
b
)
{
return
[
a
[
1
]
*
b
[
2
]
-
a
[
2
]
*
b
[
1
],
a
[
2
]
*
b
[
0
]
-
a
[
0
]
*
b
[
2
],
a
[
0
]
*
b
[
1
]
-
a
[
1
]
*
b
[
0
]
];
}
function
subtract
(
a
,
b
)
{
return
[
a
[
0
]
-
b
[
0
],
a
[
1
]
-
b
[
1
],
a
[
2
]
-
b
[
2
]
];
}
function
normalize
(
a
)
{
var
l
=
Math
.
sqrt
(
a
[
0
]
*
a
[
0
]
+
a
[
1
]
*
a
[
1
]
+
a
[
2
]
*
a
[
2
]
);
return
[
a
[
0
]
/
l
,
a
[
1
]
/
l
,
a
[
2
]
/
l
];
}
depth
=
depth
|
1
;
var
width
=
image
.
width
;
var
height
=
image
.
height
;
var
canvas
=
document
.
createElement
(
'
canvas
'
);
canvas
.
width
=
width
;
canvas
.
height
=
height
;
var
context
=
canvas
.
getContext
(
'
2d
'
);
context
.
drawImage
(
image
,
0
,
0
);
var
data
=
context
.
getImageData
(
0
,
0
,
width
,
height
).
data
;
var
imageData
=
context
.
createImageData
(
width
,
height
);
var
output
=
imageData
.
data
;
for
(
var
x
=
0
;
x
<
width
;
x
++
)
{
for
(
var
y
=
0
;
y
<
height
;
y
++
)
{
var
ly
=
y
-
1
<
0
?
0
:
y
-
1
;
var
uy
=
y
+
1
>
height
-
1
?
height
-
1
:
y
+
1
;
var
lx
=
x
-
1
<
0
?
0
:
x
-
1
;
var
ux
=
x
+
1
>
width
-
1
?
width
-
1
:
x
+
1
;
var
points
=
[];
var
origin
=
[
0
,
0
,
data
[
(
y
*
width
+
x
)
*
4
]
/
255
*
depth
];
points
.
push
(
[
-
1
,
0
,
data
[
(
y
*
width
+
lx
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
-
1
,
-
1
,
data
[
(
ly
*
width
+
lx
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
0
,
-
1
,
data
[
(
ly
*
width
+
x
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
1
,
-
1
,
data
[
(
ly
*
width
+
ux
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
1
,
0
,
data
[
(
y
*
width
+
ux
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
1
,
1
,
data
[
(
uy
*
width
+
ux
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
0
,
1
,
data
[
(
uy
*
width
+
x
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
-
1
,
1
,
data
[
(
uy
*
width
+
lx
)
*
4
]
/
255
*
depth
]
);
var
normals
=
[];
var
num_points
=
points
.
length
;
for
(
var
i
=
0
;
i
<
num_points
;
i
++
)
{
var
v1
=
points
[
i
];
var
v2
=
points
[
(
i
+
1
)
%
num_points
];
v1
=
subtract
(
v1
,
origin
);
v2
=
subtract
(
v2
,
origin
);
normals
.
push
(
normalize
(
cross
(
v1
,
v2
)
)
);
}
var
normal
=
[
0
,
0
,
0
];
for
(
var
i
=
0
;
i
<
normals
.
length
;
i
++
)
{
normal
[
0
]
+=
normals
[
i
][
0
];
normal
[
1
]
+=
normals
[
i
][
1
];
normal
[
2
]
+=
normals
[
i
][
2
];
}
normal
[
0
]
/=
normals
.
length
;
normal
[
1
]
/=
normals
.
length
;
normal
[
2
]
/=
normals
.
length
;
var
idx
=
(
y
*
width
+
x
)
*
4
;
output
[
idx
]
=
(
(
normal
[
0
]
+
1.0
)
/
2.0
*
255
)
|
0
;
output
[
idx
+
1
]
=
(
(
normal
[
1
]
+
1.0
)
/
2.0
*
255
)
|
0
;
output
[
idx
+
2
]
=
(
normal
[
2
]
*
255
)
|
0
;
output
[
idx
+
3
]
=
255
;
}
}
context
.
putImageData
(
imageData
,
0
,
0
);
return
canvas
;
},
generateDataTexture
:
function
(
width
,
height
,
color
)
{
var
size
=
width
*
height
;
var
data
=
new
Uint8Array
(
3
*
size
);
var
r
=
Math
.
floor
(
color
.
r
*
255
);
var
g
=
Math
.
floor
(
color
.
g
*
255
);
var
b
=
Math
.
floor
(
color
.
b
*
255
);
for
(
var
i
=
0
;
i
<
size
;
i
++
)
{
data
[
i
*
3
]
=
r
;
data
[
i
*
3
+
1
]
=
g
;
data
[
i
*
3
+
2
]
=
b
;
}
var
texture
=
new
THREE
.
DataTexture
(
data
,
width
,
height
,
THREE
.
RGBFormat
);
texture
.
needsUpdate
=
true
;
return
texture
;
}
};
src/extras/ImageUtils.js
浏览文件 @
b6070a0c
...
...
@@ -46,133 +46,6 @@ THREE.ImageUtils = {
console
.
error
(
'
THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.
'
)
},
getNormalMap
:
function
(
image
,
depth
)
{
// Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
function
cross
(
a
,
b
)
{
return
[
a
[
1
]
*
b
[
2
]
-
a
[
2
]
*
b
[
1
],
a
[
2
]
*
b
[
0
]
-
a
[
0
]
*
b
[
2
],
a
[
0
]
*
b
[
1
]
-
a
[
1
]
*
b
[
0
]
];
}
function
subtract
(
a
,
b
)
{
return
[
a
[
0
]
-
b
[
0
],
a
[
1
]
-
b
[
1
],
a
[
2
]
-
b
[
2
]
];
}
function
normalize
(
a
)
{
var
l
=
Math
.
sqrt
(
a
[
0
]
*
a
[
0
]
+
a
[
1
]
*
a
[
1
]
+
a
[
2
]
*
a
[
2
]
);
return
[
a
[
0
]
/
l
,
a
[
1
]
/
l
,
a
[
2
]
/
l
];
}
depth
=
depth
|
1
;
var
width
=
image
.
width
;
var
height
=
image
.
height
;
var
canvas
=
document
.
createElement
(
'
canvas
'
);
canvas
.
width
=
width
;
canvas
.
height
=
height
;
var
context
=
canvas
.
getContext
(
'
2d
'
);
context
.
drawImage
(
image
,
0
,
0
);
var
data
=
context
.
getImageData
(
0
,
0
,
width
,
height
).
data
;
var
imageData
=
context
.
createImageData
(
width
,
height
);
var
output
=
imageData
.
data
;
for
(
var
x
=
0
;
x
<
width
;
x
++
)
{
for
(
var
y
=
0
;
y
<
height
;
y
++
)
{
var
ly
=
y
-
1
<
0
?
0
:
y
-
1
;
var
uy
=
y
+
1
>
height
-
1
?
height
-
1
:
y
+
1
;
var
lx
=
x
-
1
<
0
?
0
:
x
-
1
;
var
ux
=
x
+
1
>
width
-
1
?
width
-
1
:
x
+
1
;
var
points
=
[];
var
origin
=
[
0
,
0
,
data
[
(
y
*
width
+
x
)
*
4
]
/
255
*
depth
];
points
.
push
(
[
-
1
,
0
,
data
[
(
y
*
width
+
lx
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
-
1
,
-
1
,
data
[
(
ly
*
width
+
lx
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
0
,
-
1
,
data
[
(
ly
*
width
+
x
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
1
,
-
1
,
data
[
(
ly
*
width
+
ux
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
1
,
0
,
data
[
(
y
*
width
+
ux
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
1
,
1
,
data
[
(
uy
*
width
+
ux
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
0
,
1
,
data
[
(
uy
*
width
+
x
)
*
4
]
/
255
*
depth
]
);
points
.
push
(
[
-
1
,
1
,
data
[
(
uy
*
width
+
lx
)
*
4
]
/
255
*
depth
]
);
var
normals
=
[];
var
num_points
=
points
.
length
;
for
(
var
i
=
0
;
i
<
num_points
;
i
++
)
{
var
v1
=
points
[
i
];
var
v2
=
points
[
(
i
+
1
)
%
num_points
];
v1
=
subtract
(
v1
,
origin
);
v2
=
subtract
(
v2
,
origin
);
normals
.
push
(
normalize
(
cross
(
v1
,
v2
)
)
);
}
var
normal
=
[
0
,
0
,
0
];
for
(
var
i
=
0
;
i
<
normals
.
length
;
i
++
)
{
normal
[
0
]
+=
normals
[
i
][
0
];
normal
[
1
]
+=
normals
[
i
][
1
];
normal
[
2
]
+=
normals
[
i
][
2
];
}
normal
[
0
]
/=
normals
.
length
;
normal
[
1
]
/=
normals
.
length
;
normal
[
2
]
/=
normals
.
length
;
var
idx
=
(
y
*
width
+
x
)
*
4
;
output
[
idx
]
=
(
(
normal
[
0
]
+
1.0
)
/
2.0
*
255
)
|
0
;
output
[
idx
+
1
]
=
(
(
normal
[
1
]
+
1.0
)
/
2.0
*
255
)
|
0
;
output
[
idx
+
2
]
=
(
normal
[
2
]
*
255
)
|
0
;
output
[
idx
+
3
]
=
255
;
}
}
context
.
putImageData
(
imageData
,
0
,
0
);
return
canvas
;
},
generateDataTexture
:
function
(
width
,
height
,
color
)
{
var
size
=
width
*
height
;
var
data
=
new
Uint8Array
(
3
*
size
);
var
r
=
Math
.
floor
(
color
.
r
*
255
);
var
g
=
Math
.
floor
(
color
.
g
*
255
);
var
b
=
Math
.
floor
(
color
.
b
*
255
);
for
(
var
i
=
0
;
i
<
size
;
i
++
)
{
data
[
i
*
3
]
=
r
;
data
[
i
*
3
+
1
]
=
g
;
data
[
i
*
3
+
2
]
=
b
;
}
var
texture
=
new
THREE
.
DataTexture
(
data
,
width
,
height
,
THREE
.
RGBFormat
);
texture
.
needsUpdate
=
true
;
return
texture
;
}
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录